diff options
author | Nick Dedekind <nicholas.dedekind@gmail.com> | 2013-08-05 14:29:26 +0200 |
---|---|---|
committer | Lars Uebernickel <lars.uebernickel@canonical.com> | 2013-08-05 14:29:26 +0200 |
commit | 248ae8dd5cd8320c82b4f85d0d7a3aba43a207c1 (patch) | |
tree | bcc04f481df7fc018c7b415272e89cbc23145eb1 /libqmenumodel/src/gtk | |
parent | d1c96de04570d8365c2ab2fde597ccd21c7a3dc2 (diff) | |
parent | 27e7c3bf6ee276c5956331f292a72a5dde5869ed (diff) | |
download | qmenumodel-248ae8dd5cd8320c82b4f85d0d7a3aba43a207c1.tar.gz qmenumodel-248ae8dd5cd8320c82b4f85d0d7a3aba43a207c1.tar.bz2 qmenumodel-248ae8dd5cd8320c82b4f85d0d7a3aba43a207c1.zip |
Allow changing action state
Diffstat (limited to 'libqmenumodel/src/gtk')
-rw-r--r-- | libqmenumodel/src/gtk/gtkmenutrackeritem.c | 43 | ||||
-rw-r--r-- | libqmenumodel/src/gtk/gtkmenutrackeritem.h | 8 |
2 files changed, 51 insertions, 0 deletions
diff --git a/libqmenumodel/src/gtk/gtkmenutrackeritem.c b/libqmenumodel/src/gtk/gtkmenutrackeritem.c index fb856c9..e2ed1f0 100644 --- a/libqmenumodel/src/gtk/gtkmenutrackeritem.c +++ b/libqmenumodel/src/gtk/gtkmenutrackeritem.c @@ -106,6 +106,7 @@ enum { PROP_TOGGLED, PROP_ACCEL, PROP_SUBMENU_SHOWN, + PROP_ACTION_NAME, PROP_ACTION_STATE, N_PROPS }; @@ -179,6 +180,8 @@ gtk_menu_tracker_item_get_property (GObject *object, case PROP_SUBMENU_SHOWN: g_value_set_boolean (value, gtk_menu_tracker_item_get_submenu_shown (self)); break; + case PROP_ACTION_NAME: + g_value_set_string (value, gtk_menu_tracker_item_get_action_name (self)); case PROP_ACTION_STATE: g_value_set_variant (value, self->action_state); break; @@ -239,6 +242,8 @@ gtk_menu_tracker_item_class_init (GtkMenuTrackerItemClass *class) g_param_spec_string ("accel", "", "", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE); gtk_menu_tracker_item_pspecs[PROP_SUBMENU_SHOWN] = g_param_spec_boolean ("submenu-shown", "", "", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE); + gtk_menu_tracker_item_pspecs[PROP_ACTION_NAME] = + g_param_spec_boolean ("action-name", "", "", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE); gtk_menu_tracker_item_pspecs[PROP_ACTION_STATE] = g_param_spec_boolean ("action-state", "", "", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE); @@ -612,6 +617,22 @@ gtk_menu_tracker_item_get_submenu_shown (GtkMenuTrackerItem *self) return self->submenu_shown; } +/** + * gtk_menu_tracker_item_get_action_name: + * @self: A #GtkMenuTrackerItem instance + * + * Returns the action name + */ +const gchar * +gtk_menu_tracker_item_get_action_name (GtkMenuTrackerItem *self) +{ + const gchar *action_name = NULL; + + g_menu_item_get_attribute (self->item, G_MENU_ATTRIBUTE_ACTION, "&s", &action_name); + + return action_name; +} + GVariant * gtk_menu_tracker_item_get_action_state (GtkMenuTrackerItem *self) { @@ -661,6 +682,28 @@ gtk_menu_tracker_item_activated (GtkMenuTrackerItem *self) g_variant_unref (action_target); } +void +gtk_menu_tracker_item_change_state (GtkMenuTrackerItem *self, + GVariant *value) +{ + const gchar *action_name; + + g_return_if_fail (GTK_IS_MENU_TRACKER_ITEM (self)); + + g_menu_item_get_attribute (self->item, G_MENU_ATTRIBUTE_ACTION, "&s", &action_name); + + if (self->action_namespace) + { + gchar *full_action; + + full_action = g_strjoin (".", self->action_namespace, action_name, NULL); + g_action_group_change_action_state (G_ACTION_GROUP (self->observable), full_action, g_variant_ref(value)); + g_free (full_action); + } + else + g_action_group_change_action_state (G_ACTION_GROUP (self->observable), action_name, g_variant_ref(value)); +} + typedef struct { GtkMenuTrackerItem *item; diff --git a/libqmenumodel/src/gtk/gtkmenutrackeritem.h b/libqmenumodel/src/gtk/gtkmenutrackeritem.h index 16c4415..59a7080 100644 --- a/libqmenumodel/src/gtk/gtkmenutrackeritem.h +++ b/libqmenumodel/src/gtk/gtkmenutrackeritem.h @@ -76,11 +76,19 @@ gboolean gtk_menu_tracker_item_get_should_request_show (GtkMenu void gtk_menu_tracker_item_activated (GtkMenuTrackerItem *self); +void gtk_menu_tracker_item_change_state (GtkMenuTrackerItem *self, + GVariant *value); + + + + void gtk_menu_tracker_item_request_submenu_shown (GtkMenuTrackerItem *self, gboolean shown); gboolean gtk_menu_tracker_item_get_submenu_shown (GtkMenuTrackerItem *self); +const gchar * gtk_menu_tracker_item_get_action_name (GtkMenuTrackerItem *self); + GVariant * gtk_menu_tracker_item_get_action_state (GtkMenuTrackerItem *self); gboolean gtk_menu_tracker_item_get_attribute (GtkMenuTrackerItem *self, |