summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2007-06-27 06:25:23 +0000
committergouldtj <gouldtj@users.sourceforge.net>2007-06-27 06:25:23 +0000
commit22dad424b4835fc8c994741bbebf76ff16f6e3ec (patch)
treede047ec347529b1e81e67829365fc87bcca8480e /src
parent(bzr r3124) (diff)
downloadinkscape-22dad424b4835fc8c994741bbebf76ff16f6e3ec.tar.gz
inkscape-22dad424b4835fc8c994741bbebf76ff16f6e3ec.zip
r15480@tres: ted | 2007-05-20 23:51:34 -0700
The basics are all working, no call back from the preferences yet. That's the next step. But the dialogs appear correctly, and it works in the background. (bzr r3125)
Diffstat (limited to 'src')
-rw-r--r--src/extension/effect.cpp229
-rw-r--r--src/extension/effect.h5
-rw-r--r--src/extension/extension.cpp2
-rw-r--r--src/extension/extension.h4
-rw-r--r--src/extension/implementation/implementation.cpp2
-rw-r--r--src/extension/implementation/implementation.h2
-rw-r--r--src/extension/implementation/script.cpp4
-rw-r--r--src/extension/implementation/script.h3
-rw-r--r--src/extension/internal/bluredge.cpp4
-rw-r--r--src/extension/internal/bluredge.h2
-rw-r--r--src/extension/internal/grid.cpp4
-rw-r--r--src/extension/internal/grid.h2
12 files changed, 191 insertions, 72 deletions
diff --git a/src/extension/effect.cpp b/src/extension/effect.cpp
index f33ff5154..d18599d62 100644
--- a/src/extension/effect.cpp
+++ b/src/extension/effect.cpp
@@ -31,7 +31,7 @@ Effect::Effect (Inkscape::XML::Node * in_repr, Implementation::Implementation *
_name_noprefs(Glib::ustring(get_name()) + _(" (No preferences)")),
_verb(get_id(), get_name(), NULL, NULL, this, true),
_verb_nopref(_id_noprefs.c_str(), _name_noprefs.c_str(), NULL, NULL, this, false),
- _menu_node(NULL)
+ _menu_node(NULL), _workingDialog(true)
{
Inkscape::XML::Node * local_effects_menu = NULL;
@@ -199,6 +199,164 @@ Effect::check (void)
return true;
}
+class ExecutionEnv {
+private:
+ Effect * _effect;
+ Gtk::Dialog * _visibleDialog;
+ bool _prefsVisible;
+ bool _finished;
+ bool _humanWait;
+ bool _canceled;
+ Glib::RefPtr<Glib::MainLoop> _mainloop;
+ Inkscape::UI::View::View * _doc;
+
+public:
+ void run (void);
+
+ ExecutionEnv (Effect * effect, Inkscape::UI::View::View * doc, Gtk::Widget * controls = NULL) :
+ _effect(effect),
+ _visibleDialog(NULL),
+ _prefsVisible(false),
+ _finished(false),
+ _humanWait(false),
+ _canceled(false),
+ _doc(doc) {
+
+ _mainloop = Glib::MainLoop::create(false);
+
+ if (controls != NULL) {
+ createPrefsDialog(controls);
+ } else {
+ createWorkingDialog();
+ }
+
+ return;
+ }
+
+ ~ExecutionEnv (void) {
+ if (_visibleDialog != NULL) {
+ delete _visibleDialog;
+ }
+ return;
+ }
+
+ void preferencesChange (void) {
+ if (_humanWait) {
+ _mainloop->quit();
+ documentCancel();
+ _humanWait = false;
+ } else {
+ processingCancel();
+ documentCancel();
+ }
+ return;
+ }
+
+private:
+ void createPrefsDialog (Gtk::Widget * controls) {
+ if (_visibleDialog != NULL) {
+ delete _visibleDialog;
+ }
+
+ _visibleDialog = new PrefDialog(_effect->get_name(), _effect->get_help(), controls);
+ _visibleDialog->signal_response().connect(sigc::mem_fun(this, &ExecutionEnv::preferencesResponse));
+ _visibleDialog->show();
+
+ _prefsVisible = true;
+ return;
+ }
+
+ void createWorkingDialog (void) {
+ if (_visibleDialog != NULL) {
+ delete _visibleDialog;
+ }
+
+ gchar * dlgmessage = g_strdup_printf(_("The effect '%s' is working on your document. Please wait."), _effect->get_name());
+ _visibleDialog = new Gtk::MessageDialog(dlgmessage,
+ false, // use markup
+ Gtk::MESSAGE_INFO,
+ Gtk::BUTTONS_CANCEL,
+ true); // modal
+ _visibleDialog->signal_response().connect(sigc::mem_fun(this, &ExecutionEnv::workingCanceled));
+ g_free(dlgmessage);
+ _visibleDialog->show();
+
+ _prefsVisible = false;
+ return;
+ }
+
+ void workingCanceled (const int resp) {
+ processingCancel();
+ documentCancel();
+ _finished = true;
+ return;
+ }
+
+ void preferencesResponse (const int resp) {
+ if (resp == Gtk::RESPONSE_OK) {
+ if (_humanWait) {
+ documentCommit();
+ _mainloop->quit();
+ _finished = true;
+ } else {
+ createWorkingDialog();
+ }
+ } else {
+ if (_humanWait) {
+ _mainloop->quit();
+ } else {
+ processingCancel();
+ }
+ documentCancel();
+ _finished = true;
+ }
+ return;
+ }
+
+ void processingComplete(void) {
+ if (_prefsVisible) {
+ _humanWait = true;
+ } else {
+ documentCommit();
+ _finished = true;
+ }
+ return;
+ }
+
+ void processingCancel (void) {
+ _effect->get_imp()->cancelProcessing();
+ return;
+ }
+
+ void documentCancel (void) {
+ _canceled = true;
+ return;
+ }
+
+ void documentCommit (void) {
+ sp_document_done(_doc->doc(), SP_VERB_NONE, _(_effect->get_name()));
+ Effect::set_last_effect(_effect);
+ return;
+ }
+};
+
+void
+ExecutionEnv::run (void) {
+ while (!_finished) {
+ _canceled = false;
+ if (_humanWait) {
+ _mainloop->run();
+ } else {
+ _effect->get_imp()->effect(_effect, _doc);
+ processingComplete();
+ }
+ if (_canceled) {
+ sp_document_cancel(_doc->doc());
+ }
+ }
+ return;
+}
+
bool
Effect::prefs (Inkscape::UI::View::View * doc)
{
@@ -206,22 +364,22 @@ Effect::prefs (Inkscape::UI::View::View * doc)
set_state(Extension::STATE_LOADED);
if (!loaded()) return false;
+ Glib::SignalProxyInfo changeSignalInfo = {signal_name: "Effect Preference Changed",
+ callback: NULL, notify_callback: NULL};
+ Glib::SignalProxy0<void> changeSignal(NULL, &changeSignalInfo);
+
Gtk::Widget * controls;
- controls = imp->prefs_effect(this, doc);
+ controls = imp->prefs_effect(this, doc, &changeSignal);
if (controls == NULL) {
// std::cout << "No preferences for Effect" << std::endl;
return true;
}
- PrefDialog * dialog = new PrefDialog(this->get_name(), this->get_help(), controls);
- int response = dialog->run();
- dialog->hide();
-
- delete dialog;
-
- if (response == Gtk::RESPONSE_OK) return true;
+ ExecutionEnv executionEnv(this, doc, controls);
+ //changeSignal.connect(sigc::mem_fun(executionEnv, &ExecutionEnv::preferencesChange));
+ executionEnv.run();
- return false;
+ return true;
}
/**
@@ -241,47 +399,10 @@ Effect::effect (Inkscape::UI::View::View * doc)
set_state(Extension::STATE_LOADED);
if (!loaded()) return;
- gchar * dlgmessage = g_strdup_printf(_("The effect '%s' is working on your document. Please wait."), get_name());
- Gtk::MessageDialog working(dlgmessage,
- false, // use markup
- Gtk::MESSAGE_INFO,
- Gtk::BUTTONS_CANCEL,
- true); // modal
- working.signal_response().connect(sigc::mem_fun(this, &Effect::workingCanceled));
- g_free(dlgmessage);
- _canceled = false;
- working.show();
-
- set_last_effect(this);
- imp->effect(this, doc);
-
- if (!_canceled) {
- sp_document_done(doc->doc(), SP_VERB_NONE, _(this->get_name()));
- } else {
- sp_document_cancel(doc->doc());
- }
-
- working.hide();
-
- return;
-}
-/** \internal
- \brief A function used by the working dialog to recieve the cancel
- button press
- \param resp The key that was pressed (should always be cancel)
+ ExecutionEnv executionEnv(this, doc, NULL);
+ executionEnv.run();
- This function recieves the key event and marks the effect as being
- canceled. It calls the function in the implementation that would
- cancel the implementation.
-*/
-void
-Effect::workingCanceled (const int resp) {
- if (resp == Gtk::RESPONSE_CANCEL) {
- std::cout << "Canceling Effect" << std::endl;
- _canceled = true;
- imp->cancelProcessing();
- }
return;
}
@@ -360,13 +481,11 @@ Effect::EffectVerb::perform (SPAction *action, void * data, void *pdata)
if (effect == NULL) return;
if (current_view == NULL) return;
- // std::cout << "Executing: " << effect->get_name() << std::endl;
- bool execute = true;
-
- if (ev->_showPrefs)
- execute = effect->prefs(current_view);
- if (execute)
+ if (ev->_showPrefs) {
+ effect->prefs(current_view);
+ } else {
effect->effect(current_view);
+ }
return;
}
diff --git a/src/extension/effect.h b/src/extension/effect.h
index 53d31cf06..bebdb1c4f 100644
--- a/src/extension/effect.h
+++ b/src/extension/effect.h
@@ -86,6 +86,8 @@ class Effect : public Extension {
EffectVerb _verb_nopref;
/** \brief Menu node created for this effect */
Inkscape::XML::Node * _menu_node;
+ /** \brief Whehter a working dialog should be shown */
+ bool _workingDialog;
public:
Effect (Inkscape::XML::Node * in_repr,
Implementation::Implementation * in_imp);
@@ -109,9 +111,6 @@ public:
private:
static gchar * remove_ (gchar * instr);
-
- bool _canceled;
- void workingCanceled (const int resp);
};
} } /* namespace Inkscape, Extension */
diff --git a/src/extension/extension.cpp b/src/extension/extension.cpp
index 553b05583..ffb533eda 100644
--- a/src/extension/extension.cpp
+++ b/src/extension/extension.cpp
@@ -623,7 +623,7 @@ public:
If there are no parameters, this function just returns NULL.
*/
Gtk::Widget *
-Extension::autogui (SPDocument * doc, Inkscape::XML::Node * node)
+Extension::autogui (SPDocument * doc, Inkscape::XML::Node * node, Glib::SignalProxy0<void> * changeSignal)
{
if (g_slist_length(parameters) == 0) return NULL;
diff --git a/src/extension/extension.h b/src/extension/extension.h
index f22c1a476..d1613e711 100644
--- a/src/extension/extension.h
+++ b/src/extension/extension.h
@@ -120,7 +120,7 @@ public:
void deactivate (void);
bool deactivated (void);
void printFailure (Glib::ustring reason);
-
+ Implementation::Implementation * get_imp (void) { return imp; };
/* Parameter Stuff */
private:
@@ -182,7 +182,7 @@ public:
static void error_file_close (void);
public:
- Gtk::Widget * autogui (SPDocument * doc, Inkscape::XML::Node * node);
+ Gtk::Widget * autogui (SPDocument * doc, Inkscape::XML::Node * node, Glib::SignalProxy0<void> * changeSignal = NULL);
void paramListString (std::list <std::string> & retlist);
/* Extension editor dialog stuff */
diff --git a/src/extension/implementation/implementation.cpp b/src/extension/implementation/implementation.cpp
index d01f52cb4..e28dbcba6 100644
--- a/src/extension/implementation/implementation.cpp
+++ b/src/extension/implementation/implementation.cpp
@@ -72,7 +72,7 @@ Implementation::save(Inkscape::Extension::Output *module, SPDocument *doc, gchar
} /* Implementation::save */
Gtk::Widget *
-Implementation::prefs_effect(Inkscape::Extension::Effect *module, Inkscape::UI::View::View *view) {
+Implementation::prefs_effect(Inkscape::Extension::Effect *module, Inkscape::UI::View::View *view, Glib::SignalProxy0<void> * changeSignal) {
return module->autogui(NULL, NULL);
} /* Implementation::prefs_effect */
diff --git a/src/extension/implementation/implementation.h b/src/extension/implementation/implementation.h
index fbe84249c..cfffecad9 100644
--- a/src/extension/implementation/implementation.h
+++ b/src/extension/implementation/implementation.h
@@ -63,7 +63,7 @@ public:
/* ----- Effect functions ----- */
/** Find out information about the file. */
- virtual Gtk::Widget * prefs_effect(Inkscape::Extension::Effect *module, Inkscape::UI::View::View * view);
+ virtual Gtk::Widget * prefs_effect(Inkscape::Extension::Effect *module, Inkscape::UI::View::View * view, Glib::SignalProxy0<void> * changeSignal);
/* TODO: need to figure out what we need here */
virtual void effect(Inkscape::Extension::Effect *module,
diff --git a/src/extension/implementation/script.cpp b/src/extension/implementation/script.cpp
index b5e995b65..857c36bc3 100644
--- a/src/extension/implementation/script.cpp
+++ b/src/extension/implementation/script.cpp
@@ -549,9 +549,9 @@ Script::prefs_output(Inkscape::Extension::Output *module)
*/
Gtk::Widget *
Script::prefs_effect(Inkscape::Extension::Effect *module,
- Inkscape::UI::View::View *view)
+ Inkscape::UI::View::View *view,
+ Glib::SignalProxy0<void> * changeSignal)
{
-
SPDocument * current_document = view->doc();
using Inkscape::Util::GSListConstIterator;
diff --git a/src/extension/implementation/script.h b/src/extension/implementation/script.h
index bac1f7ccb..155abf735 100644
--- a/src/extension/implementation/script.h
+++ b/src/extension/implementation/script.h
@@ -89,7 +89,8 @@ public:
*
*/
virtual Gtk::Widget *prefs_effect(Inkscape::Extension::Effect *module,
- Inkscape::UI::View::View * view);
+ Inkscape::UI::View::View * view,
+ Glib::SignalProxy0<void> * changeSignal);
/**
*
diff --git a/src/extension/internal/bluredge.cpp b/src/extension/internal/bluredge.cpp
index 3989f9427..248cf1c7d 100644
--- a/src/extension/internal/bluredge.cpp
+++ b/src/extension/internal/bluredge.cpp
@@ -117,9 +117,9 @@ BlurEdge::effect (Inkscape::Extension::Effect *module, Inkscape::UI::View::View
}
Gtk::Widget *
-BlurEdge::prefs_effect(Inkscape::Extension::Effect * module, Inkscape::UI::View::View * view)
+BlurEdge::prefs_effect(Inkscape::Extension::Effect * module, Inkscape::UI::View::View * view, Glib::SignalProxy0<void> * changeSignal)
{
- return module->autogui(NULL, NULL);
+ return module->autogui(NULL, NULL, changeSignal);
}
#include "clear-n_.h"
diff --git a/src/extension/internal/bluredge.h b/src/extension/internal/bluredge.h
index a442f570e..c84d16e96 100644
--- a/src/extension/internal/bluredge.h
+++ b/src/extension/internal/bluredge.h
@@ -22,7 +22,7 @@ class BlurEdge : public Inkscape::Extension::Implementation::Implementation {
public:
bool load(Inkscape::Extension::Extension *module);
void effect(Inkscape::Extension::Effect *module, Inkscape::UI::View::View *document);
- Gtk::Widget * prefs_effect(Inkscape::Extension::Effect * module, Inkscape::UI::View::View * view);
+ Gtk::Widget * prefs_effect(Inkscape::Extension::Effect * module, Inkscape::UI::View::View * view, Glib::SignalProxy0<void> * changeSignal);
static void init (void);
};
diff --git a/src/extension/internal/grid.cpp b/src/extension/internal/grid.cpp
index 47034dd2b..099268176 100644
--- a/src/extension/internal/grid.cpp
+++ b/src/extension/internal/grid.cpp
@@ -169,7 +169,7 @@ PrefAdjustment::val_changed (void)
Uses AutoGUI for creating the GUI.
*/
Gtk::Widget *
-Grid::prefs_effect(Inkscape::Extension::Effect *module, Inkscape::UI::View::View * view)
+Grid::prefs_effect(Inkscape::Extension::Effect *module, Inkscape::UI::View::View * view, Glib::SignalProxy0<void> * changeSignal)
{
SPDocument * current_document = view->doc();
@@ -179,7 +179,7 @@ Grid::prefs_effect(Inkscape::Extension::Effect *module, Inkscape::UI::View::View
if (selected != NULL)
first_select = SP_OBJECT_REPR(*selected);
- return module->autogui(current_document, first_select);
+ return module->autogui(current_document, first_select, changeSignal);
}
#include "clear-n_.h"
diff --git a/src/extension/internal/grid.h b/src/extension/internal/grid.h
index 41ac56356..1fedbb177 100644
--- a/src/extension/internal/grid.h
+++ b/src/extension/internal/grid.h
@@ -22,7 +22,7 @@ class Grid : public Inkscape::Extension::Implementation::Implementation {
public:
bool load(Inkscape::Extension::Extension *module);
void effect(Inkscape::Extension::Effect *module, Inkscape::UI::View::View *document);
- Gtk::Widget * prefs_effect(Inkscape::Extension::Effect *module, Inkscape::UI::View::View * view);
+ Gtk::Widget * prefs_effect(Inkscape::Extension::Effect *module, Inkscape::UI::View::View * view, Glib::SignalProxy0<void> * changeSignal);
static void init (void);
};