Merge lp:~attente/gtk/x-canonical-accel into lp:~ubuntu-desktop/gtk/ubuntugtk3

Proposed by William Hua on 2014-03-31
Status: Merged
Merged at revision: 333
Proposed branch: lp:~attente/gtk/x-canonical-accel
Merge into: lp:~ubuntu-desktop/gtk/ubuntugtk3
Diff against target: 252 lines (+225/-0)
3 files modified
debian/changelog (+5/-0)
debian/patches/series (+1/-0)
debian/patches/x-canonical-accel.patch (+219/-0)
To merge this branch: bzr merge lp:~attente/gtk/x-canonical-accel
Reviewer Review Type Date Requested Status
Lars Karlitski (community) Approve on 2014-04-03
Ubuntu Desktop 2014-03-31 Pending
Review via email: mp+213395@code.launchpad.net

Commit message

* debian/patches/x-canonical-accel.patch:
  - allow setting menu item accelerator text directly (lp: #1208019)

Description of the change

Add a custom GMenuItem attribute called "x-canonical-accel" that allows the accelerator text to be set directly without needing a key code and modifier. We need this because sometimes all we have is the translated accelerator text, and parsing this is difficult considering the user's language may not be English.

To post a comment you must log in.
Lars Karlitski (larsu) wrote :

It's unlikely that this will make it upstream. We should try to get apps to fix their menus in the medium term.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2014-03-06 14:09:33 +0000
3+++ debian/changelog 2014-03-31 01:03:48 +0000
4@@ -1,10 +1,15 @@
5 gtk+3.0 (3.10.7-0ubuntu5) UNRELEASED; urgency=medium
6
7+ [ Sebastien Bacher ]
8 * debian/patches/git_grid_theming.patch:
9 - "grid: draw css background and borders", that's needed to be able to
10 workraround background color issues with our scrollbars/theme,
11 thanks Lars Uebernickel
12
13+ [ William Hua ]
14+ * debian/patches/x-canonical-accel.patch:
15+ - allow setting menu item accelerator text directly (lp: #1208019)
16+
17 -- Sebastien Bacher <seb128@ubuntu.com> Thu, 06 Mar 2014 15:04:42 +0100
18
19 gtk+3.0 (3.10.7-0ubuntu4) trusty; urgency=medium
20
21=== modified file 'debian/patches/series'
22--- debian/patches/series 2014-03-06 14:09:33 +0000
23+++ debian/patches/series 2014-03-31 01:03:48 +0000
24@@ -24,3 +24,4 @@
25 git_subtitle_typo.patch
26 git_popup_menu_shift.patch
27 git_grid_theming.patch
28+x-canonical-accel.patch
29
30=== added file 'debian/patches/x-canonical-accel.patch'
31--- debian/patches/x-canonical-accel.patch 1970-01-01 00:00:00 +0000
32+++ debian/patches/x-canonical-accel.patch 2014-03-31 01:03:48 +0000
33@@ -0,0 +1,219 @@
34+Description: Allow setting menu item accelerator text directly
35+ Add a custom GMenuItem attribute called "x-canonical-accel" that
36+ allows the accelerator text to be set directly without needing a
37+ key code and modifier. We need this because sometimes all we have
38+ is the translated accelerator text, and parsing this is difficult
39+ considering the user's language may not be English.
40+
41+Author: William Hua <william.hua@canonical.com>
42+Bug-Ubuntu: https://bugs.launchpad.net/bugs/1208019
43+
44+Index: gtk+3.0-3.10.7/gtk/gtkmenutrackeritem.c
45+===================================================================
46+--- gtk+3.0-3.10.7.orig/gtk/gtkmenutrackeritem.c 2014-03-31 10:57:23.969527294 +1300
47++++ gtk+3.0-3.10.7/gtk/gtkmenutrackeritem.c 2014-03-31 11:01:19.941518966 +1300
48+@@ -104,6 +104,7 @@
49+ PROP_ROLE,
50+ PROP_TOGGLED,
51+ PROP_ACCEL,
52++ PROP_ACCEL_TEXT,
53+ PROP_SUBMENU_SHOWN,
54+ N_PROPS
55+ };
56+@@ -174,6 +175,9 @@
57+ case PROP_ACCEL:
58+ g_value_set_string (value, gtk_menu_tracker_item_get_accel (self));
59+ break;
60++ case PROP_ACCEL_TEXT:
61++ g_value_set_string (value, gtk_menu_tracker_item_get_accel_text (self));
62++ break;
63+ case PROP_SUBMENU_SHOWN:
64+ g_value_set_boolean (value, gtk_menu_tracker_item_get_submenu_shown (self));
65+ break;
66+@@ -229,6 +233,8 @@
67+ g_param_spec_boolean ("toggled", "", "", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE);
68+ gtk_menu_tracker_item_pspecs[PROP_ACCEL] =
69+ g_param_spec_string ("accel", "", "", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE);
70++ gtk_menu_tracker_item_pspecs[PROP_ACCEL_TEXT] =
71++ g_param_spec_string ("accel-text", "", "", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE);
72+ gtk_menu_tracker_item_pspecs[PROP_SUBMENU_SHOWN] =
73+ g_param_spec_boolean ("submenu-shown", "", "", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE);
74+
75+@@ -551,6 +557,16 @@
76+ return accel;
77+ }
78+
79++const gchar *
80++gtk_menu_tracker_item_get_accel_text (GtkMenuTrackerItem *self)
81++{
82++ const gchar *accel_text = NULL;
83++
84++ g_menu_item_get_attribute (self->item, "x-canonical-accel", "&s", &accel_text);
85++
86++ return accel_text;
87++}
88++
89+ GMenuModel *
90+ _gtk_menu_tracker_item_get_submenu (GtkMenuTrackerItem *self)
91+ {
92+Index: gtk+3.0-3.10.7/gtk/gtkmenutrackeritem.h
93+===================================================================
94+--- gtk+3.0-3.10.7.orig/gtk/gtkmenutrackeritem.h 2014-03-31 10:57:23.969527294 +1300
95++++ gtk+3.0-3.10.7/gtk/gtkmenutrackeritem.h 2014-03-31 10:59:10.013523551 +1300
96+@@ -68,6 +68,8 @@
97+
98+ const gchar * gtk_menu_tracker_item_get_accel (GtkMenuTrackerItem *self);
99+
100++const gchar * gtk_menu_tracker_item_get_accel_text (GtkMenuTrackerItem *self);
101++
102+ GMenuModel * _gtk_menu_tracker_item_get_submenu (GtkMenuTrackerItem *self);
103+
104+ gchar * _gtk_menu_tracker_item_get_submenu_namespace (GtkMenuTrackerItem *self);
105+Index: gtk+3.0-3.10.7/gtk/gtkmodelmenuitem.c
106+===================================================================
107+--- gtk+3.0-3.10.7.orig/gtk/gtkmodelmenuitem.c 2014-01-28 11:40:16.000000000 +1300
108++++ gtk+3.0-3.10.7/gtk/gtkmodelmenuitem.c 2014-03-31 11:20:07.301479178 +1300
109+@@ -43,7 +43,8 @@
110+ PROP_ICON,
111+ PROP_TEXT,
112+ PROP_TOGGLED,
113+- PROP_ACCEL
114++ PROP_ACCEL,
115++ PROP_ACCEL_TEXT
116+ };
117+
118+ static void
119+@@ -286,6 +287,44 @@
120+ }
121+ }
122+
123++void _gtk_accel_label_set_accel_text (GtkAccelLabel *accel_label,
124++ const gchar *accel_text);
125++
126++static void
127++gtk_model_menu_item_set_accel_text (GtkModelMenuItem *item,
128++ const gchar *accel_text)
129++{
130++ GtkWidget *child;
131++ GList *children;
132++
133++ child = gtk_bin_get_child (GTK_BIN (item));
134++ if (child == NULL)
135++ {
136++ gtk_menu_item_get_label (GTK_MENU_ITEM (item));
137++ child = gtk_bin_get_child (GTK_BIN (item));
138++ g_assert (GTK_IS_LABEL (child));
139++ }
140++
141++ if (GTK_IS_LABEL (child))
142++ {
143++ _gtk_accel_label_set_accel_text (GTK_ACCEL_LABEL (child), accel_text);
144++ return;
145++ }
146++
147++ if (!GTK_IS_CONTAINER (child))
148++ return;
149++
150++ children = gtk_container_get_children (GTK_CONTAINER (child));
151++
152++ while (children)
153++ {
154++ if (GTK_IS_ACCEL_LABEL (children->data))
155++ _gtk_accel_label_set_accel_text (children->data, accel_text);
156++
157++ children = g_list_delete_link (children, children);
158++ }
159++}
160++
161+ void
162+ gtk_model_menu_item_set_property (GObject *object, guint prop_id,
163+ const GValue *value, GParamSpec *pspec)
164+@@ -314,6 +353,10 @@
165+ gtk_model_menu_item_set_accel (item, g_value_get_string (value));
166+ break;
167+
168++ case PROP_ACCEL_TEXT:
169++ gtk_model_menu_item_set_accel_text (item, g_value_get_string (value));
170++ break;
171++
172+ default:
173+ g_assert_not_reached ();
174+ }
175+@@ -355,6 +398,9 @@
176+ g_object_class_install_property (object_class, PROP_ACCEL,
177+ g_param_spec_string ("accel", "accel", "accel", NULL,
178+ G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
179++ g_object_class_install_property (object_class, PROP_ACCEL_TEXT,
180++ g_param_spec_string ("accel-text", "accel-text", "accel-text", NULL,
181++ G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
182+ }
183+
184+ GtkWidget *
185+Index: gtk+3.0-3.10.7/gtk/gtkmenushell.c
186+===================================================================
187+--- gtk+3.0-3.10.7.orig/gtk/gtkmenushell.c 2014-03-31 10:57:23.969527294 +1300
188++++ gtk+3.0-3.10.7/gtk/gtkmenushell.c 2014-03-31 11:09:20.221502015 +1300
189+@@ -2192,6 +2192,7 @@
190+ g_object_bind_property (item, "role", widget, "action-role", G_BINDING_SYNC_CREATE);
191+ g_object_bind_property (item, "toggled", widget, "toggled", G_BINDING_SYNC_CREATE);
192+ g_object_bind_property (item, "accel", widget, "accel", G_BINDING_SYNC_CREATE);
193++ g_object_bind_property (item, "accel-text", widget, "accel-text", G_BINDING_SYNC_CREATE);
194+
195+ g_signal_connect (widget, "activate", G_CALLBACK (gtk_menu_shell_item_activate), item);
196+ }
197+Index: gtk+3.0-3.10.7/gtk/gtkaccellabel.c
198+===================================================================
199+--- gtk+3.0-3.10.7.orig/gtk/gtkaccellabel.c 2014-01-28 11:40:16.000000000 +1300
200++++ gtk+3.0-3.10.7/gtk/gtkaccellabel.c 2014-03-31 11:34:42.961448273 +1300
201+@@ -107,6 +107,8 @@
202+
203+ guint accel_key; /* manual accel key specification if != 0 */
204+ GdkModifierType accel_mods;
205++
206++ gchar *accel_text; /* already-translated accel_string */
207+ };
208+
209+ static void gtk_accel_label_set_property (GObject *object,
210+@@ -259,6 +261,7 @@
211+ priv->accel_closure = NULL;
212+ priv->accel_group = NULL;
213+ priv->accel_string = NULL;
214++ priv->accel_text = NULL;
215+ }
216+
217+ /**
218+@@ -300,6 +303,7 @@
219+ GtkAccelLabel *accel_label = GTK_ACCEL_LABEL (object);
220+
221+ g_free (accel_label->priv->accel_string);
222++ g_free (accel_label->priv->accel_text);
223+
224+ G_OBJECT_CLASS (gtk_accel_label_parent_class)->finalize (object);
225+ }
226+@@ -902,6 +906,12 @@
227+ accel_label->priv->accel_string = NULL;
228+ }
229+
230++ if (accel_label->priv->accel_text)
231++ {
232++ accel_label->priv->accel_string = g_strdup (accel_label->priv->accel_text);
233++ return FALSE;
234++ }
235++
236+ g_object_get (gtk_widget_get_settings (GTK_WIDGET (accel_label)),
237+ "gtk-enable-accels", &enable_accels,
238+ NULL);
239+@@ -986,3 +996,13 @@
240+
241+ gtk_accel_label_reset (accel_label);
242+ }
243++
244++void
245++_gtk_accel_label_set_accel_text (GtkAccelLabel *accel_label,
246++ const gchar *accel_text)
247++{
248++ g_free (accel_label->priv->accel_text);
249++ accel_label->priv->accel_text = g_strdup (accel_text);
250++
251++ gtk_accel_label_reset (accel_label);
252++}

Subscribers

People subscribed via source and target branches

to all changes: