diff options
| author | Ted Gould <ted@gould.cx> | 2012-06-13 14:27:08 -0500 |
|---|---|---|
| committer | Ted Gould <ted@gould.cx> | 2012-06-13 14:27:08 -0500 |
| commit | e3950826c9eae772094139ae3abd6a966d6b39e0 (patch) | |
| tree | 853d23921340babcf66baba411fdebe16ef5f95a /libdbusmenu-gtk | |
| parent | b30eb6635cdc00589e85b2867ce056d33dee8451 (diff) | |
| parent | 4e49daa82ca948228a7cef9fb552f703d0c80757 (diff) | |
| download | libdbusmenu-e3950826c9eae772094139ae3abd6a966d6b39e0.tar.gz libdbusmenu-e3950826c9eae772094139ae3abd6a966d6b39e0.tar.bz2 libdbusmenu-e3950826c9eae772094139ae3abd6a966d6b39e0.zip | |
Merging in Ubuntu Desktop
Diffstat (limited to 'libdbusmenu-gtk')
| -rw-r--r-- | libdbusmenu-gtk/genericmenuitem.c | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/libdbusmenu-gtk/genericmenuitem.c b/libdbusmenu-gtk/genericmenuitem.c index 9effd82..4125828 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 "_" */ +G_INLINE_FUNC 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) @@ -314,11 +335,15 @@ set_label (GtkMenuItem * menu_item, const gchar * in_label) labelw = GTK_LABEL(gtk_accel_label_new(local_label)); gtk_label_set_use_markup(GTK_LABEL(labelw), TRUE); gtk_misc_set_alignment(GTK_MISC(labelw), 0.0, 0.5); + gtk_accel_label_set_accel_widget(GTK_ACCEL_LABEL(labelw), GTK_WIDGET(menu_item)); if (has_mnemonic(in_label, FALSE)) { 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)); @@ -340,10 +365,11 @@ set_label (GtkMenuItem * menu_item, const gchar * in_label) } else { if (has_mnemonic(in_label, FALSE)) { 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 { - gtk_label_set_markup(labelw, local_label); + gchar * sanitized = sanitize_label(local_label); + gtk_label_set_markup(labelw, sanitized); + g_free(sanitized); } } } |
