diff options
| author | Eduard Braun <eduard.braun2@gmx.de> | 2017-12-20 23:11:30 +0000 |
|---|---|---|
| committer | Eduard Braun <eduard.braun2@gmx.de> | 2017-12-20 23:11:30 +0000 |
| commit | cabdde6554a95e6d0fee5ab39f850f7645df3cbb (patch) | |
| tree | f85847d899169d369929df0f570e40c871c5c361 /src | |
| parent | Effects: make "Working..." dialog transient for preferences dialog (diff) | |
| download | inkscape-cabdde6554a95e6d0fee5ab39f850f7645df3cbb.tar.gz inkscape-cabdde6554a95e6d0fee5ab39f850f7645df3cbb.zip | |
Make script warnings transient for "Working..." dialog
This turned out to be a bit of a mess due to the interplay between
the classes Script / ExecutionEnv / Effect / PrefDialog.
(Basically they don't talk to each other much but all want to
contribute to the GUI)
Likely "Script" (and possibly "ExecutionEnv") should be refactored
to let the other classes handle UI exclusively and throw errors
where suitable.
Diffstat (limited to 'src')
| -rw-r--r-- | src/extension/effect.cpp | 1 | ||||
| -rw-r--r-- | src/extension/execution-env.h | 3 | ||||
| -rw-r--r-- | src/extension/extension.cpp | 1 | ||||
| -rw-r--r-- | src/extension/extension.h | 4 | ||||
| -rw-r--r-- | src/extension/implementation/script.cpp | 18 | ||||
| -rw-r--r-- | src/extension/implementation/script.h | 9 | ||||
| -rw-r--r-- | src/extension/prefdialog.cpp | 4 |
7 files changed, 35 insertions, 5 deletions
diff --git a/src/extension/effect.cpp b/src/extension/effect.cpp index 38e437ac9..93b940732 100644 --- a/src/extension/effect.cpp +++ b/src/extension/effect.cpp @@ -274,6 +274,7 @@ Effect::effect (Inkscape::UI::View::View * doc) ExecutionEnv executionEnv(this, doc); + execution_env = &executionEnv; timer->lock(); executionEnv.run(); if (executionEnv.wait()) { diff --git a/src/extension/execution-env.h b/src/extension/execution-env.h index a57c7b8c9..199e3a5e2 100644 --- a/src/extension/execution-env.h +++ b/src/extension/execution-env.h @@ -98,6 +98,9 @@ public: /** \brief Wait for the effect to complete if it hasn't. */ bool wait (void); + /** \brief Return reference to working dialog (if any) */ + Gtk::Dialog *get_working_dialog (void) { return _visibleDialog; }; + private: void runComplete (void); void createPrefsDialog (Gtk::Widget * controls); diff --git a/src/extension/extension.cpp b/src/extension/extension.cpp index 240d28a59..49ae0075c 100644 --- a/src/extension/extension.cpp +++ b/src/extension/extension.cpp @@ -57,6 +57,7 @@ Extension::Extension (Inkscape::XML::Node * in_repr, Implementation::Implementat : _help(NULL) , silent(false) , _gui(true) + , execution_env(NULL) { repr = in_repr; Inkscape::GC::anchor(in_repr); diff --git a/src/extension/extension.h b/src/extension/extension.h index 9ccc9869b..a00eca21f 100644 --- a/src/extension/extension.h +++ b/src/extension/extension.h @@ -71,6 +71,7 @@ class SPDocument; namespace Inkscape { namespace Extension { +class ExecutionEnv; class Dependency; class ExpirationTimer; class ExpirationTimer; @@ -109,6 +110,7 @@ private: protected: Inkscape::XML::Node *repr; /**< The XML description of the Extension */ Implementation::Implementation * imp; /**< An object that holds all the functions for making this work */ + ExecutionEnv * execution_env; /**< Execution environment of the extension (currently only used by Effects) */ ExpirationTimer * timer; /**< Timeout to unload after a given time */ public: @@ -130,6 +132,8 @@ public: bool deactivated (void); void printFailure (Glib::ustring reason); Implementation::Implementation * get_imp (void) { return imp; }; + void set_execution_env (ExecutionEnv * env) { execution_env = env; }; + ExecutionEnv *get_execution_env (void) { return execution_env; }; /* Parameter Stuff */ private: diff --git a/src/extension/implementation/script.cpp b/src/extension/implementation/script.cpp index 0f0a79bfb..260204cb0 100644 --- a/src/extension/implementation/script.cpp +++ b/src/extension/implementation/script.cpp @@ -28,6 +28,7 @@ #include "desktop.h" #include "ui/dialog-events.h" #include "extension/effect.h" +#include "extension/execution-env.h" #include "extension/output.h" #include "extension/input.h" #include "extension/db.h" @@ -145,9 +146,10 @@ std::string Script::resolveInterpreterExecutable(const Glib::ustring &interpName officially in the load function. This allows for less allocation of memory in the unloaded state. */ -Script::Script() : - Implementation(), - _canceled(false) +Script::Script() + : Implementation() + , _canceled(false) + , parent_window(NULL) { } @@ -652,6 +654,8 @@ void Script::effect(Inkscape::Extension::Effect *module, std::list<std::string> params; module->paramListString(params); + parent_window = module->get_execution_env()->get_working_dialog(); + if (module->no_doc) { // this is a no-doc extension, e.g. a Help menu command; // just run the command without any files, ignoring errors @@ -741,7 +745,7 @@ void Script::effect(Inkscape::Extension::Effect *module, Gtk::MessageDialog warning( _("The output from the extension could not be parsed."), false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_OK, true); - warning.set_transient_for( *(INKSCAPE.active_desktop()->getToplevel()) ); + warning.set_transient_for( parent_window ? *parent_window : *(INKSCAPE.active_desktop()->getToplevel()) ); warning.run(); } } // data_read @@ -932,7 +936,11 @@ void Script::checkStderr (const Glib::ustring &data, Gtk::MessageDialog warning(message, false, type, Gtk::BUTTONS_OK, true); warning.set_resizable(true); GtkWidget *dlg = GTK_WIDGET(warning.gobj()); - sp_transientize(dlg); + if (parent_window) { + warning.set_transient_for(*parent_window); + } else { + sp_transientize(dlg); + } auto vbox = warning.get_content_area(); diff --git a/src/extension/implementation/script.h b/src/extension/implementation/script.h index 684719895..c6ae117c7 100644 --- a/src/extension/implementation/script.h +++ b/src/extension/implementation/script.h @@ -15,6 +15,7 @@ #include "implementation.h" #include <gtkmm/enums.h> +#include <gtkmm/window.h> #include <glibmm/main.h> #include <glibmm/spawn.h> #include <glibmm/fileutils.h> @@ -66,6 +67,14 @@ private: */ Glib::ustring helper_extension; + /** + * The window which should be considered as "parent window" of the script execution, + * e.g. when showin warning messages + * + * If set to NULL the main window of the currently active document is used. + */ + Gtk::Window *parent_window; + std::string solve_reldir(Inkscape::XML::Node *repr_in); bool check_existence (std::string const& command); void copy_doc(Inkscape::XML::Node * olddoc, Inkscape::XML::Node * newdoc); diff --git a/src/extension/prefdialog.cpp b/src/extension/prefdialog.cpp index 92ddd3050..0247e18e9 100644 --- a/src/extension/prefdialog.cpp +++ b/src/extension/prefdialog.cpp @@ -131,6 +131,7 @@ PrefDialog::~PrefDialog ( ) _exEnv->cancel(); delete _exEnv; _exEnv = NULL; + _effect->set_execution_env(_exEnv); } if (_effect != NULL) { @@ -173,6 +174,7 @@ PrefDialog::preview_toggle (void) { set_modal(true); if (_exEnv == NULL) { _exEnv = new ExecutionEnv(_effect, SP_ACTIVE_DESKTOP, NULL, false, false); + _effect->set_execution_env(_exEnv); _exEnv->run(); } } else { @@ -182,6 +184,7 @@ PrefDialog::preview_toggle (void) { _exEnv->undo(); delete _exEnv; _exEnv = NULL; + _effect->set_execution_env(_exEnv); } } } @@ -230,6 +233,7 @@ PrefDialog::on_response (int signal) { } delete _exEnv; _exEnv = NULL; + _effect->set_execution_env(_exEnv); } } |
