[gtk+/wip/gmenu] GtkApplicationWindow: Set the accel group on constructed windows
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/gmenu] GtkApplicationWindow: Set the accel group on constructed windows
- Date: Mon, 5 Dec 2011 22:53:40 +0000 (UTC)
commit be861b2f7ea153bdd1e49a0b257dc471bc1085be
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Dec 5 17:14:57 2011 -0500
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.
gtk/gtkapplicationwindow.c | 2 +-
gtk/gtkmodelmenu.c | 16 +++++++++++-----
gtk/gtkmodelmenu.h | 8 ++++++--
gtk/gtkmodelmenuitem.c | 32 ++++++++++++++++++++++++++++----
gtk/gtkmodelmenuitem.h | 3 ++-
5 files changed, 48 insertions(+), 13 deletions(-)
---
diff --git a/gtk/gtkapplicationwindow.c b/gtk/gtkapplicationwindow.c
index 24da226..16cdcfc 100644
--- a/gtk/gtkapplicationwindow.c
+++ b/gtk/gtkapplicationwindow.c
@@ -122,7 +122,7 @@ gtk_application_window_update_menubar (GtkApplicationWindow *window)
g_menu_append_section (combined, NULL, G_MENU_MODEL (window->priv->app_menu_section));
g_menu_append_section (combined, NULL, G_MENU_MODEL (window->priv->menubar_section));
- window->priv->menubar = gtk_model_menu_create_menu_bar (G_MENU_MODEL (combined), G_ACTION_OBSERVABLE (muxer));
+ window->priv->menubar = gtk_model_menu_create_menu_bar (G_MENU_MODEL (combined), G_ACTION_OBSERVABLE (muxer), window->priv->accels);
gtk_widget_set_parent (window->priv->menubar, GTK_WIDGET (window));
gtk_widget_show_all (window->priv->menubar);
g_object_unref (combined);
diff --git a/gtk/gtkmodelmenu.c b/gtk/gtkmodelmenu.c
index a9979cd..2c3db13 100644
--- a/gtk/gtkmodelmenu.c
+++ b/gtk/gtkmodelmenu.c
@@ -33,6 +33,7 @@
typedef struct {
GActionObservable *actions;
GMenuModel *model;
+ GtkAccelGroup *accels;
GtkMenuShell *shell;
guint update_idle;
GSList *connected;
@@ -85,7 +86,7 @@ gtk_model_menu_binding_append_item (GtkModelMenuBinding *binding,
{
GtkMenuItem *item;
- item = gtk_model_menu_item_new (model, item_index, binding->actions);
+ item = gtk_model_menu_item_new (model, item_index, binding->actions, binding->accels);
gtk_menu_shell_append (binding->shell, GTK_WIDGET (item));
gtk_widget_show (GTK_WIDGET (item));
binding->n_items++;
@@ -225,6 +226,7 @@ void
gtk_model_menu_bind (GtkMenuShell *shell,
GMenuModel *model,
GActionObservable *actions,
+ GtkAccelGroup *accels,
gboolean with_separators)
{
GtkModelMenuBinding *binding;
@@ -232,6 +234,7 @@ gtk_model_menu_bind (GtkMenuShell *shell,
binding = g_slice_new (GtkModelMenuBinding);
binding->model = g_object_ref (model);
binding->actions = g_object_ref (actions);
+ binding->accels = accels;
binding->shell = shell;
binding->update_idle = 0;
binding->connected = NULL;
@@ -243,24 +246,27 @@ gtk_model_menu_bind (GtkMenuShell *shell,
GtkWidget *
gtk_model_menu_create_menu (GMenuModel *model,
- GActionObservable *actions)
+ GActionObservable *actions,
+ GtkAccelGroup *accels)
{
GtkWidget *menu;
menu = gtk_menu_new ();
- gtk_model_menu_bind (GTK_MENU_SHELL (menu), model, actions, TRUE);
+ gtk_menu_set_accel_group (GTK_MENU (menu), accels);
+ gtk_model_menu_bind (GTK_MENU_SHELL (menu), model, actions, accels, TRUE);
return menu;
}
GtkWidget *
gtk_model_menu_create_menu_bar (GMenuModel *model,
- GActionObservable *actions)
+ GActionObservable *actions,
+ GtkAccelGroup *accels)
{
GtkWidget *menubar;
menubar = gtk_menu_bar_new ();
- gtk_model_menu_bind (GTK_MENU_SHELL (menubar), model, actions, FALSE);
+ gtk_model_menu_bind (GTK_MENU_SHELL (menubar), model, actions, accels, FALSE);
return menubar;
}
diff --git a/gtk/gtkmodelmenu.h b/gtk/gtkmodelmenu.h
index 409d1f9..827d143 100644
--- a/gtk/gtkmodelmenu.h
+++ b/gtk/gtkmodelmenu.h
@@ -24,20 +24,24 @@
#include <gtk/gactionobservable.h>
#include <gtk/gtkmenushell.h>
+#include <gtk/gtkaccelgroup.h>
#include <gio/gio.h>
G_GNUC_INTERNAL
void gtk_model_menu_bind (GtkMenuShell *shell,
GMenuModel *model,
GActionObservable *actions,
+ GtkAccelGroup *accels,
gboolean with_separators);
G_GNUC_INTERNAL
GtkWidget * gtk_model_menu_create_menu_bar (GMenuModel *model,
- GActionObservable *actions);
+ GActionObservable *actions,
+ GtkAccelGroup *accels);
G_GNUC_INTERNAL
GtkWidget * gtk_model_menu_create_menu (GMenuModel *model,
- GActionObservable *actions);
+ GActionObservable *actions,
+ GtkAccelGroup *accels);
#endif /* __GTK_MODEL_MENU_H__ */
diff --git a/gtk/gtkmodelmenuitem.c b/gtk/gtkmodelmenuitem.c
index 30ca3f4..4e2fd09 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);
}
diff --git a/gtk/gtkmodelmenuitem.h b/gtk/gtkmodelmenuitem.h
index 4146bf9..176d68f 100644
--- a/gtk/gtkmodelmenuitem.h
+++ b/gtk/gtkmodelmenuitem.h
@@ -39,6 +39,7 @@ GType gtk_model_menu_item_get_type (void) G
G_GNUC_INTERNAL
GtkMenuItem * gtk_model_menu_item_new (GMenuModel *model,
gint item_index,
- GActionObservable *actions);
+ GActionObservable *actions,
+ GtkAccelGroup *accels);
#endif /* __GTK_MODEL_MENU_ITEM_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]