im.pidgin.pidgin.next.minor: 51f805cc8b320f8908d9b9d6049078631c011dc6

sadrul at pidgin.im sadrul at pidgin.im
Sat Oct 20 01:50:47 EDT 2007


-----------------------------------------------------------------
Revision: 51f805cc8b320f8908d9b9d6049078631c011dc6
Ancestor: 6b41377e2b7f1084d5d3115aed3cd16fe876128b
Author: sadrul at pidgin.im
Date: 2007-10-20T05:52:52
Branch: im.pidgin.pidgin.next.minor

Modified files:
        ChangeLog.API finch/libgnt/gntmenu.c
        finch/libgnt/gntmenuitem.c finch/libgnt/gntmenuitem.h

ChangeLog: 

Add gnt_menuitem_activate, and 'activate' signal for GntMenuItem.

-------------- next part --------------
============================================================
--- ChangeLog.API	f7b5a6570ae0ba270ca65e251e483594318cfdfa
+++ ChangeLog.API	11580a9fd951a85ec11225d41919683afea1026b
@@ -104,6 +104,8 @@ version 2.3.0 (??/??/????):
 		  bound to a keystroke.
 		* Added gnt_menu_get_item to activate and return a menuitem of the
 		  given id from a menu.
+		* Added gnt_menuitem_activate, which triggers the 'activate' signal on
+		  the menuitem and calls the callback function, if available.
 
 version 2.2.2 (??/??/????):
 	libpurple:
============================================================
--- finch/libgnt/gntmenu.c	70c40d772370f9b7f3e9beb1513ab0e089ec600f
+++ finch/libgnt/gntmenu.c	d74770a6a8fed6a1999c6842417980d24e568cde
@@ -181,7 +181,15 @@ menuitem_activate(GntMenu *menu, GntMenu
 static void
 menuitem_activate(GntMenu *menu, GntMenuItem *item)
 {
-	if (item) {
+	if (!item)
+		return;
+
+	if (gnt_menuitem_activate(item)) {
+		while (menu) {
+			gnt_widget_hide(GNT_WIDGET(menu));
+			menu = menu->parentmenu;
+		}
+	} else {
 		if (item->submenu) {
 			GntMenu *sub = GNT_MENU(item->submenu);
 			menu->submenu = sub;
@@ -195,12 +203,6 @@ menuitem_activate(GntMenu *menu, GntMenu
 			gnt_widget_set_position(GNT_WIDGET(sub), item->priv.x, item->priv.y);
 			GNT_WIDGET_UNSET_FLAGS(GNT_WIDGET(sub), GNT_WIDGET_INVISIBLE);
 			gnt_widget_draw(GNT_WIDGET(sub));
-		} else if (item->callback) {
-			item->callback(item, item->callbackdata);
-			while (menu) {
-				gnt_widget_hide(GNT_WIDGET(menu));
-				menu = menu->parentmenu;
-			}
 		}
 	}
 }
@@ -326,8 +328,7 @@ gnt_menu_toggled(GntTree *tree, gpointer
 	GntMenu *menu = GNT_MENU(tree);
 	gboolean check = gnt_menuitem_check_get_checked(GNT_MENU_ITEM_CHECK(item));
 	gnt_menuitem_check_set_checked(GNT_MENU_ITEM_CHECK(item), !check);
-	if (item->callback)
-		item->callback(item, item->callbackdata);
+	gnt_menuitem_activate(item);
 	while (menu) {
 		gnt_widget_hide(GNT_WIDGET(menu));
 		menu = menu->parentmenu;
============================================================
--- finch/libgnt/gntmenuitem.c	a55c798823969a932e993976b4ab9cd2852d2e03
+++ finch/libgnt/gntmenuitem.c	9480410c5eb485a343e59f825af742affde56d03
@@ -23,6 +23,13 @@
 #include "gntmenu.h"
 #include "gntmenuitem.h"
 
+enum
+{
+	SIG_ACTIVATE,
+	SIGS
+};
+static guint signals[SIGS] = { 0 };
+
 static GObjectClass *parent_class = NULL;
 
 static void
@@ -44,10 +51,18 @@ gnt_menuitem_class_init(GntMenuItemClass
 	parent_class = g_type_class_peek_parent(klass);
 
 	obj_class->dispose = gnt_menuitem_destroy;
+
+	signals[SIG_ACTIVATE] =
+		g_signal_new("activate",
+					 G_TYPE_FROM_CLASS(klass),
+					 G_SIGNAL_RUN_LAST,
+					 0, NULL, NULL,
+					 g_cclosure_marshal_VOID__VOID,
+					 G_TYPE_NONE, 0);
 }
 
 static void
-gnt_menuitem_init(GTypeInstance *instance, gpointer class)
+gnt_menuitem_init(GTypeInstance *instance, gpointer klass)
 {
 }
 
@@ -131,3 +146,13 @@ const char * gnt_menuitem_get_id(GntMenu
 	return item->priv.id;
 }
 
+gboolean gnt_menuitem_activate(GntMenuItem *item)
+{
+	g_signal_emit(item, signals[SIG_ACTIVATE], 0);
+	if (item->callback) {
+		item->callback(item, item->callbackdata);
+		return TRUE;
+	}
+	return FALSE;
+}
+
============================================================
--- finch/libgnt/gntmenuitem.h	d9355e4ae960318b710bef839b16ec4fee8d15fc
+++ finch/libgnt/gntmenuitem.h	85b21488682cb71bde647510cdceb12f1838f4fd
@@ -168,6 +168,19 @@ const char * gnt_menuitem_get_id(GntMenu
  */
 const char * gnt_menuitem_get_id(GntMenuItem *item);
 
+/**
+ * Activate a menuitem.
+ * Activating the menuitem will first trigger the 'activate' signal for the
+ * menuitem. Then the callback for the menuitem is triggered, if there is one.
+ *
+ * @param item   The menuitem.
+ *
+ * @return  Whether the callback for the menuitem was called.
+ *
+ * @since 2.3.0
+ */
+gboolean gnt_menuitem_activate(GntMenuItem *item);
+
 G_END_DECLS
 
 #endif /* GNT_MENUITEM_H */


More information about the Commits mailing list