Code

r15704@tres: ted | 2007-07-02 16:03:34 -0700
authorgouldtj <gouldtj@users.sourceforge.net>
Tue, 3 Jul 2007 03:48:15 +0000 (03:48 +0000)
committergouldtj <gouldtj@users.sourceforge.net>
Tue, 3 Jul 2007 03:48:15 +0000 (03:48 +0000)
 Split out the execution environment object.

src/extension/Makefile_insert
src/extension/effect.cpp
src/extension/execution-env.cpp [new file with mode: 0644]
src/extension/execution-env.h [new file with mode: 0644]

index 1eaa7ce5d8826001f47924b7aed02e4e4e7dcb79..3df936cd92555c4cf34b4367265bde90892f5589 100644 (file)
@@ -15,6 +15,8 @@ extension_libextension_a_SOURCES =    \
        extension/dependency.h \
        extension/error-file.cpp \
        extension/error-file.h \
+       extension/execution-env.cpp \
+       extension/execution-env.h \
        extension/init.cpp      \
        extension/init.h        \
        extension/parameter.h \
index 4042a6dcba998d7d9a3cfe42385103366ed2ed90..aa702a1aeba7f0e322e5c16208d466dd35ea8d5f 100644 (file)
 #include "selection.h"
 #include "sp-namedview.h"
 #include "document.h"
-#include "prefdialog.h"
 #include "implementation/implementation.h"
 #include "effect.h"
+#include "execution-env.h"
 #include "timer.h"
-#include "ui/view/view.h"
 
-#include "gtkmm/messagedialog.h"
 
-#include "util/glib-list-iterators.h"
 
 /* Inkscape::Extension::Effect */
 
@@ -206,205 +203,6 @@ Effect::check (void)
     return true;
 }
 
-class ExecutionEnv {
-private:
-    Effect * _effect;
-    Gtk::Dialog * _visibleDialog;
-    bool _prefsVisible;
-    bool _finished;
-    bool _humanWait;
-    bool _canceled;
-    bool _prefsChanged;
-    Glib::RefPtr<Glib::MainLoop> _mainloop;
-    Inkscape::UI::View::View * _doc;
-    std::list<Glib::ustring> _selected;
-
-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),
-        _prefsChanged(false),
-        _doc(doc) {
-
-        SPDesktop *desktop = (SPDesktop *)_doc;
-        sp_namedview_document_from_window(desktop);
-
-        if (desktop != NULL) {
-            Inkscape::Util::GSListConstIterator<SPItem *> selected =
-                 sp_desktop_selection(desktop)->itemList();
-            while ( selected != NULL ) {
-                Glib::ustring selected_id;
-                selected_id = SP_OBJECT_ID(*selected);
-                _selected.insert(_selected.end(), selected_id);
-                //std::cout << "Selected: " << selected_id << std::endl;
-                ++selected;
-            }
-        }
-
-        _mainloop = Glib::MainLoop::create(false);
-
-        if (controls != NULL) {
-            createPrefsDialog(controls);
-        } else {
-            createWorkingDialog();
-        }
-
-        return;
-    }
-
-    ~ExecutionEnv (void) {
-        if (_visibleDialog != NULL) {
-            delete _visibleDialog;
-        }
-        return;
-    }
-
-    void preferencesChange (void) {
-        //std::cout << "Preferences are a changin'" << std::endl;
-        _prefsChanged = true;
-        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) {
-        //std::cout << "Processing Complete" << std::endl;
-        if (_prefsChanged) { return; } // do it all again
-        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 reselect (void) {
-        SPDocument * doc = _doc->doc();
-
-        SPDesktop *desktop = (SPDesktop *)_doc;
-        sp_namedview_document_from_window(desktop);
-
-        if (desktop == NULL) { return; }
-
-        Inkscape::Selection * selection = sp_desktop_selection(desktop);
-
-        for (std::list<Glib::ustring>::iterator i = _selected.begin(); i != _selected.end(); i++) {
-            selection->add(doc->getObjectById(i->c_str()));
-        }
-
-        return;
-    }
-};
-
-void
-ExecutionEnv::run (void) {
-    while (!_finished) {
-        _canceled = false;
-        if (_humanWait) {
-            _mainloop->run();
-        } else {
-            _prefsChanged = false;
-            _effect->get_imp()->effect(_effect, _doc);
-            processingComplete();
-        }
-        if (_canceled) {
-            sp_document_cancel(_doc->doc());
-            reselect();
-        }
-    }
-    return;
-}
-
 bool
 Effect::prefs (Inkscape::UI::View::View * doc)
 {
diff --git a/src/extension/execution-env.cpp b/src/extension/execution-env.cpp
new file mode 100644 (file)
index 0000000..4fc559b
--- /dev/null
@@ -0,0 +1,237 @@
+/*
+ * Authors:
+ *   Ted Gould <ted@gould.cx>
+ *
+ * Copyright (C) 2007 Authors
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include <config.h>
+
+#include "gtkmm/messagedialog.h"
+
+#include "execution-env.h"
+#include "prefdialog.h"
+#include "implementation/implementation.h"
+
+#include "selection.h"
+#include "effect.h"
+#include "document.h"
+#include "ui/view/view.h"
+#include "sp-namedview.h"
+#include "desktop-handles.h"
+
+#include "util/glib-list-iterators.h"
+
+namespace Inkscape {
+namespace Extension {
+
+
+ExecutionEnv::ExecutionEnv (Effect * effect, Inkscape::UI::View::View * doc, Gtk::Widget * controls) :
+    _effect(effect),
+    _visibleDialog(NULL),
+    _prefsVisible(false),
+    _finished(false),
+    _humanWait(false),
+    _canceled(false),
+    _prefsChanged(false),
+    _doc(doc) {
+
+    SPDesktop *desktop = (SPDesktop *)_doc;
+    sp_namedview_document_from_window(desktop);
+
+    if (desktop != NULL) {
+        Inkscape::Util::GSListConstIterator<SPItem *> selected =
+             sp_desktop_selection(desktop)->itemList();
+        while ( selected != NULL ) {
+            Glib::ustring selected_id;
+            selected_id = SP_OBJECT_ID(*selected);
+            _selected.insert(_selected.end(), selected_id);
+            //std::cout << "Selected: " << selected_id << std::endl;
+            ++selected;
+        }
+    }
+
+    _mainloop = Glib::MainLoop::create(false);
+
+    if (controls != NULL) {
+        createPrefsDialog(controls);
+    } else {
+        createWorkingDialog();
+    }
+
+    return;
+}
+
+ExecutionEnv::~ExecutionEnv (void) {
+    if (_visibleDialog != NULL) {
+        delete _visibleDialog;
+    }
+    return;
+}
+
+void
+ExecutionEnv::preferencesChange (void) {
+    //std::cout << "Preferences are a changin'" << std::endl;
+    _prefsChanged = true;
+    if (_humanWait) {
+        _mainloop->quit();
+        documentCancel();
+        _humanWait = false;
+    } else {
+        processingCancel();
+        documentCancel();
+    }
+    return;
+}
+
+void
+ExecutionEnv::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
+ExecutionEnv::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
+ExecutionEnv::workingCanceled (const int resp) {
+    processingCancel();
+    documentCancel();
+    _finished = true;
+    return;
+}
+
+void
+ExecutionEnv::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
+ExecutionEnv::processingComplete(void) {
+    //std::cout << "Processing Complete" << std::endl;
+    if (_prefsChanged) { return; } // do it all again
+    if (_prefsVisible) {
+        _humanWait = true;
+    } else {
+        documentCommit();
+        _finished = true;
+    }
+    return;
+}
+
+void
+ExecutionEnv::processingCancel (void) {
+    _effect->get_imp()->cancelProcessing();
+    return;
+}
+
+void
+ExecutionEnv::documentCancel (void) {
+    _canceled = true;
+    return;
+}
+
+void
+ExecutionEnv::documentCommit (void) {
+    sp_document_done(_doc->doc(), SP_VERB_NONE, _(_effect->get_name()));
+    Effect::set_last_effect(_effect);
+    return;
+}
+
+void
+ExecutionEnv::reselect (void) {
+    SPDocument * doc = _doc->doc();
+
+    SPDesktop *desktop = (SPDesktop *)_doc;
+    sp_namedview_document_from_window(desktop);
+
+    if (desktop == NULL) { return; }
+
+    Inkscape::Selection * selection = sp_desktop_selection(desktop);
+
+    for (std::list<Glib::ustring>::iterator i = _selected.begin(); i != _selected.end(); i++) {
+        selection->add(doc->getObjectById(i->c_str()));
+    }
+
+    return;
+}
+
+void
+ExecutionEnv::run (void) {
+    while (!_finished) {
+        _canceled = false;
+        if (_humanWait) {
+            _mainloop->run();
+        } else {
+            _prefsChanged = false;
+            _effect->get_imp()->effect(_effect, _doc);
+            processingComplete();
+        }
+        if (_canceled) {
+            sp_document_cancel(_doc->doc());
+            reselect();
+        }
+    }
+    return;
+}
+
+
+
+} }  /* namespace Inkscape, Extension */
+
+
+
+/*
+  Local Variables:
+  mode:c++
+  c-file-style:"stroustrup"
+  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+  indent-tabs-mode:nil
+  fill-column:99
+  End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
diff --git a/src/extension/execution-env.h b/src/extension/execution-env.h
new file mode 100644 (file)
index 0000000..1e145de
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Authors:
+ *   Ted Gould <ted@gould.cx>
+ *
+ * Copyright (C) 2007 Authors
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#ifndef INKSCAPE_EXTENSION_EXECUTION_ENV_H__
+#define INKSCAPE_EXTENSION_EXECUTION_ENV_H__
+
+#include <config.h>
+
+#include <glibmm/main.h>
+#include <glibmm/ustring.h>
+
+#include <gtkmm/dialog.h>
+
+#include "forward.h"
+#include "extension-forward.h"
+
+namespace Inkscape {
+namespace Extension {
+
+class ExecutionEnv {
+private:
+    Effect * _effect;
+    Gtk::Dialog * _visibleDialog;
+    bool _prefsVisible;
+    bool _finished;
+    bool _humanWait;
+    bool _canceled;
+    bool _prefsChanged;
+    Glib::RefPtr<Glib::MainLoop> _mainloop;
+    Inkscape::UI::View::View * _doc;
+    std::list<Glib::ustring> _selected;
+
+public:
+    ExecutionEnv (Effect * effect, Inkscape::UI::View::View * doc, Gtk::Widget * controls = NULL);
+    ~ExecutionEnv (void);
+
+    void run (void);
+    void preferencesChange (void);
+
+private:
+    void createPrefsDialog (Gtk::Widget * controls);
+    void createWorkingDialog (void);
+    void workingCanceled (const int resp);
+    void preferencesResponse (const int resp);
+    void processingCancel (void);
+    void processingComplete(void);
+    void documentCancel (void);
+    void documentCommit (void);
+    void reselect (void);
+};
+
+} }  /* namespace Inkscape, Extension */
+#endif /* INKSCAPE_EXTENSION_EXECUTION_ENV_H__ */
+
+/*
+  Local Variables:
+  mode:c++
+  c-file-style:"stroustrup"
+  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+  indent-tabs-mode:nil
+  fill-column:99
+  End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :