[gtk+] GtkMenuTrackerItem: add support for dynamic accels
- From: Ryan Lortie <desrt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] GtkMenuTrackerItem: add support for dynamic accels
- Date: Tue, 15 Oct 2013 13:24:41 +0000 (UTC)
commit afa8b0178fa57b49eb13aa4c4e3b460bcedcd9c9
Author: Ryan Lortie <desrt desrt ca>
Date: Tue Jul 9 22:50:14 2013 -0400
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.
gtk/gtkmenutrackeritem.c | 27 ++++++++++++++++++++++++---
1 files changed, 24 insertions(+), 3 deletions(-)
---
diff --git a/gtk/gtkmenutrackeritem.c b/gtk/gtkmenutrackeritem.c
index 22bc394..d220041 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 *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]