Merge lp:~ted/libdbusmenu/lp903200 into lp:libdbusmenu/0.6

Proposed by Ted Gould
Status: Merged
Approved by: Charles Kerr
Approved revision: 381
Merged at revision: 412
Proposed branch: lp:~ted/libdbusmenu/lp903200
Merge into: lp:libdbusmenu/0.6
Diff against target: 68 lines (+39/-4)
1 file modified
libdbusmenu-gtk/genericmenuitem.c (+39/-4)
To merge this branch: bzr merge lp:~ted/libdbusmenu/lp903200
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
Review via email: mp+101257@code.launchpad.net

Description of the change

Being more explicit about what is a mnemonic and what is not.

To post a comment you must log in.
Revision history for this message
Charles Kerr (charlesk) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libdbusmenu-gtk/genericmenuitem.c'
2--- libdbusmenu-gtk/genericmenuitem.c 2012-03-01 22:25:25 +0000
3+++ libdbusmenu-gtk/genericmenuitem.c 2012-04-09 17:14:18 +0000
4@@ -216,6 +216,31 @@
5 return g_strdup(values[disposition].default_color);
6 }
7
8+/* Check to see if we've got mnemonic stuff goin' on */
9+static gboolean
10+has_mnemonic (const gchar * string, gboolean previous_underscore)
11+{
12+ if (string == NULL || string[0] == '\0') {
13+ return FALSE;
14+ }
15+
16+ if (g_utf8_get_char(string) == '_') {
17+ if (previous_underscore) {
18+ return has_mnemonic(g_utf8_next_char(string), FALSE);
19+ } else {
20+ return has_mnemonic(g_utf8_next_char(string), TRUE);
21+ }
22+ } else {
23+ if (previous_underscore) {
24+ return TRUE;
25+ } else {
26+ return has_mnemonic(g_utf8_next_char(string), FALSE);
27+ }
28+ }
29+
30+ return FALSE;
31+}
32+
33 /* Set the label on the item */
34 static void
35 set_label (GtkMenuItem * menu_item, const gchar * in_label)
36@@ -287,11 +312,15 @@
37 if (labelw == NULL) {
38 /* Build it */
39 labelw = GTK_LABEL(gtk_accel_label_new(local_label));
40- gtk_label_set_use_underline(GTK_LABEL(labelw), TRUE);
41 gtk_label_set_use_markup(GTK_LABEL(labelw), TRUE);
42 gtk_misc_set_alignment(GTK_MISC(labelw), 0.0, 0.5);
43- gtk_accel_label_set_accel_widget(GTK_ACCEL_LABEL(labelw), GTK_WIDGET(menu_item));
44- gtk_label_set_markup_with_mnemonic(labelw, local_label);
45+
46+ if (has_mnemonic(in_label, FALSE)) {
47+ gtk_label_set_use_underline(GTK_LABEL(labelw), TRUE);
48+ gtk_accel_label_set_accel_widget(GTK_ACCEL_LABEL(labelw), GTK_WIDGET(menu_item));
49+ gtk_label_set_markup_with_mnemonic(labelw, local_label);
50+ }
51+
52 gtk_widget_show(GTK_WIDGET(labelw));
53
54 /* Check to see if it needs to be in the bin for this
55@@ -309,7 +338,13 @@
56 getting in. */
57 suppress_update = TRUE;
58 } else {
59- gtk_label_set_markup_with_mnemonic(labelw, local_label);
60+ if (has_mnemonic(in_label, FALSE)) {
61+ gtk_label_set_use_underline(GTK_LABEL(labelw), TRUE);
62+ gtk_accel_label_set_accel_widget(GTK_ACCEL_LABEL(labelw), GTK_WIDGET(menu_item));
63+ gtk_label_set_markup_with_mnemonic(labelw, local_label);
64+ } else {
65+ gtk_label_set_markup(labelw, local_label);
66+ }
67 }
68 }
69

Subscribers

People subscribed via source and target branches

to all changes: