[gtk+/wip/gmenu: 18/87] testgmenu: Use activate for toggle actions
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/gmenu: 18/87] testgmenu: Use activate for toggle actions
- Date: Sat, 3 Dec 2011 23:49:40 +0000 (UTC)
commit 2f68fc90fa74c33ee2dc926777f7a607fdc64c7b
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Nov 26 11:56:42 2011 -0500
testgmenu: Use activate for toggle actions
This is how stateful actions are supposed to be activated, using
change_state for this was not right at all.
tests/testgmenu.c | 42 +++++++++++++++++++++---------------------
1 files changed, 21 insertions(+), 21 deletions(-)
---
diff --git a/tests/testgmenu.c b/tests/testgmenu.c
index 4674362..68b8340 100644
--- a/tests/testgmenu.c
+++ b/tests/testgmenu.c
@@ -90,6 +90,7 @@ typedef struct {
gchar *target;
gulong enabled_changed_id;
gulong state_changed_id;
+ gulong activate_handler;
} ActionData;
static void
@@ -125,7 +126,12 @@ toggle_state_changed (GActionGroup *group,
GVariant *state,
GtkCheckMenuItem *w)
{
+ ActionData *a;
+
+ a = g_object_get_data (G_OBJECT (w), "action");
+ g_signal_handler_block (w, a->activate_handler);
gtk_check_menu_item_set_active (w, g_variant_get_boolean (state));
+ g_signal_handler_unblock (w, a->activate_handler);
}
static void
@@ -156,19 +162,6 @@ item_activated (GtkWidget *w,
}
static void
-toggle_item_toggled (GtkCheckMenuItem *w,
- gpointer data)
-{
- ActionData *a;
- gboolean b;
-
- a = g_object_get_data (G_OBJECT (w), "action");
- b = gtk_check_menu_item_get_active (w);
- g_action_group_change_action_state (a->group, a->name,
- g_variant_new_boolean (b));
-}
-
-static void
radio_item_toggled (GtkCheckMenuItem *w,
gpointer data)
{
@@ -244,10 +237,10 @@ create_menuitem_from_model (GMenuModel *model,
g_free (s);
if (type == NULL)
- g_signal_connect (w, "activate", G_CALLBACK (item_activated), NULL);
+ a->activate_handler = g_signal_connect (w, "activate", G_CALLBACK (item_activated), NULL);
else if (g_variant_type_equal (type, G_VARIANT_TYPE_BOOLEAN))
{
- g_signal_connect (w, "toggled", G_CALLBACK (toggle_item_toggled), NULL);
+ a->activate_handler = g_signal_connect (w, "activate", G_CALLBACK (item_activated), NULL);
s = g_strconcat ("action-state-changed::", action, NULL);
a->state_changed_id = g_signal_connect (group, s,
G_CALLBACK (toggle_state_changed), w);
@@ -462,13 +455,20 @@ activate_action (GSimpleAction *action, GVariant *parameter, gpointer user_data)
}
static void
-toggle_changed (GSimpleAction *action, GVariant *value, gpointer user_data)
+activate_toggle (GSimpleAction *action, GVariant *parameter, gpointer user_data)
{
- g_print ("Toggle action %s state changed to %d\n",
+ GVariant *old_state, *new_state;
+
+ old_state = g_action_get_state (G_ACTION (action));
+ new_state = g_variant_new_boolean (!g_variant_get_boolean (old_state));
+
+ g_print ("Toggle action %s activated, state changes from %d to %d\n",
g_action_get_name (G_ACTION (action)),
- g_variant_get_boolean (value));
+ g_variant_get_boolean (old_state),
+ g_variant_get_boolean (new_state));
- g_simple_action_set_state (action, value);
+ g_simple_action_set_state (action, new_state);
+ g_variant_unref (old_state);
}
static void
@@ -487,7 +487,7 @@ static GActionEntry actions[] = {
{ "cut", activate_action, NULL, NULL, NULL },
{ "copy", activate_action, NULL, NULL, NULL },
{ "paste", activate_action, NULL, NULL, NULL },
- { "bold", NULL, NULL, "true", toggle_changed },
+ { "bold", activate_toggle, NULL, "true", NULL },
{ "lang", NULL, NULL, "'latin'", radio_changed },
};
@@ -803,7 +803,7 @@ toggle_italic (GtkToggleButton *button, gpointer data)
{
action = g_simple_action_new_stateful ("italic", NULL, g_variant_new_boolean (FALSE));
g_simple_action_group_insert (G_SIMPLE_ACTION_GROUP (group), G_ACTION (action));
- g_signal_connect (action, "change-state", G_CALLBACK (toggle_changed), NULL);
+ g_signal_connect (action, "activate", G_CALLBACK (activate_toggle), NULL);
g_object_unref (action);
action_list_add (store, "italic");
g_menu_insert (G_MENU (m), 1, "Italic", "italic");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]