What is acceptable as an action proxy ?



Currently, GtkActions can connect to toolbuttons and menuitems. It would
be very easy to make this work for regular buttons as well. While I
don't think it makes a lot of sense to generate the buttons from an
XML ui description, being able to write

  button = gtk_toggle_button_new ();
  action = gtk_action_group_get_action (action_group, "toggle-cnp");
  gtk_action_connect_proxy (action, button);

and have the button automatically activate the same action as the
corresponding menu and toolbar entries and monitor the sensitivity of
the action might be handy.

What do you think about this ?

Matthias



Index: gtkaction.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkaction.c,v
retrieving revision 1.2
diff -u -p -r1.2 gtkaction.c
--- gtkaction.c	26 Aug 2003 00:13:57 -0000	1.2
+++ gtkaction.c	27 Aug 2003 23:52:36 -0000
@@ -31,6 +31,7 @@
 #include <config.h>
 
 #include "gtkaction.h"
+#include "gtkbutton.h"
 #include "gtktoolbutton.h"
 #include "gtkmenuitem.h"
 #include "gtkimagemenuitem.h"
@@ -602,6 +603,23 @@ connect_proxy (GtkAction *action, 
 			       G_CALLBACK (gtk_action_create_menu_proxy),
 			       action, 0);
 
+      g_signal_connect_object (proxy, "clicked",
+			       G_CALLBACK (gtk_action_activate), action,
+			       G_CONNECT_SWAPPED);
+    }
+  else if (GTK_IS_BUTTON (proxy))
+    {
+      /* button specific synchronisers ... */
+
+      /* synchronise the label */
+      g_object_set (G_OBJECT (proxy),
+		    "label", action->private_data->short_label,
+		    "use_underline", TRUE,
+		    NULL);
+      g_signal_connect_object (action, "notify::short_label",
+			       G_CALLBACK (gtk_action_sync_short_label),
+			       proxy, 0);
+      
       g_signal_connect_object (proxy, "clicked",
 			       G_CALLBACK (gtk_action_activate), action,
 			       G_CONNECT_SWAPPED);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]