[gtk+] GtkApplication: use activate for actions here, too
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] GtkApplication: use activate for actions here, too
- Date: Mon, 19 Dec 2011 17:55:38 +0000 (UTC)
commit 92af3d04b88adcfea5170cd69ddc992cb8ec7c97
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Nov 26 13:06:04 2011 -0500
GtkApplication: use activate for actions here, too
gtk/gtkapplication.c | 59 +++++++++++++++++---------------------------------
1 files changed, 20 insertions(+), 39 deletions(-)
---
diff --git a/gtk/gtkapplication.c b/gtk/gtkapplication.c
index 38d2e9c..9bbc4c2 100644
--- a/gtk/gtkapplication.c
+++ b/gtk/gtkapplication.c
@@ -359,6 +359,7 @@ typedef struct {
gchar *target;
gulong enabled_changed_id;
gulong state_changed_id;
+ gulong activate_handler;
} ActionData;
static void
@@ -393,44 +394,16 @@ item_activated (GtkWidget *w,
gpointer data)
{
ActionData *a;
+ GVariant *parameter;
a = g_object_get_data (G_OBJECT (w), "action");
- g_action_group_activate_action (a->group, a->name, NULL);
-}
-
-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)
-{
- ActionData *a;
- GVariant *v;
-
- a = g_object_get_data (G_OBJECT (w), "action");
- if (gtk_check_menu_item_get_active (w))
- {
- g_action_group_change_action_state (a->group, a->name,
- g_variant_new_string (a->target));
- }
+ if (a->target)
+ parameter = g_variant_ref_sink (g_variant_new_string (a->target));
else
- {
- v = g_action_group_get_action_state (a->group, a->name);
- if (g_strcmp0 (g_variant_get_string (v, NULL), a->target) == 0)
- gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (w), TRUE);
- g_variant_unref (v);
- }
+ parameter = NULL;
+ g_action_group_activate_action (a->group, a->name, parameter);
+ if (parameter)
+ g_variant_unref (parameter);
}
static void
@@ -439,7 +412,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
@@ -452,9 +430,10 @@ radio_state_changed (GActionGroup *group,
gboolean b;
a = g_object_get_data (G_OBJECT (w), "action");
+ g_signal_handler_block (w, a->activate_handler);
b = g_strcmp0 (a->target, g_variant_get_string (state, NULL)) == 0;
-
gtk_check_menu_item_set_active (w, b);
+ g_signal_handler_unblock (w, a->activate_handler);
}
static GtkWidget *
@@ -507,12 +486,15 @@ create_menuitem_from_model (GMenuModel *model,
a->enabled_changed_id = g_signal_connect (group, s,
G_CALLBACK (enabled_changed), w);
g_free (s);
+ a->activate_handler = g_signal_connect (w, "activate",
+ G_CALLBACK (item_activated), NULL);
if (type == NULL)
- g_signal_connect (w, "activate", G_CALLBACK (item_activated), NULL);
+ {
+ /* all set */
+ }
else if (g_variant_type_equal (type, G_VARIANT_TYPE_BOOLEAN))
{
- g_signal_connect (w, "toggled", G_CALLBACK (toggle_item_toggled), NULL);
s = g_strconcat ("action-state-changed::", action, NULL);
a->state_changed_id = g_signal_connect (group, s,
G_CALLBACK (toggle_state_changed), w);
@@ -524,7 +506,6 @@ create_menuitem_from_model (GMenuModel *model,
}
else if (g_variant_type_equal (type, G_VARIANT_TYPE_STRING))
{
- g_signal_connect (w, "toggled", G_CALLBACK (radio_item_toggled), NULL);
s = g_strconcat ("action-state-changed::", action, NULL);
a->state_changed_id = g_signal_connect (group, s,
G_CALLBACK (radio_state_changed), w);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]