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
=== modified file 'lib/unity-gtk-menu-item-private.h'
--- lib/unity-gtk-menu-item-private.h 2014-03-25 21:48:16 +0000
+++ lib/unity-gtk-menu-item-private.h 2014-03-31 01:05:21 +0000
@@ -89,6 +89,9 @@
89void unity_gtk_menu_item_print (UnityGtkMenuItem *item,89void unity_gtk_menu_item_print (UnityGtkMenuItem *item,
90 guint indent) G_GNUC_INTERNAL;90 guint indent) G_GNUC_INTERNAL;
9191
92GtkLabel * gtk_menu_item_get_nth_label (GtkMenuItem *menu_item,
93 guint index) G_GNUC_INTERNAL;
94
92const gchar * gtk_menu_item_get_nth_label_label (GtkMenuItem *menu_item,95const gchar * gtk_menu_item_get_nth_label_label (GtkMenuItem *menu_item,
93 guint index) G_GNUC_INTERNAL;96 guint index) G_GNUC_INTERNAL;
9497
9598
=== modified file 'lib/unity-gtk-menu-item.c'
--- lib/unity-gtk-menu-item.c 2014-03-27 19:52:20 +0000
+++ lib/unity-gtk-menu-item.c 2014-03-31 01:05:21 +0000
@@ -57,7 +57,7 @@
57 }57 }
58}58}
5959
60static GtkLabel *60GtkLabel *
61gtk_menu_item_get_nth_label (GtkMenuItem *menu_item,61gtk_menu_item_get_nth_label (GtkMenuItem *menu_item,
62 guint index)62 guint index)
63{63{
@@ -368,6 +368,23 @@
368}368}
369369
370static void370static void
371unity_gtk_menu_item_handle_accel_closures_changed (GtkWidget *widget,
372 gpointer user_data)
373{
374 UnityGtkMenuItem *item;
375 UnityGtkMenuShell *parent_shell;
376
377 g_return_if_fail (UNITY_GTK_IS_MENU_ITEM (user_data));
378
379 item = UNITY_GTK_MENU_ITEM (user_data);
380 parent_shell = item->parent_shell;
381
382 g_return_if_fail (parent_shell != NULL);
383
384 unity_gtk_menu_shell_handle_item_notify (parent_shell, item, "accel-path");
385}
386
387static void
371unity_gtk_menu_item_set_menu_item (UnityGtkMenuItem *item,388unity_gtk_menu_item_set_menu_item (UnityGtkMenuItem *item,
372 GtkMenuItem *menu_item)389 GtkMenuItem *menu_item)
373{390{
@@ -410,6 +427,8 @@
410 if (label != NULL)427 if (label != NULL)
411 g_signal_connect (label, "notify", G_CALLBACK (unity_gtk_menu_item_handle_label_notify), item);428 g_signal_connect (label, "notify", G_CALLBACK (unity_gtk_menu_item_handle_label_notify), item);
412429
430 g_signal_connect (menu_item, "accel-closures-changed", G_CALLBACK (unity_gtk_menu_item_handle_accel_closures_changed), item);
431
413 /* LP: #1208019 */432 /* LP: #1208019 */
414 if (gtk_menu_item_get_submenu (menu_item) != NULL)433 if (gtk_menu_item_get_submenu (menu_item) != NULL)
415 g_signal_emit_by_name (gtk_menu_item_get_submenu (menu_item), "show");434 g_signal_emit_by_name (gtk_menu_item_get_submenu (menu_item), "show");
416435
=== modified file 'lib/unity-gtk-menu-section.c'
--- lib/unity-gtk-menu-section.c 2014-03-25 21:48:16 +0000
+++ lib/unity-gtk-menu-section.c 2014-03-31 01:05:21 +0000
@@ -23,6 +23,10 @@
23#define G_MENU_ATTRIBUTE_ACCEL "accel"23#define G_MENU_ATTRIBUTE_ACCEL "accel"
24#endif24#endif
2525
26#ifndef G_MENU_ATTRIBUTE_ACCEL_TEXT
27#define G_MENU_ATTRIBUTE_ACCEL_TEXT "x-canonical-accel"
28#endif
29
26G_DEFINE_TYPE (UnityGtkMenuSection,30G_DEFINE_TYPE (UnityGtkMenuSection,
27 unity_gtk_menu_section,31 unity_gtk_menu_section,
28 G_TYPE_MENU_MODEL);32 G_TYPE_MENU_MODEL);
@@ -35,6 +39,14 @@
35 return GPOINTER_TO_INT (a) - GPOINTER_TO_INT (b);39 return GPOINTER_TO_INT (a) - GPOINTER_TO_INT (b);
36}40}
3741
42static gboolean
43g_closure_equal (GtkAccelKey *key,
44 GClosure *closure,
45 gpointer data)
46{
47 return closure == data;
48}
49
38static void50static void
39unity_gtk_menu_section_set_parent_shell (UnityGtkMenuSection *section,51unity_gtk_menu_section_set_parent_shell (UnityGtkMenuSection *section,
40 UnityGtkMenuShell *parent_shell)52 UnityGtkMenuShell *parent_shell)
@@ -166,10 +178,49 @@
166 }178 }
167179
168 if (accel_name == NULL)180 if (accel_name == NULL)
169 accel_name = g_strdup (gtk_menu_item_get_nth_label_label (item->menu_item, 1));181 {
182 GList *closures = gtk_widget_list_accel_closures (GTK_WIDGET (item->menu_item));
183 GList *iter;
184
185 for (iter = closures; iter != NULL && accel_name == NULL; iter = g_list_next (iter))
186 {
187 GClosure *closure = iter->data;
188 GtkAccelGroup *accel_group = gtk_accel_group_from_accel_closure (closure);
189
190 if (accel_group != NULL)
191 {
192 GtkAccelKey *accel_key = gtk_accel_group_find (accel_group, g_closure_equal, closure);
193
194 if (accel_key != NULL)
195 accel_name = gtk_accelerator_name (accel_key->accel_key, accel_key->accel_mods);
196 }
197 }
198
199 g_list_free (closures);
200 }
170201
171 if (accel_name != NULL)202 if (accel_name != NULL)
172 g_hash_table_insert (*attributes, G_MENU_ATTRIBUTE_ACCEL, g_variant_ref_sink (g_variant_new_string (accel_name)));203 g_hash_table_insert (*attributes, G_MENU_ATTRIBUTE_ACCEL, g_variant_ref_sink (g_variant_new_string (accel_name)));
204 else
205 {
206#if GTK_MAJOR_VERSION == 2
207 /* LP: #1208019 */
208 GtkLabel *accel_label = gtk_menu_item_get_nth_label (item->menu_item, 0);
209
210 if (GTK_IS_ACCEL_LABEL (accel_label))
211 {
212 /* Eclipse uses private API. */
213 if (GTK_ACCEL_LABEL (accel_label)->accel_string != NULL)
214 accel_name = g_strdup (GTK_ACCEL_LABEL (accel_label)->accel_string);
215 }
216#endif
217
218 if (accel_name == NULL)
219 accel_name = g_strdup (gtk_menu_item_get_nth_label_label (item->menu_item, 1));
220
221 if (accel_name != NULL)
222 g_hash_table_insert (*attributes, G_MENU_ATTRIBUTE_ACCEL_TEXT, g_variant_ref_sink (g_variant_new_string (accel_name)));
223 }
173224
174 g_free (accel_name);225 g_free (accel_name);
175 }226 }

Subscribers

People subscribed via source and target branches