summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Lortie <desrt@desrt.ca>2013-07-09 22:48:29 -0400
committerRyan Lortie <desrt@desrt.ca>2013-10-15 09:24:11 -0400
commit2074daccf5ac06342e66620ef0fef5e76bd03275 (patch)
tree24a5f9c1ae26dbb7a735147742c6c38642eee6e9
parent3f8c235593ec093d84545462d1d36797bcefdc16 (diff)
downloadgtk+-2074daccf5ac06342e66620ef0fef5e76bd03275.tar.gz
GtkMenuTrackerItem: use "action and target" format
Store "action and target" format inside each GtkMenuTrackerItem. This makes action invocation more efficient (no hash table lookups or allocations) and slightly simplifies handling of action namespace. More importantly, this will be used when we start to get accels from GtkActionMuxer.
-rw-r--r--gtk/gtkmenutrackeritem.c44
1 files changed, 19 insertions, 25 deletions
diff --git a/gtk/gtkmenutrackeritem.c b/gtk/gtkmenutrackeritem.c
index 2d712a1c1b..22bc394de5 100644
--- a/gtk/gtkmenutrackeritem.c
+++ b/gtk/gtkmenutrackeritem.c
@@ -23,6 +23,10 @@
#include "gtkmenutrackeritem.h"
+#include "gtkactionmuxer.h"
+
+#include <string.h>
+
/**
* SECTION:gtkmenutrackeritem
* @Title: GtkMenuTrackerItem
@@ -83,6 +87,7 @@ struct _GtkMenuTrackerItem
GtkActionObservable *observable;
gchar *action_namespace;
+ gchar *action_and_target;
GMenuItem *item;
GtkMenuTrackerItemRole role : 4;
guint is_separator : 1;
@@ -406,26 +411,24 @@ _gtk_menu_tracker_item_new (GtkActionObservable *observable,
{
GActionGroup *group = G_ACTION_GROUP (observable);
const GVariantType *parameter_type;
+ GVariant *target;
gboolean enabled;
GVariant *state;
gboolean found;
- state = NULL;
+ target = g_menu_item_get_attribute_value (self->item, "target", NULL);
- if (action_namespace)
- {
- gchar *full_action;
+ self->action_and_target = gtk_print_action_and_target (action_namespace, action_name, target);
- full_action = g_strjoin (".", action_namespace, action_name, NULL);
- gtk_action_observable_register_observer (self->observable, full_action, GTK_ACTION_OBSERVER (self));
- found = g_action_group_query_action (group, full_action, &enabled, &parameter_type, NULL, NULL, &state);
- g_free (full_action);
- }
- else
- {
- gtk_action_observable_register_observer (self->observable, action_name, GTK_ACTION_OBSERVER (self));
- found = g_action_group_query_action (group, action_name, &enabled, &parameter_type, NULL, NULL, &state);
- }
+ if (target)
+ g_variant_unref (target);
+
+ action_name = strrchr (self->action_and_target, '|') + 1;
+
+ state = NULL;
+
+ gtk_action_observable_register_observer (self->observable, action_name, GTK_ACTION_OBSERVER (self));
+ found = g_action_group_query_action (group, action_name, &enabled, &parameter_type, NULL, NULL, &state);
if (found)
gtk_menu_tracker_item_action_added (GTK_ACTION_OBSERVER (self), observable, NULL, parameter_type, enabled, state);
@@ -607,19 +610,10 @@ gtk_menu_tracker_item_activated (GtkMenuTrackerItem *self)
if (!self->can_activate)
return;
- g_menu_item_get_attribute (self->item, G_MENU_ATTRIBUTE_ACTION, "&s", &action_name);
+ action_name = strrchr (self->action_and_target, '|') + 1;
action_target = g_menu_item_get_attribute_value (self->item, G_MENU_ATTRIBUTE_TARGET, NULL);
- if (self->action_namespace)
- {
- gchar *full_action;
-
- full_action = g_strjoin (".", self->action_namespace, action_name, NULL);
- g_action_group_activate_action (G_ACTION_GROUP (self->observable), full_action, action_target);
- g_free (full_action);
- }
- else
- g_action_group_activate_action (G_ACTION_GROUP (self->observable), action_name, action_target);
+ g_action_group_activate_action (G_ACTION_GROUP (self->observable), action_name, action_target);
if (action_target)
g_variant_unref (action_target);