Merge lp:~attente/unity-gtk-module/eclipse-accelerators into lp:unity-gtk-module/14.04

Proposed by William Hua
Status: Merged
Approved by: Charles Kerr
Approved revision: 326
Merged at revision: 325
Proposed branch: lp:~attente/unity-gtk-module/eclipse-accelerators
Merge into: lp:unity-gtk-module/14.04
Diff against target: 140 lines (+75/-2)
3 files modified
lib/unity-gtk-menu-item-private.h (+3/-0)
lib/unity-gtk-menu-item.c (+20/-1)
lib/unity-gtk-menu-section.c (+52/-1)
To merge this branch: bzr merge lp:~attente/unity-gtk-module/eclipse-accelerators
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+213396@code.launchpad.net

Commit message

Forward original accelerator text for Eclipse, Inkscape, Emacs.

Description of the change

Forward original accelerator text for Eclipse, Inkscape, Emacs.

This branch needs https://code.launchpad.net/~attente/gtk/x-canonical-accel/+merge/213395.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) wrote :

Will, I'm not sure that I understand this patch. Where does the x-canonical-accel attribute get used?

Revision history for this message
Charles Kerr (charlesk) wrote :

Oh of course, in https://code.launchpad.net/~attente/gtk/x-canonical-accel/+merge/213395

This side of the patch looks fine.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/unity-gtk-menu-item-private.h'
2--- lib/unity-gtk-menu-item-private.h 2014-03-25 21:48:16 +0000
3+++ lib/unity-gtk-menu-item-private.h 2014-03-31 01:05:21 +0000
4@@ -89,6 +89,9 @@
5 void unity_gtk_menu_item_print (UnityGtkMenuItem *item,
6 guint indent) G_GNUC_INTERNAL;
7
8+GtkLabel * gtk_menu_item_get_nth_label (GtkMenuItem *menu_item,
9+ guint index) G_GNUC_INTERNAL;
10+
11 const gchar * gtk_menu_item_get_nth_label_label (GtkMenuItem *menu_item,
12 guint index) G_GNUC_INTERNAL;
13
14
15=== modified file 'lib/unity-gtk-menu-item.c'
16--- lib/unity-gtk-menu-item.c 2014-03-27 19:52:20 +0000
17+++ lib/unity-gtk-menu-item.c 2014-03-31 01:05:21 +0000
18@@ -57,7 +57,7 @@
19 }
20 }
21
22-static GtkLabel *
23+GtkLabel *
24 gtk_menu_item_get_nth_label (GtkMenuItem *menu_item,
25 guint index)
26 {
27@@ -368,6 +368,23 @@
28 }
29
30 static void
31+unity_gtk_menu_item_handle_accel_closures_changed (GtkWidget *widget,
32+ gpointer user_data)
33+{
34+ UnityGtkMenuItem *item;
35+ UnityGtkMenuShell *parent_shell;
36+
37+ g_return_if_fail (UNITY_GTK_IS_MENU_ITEM (user_data));
38+
39+ item = UNITY_GTK_MENU_ITEM (user_data);
40+ parent_shell = item->parent_shell;
41+
42+ g_return_if_fail (parent_shell != NULL);
43+
44+ unity_gtk_menu_shell_handle_item_notify (parent_shell, item, "accel-path");
45+}
46+
47+static void
48 unity_gtk_menu_item_set_menu_item (UnityGtkMenuItem *item,
49 GtkMenuItem *menu_item)
50 {
51@@ -410,6 +427,8 @@
52 if (label != NULL)
53 g_signal_connect (label, "notify", G_CALLBACK (unity_gtk_menu_item_handle_label_notify), item);
54
55+ g_signal_connect (menu_item, "accel-closures-changed", G_CALLBACK (unity_gtk_menu_item_handle_accel_closures_changed), item);
56+
57 /* LP: #1208019 */
58 if (gtk_menu_item_get_submenu (menu_item) != NULL)
59 g_signal_emit_by_name (gtk_menu_item_get_submenu (menu_item), "show");
60
61=== modified file 'lib/unity-gtk-menu-section.c'
62--- lib/unity-gtk-menu-section.c 2014-03-25 21:48:16 +0000
63+++ lib/unity-gtk-menu-section.c 2014-03-31 01:05:21 +0000
64@@ -23,6 +23,10 @@
65 #define G_MENU_ATTRIBUTE_ACCEL "accel"
66 #endif
67
68+#ifndef G_MENU_ATTRIBUTE_ACCEL_TEXT
69+#define G_MENU_ATTRIBUTE_ACCEL_TEXT "x-canonical-accel"
70+#endif
71+
72 G_DEFINE_TYPE (UnityGtkMenuSection,
73 unity_gtk_menu_section,
74 G_TYPE_MENU_MODEL);
75@@ -35,6 +39,14 @@
76 return GPOINTER_TO_INT (a) - GPOINTER_TO_INT (b);
77 }
78
79+static gboolean
80+g_closure_equal (GtkAccelKey *key,
81+ GClosure *closure,
82+ gpointer data)
83+{
84+ return closure == data;
85+}
86+
87 static void
88 unity_gtk_menu_section_set_parent_shell (UnityGtkMenuSection *section,
89 UnityGtkMenuShell *parent_shell)
90@@ -166,10 +178,49 @@
91 }
92
93 if (accel_name == NULL)
94- accel_name = g_strdup (gtk_menu_item_get_nth_label_label (item->menu_item, 1));
95+ {
96+ GList *closures = gtk_widget_list_accel_closures (GTK_WIDGET (item->menu_item));
97+ GList *iter;
98+
99+ for (iter = closures; iter != NULL && accel_name == NULL; iter = g_list_next (iter))
100+ {
101+ GClosure *closure = iter->data;
102+ GtkAccelGroup *accel_group = gtk_accel_group_from_accel_closure (closure);
103+
104+ if (accel_group != NULL)
105+ {
106+ GtkAccelKey *accel_key = gtk_accel_group_find (accel_group, g_closure_equal, closure);
107+
108+ if (accel_key != NULL)
109+ accel_name = gtk_accelerator_name (accel_key->accel_key, accel_key->accel_mods);
110+ }
111+ }
112+
113+ g_list_free (closures);
114+ }
115
116 if (accel_name != NULL)
117 g_hash_table_insert (*attributes, G_MENU_ATTRIBUTE_ACCEL, g_variant_ref_sink (g_variant_new_string (accel_name)));
118+ else
119+ {
120+#if GTK_MAJOR_VERSION == 2
121+ /* LP: #1208019 */
122+ GtkLabel *accel_label = gtk_menu_item_get_nth_label (item->menu_item, 0);
123+
124+ if (GTK_IS_ACCEL_LABEL (accel_label))
125+ {
126+ /* Eclipse uses private API. */
127+ if (GTK_ACCEL_LABEL (accel_label)->accel_string != NULL)
128+ accel_name = g_strdup (GTK_ACCEL_LABEL (accel_label)->accel_string);
129+ }
130+#endif
131+
132+ if (accel_name == NULL)
133+ accel_name = g_strdup (gtk_menu_item_get_nth_label_label (item->menu_item, 1));
134+
135+ if (accel_name != NULL)
136+ g_hash_table_insert (*attributes, G_MENU_ATTRIBUTE_ACCEL_TEXT, g_variant_ref_sink (g_variant_new_string (accel_name)));
137+ }
138
139 g_free (accel_name);
140 }

Subscribers

People subscribed via source and target branches