diff options
author | Matthias Clasen <mclasen@redhat.com> | 2011-12-05 17:14:57 -0500 |
---|---|---|
committer | Ryan Lortie <desrt@desrt.ca> | 2011-12-19 12:51:11 -0500 |
commit | 1c6d0c3e274a932450cb66f5fd3ff2a29c40e91b (patch) | |
tree | 2088ff62c9f5e3b3e4a44eff623a11777bda18fe /gtk/gtkmodelmenuitem.c | |
parent | 9d62d24d6591510101b64eae400206d406fb5604 (diff) | |
download | gtk+-1c6d0c3e274a932450cb66f5fd3ff2a29c40e91b.tar.gz |
GtkApplicationWindow: Set the accel group on constructed windows
This will make the menuitems pick up matching accel map entries
automatically. Currently, nothing creates such accel map entries,
though.
Diffstat (limited to 'gtk/gtkmodelmenuitem.c')
-rw-r--r-- | gtk/gtkmodelmenuitem.c | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/gtk/gtkmodelmenuitem.c b/gtk/gtkmodelmenuitem.c index 30ca3f4fc0..4e2fd09d0f 100644 --- a/gtk/gtkmodelmenuitem.c +++ b/gtk/gtkmodelmenuitem.c @@ -23,6 +23,7 @@ #include "gtkmodelmenuitem.h" +#include "gtkaccelmap.h" #include "gtkmodelmenu.h" struct _GtkModelMenuItem @@ -188,11 +189,28 @@ gtk_model_menu_item_action_removed (GActionObserver *observer, gtk_widget_queue_resize (GTK_WIDGET (item)); } +static gchar * +get_accel_path (const gchar *action_name, + GVariant *parameter) +{ + GString *s; + + s = g_string_new ("<Actions>/"); + g_string_append (s, action_name); + if (parameter) + { + g_string_append_c (s, '/'); + g_variant_print_string (parameter, s, FALSE); + } + return g_string_free (s, FALSE); +} + static void gtk_model_menu_item_setup (GtkModelMenuItem *item, GMenuModel *model, gint item_index, - GActionObservable *actions) + GActionObservable *actions, + GtkAccelGroup *accels) { GMenuAttributeIter *iter; GMenuModel *submenu; @@ -201,7 +219,7 @@ gtk_model_menu_item_setup (GtkModelMenuItem *item, if ((submenu = g_menu_model_get_item_link (model, item_index, "submenu"))) { - gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), gtk_model_menu_create_menu (submenu, actions)); + gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), gtk_model_menu_create_menu (submenu, actions, accels)); g_object_unref (submenu); } @@ -228,6 +246,7 @@ gtk_model_menu_item_setup (GtkModelMenuItem *item, const GVariantType *type; gboolean enabled; GVariant *state; + gchar *path; /* observer already causes us to hold a hard ref on the group */ item->actions = G_ACTION_GROUP (actions); @@ -242,6 +261,10 @@ gtk_model_menu_item_setup (GtkModelMenuItem *item, if (state != NULL) g_variant_unref (state); + + path = get_accel_path (item->action_name, item->target); + gtk_menu_item_set_accel_path (GTK_MENU_ITEM (item), path); + g_free (path); } } @@ -284,13 +307,14 @@ gtk_model_menu_item_class_init (GtkModelMenuItemClass *class) GtkMenuItem * gtk_model_menu_item_new (GMenuModel *model, gint item_index, - GActionObservable *actions) + GActionObservable *actions, + GtkAccelGroup *accels) { GtkModelMenuItem *item; item = g_object_new (GTK_TYPE_MODEL_MENU_ITEM, NULL); - gtk_model_menu_item_setup (item, model, item_index, actions); + gtk_model_menu_item_setup (item, model, item_index, actions, accels); return GTK_MENU_ITEM (item); } |