Merge lp:~mterry/libdbusmenu/pass-mnemonics into lp:libdbusmenu/0.5

Proposed by Michael Terry
Status: Merged
Merged at revision: 259
Proposed branch: lp:~mterry/libdbusmenu/pass-mnemonics
Merge into: lp:libdbusmenu/0.5
Diff against target: 65 lines (+26/-5)
1 file modified
libdbusmenu-gtk/parser.c (+26/-5)
To merge this branch: bzr merge lp:~mterry/libdbusmenu/pass-mnemonics
Reviewer Review Type Date Requested Status
Ted Gould (community) Approve
Aurélien Gâteau qt impact Pending
Matthew Paul Thomas design Pending
Review via email: mp+52577@code.launchpad.net

Description of the change

This passes the mnemonics and markup from GtkLabel to the dbusmenuitem.

Interestingly, for appmenu, the mnemonics are always shown (instead of only when Alt is pressed), but that's a separate issue, affecting the indicator side of things.

To post a comment you must log in.
Revision history for this message
Ted Gould (ted) wrote :

I'm not sure if we want to have markup passed to dbusmenu. Mnemonics yes, but markup I'm not as sure about. It seems like we'd need a filter or want to encode that perhaps more sensibly than allowing for single bold or italic words for instance.

258. By Michael Terry

sanitize label text to strip pango markup

Revision history for this message
Michael Terry (mterry) wrote :

Here's a version that strips pango markup.

Revision history for this message
Ted Gould (ted) wrote :

Thanks, I think we need to handle the markup at some point and have a more general solution. I don't think we're ready for that yet :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libdbusmenu-gtk/parser.c'
2--- libdbusmenu-gtk/parser.c 2011-03-01 17:41:58 +0000
3+++ libdbusmenu-gtk/parser.c 2011-03-09 13:29:11 +0000
4@@ -340,6 +340,23 @@
5 return;
6 }
7
8+static gchar *
9+sanitize_label_text (const gchar * label)
10+{
11+ /* Label contains underscores, which we like, and pango markup,
12+ which we don't. */
13+ gchar * sanitized = NULL;
14+ GError * error = NULL;
15+ if (pango_parse_markup (label, -1, 0, NULL, &sanitized, NULL, &error)) {
16+ return sanitized;
17+ }
18+ else {
19+ g_warning ("Could not parse '%s': %s", label, error->message);
20+ g_error_free (error);
21+ return g_strdup (label);
22+ }
23+}
24+
25 /* Turn a widget into a dbusmenu item depending on the type of GTK
26 object that it is. */
27 static DbusmenuMenuitem *
28@@ -423,9 +440,9 @@
29 {
30 // Sometimes, an app will directly find and modify the label
31 // (like empathy), so watch the label especially for that.
32- dbusmenu_menuitem_property_set (mi,
33- "label",
34- gtk_label_get_text (GTK_LABEL (label)));
35+ gchar * text = sanitize_label_text (gtk_label_get_label (GTK_LABEL (label)));
36+ dbusmenu_menuitem_property_set (mi, "label", text);
37+ g_free (text);
38
39 pdata->label = label;
40 g_signal_connect (G_OBJECT (label),
41@@ -668,9 +685,11 @@
42
43 if (pspec->name == g_intern_static_string ("label"))
44 {
45+ gchar * text = sanitize_label_text (gtk_label_get_label (GTK_LABEL (widget)));
46 dbusmenu_menuitem_property_set (child,
47 DBUSMENU_MENUITEM_PROP_LABEL,
48- gtk_label_get_text (GTK_LABEL (widget)));
49+ text);
50+ g_free (text);
51 }
52 }
53
54@@ -724,9 +743,11 @@
55 }
56 else if (pspec->name == g_intern_static_string ("label"))
57 {
58+ gchar * text = sanitize_label_text (gtk_action_get_label (action));
59 dbusmenu_menuitem_property_set (mi,
60 DBUSMENU_MENUITEM_PROP_LABEL,
61- gtk_action_get_label (action));
62+ text);
63+ g_free (text);
64 }
65 }
66

Subscribers

People subscribed via source and target branches