1 /*
2 * Authors:
3 * Ted Gould <ted@gould.cx>
4 *
5 * Copyright (C) 2007 Authors
6 *
7 * Released under GNU GPL, read the file 'COPYING' for more information
8 */
10 #ifndef INKSCAPE_EXTENSION_EXECUTION_ENV_H__
11 #define INKSCAPE_EXTENSION_EXECUTION_ENV_H__
13 #include <config.h>
15 #include <glibmm/main.h>
16 #include <glibmm/ustring.h>
18 #include <gtkmm/dialog.h>
20 #include "forward.h"
21 #include "extension-forward.h"
22 #include "extension.h"
24 namespace Inkscape {
25 namespace Extension {
27 class ExecutionEnv {
28 private:
29 enum state_t {
30 INIT, //< The context has been initialized
31 COMPLETE, //< We've completed atleast once
32 RUNNING //< The effect is currently running
33 };
34 /** \brief What state the execution engine is in. */
35 state_t _state;
37 /** \brief If there is a working dialog it'll be referenced
38 right here. */
39 Gtk::Dialog * _visibleDialog;
40 /** \brief Signal that the run is complete. */
41 sigc::signal<void> _runComplete;
42 /** \brief In some cases we need a mainLoop, when we do, this is
43 a pointer to it. */
44 Glib::RefPtr<Glib::MainLoop> _mainloop;
45 /** \brief The document that we're working on. */
46 Inkscape::UI::View::View * _doc;
47 /** \brief A list of the IDs of all the selected objects before
48 we started to work on this document. */
49 std::list<Glib::ustring> _selected;
50 /** \brief A document cache if we were passed one. */
51 Implementation::ImplementationDocumentCache * _docCache;
53 /** \brief The effect that we're executing in this context. */
54 Effect * _effect;
56 /** \brief Show the working dialog when the effect is executing. */
57 bool _show_working;
58 /** \brief Display errors if they occur. */
59 bool _show_errors;
60 public:
62 /** \brief Create a new context for exection of an effect
63 \param effect The effect to execute
64 \param doc The document to execute the effect on
65 \param docCache The implementation cache of the document. May be
66 NULL in which case it'll be created by the execution
67 environment.
68 \prarm show_working Show a small dialog signaling the effect
69 is working. Allows for user canceling.
70 \param show_errors If the effect has an error, show it or not.
71 */
72 ExecutionEnv (Effect * effect,
73 Inkscape::UI::View::View * doc,
74 Implementation::ImplementationDocumentCache * docCache = NULL,
75 bool show_working = true,
76 bool show_errors = true);
77 virtual ~ExecutionEnv (void);
79 /** \brief Starts the execution of the effect
80 \return Returns whether the effect was executed to completion */
81 void run (void);
82 /** \brief Cancel the execution of the effect */
83 void cancel (void);
84 /** \brief Commit the changes to the document */
85 void commit (void);
86 /** \brief Undoes what the effect completed. */
87 void undo (void);
88 /** \brief Wait for the effect to complete if it hasn't. */
89 bool wait (void);
91 private:
92 void runComplete (void);
93 void createPrefsDialog (Gtk::Widget * controls);
94 void createWorkingDialog (void);
95 void workingCanceled (const int resp);
96 void processingCancel (void);
97 void processingComplete(void);
98 void documentCancel (void);
99 void documentCommit (void);
100 void reselect (void);
101 void genDocCache (void);
102 void killDocCache (void);
103 };
105 } } /* namespace Inkscape, Extension */
106 #endif /* INKSCAPE_EXTENSION_EXECUTION_ENV_H__ */
108 /*
109 Local Variables:
110 mode:c++
111 c-file-style:"stroustrup"
112 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
113 indent-tabs-mode:nil
114 fill-column:99
115 End:
116 */
117 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :