diff options
author | Ted Gould <ted@gould.cx> | 2012-04-11 16:25:22 -0500 |
---|---|---|
committer | Ted Gould <ted@gould.cx> | 2012-04-11 16:25:22 -0500 |
commit | 4b1d462aeb7ba623b007799daab4f2dfd5f6f540 (patch) | |
tree | 6525da0e65b83f0c1d7162ea62f9bd6a81dc7d27 | |
parent | 419e0fac4abedd8b61ad452bdaa1eee2758de103 (diff) | |
download | libdbusmenu-4b1d462aeb7ba623b007799daab4f2dfd5f6f540.tar.gz libdbusmenu-4b1d462aeb7ba623b007799daab4f2dfd5f6f540.tar.bz2 libdbusmenu-4b1d462aeb7ba623b007799daab4f2dfd5f6f540.zip |
Provide a function to sanitize the label and use that as Pango isn't doing it for us now
-rw-r--r-- | libdbusmenu-gtk/genericmenuitem.c | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/libdbusmenu-gtk/genericmenuitem.c b/libdbusmenu-gtk/genericmenuitem.c index 9effd82..bff4ee5 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; } +static GRegex * underscore_regex = NULL; + +/* Sanitize the label by removing "__" meaning "_" */ +gchar * +sanitize_label (const gchar * in_label) +{ + 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); } } } |