aboutsummaryrefslogtreecommitdiff
path: root/libdbusmenu-gtk
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2011-03-09 08:33:41 -0600
committerTed Gould <ted@gould.cx>2011-03-09 08:33:41 -0600
commitad8d65a45264aa052f3d3ae07af62c92954449bb (patch)
treeac498b30dcc1b6cbe7d552b9bf6e01fe26581e01 /libdbusmenu-gtk
parentb9fd862324444b0bc9256dfa43f1381c2d736a05 (diff)
parent415011b666e92ec899b2c53c80708fdfc1d90322 (diff)
downloadlibdbusmenu-ad8d65a45264aa052f3d3ae07af62c92954449bb.tar.gz
libdbusmenu-ad8d65a45264aa052f3d3ae07af62c92954449bb.tar.bz2
libdbusmenu-ad8d65a45264aa052f3d3ae07af62c92954449bb.zip
Get the label and remove markup so that we get the mnemonics
Diffstat (limited to 'libdbusmenu-gtk')
-rw-r--r--libdbusmenu-gtk/parser.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c
index b0a5cfd..8954d64 100644
--- a/libdbusmenu-gtk/parser.c
+++ b/libdbusmenu-gtk/parser.c
@@ -345,6 +345,23 @@ parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse)
return;
}
+static gchar *
+sanitize_label_text (const gchar * label)
+{
+ /* Label contains underscores, which we like, and pango markup,
+ which we don't. */
+ gchar * sanitized = NULL;
+ GError * error = NULL;
+ if (pango_parse_markup (label, -1, 0, NULL, &sanitized, NULL, &error)) {
+ return sanitized;
+ }
+ else {
+ g_warning ("Could not parse '%s': %s", label, error->message);
+ g_error_free (error);
+ return g_strdup (label);
+ }
+}
+
/* Turn a widget into a dbusmenu item depending on the type of GTK
object that it is. */
static DbusmenuMenuitem *
@@ -428,9 +445,9 @@ construct_dbusmenu_for_widget (GtkWidget * widget)
{
// Sometimes, an app will directly find and modify the label
// (like empathy), so watch the label especially for that.
- dbusmenu_menuitem_property_set (mi,
- "label",
- gtk_label_get_text (GTK_LABEL (label)));
+ gchar * text = sanitize_label_text (gtk_label_get_label (GTK_LABEL (label)));
+ dbusmenu_menuitem_property_set (mi, "label", text);
+ g_free (text);
pdata->label = label;
g_signal_connect (G_OBJECT (label),
@@ -673,9 +690,11 @@ label_notify_cb (GtkWidget *widget,
if (pspec->name == g_intern_static_string ("label"))
{
+ gchar * text = sanitize_label_text (gtk_label_get_label (GTK_LABEL (widget)));
dbusmenu_menuitem_property_set (child,
DBUSMENU_MENUITEM_PROP_LABEL,
- gtk_label_get_text (GTK_LABEL (widget)));
+ text);
+ g_free (text);
}
}
@@ -729,9 +748,11 @@ action_notify_cb (GtkAction *action,
}
else if (pspec->name == g_intern_static_string ("label"))
{
+ gchar * text = sanitize_label_text (gtk_action_get_label (action));
dbusmenu_menuitem_property_set (mi,
DBUSMENU_MENUITEM_PROP_LABEL,
- gtk_action_get_label (action));
+ text);
+ g_free (text);
}
}