aboutsummaryrefslogtreecommitdiff
path: root/libdbusmenu-gtk
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2012-04-11 17:26:45 -0500
committerCharles Kerr <charles.kerr@canonical.com>2012-04-11 17:26:45 -0500
commitc45a8fe03a7b3653af2d2f8586668dcb3c21899b (patch)
treea4f4042b22a7475d38b391fc8747f9781c0ec029 /libdbusmenu-gtk
parent2421f72a9f0acb6afb3e5209a434c409bf3a409d (diff)
parent9dd4e51920a5adccafbc2091d6e29391ab0c3bb5 (diff)
downloadlibdbusmenu-c45a8fe03a7b3653af2d2f8586668dcb3c21899b.tar.gz
libdbusmenu-c45a8fe03a7b3653af2d2f8586668dcb3c21899b.tar.bz2
libdbusmenu-c45a8fe03a7b3653af2d2f8586668dcb3c21899b.zip
merge lp:~ted/dbusmenu/double-underscore to fix the double underscore regression introduced earlier.
Diffstat (limited to 'libdbusmenu-gtk')
-rw-r--r--libdbusmenu-gtk/genericmenuitem.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/libdbusmenu-gtk/genericmenuitem.c b/libdbusmenu-gtk/genericmenuitem.c
index 9effd82..81d67fe 100644
--- a/libdbusmenu-gtk/genericmenuitem.c
+++ b/libdbusmenu-gtk/genericmenuitem.c
@@ -241,6 +241,27 @@ has_mnemonic (const gchar * string, gboolean previous_underscore)
return FALSE;
}
+/* Sanitize the label by removing "__" meaning "_" */
+gchar *
+sanitize_label (const gchar * in_label)
+{
+ static GRegex * underscore_regex = NULL;
+
+ g_return_val_if_fail(in_label != NULL, NULL);
+
+ if (underscore_regex == NULL) {
+ underscore_regex = g_regex_new("__", 0, 0, NULL);
+ }
+
+ return g_regex_replace_literal(underscore_regex,
+ in_label,
+ -1, /* length */
+ 0, /* start */
+ "_", /* replacement */
+ 0, /* flags */
+ NULL); /* error */
+}
+
/* Set the label on the item */
static void
set_label (GtkMenuItem * menu_item, const gchar * in_label)
@@ -319,6 +340,10 @@ set_label (GtkMenuItem * menu_item, const gchar * in_label)
gtk_label_set_use_underline(GTK_LABEL(labelw), TRUE);
gtk_accel_label_set_accel_widget(GTK_ACCEL_LABEL(labelw), GTK_WIDGET(menu_item));
gtk_label_set_markup_with_mnemonic(labelw, local_label);
+ } else {
+ gchar * sanitized = sanitize_label(local_label);
+ gtk_label_set_markup(labelw, sanitized);
+ g_free(sanitized);
}
gtk_widget_show(GTK_WIDGET(labelw));
@@ -343,7 +368,9 @@ set_label (GtkMenuItem * menu_item, const gchar * in_label)
gtk_accel_label_set_accel_widget(GTK_ACCEL_LABEL(labelw), GTK_WIDGET(menu_item));
gtk_label_set_markup_with_mnemonic(labelw, local_label);
} else {
- gtk_label_set_markup(labelw, local_label);
+ gchar * sanitized = sanitize_label(local_label);
+ gtk_label_set_markup(labelw, sanitized);
+ g_free(sanitized);
}
}
}