aboutsummaryrefslogtreecommitdiff
path: root/libdbusmenu-gtk
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2010-06-14 12:12:35 -0500
committerTed Gould <ted@gould.cx>2010-06-14 12:12:35 -0500
commit7fc24062ed7fea97fec2a3cd873dcc68edc9c488 (patch)
treeb538ebff8f056b156374f1753305a33df9627f29 /libdbusmenu-gtk
parent50dcdae3889fef7da43c6618b35b70847ba59d72 (diff)
downloadlibdbusmenu-7fc24062ed7fea97fec2a3cd873dcc68edc9c488.tar.gz
libdbusmenu-7fc24062ed7fea97fec2a3cd873dcc68edc9c488.tar.bz2
libdbusmenu-7fc24062ed7fea97fec2a3cd873dcc68edc9c488.zip
Fleshing out getting the accelerator from the menuitem.
Diffstat (limited to 'libdbusmenu-gtk')
-rw-r--r--libdbusmenu-gtk/menuitem.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c
index 6f5c6b3..dfd83b0 100644
--- a/libdbusmenu-gtk/menuitem.c
+++ b/libdbusmenu-gtk/menuitem.c
@@ -205,6 +205,14 @@ dbusmenu_menuitem_property_set_shortcut (DbusmenuMenuitem * menuitem, guint key,
return TRUE;
}
+/* Look at the closures in an accel group and find
+ the one that matches the one we've been passed */
+static gboolean
+find_closure (GtkAccelKey * key, GClosure * closure, gpointer user_data)
+{
+ return closure == user_data;
+}
+
/**
dbusmenu_menuitem_property_set_shortcut_menuitem:
@menuitem: The #DbusmenuMenuitem to set the shortcut on
@@ -219,8 +227,32 @@ dbusmenu_menuitem_property_set_shortcut (DbusmenuMenuitem * menuitem, guint key,
gboolean
dbusmenu_menuitem_property_set_shortcut_menuitem (DbusmenuMenuitem * menuitem, const GtkMenuItem * gmi)
{
+ g_return_val_if_fail(DBUSMENU_IS_MENUITEM(menuitem), FALSE);
+ g_return_val_if_fail(GTK_IS_MENU_ITEM(gmi), FALSE);
+
+ GClosure * closure = NULL;
+ GList * clist;
+
+ clist = gtk_widget_list_accel_closures(GTK_WIDGET(gmi));
+ if (clist == NULL) {
+ g_warning("Menuitem does not have any closures.");
+ return FALSE;
+ }
+
+ closure = (GClosure *)clist->data;
+ g_list_free(clist);
+
+ GtkAccelGroup * group = gtk_accel_group_from_accel_closure(closure);
+
+ /* Seriously, if this returns NULL something is seriously
+ wrong in GTK. */
+ g_return_val_if_fail(group != NULL, FALSE);
+
+ GtkAccelKey * key = gtk_accel_group_find(group, find_closure, closure);
+ /* Again, not much we can do except complain loudly. */
+ g_return_val_if_fail(key != NULL, FALSE);
- return FALSE;
+ return dbusmenu_menuitem_property_set_shortcut(menuitem, key->accel_key, key->accel_mods);
}
/**