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.
This commit is contained in:
Ryan Lortie 2013-07-09 22:50:14 -04:00
parent 2074daccf5
commit afa8b0178f

View File

@ -22,6 +22,7 @@
#include "config.h"
#include "gtkmenutrackeritem.h"
#include "gtkactionmuxer.h"
#include "gtkactionmuxer.h"
@ -379,6 +380,18 @@ gtk_menu_tracker_item_action_removed (GtkActionObserver *observer,
g_object_thaw_notify (G_OBJECT (self));
}
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)
{
@ -386,6 +399,7 @@ gtk_menu_tracker_item_init_observer_iface (GtkActionObserverInterface *iface)
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;
g_menu_item_get_attribute (self->item, "accel", "&s", &accel);
if (!self->action_and_target)
return NULL;
return accel;
if (g_menu_item_get_attribute (self->item, "accel", "&s", &accel))
return accel;
if (!GTK_IS_ACTION_MUXER (self->observable))
return NULL;
return gtk_action_muxer_get_primary_accel (GTK_ACTION_MUXER (self->observable), self->action_and_target);
}
GMenuModel *