diff options
| author | Alexander Valavanis <valavanisalex@gmail.com> | 2019-01-22 01:31:41 +0000 |
|---|---|---|
| committer | Alexander Valavanis <valavanisalex@gmail.com> | 2019-01-22 01:31:41 +0000 |
| commit | 355d673e61eae70c5e83f6d2e09997047b248ddd (patch) | |
| tree | bb9918e932562e6337da499f0ca82b86b28a0b5a /src/ui | |
| parent | Tidy more memory mgmt in toolbars (diff) | |
| download | inkscape-355d673e61eae70c5e83f6d2e09997047b248ddd.tar.gz inkscape-355d673e61eae70c5e83f6d2e09997047b248ddd.zip | |
Tidy up toolbox utilities
Diffstat (limited to 'src/ui')
| -rw-r--r-- | src/ui/CMakeLists.txt | 6 | ||||
| -rw-r--r-- | src/ui/pref-pusher.cpp | 70 | ||||
| -rw-r--r-- | src/ui/pref-pusher.h | 77 | ||||
| -rw-r--r-- | src/ui/toolbar/arc-toolbar.cpp | 1 | ||||
| -rw-r--r-- | src/ui/toolbar/box3d-toolbar.cpp | 1 | ||||
| -rw-r--r-- | src/ui/toolbar/calligraphy-toolbar.cpp | 5 | ||||
| -rw-r--r-- | src/ui/toolbar/calligraphy-toolbar.h | 4 | ||||
| -rw-r--r-- | src/ui/toolbar/connector-toolbar.cpp | 1 | ||||
| -rw-r--r-- | src/ui/toolbar/eraser-toolbar.cpp | 11 | ||||
| -rw-r--r-- | src/ui/toolbar/eraser-toolbar.h | 5 | ||||
| -rw-r--r-- | src/ui/toolbar/measure-toolbar.cpp | 1 | ||||
| -rw-r--r-- | src/ui/toolbar/mesh-toolbar.cpp | 6 | ||||
| -rw-r--r-- | src/ui/toolbar/mesh-toolbar.h | 5 | ||||
| -rw-r--r-- | src/ui/toolbar/node-toolbar.cpp | 1 | ||||
| -rw-r--r-- | src/ui/toolbar/paintbucket-toolbar.cpp | 1 | ||||
| -rw-r--r-- | src/ui/toolbar/pencil-toolbar.cpp | 1 | ||||
| -rw-r--r-- | src/ui/toolbar/rect-toolbar.cpp | 1 | ||||
| -rw-r--r-- | src/ui/toolbar/spiral-toolbar.cpp | 1 | ||||
| -rw-r--r-- | src/ui/toolbar/spray-toolbar.cpp | 5 | ||||
| -rw-r--r-- | src/ui/toolbar/spray-toolbar.h | 4 | ||||
| -rw-r--r-- | src/ui/toolbar/star-toolbar.cpp | 1 | ||||
| -rw-r--r-- | src/ui/toolbar/text-toolbar.cpp | 1 | ||||
| -rw-r--r-- | src/ui/toolbar/tweak-toolbar.cpp | 2 |
23 files changed, 180 insertions, 31 deletions
diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 35e6a99fe..8cc446609 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -9,6 +9,7 @@ set(ui_SRC icon-loader.cpp interface.cpp monitor.cpp + pref-pusher.cpp previewholder.cpp selected-color.cpp shape-editor.cpp @@ -224,14 +225,15 @@ set(ui_SRC icon-names.h icon-loader.h interface.h - monitor.h + monitor.h + pref-pusher.h previewable.h previewholder.h selected-color.h shape-editor.h tool-factory.h tools-switch.h - util.h + util.h uxmanager.h cache/svg_preview_cache.h diff --git a/src/ui/pref-pusher.cpp b/src/ui/pref-pusher.cpp new file mode 100644 index 000000000..3b84ba65a --- /dev/null +++ b/src/ui/pref-pusher.cpp @@ -0,0 +1,70 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "pref-pusher.h" + +#include <gtk/gtk.h> + +namespace Inkscape { +namespace UI { +PrefPusher::PrefPusher( GtkToggleAction *act, Glib::ustring const &path, void (*callback)(gpointer), gpointer cbData ) : + Observer(path), + act(act), + callback(callback), + cbData(cbData), + freeze(false) +{ + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggleCB), this); + freeze = true; + gtk_toggle_action_set_active( act, Inkscape::Preferences::get()->getBool(observed_path) ); + freeze = false; + + Inkscape::Preferences::get()->addObserver(*this); +} + +PrefPusher::~PrefPusher() +{ + Inkscape::Preferences::get()->removeObserver(*this); +} + +void PrefPusher::toggleCB( GtkToggleAction * /*act*/, PrefPusher *self ) +{ + if (self) { + self->handleToggled(); + } +} + +void PrefPusher::handleToggled() +{ + if (!freeze) { + freeze = true; + Inkscape::Preferences::get()->setBool(observed_path, gtk_toggle_action_get_active( act )); + if (callback) { + (*callback)(cbData); + } + freeze = false; + } +} + +void PrefPusher::notify(Inkscape::Preferences::Entry const &newVal) +{ + bool newBool = newVal.getBool(); + bool oldBool = gtk_toggle_action_get_active(act); + + if (!freeze && (newBool != oldBool)) { + gtk_toggle_action_set_active( act, newBool ); + } +} + +} +} + +/* + 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/ui/pref-pusher.h b/src/ui/pref-pusher.h new file mode 100644 index 000000000..2ae4e6842 --- /dev/null +++ b/src/ui/pref-pusher.h @@ -0,0 +1,77 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#ifndef SEEN_PREF_PUSHER_H +#define SEEN_PREF_PUSHER_H + +#include "preferences.h" + +typedef struct _GtkToggleAction GtkToggleAction; + +namespace Inkscape { +namespace UI { + +/** + * A simple mediator class that keeps UI controls matched to the preference values they set. + */ +class PrefPusher : public Inkscape::Preferences::Observer +{ +public: + /** + * Constructor for a boolean value that syncs to the supplied path. + * Initializes the widget to the current preference stored state and registers callbacks + * for widget changes and preference changes. + * + * @param act the widget to synchronize preference with. + * @param path the path to the preference the widget is synchronized with. + * @param callback function to invoke when changes are pushed. + * @param cbData data to be passed on to the callback function. + */ + PrefPusher( GtkToggleAction *act, + Glib::ustring const & path, + void (*callback)(gpointer) = nullptr, + gpointer cbData = nullptr ); + + /** + * Destructor that unregisters the preference callback. + */ + ~PrefPusher() override; + + /** + * Callback method invoked when the preference setting changes. + */ + void notify(Inkscape::Preferences::Entry const &new_val) override; + + +private: + /** + * Callback hook invoked when the widget changes. + * + * @param act the toggle action widget that was changed. + * @param self the PrefPusher instance the callback was registered to. + */ + static void toggleCB( GtkToggleAction *act, PrefPusher *self ); + + /** + * Method to handle the widget change. + */ + void handleToggled(); + + GtkToggleAction *act; + void (*callback)(gpointer); + gpointer cbData; + bool freeze; +}; + +} +} +#endif + +/* + 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/ui/toolbar/arc-toolbar.cpp b/src/ui/toolbar/arc-toolbar.cpp index d964846cf..ec0388f2c 100644 --- a/src/ui/toolbar/arc-toolbar.cpp +++ b/src/ui/toolbar/arc-toolbar.cpp @@ -40,6 +40,7 @@ #include "object/sp-ellipse.h" #include "ui/icon-names.h" +#include "ui/pref-pusher.h" #include "ui/tools/arc-tool.h" #include "ui/uxmanager.h" #include "ui/widget/ink-select-one-action.h" diff --git a/src/ui/toolbar/box3d-toolbar.cpp b/src/ui/toolbar/box3d-toolbar.cpp index e42700c93..a0d9f8eb1 100644 --- a/src/ui/toolbar/box3d-toolbar.cpp +++ b/src/ui/toolbar/box3d-toolbar.cpp @@ -41,6 +41,7 @@ #include "object/persp3d.h" #include "ui/icon-names.h" +#include "ui/pref-pusher.h" #include "ui/tools/box3d-tool.h" #include "ui/uxmanager.h" diff --git a/src/ui/toolbar/calligraphy-toolbar.cpp b/src/ui/toolbar/calligraphy-toolbar.cpp index faad6edd0..a776b7508 100644 --- a/src/ui/toolbar/calligraphy-toolbar.cpp +++ b/src/ui/toolbar/calligraphy-toolbar.cpp @@ -36,6 +36,7 @@ #include "widgets/ink-toggle-action.h" #include "widgets/toolbox.h" #include "ui/icon-names.h" +#include "ui/pref-pusher.h" #include "ui/uxmanager.h" #include "ui/widget/ink-select-one-action.h" @@ -62,6 +63,10 @@ namespace Inkscape { namespace UI { namespace Toolbar { +CalligraphyToolbar::CalligraphyToolbar(SPDesktop *desktop) + : Toolbar(desktop) +{} + GtkWidget * CalligraphyToolbar::prep(SPDesktop *desktop, GtkActionGroup* mainActions) { diff --git a/src/ui/toolbar/calligraphy-toolbar.h b/src/ui/toolbar/calligraphy-toolbar.h index f37d84808..2cf313948 100644 --- a/src/ui/toolbar/calligraphy-toolbar.h +++ b/src/ui/toolbar/calligraphy-toolbar.h @@ -86,9 +86,7 @@ private: static void tilt_state_changed( GtkToggleAction *act, gpointer data ); protected: - CalligraphyToolbar(SPDesktop *desktop) - : Toolbar(desktop) - {} + CalligraphyToolbar(SPDesktop *desktop); public: static GtkWidget * prep(SPDesktop *desktop, GtkActionGroup* mainActions); diff --git a/src/ui/toolbar/connector-toolbar.cpp b/src/ui/toolbar/connector-toolbar.cpp index 1855fe734..56fb03812 100644 --- a/src/ui/toolbar/connector-toolbar.cpp +++ b/src/ui/toolbar/connector-toolbar.cpp @@ -55,7 +55,6 @@ using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; -using Inkscape::UI::PrefPusher; static Inkscape::XML::NodeEventVector connector_tb_repr_events = { nullptr, /* child_added */ diff --git a/src/ui/toolbar/eraser-toolbar.cpp b/src/ui/toolbar/eraser-toolbar.cpp index f5631f362..a5225a75e 100644 --- a/src/ui/toolbar/eraser-toolbar.cpp +++ b/src/ui/toolbar/eraser-toolbar.cpp @@ -38,20 +38,21 @@ #include "widgets/toolbox.h" #include "ui/widget/ink-select-one-action.h" #include "ui/icon-names.h" +#include "ui/pref-pusher.h" #include "ui/tools/eraser-tool.h" using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; using Inkscape::UI::PrefPusher; -//######################## -//## Eraser ## -//######################## - - namespace Inkscape { namespace UI { namespace Toolbar { +EraserToolbar::EraserToolbar(SPDesktop *desktop) + : Toolbar(desktop), + _freeze(false) +{} + GtkWidget * EraserToolbar::prep(SPDesktop *desktop, GtkActionGroup* mainActions) { diff --git a/src/ui/toolbar/eraser-toolbar.h b/src/ui/toolbar/eraser-toolbar.h index de083830b..4ff431526 100644 --- a/src/ui/toolbar/eraser-toolbar.h +++ b/src/ui/toolbar/eraser-toolbar.h @@ -78,10 +78,7 @@ private: gpointer data); protected: - EraserToolbar(SPDesktop *desktop) - : Toolbar(desktop), - _freeze(false) - {} + EraserToolbar(SPDesktop *desktop); public: static GtkWidget * prep(SPDesktop *desktop, GtkActionGroup* mainActions); diff --git a/src/ui/toolbar/measure-toolbar.cpp b/src/ui/toolbar/measure-toolbar.cpp index 9f58391c0..9fb2c4d7c 100644 --- a/src/ui/toolbar/measure-toolbar.cpp +++ b/src/ui/toolbar/measure-toolbar.cpp @@ -49,7 +49,6 @@ using Inkscape::UI::Widget::UnitTracker; using Inkscape::Util::Unit; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; -using Inkscape::UI::PrefPusher; using Inkscape::UI::Tools::MeasureTool; //######################## diff --git a/src/ui/toolbar/mesh-toolbar.cpp b/src/ui/toolbar/mesh-toolbar.cpp index 045d7c11a..2f06d8e0c 100644 --- a/src/ui/toolbar/mesh-toolbar.cpp +++ b/src/ui/toolbar/mesh-toolbar.cpp @@ -39,6 +39,7 @@ #include "svg/css-ostringstream.h" #include "ui/icon-names.h" +#include "ui/pref-pusher.h" #include "ui/tools/gradient-tool.h" #include "ui/tools/mesh-tool.h" #include "ui/widget/color-preview.h" @@ -191,6 +192,11 @@ static void mesh_toolbox_watch_ec(SPDesktop* dt, Inkscape::UI::Tools::ToolBase* namespace Inkscape { namespace UI { namespace Toolbar { +MeshToolbar::MeshToolbar(SPDesktop *desktop) + : Toolbar(desktop), + _edit_fill_pusher(nullptr) +{} + /** * Mesh auxiliary toolbar construction and setup. * Don't forget to add to XML in widgets/toolbox.cpp! diff --git a/src/ui/toolbar/mesh-toolbar.h b/src/ui/toolbar/mesh-toolbar.h index 76d031f25..5e6e61bb1 100644 --- a/src/ui/toolbar/mesh-toolbar.h +++ b/src/ui/toolbar/mesh-toolbar.h @@ -72,10 +72,7 @@ private: void type_changed(int mode); protected: - MeshToolbar(SPDesktop *desktop) - : Toolbar(desktop), - _edit_fill_pusher(nullptr) - {} + MeshToolbar(SPDesktop *desktop); public: static GtkWidget * prep(SPDesktop *desktop, GtkActionGroup* mainActions); diff --git a/src/ui/toolbar/node-toolbar.cpp b/src/ui/toolbar/node-toolbar.cpp index 5915bf1cb..7fd28185e 100644 --- a/src/ui/toolbar/node-toolbar.cpp +++ b/src/ui/toolbar/node-toolbar.cpp @@ -43,6 +43,7 @@ #include "object/sp-namedview.h" #include "ui/icon-names.h" +#include "ui/pref-pusher.h" #include "ui/tool/control-point-selection.h" #include "ui/tool/multi-path-manipulator.h" #include "ui/tools/node-tool.h" diff --git a/src/ui/toolbar/paintbucket-toolbar.cpp b/src/ui/toolbar/paintbucket-toolbar.cpp index 1ad411c1c..4efe27835 100644 --- a/src/ui/toolbar/paintbucket-toolbar.cpp +++ b/src/ui/toolbar/paintbucket-toolbar.cpp @@ -45,7 +45,6 @@ using Inkscape::UI::Widget::UnitTracker; using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; -using Inkscape::UI::PrefPusher; using Inkscape::Util::unit_table; diff --git a/src/ui/toolbar/pencil-toolbar.cpp b/src/ui/toolbar/pencil-toolbar.cpp index b20393ba1..165977a86 100644 --- a/src/ui/toolbar/pencil-toolbar.cpp +++ b/src/ui/toolbar/pencil-toolbar.cpp @@ -60,7 +60,6 @@ using Inkscape::UI::UXManager; using Inkscape::UI::ToolboxFactory; -using Inkscape::UI::PrefPusher; /* diff --git a/src/ui/toolbar/rect-toolbar.cpp b/src/ui/toolbar/rect-toolbar.cpp index 44d0cc7ce..e97e7c8ee 100644 --- a/src/ui/toolbar/rect-toolbar.cpp +++ b/src/ui/toolbar/rect-toolbar.cpp @@ -56,7 +56,6 @@ using Inkscape::UI::Widget::UnitTracker; using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; -using Inkscape::UI::PrefPusher; using Inkscape::Util::Unit; using Inkscape::Util::Quantity; using Inkscape::Util::unit_table; diff --git a/src/ui/toolbar/spiral-toolbar.cpp b/src/ui/toolbar/spiral-toolbar.cpp index 4792d6f6b..ba50f4772 100644 --- a/src/ui/toolbar/spiral-toolbar.cpp +++ b/src/ui/toolbar/spiral-toolbar.cpp @@ -51,7 +51,6 @@ using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; -using Inkscape::UI::PrefPusher; static Inkscape::XML::NodeEventVector spiral_tb_repr_events = { nullptr, /* child_added */ diff --git a/src/ui/toolbar/spray-toolbar.cpp b/src/ui/toolbar/spray-toolbar.cpp index f38aee05e..1a69af8b8 100644 --- a/src/ui/toolbar/spray-toolbar.cpp +++ b/src/ui/toolbar/spray-toolbar.cpp @@ -37,6 +37,7 @@ #include "ui/dialog/clonetiler.h" #include "ui/dialog/dialog-manager.h" #include "ui/dialog/panel-dialog.h" +#include "ui/pref-pusher.h" #include "ui/widget/ink-select-one-action.h" #include "ui/icon-names.h" @@ -72,6 +73,10 @@ Inkscape::UI::Dialog::CloneTiler *get_clone_tiler_panel(SPDesktop *desktop) namespace Inkscape { namespace UI { namespace Toolbar { +SprayToolbar::SprayToolbar(SPDesktop *desktop) : + Toolbar(desktop) +{} + GtkWidget * SprayToolbar::prep(SPDesktop *desktop, GtkActionGroup* mainActions) { diff --git a/src/ui/toolbar/spray-toolbar.h b/src/ui/toolbar/spray-toolbar.h index 5f0065680..7d6cad56d 100644 --- a/src/ui/toolbar/spray-toolbar.h +++ b/src/ui/toolbar/spray-toolbar.h @@ -105,9 +105,7 @@ private: gpointer user_data); protected: - SprayToolbar(SPDesktop *desktop) : - Toolbar(desktop) - {} + SprayToolbar(SPDesktop *desktop); public: static GtkWidget * prep(SPDesktop *desktop, GtkActionGroup* mainActions); diff --git a/src/ui/toolbar/star-toolbar.cpp b/src/ui/toolbar/star-toolbar.cpp index 18bc1c2ec..b656f8cdb 100644 --- a/src/ui/toolbar/star-toolbar.cpp +++ b/src/ui/toolbar/star-toolbar.cpp @@ -51,7 +51,6 @@ using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; -using Inkscape::UI::PrefPusher; //######################## diff --git a/src/ui/toolbar/text-toolbar.cpp b/src/ui/toolbar/text-toolbar.cpp index b55ed02ed..f6ad7f4e6 100644 --- a/src/ui/toolbar/text-toolbar.cpp +++ b/src/ui/toolbar/text-toolbar.cpp @@ -64,7 +64,6 @@ using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; -using Inkscape::UI::PrefPusher; using Inkscape::Util::Unit; using Inkscape::Util::Quantity; using Inkscape::Util::unit_table; diff --git a/src/ui/toolbar/tweak-toolbar.cpp b/src/ui/toolbar/tweak-toolbar.cpp index e3a58ff24..d6bc11cc6 100644 --- a/src/ui/toolbar/tweak-toolbar.cpp +++ b/src/ui/toolbar/tweak-toolbar.cpp @@ -45,8 +45,6 @@ using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; -using Inkscape::UI::PrefPusher; - //######################## //## Tweak ## |
