Code

Fix "show handles" button state on Ctrl+H
authorKrzysztof Kosiński <tweenk.pl@gmail.com>
Tue, 6 Apr 2010 14:47:48 +0000 (16:47 +0200)
committerKrzysztof Kosiński <tweenk.pl@gmail.com>
Tue, 6 Apr 2010 14:47:48 +0000 (16:47 +0200)
src/widgets/toolbox.cpp

index 4b0d84d90a0a5d0b0ef26811ecaea244f93bc089..5c890333f049bea49f4d76fa430982a8c63aa7cb 100644 (file)
@@ -1289,6 +1289,31 @@ sp_node_toolbox_sel_modified (Inkscape::Selection *selection, guint /*flags*/, G
 //##    Node Editing Toolbox    ##
 //################################
 
+class ShowHandlesObserver
+    : public Inkscape::Preferences::Observer
+{
+public:
+    ShowHandlesObserver(InkToggleAction *act)
+        : Inkscape::Preferences::Observer("/tools/nodes/show_handles")
+        , _act(act)
+    {
+        Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+        prefs->addObserver(*this);
+    }
+    ~ShowHandlesObserver() {
+        Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+        prefs->removeObserver(*this);
+    }
+    virtual void notify(Inkscape::Preferences::Entry const &v) {
+        gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(_act), v.getBool());
+    }
+    static void destroy(ShowHandlesObserver *s, InkToggleAction *) {
+        delete s;
+    }
+private:
+    InkToggleAction *_act;
+};
+
 static void sp_node_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder)
 {
     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
@@ -1442,6 +1467,8 @@ static void sp_node_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions
         gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
         g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_show_handles), desktop );
         gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/nodes/show_handles", true) );
+        ShowHandlesObserver *s = new ShowHandlesObserver(act);
+        g_object_weak_ref(G_OBJECT(act), (GWeakNotify) ShowHandlesObserver::destroy, (gpointer) s);
     }
 
     {