aboutsummaryrefslogtreecommitdiff
path: root/libdbusmenu-gtk
diff options
context:
space:
mode:
authorAlbert Astals <albert.astals@canonical.com>2012-06-04 13:18:43 +0200
committerAlbert Astals <albert.astals@canonical.com>2012-06-04 13:18:43 +0200
commit75bdca54d5e6838aece55c84db3fd3249a624dfb (patch)
tree1861f07fcc9ab4117fd81ab4bd10941f6f960a53 /libdbusmenu-gtk
parent8093d960da6b3d32549ba3fc58f2bdb58bffa768 (diff)
downloadlibdbusmenu-75bdca54d5e6838aece55c84db3fd3249a624dfb.tar.gz
libdbusmenu-75bdca54d5e6838aece55c84db3fd3249a624dfb.tar.bz2
libdbusmenu-75bdca54d5e6838aece55c84db3fd3249a624dfb.zip
Replace & with &amp; since we are using set_markup in the label
Diffstat (limited to 'libdbusmenu-gtk')
-rw-r--r--libdbusmenu-gtk/genericmenuitem.c29
1 files changed, 27 insertions, 2 deletions
diff --git a/libdbusmenu-gtk/genericmenuitem.c b/libdbusmenu-gtk/genericmenuitem.c
index 75bdbbd..ab57e86 100644
--- a/libdbusmenu-gtk/genericmenuitem.c
+++ b/libdbusmenu-gtk/genericmenuitem.c
@@ -262,6 +262,27 @@ sanitize_label (const gchar * in_label)
NULL); /* error */
}
+/* Replace '&' with '&amp' in the label */
+static gchar *
+replace_amps (const gchar * in_label)
+{
+ static GRegex * amp_regex = NULL;
+
+ g_return_val_if_fail(in_label != NULL, NULL);
+
+ if (amp_regex == NULL) {
+ amp_regex = g_regex_new("&", 0, 0, NULL);
+ }
+
+ return g_regex_replace_literal(amp_regex,
+ in_label,
+ -1, /* length */
+ 0, /* start */
+ "&amp;", /* replacement */
+ 0, /* flags */
+ NULL); /* error */
+}
+
/* Set the label on the item */
static void
set_label (GtkMenuItem * menu_item, const gchar * in_label)
@@ -338,11 +359,15 @@ set_label (GtkMenuItem * menu_item, const gchar * in_label)
gtk_accel_label_set_accel_widget(GTK_ACCEL_LABEL(labelw), GTK_WIDGET(menu_item));
if (has_mnemonic(in_label, FALSE)) {
+ gchar * amp_replaced = replace_amps (local_label);
gtk_label_set_use_underline(GTK_LABEL(labelw), TRUE);
- gtk_label_set_markup_with_mnemonic(labelw, local_label);
+ gtk_label_set_markup_with_mnemonic(labelw, amp_replaced);
+ g_free(amp_replaced);
} else {
gchar * sanitized = sanitize_label(local_label);
- gtk_label_set_markup(labelw, sanitized);
+ gchar * amp_replaced = replace_amps (sanitized);
+ gtk_label_set_markup(labelw, amp_replaced);
+ g_free(amp_replaced);
g_free(sanitized);
}