Inkscape
Vector Graphics Editor
execution-env.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Authors:
4 * Ted Gould <ted@gould.cx>
5 * Abhishek Sharma
6 *
7 * Copyright (C) 2007-2008 Authors
8 *
9 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
10 */
11
12#include "execution-env.h"
13
14#include <gtkmm/dialog.h>
15#include <gtkmm/messagedialog.h>
16
17#include "desktop.h"
18#include "document-undo.h"
19#include "effect.h"
20#include "inkscape.h"
21#include "selection.h"
22
25#include "ui/widget/canvas.h" // To get window (perverse!)
26
27namespace Inkscape {
28namespace Extension {
29
41ExecutionEnv::ExecutionEnv (Effect * effect, SPDesktop *desktop, Implementation::ImplementationDocumentCache * docCache, bool show_working, bool show_errors) :
42 _state(ExecutionEnv::INIT),
43 _desktop(desktop),
44 _docCache(docCache),
45 _effect(effect),
46 _show_working(show_working)
47{
48 if (_desktop) {
49 _document = desktop->doc();
50 }
51 if (_document) {
52 // Temporarily prevent undo in this scope
54 Inkscape::Selection *selection = desktop->getSelection();
55 if (selection) {
56 // Make sure all selected objects have an ID attribute
57 selection->enforceIds();
58 }
60 }
61}
62
68 if (_visibleDialog != nullptr) {
69 _visibleDialog->set_visible(false);
70 delete _visibleDialog;
71 _visibleDialog = nullptr;
72 }
74 return;
75}
76
82void
84 if (_docCache == nullptr && _desktop) {
85 // printf("Gen Doc Cache\n");
87 }
88 return;
89}
90
95void
97 if (_docCache != nullptr) {
98 // printf("Killed Doc Cache\n");
99 delete _docCache;
100 _docCache = nullptr;
101 }
102 return;
103}
104
110void
112 if (!_desktop)
113 return;
114
115 if (_visibleDialog != nullptr) {
116 _visibleDialog->set_visible(false);
117 delete _visibleDialog;
118 _visibleDialog = nullptr;
119 }
120
121 auto const root = _desktop->getCanvas()->get_root();
122 auto const window = dynamic_cast<Gtk::Window *>(root);
123 if (!window) {
124 return;
125 }
126
127 gchar * dlgmessage = g_strdup_printf(_("'%s' complete, loading result..."), _effect->get_name());
128 _visibleDialog = new Gtk::MessageDialog(*window,
129 dlgmessage,
130 false, // use markup
131 Gtk::MessageType::INFO,
132 Gtk::ButtonsType::CANCEL,
133 true); // modal
134 _visibleDialog->signal_response().connect(sigc::mem_fun(*this, &ExecutionEnv::workingCanceled));
135 g_free(dlgmessage);
136
137 Gtk::Dialog *dlg = _effect->get_pref_dialog();
138 if (dlg) {
139 _visibleDialog->set_transient_for(*dlg);
140 } else {
141 // ToDo: Do we need to make the window transient for the main window here?
142 // Currently imossible to test because of GUI freezing during save,
143 // see https://bugs.launchpad.net/inkscape/+bug/967416
144 }
145}
146
147void
148ExecutionEnv::workingCanceled( const int /*resp*/) {
149 cancel();
150 undo();
151 return;
152}
153
154void
158 return;
159}
160
161void
164 return;
165}
166
167void
172 killDocCache();
173 return;
174}
175
176void
178 if(_desktop) {
180 if (selection) {
181 selection->restoreBackup();
182 }
183 }
184 return;
185}
186
187void
190 Inkscape::Selection *selection = nullptr;
191
192 if (_desktop) {
193 if (_show_working) {
195 }
196 selection = _desktop->getSelection();
197 selection->setBackup();
199
201
203 selection->restoreBackup();
204 } else {
206 }
208 // _runComplete.signal();
209 return;
210}
211
212void
214 _mainloop->quit();
215}
216
217bool
220 if (_mainloop) {
222 }
223
224 sigc::connection conn = _runComplete.connect(sigc::mem_fun(*this, &ExecutionEnv::runComplete));
225 _mainloop->run();
226
227 conn.disconnect();
228 }
229
230 return true;
231}
232
233
234
235} } /* namespace Inkscape, Extension */
236
237
238
239/*
240 Local Variables:
241 mode:c++
242 c-file-style:"stroustrup"
243 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
244 indent-tabs-mode:nil
245 fill-column:99
246 End:
247*/
248// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
Inkscape canvas widget.
RAII-style mechanism for creating a temporary undo-insensitive context.
Definition: document-undo.h:69
static void done(SPDocument *document, Glib::ustring const &event_description, Glib::ustring const &undo_icon)
static void cancel(SPDocument *document)
Effects are extensions that take a document and do something to it in place.
Definition: effect.h:39
static void set_last_effect(Effect *in_effect)
Sets which effect was called last.
Definition: effect.cpp:255
PrefDialog * get_pref_dialog()
Definition: effect.cpp:292
void undo()
Undoes what the effect completed.
void createWorkingDialog()
Create the working dialog.
bool wait()
Wait for the effect to complete if it hasn't.
Gtk::Dialog * _visibleDialog
If there is a working dialog it'll be referenced right here.
Definition: execution-env.h:44
state_t _state
What state the execution engine is in.
Definition: execution-env.h:40
void workingCanceled(const int resp)
bool _show_working
Show the working dialog when the effect is executing.
Definition: execution-env.h:60
virtual ~ExecutionEnv()
Destroy an execution environment.
Implementation::ImplementationDocumentCache * _docCache
A document cache if we were passed one.
Definition: execution-env.h:54
Glib::RefPtr< Glib::MainLoop > _mainloop
In some cases we need a mainLoop, when we do, this is a pointer to it.
Definition: execution-env.h:49
void commit()
Commit the changes to the document.
ExecutionEnv(Effect *effect, SPDesktop *desktop, Implementation::ImplementationDocumentCache *docCache=nullptr, bool show_working=true, bool show_errors=true)
Create a new context for execution of an effect.
sigc::signal< void()> _runComplete
Signal that the run is complete.
Definition: execution-env.h:46
void killDocCache()
Destroy a document cache.
void cancel()
Cancel the execution of the effect.
SPDesktop * _desktop
The desktop containing the document that we're working on.
Definition: execution-env.h:51
void run()
Starts the execution of the effect.
void genDocCache()
Generate a document cache if needed.
Effect * _effect
The effect that we're executing in this context.
Definition: execution-env.h:57
char const * get_name() const
Get the name of this extension - not a copy don't delete!
Definition: extension.cpp:326
Implementation::Implementation * get_imp()
Definition: extension.h:190
A cache for the document and this implementation.
virtual void effect(Inkscape::Extension::Effect *, SPDesktop *, ImplementationDocumentCache *)
virtual ImplementationDocumentCache * newDocCache(Inkscape::Extension::Extension *, SPDesktop *)
Create a new document cache object.
void enforceIds()
Assign IDs to selected objects that don't have an ID attribute Checks if the object's id attribute is...
Definition: object-set.cpp:377
The set of selected SPObjects for a given document and layer model.
Definition: selection.h:55
void setBackup()
Set a backup of current selection and store it also to be command line readable by extension system.
Definition: selection.cpp:285
void restoreBackup()
Restore a selection from a existing backup.
Definition: selection.cpp:348
To do: update description of desktop.
Definition: desktop.h:150
Inkscape::UI::Widget::Canvas * getCanvas() const
Definition: desktop.h:188
Inkscape::Selection * getSelection() const
Definition: desktop.h:186
SPDocument * doc() const
Definition: desktop.h:163
void clearWaitingCursor()
Definition: desktop.cpp:1310
void setWaitingCursor()
Definition: desktop.cpp:1299
RootCluster root
Definition: containment.cpp:50
Editable view implementation.
TODO: insert short description here.
CMYK to sRGB conversion routines.
std::unique_ptr< Toolbar >(* create)(SPDesktop *desktop)
Definition: toolbars.cpp:63