diff options
author | Ryan Lortie <desrt@desrt.ca> | 2013-07-09 22:50:14 -0400 |
---|---|---|
committer | Ryan Lortie <desrt@desrt.ca> | 2013-10-15 09:24:12 -0400 |
commit | afa8b0178fa57b49eb13aa4c4e3b460bcedcd9c9 (patch) | |
tree | d1a1a8fa3ef41926f4176447afe25549840c5dfc /gtk/gtkmenutrackeritem.c | |
parent | 2074daccf5ac06342e66620ef0fef5e76bd03275 (diff) | |
download | gtk+-afa8b0178fa57b49eb13aa4c4e3b460bcedcd9c9.tar.gz |
GtkMenuTrackerItem: add support for dynamic accels
Add support for pulling the primary accel out of the GtkActionMuxer.
With this change, it is no longer necessary to have the accel=''
attribute hardcoded onto each menu item (and, in fact, it should be left
off if you intend to have support for dynamic accelerator changing).
Specifying accel='' is a good way to force an accelerator not to be
displayed on a menu item.
Diffstat (limited to 'gtk/gtkmenutrackeritem.c')
-rw-r--r-- | gtk/gtkmenutrackeritem.c | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/gtk/gtkmenutrackeritem.c b/gtk/gtkmenutrackeritem.c index 22bc394de5..d220041174 100644 --- a/gtk/gtkmenutrackeritem.c +++ b/gtk/gtkmenutrackeritem.c @@ -22,6 +22,7 @@ #include "config.h" #include "gtkmenutrackeritem.h" +#include "gtkactionmuxer.h" #include "gtkactionmuxer.h" @@ -380,12 +381,25 @@ gtk_menu_tracker_item_action_removed (GtkActionObserver *observer, } static void +gtk_menu_tracker_item_primary_accel_changed (GtkActionObserver *observer, + GtkActionObservable *observable, + const gchar *action_name, + const gchar *action_and_target) +{ + GtkMenuTrackerItem *self = GTK_MENU_TRACKER_ITEM (observer); + + if (g_str_equal (action_and_target, self->action_and_target)) + g_object_notify_by_pspec (G_OBJECT (self), gtk_menu_tracker_item_pspecs[PROP_ACCEL]); +} + +static void gtk_menu_tracker_item_init_observer_iface (GtkActionObserverInterface *iface) { iface->action_added = gtk_menu_tracker_item_action_added; iface->action_enabled_changed = gtk_menu_tracker_item_action_enabled_changed; iface->action_state_changed = gtk_menu_tracker_item_action_state_changed; iface->action_removed = gtk_menu_tracker_item_action_removed; + iface->primary_accel_changed = gtk_menu_tracker_item_primary_accel_changed; } GtkMenuTrackerItem * @@ -547,11 +561,18 @@ gtk_menu_tracker_item_get_toggled (GtkMenuTrackerItem *self) const gchar * gtk_menu_tracker_item_get_accel (GtkMenuTrackerItem *self) { - const gchar *accel = NULL; + const gchar *accel; + + if (!self->action_and_target) + return NULL; - g_menu_item_get_attribute (self->item, "accel", "&s", &accel); + if (g_menu_item_get_attribute (self->item, "accel", "&s", &accel)) + return accel; + + if (!GTK_IS_ACTION_MUXER (self->observable)) + return NULL; - return accel; + return gtk_action_muxer_get_primary_accel (GTK_ACTION_MUXER (self->observable), self->action_and_target); } GMenuModel * |