Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
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 "inkscape-window.h"
22#include "selection.h"
23
26#include "ui/widget/canvas.h" // To get window (perverse!)
27
28namespace Inkscape {
29namespace Extension {
30
42ExecutionEnv::ExecutionEnv (Effect * effect, SPDesktop *desktop, Implementation::ImplementationDocumentCache * docCache, bool show_working, bool show_errors) :
43 _state(ExecutionEnv::INIT),
44 _desktop(desktop),
45 _docCache(docCache),
46 _effect(effect),
47 _show_working(show_working)
48{
49 if (_desktop) {
51 }
52 if (_document) {
53 // Temporarily prevent undo in this scope
56 if (selection) {
57 // Make sure all selected objects have an ID attribute
58 selection->enforceIds();
59 }
61 }
62}
63
69 if (_visibleDialog != nullptr) {
70 _visibleDialog->set_visible(false);
71 delete _visibleDialog;
72 _visibleDialog = nullptr;
73 }
75 return;
76}
77
83void
85 if (_docCache == nullptr && _desktop) {
86 // printf("Gen Doc Cache\n");
88 }
89 return;
90}
91
96void
98 if (_docCache != nullptr) {
99 // printf("Killed Doc Cache\n");
100 delete _docCache;
101 _docCache = nullptr;
102 }
103 return;
104}
105
111void
113 if (!_desktop)
114 return;
115
116 if (_visibleDialog != nullptr) {
117 _visibleDialog->set_visible(false);
118 delete _visibleDialog;
119 _visibleDialog = nullptr;
120 }
121
122 auto const root = _desktop->getCanvas()->get_root();
123 auto const window = dynamic_cast<Gtk::Window *>(root);
124 if (!window) {
125 return;
126 }
127
128 gchar * dlgmessage = g_strdup_printf(_("'%s' complete, loading result..."), _effect->get_name());
129 _visibleDialog = new Gtk::MessageDialog(*window,
130 dlgmessage,
131 false, // use markup
132 Gtk::MessageType::INFO,
133 Gtk::ButtonsType::CANCEL,
134 true); // modal
135 _visibleDialog->signal_response().connect(sigc::mem_fun(*this, &ExecutionEnv::workingCanceled));
136 g_free(dlgmessage);
137
138 Gtk::Dialog *dlg = _effect->get_pref_dialog();
139 if (dlg) {
140 _visibleDialog->set_transient_for(*dlg);
141 } else {
142 _visibleDialog->set_transient_for(*_desktop->getInkscapeWindow());
143 }
144}
145
146void
147ExecutionEnv::workingCanceled( const int /*resp*/) {
148 cancel();
149 undo();
150 return;
151}
152
153void
159
160void
165
166void
174
175void
177 if (_desktop && _selectionState) {
178 if (auto selection = _desktop->getSelection()) {
179 selection->setState(*_selectionState);
180 }
181 }
182 return;
183}
184
185void
188
189 if (_desktop) {
190 if (_show_working) {
192 }
193 auto selection = _desktop->getSelection();
194 // Save selection state
195 _selectionState = std::make_unique<Inkscape::SelectionState>(selection->getState());
196 if (_show_working) {
198 }
200 if (_show_working) {
202 }
203 // Restore selection state
204 selection->setState(*_selectionState);
205 _selectionState.reset();
206 } else {
208 }
210 // _runComplete.signal();
211}
212
213void
217
218bool
221 if (_mainloop) {
222 _mainloop = Glib::MainLoop::create(false);
223 }
224
225 sigc::connection conn = _runComplete.connect(sigc::mem_fun(*this, &ExecutionEnv::runComplete));
226 _mainloop->run();
227
228 conn.disconnect();
229 }
230
231 return true;
232}
233
234
235
236} } /* namespace Inkscape, Extension */
237
238
239
240/*
241 Local Variables:
242 mode:c++
243 c-file-style:"stroustrup"
244 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
245 indent-tabs-mode:nil
246 fill-column:99
247 End:
248*/
249// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
Inkscape canvas widget.
RAII-style mechanism for creating a temporary undo-insensitive context.
static void done(SPDocument *document, Glib::ustring const &event_description, Glib::ustring const &undo_icon, unsigned int object_modified_tag=0)
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:261
PrefDialog * get_pref_dialog()
Definition effect.cpp:298
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.
state_t _state
What state the execution engine is in.
bool _show_working
Show the working dialog when the effect is executing.
virtual ~ExecutionEnv()
Destroy an execution environment.
Implementation::ImplementationDocumentCache * _docCache
A document cache if we were passed one.
Glib::RefPtr< Glib::MainLoop > _mainloop
In some cases we need a mainLoop, when we do, this is a pointer to it.
void commit()
Commit the changes to the document.
std::unique_ptr< Inkscape::SelectionState > _selectionState
Saved selection state before running the effect.
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.
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.
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.
char const * get_name() const
Get the name of this extension - not a copy don't delete!
Implementation::Implementation * get_imp()
Definition extension.h:191
A cache for the document and this implementation.
virtual ImplementationDocumentCache * newDocCache(Inkscape::Extension::Extension *, SPDesktop *)
Create a new document cache object.
virtual void effect(Inkscape::Extension::Effect *, ExecutionEnv *, SPDesktop *, ImplementationDocumentCache *)
void enforceIds()
Assign IDs to selected objects that don't have an ID attribute Checks if the object's id attribute is...
The set of selected SPObjects for a given document and layer model.
Definition selection.h:80
To do: update description of desktop.
Definition desktop.h:149
Inkscape::UI::Widget::Canvas * getCanvas() const
Definition desktop.h:190
InkscapeWindow const * getInkscapeWindow() const
Definition desktop.cpp:975
Inkscape::Selection * getSelection() const
Definition desktop.h:188
SPDocument * doc() const
Definition desktop.h:159
void clearWaitingCursor()
Definition desktop.cpp:1166
void setWaitingCursor()
Definition desktop.cpp:1155
RootCluster root
Editable view implementation.
TODO: insert short description here.
Inkscape - An SVG editor.
Helper class to stream background task notifications as a series of messages.
SPDesktop * desktop