diff options
author | Ted Gould <ted@gould.cx> | 2012-04-09 12:02:05 -0500 |
---|---|---|
committer | Ted Gould <ted@gould.cx> | 2012-04-09 12:02:05 -0500 |
commit | ef2f1b8d2e827050e91b2bcdaf75ebc2cdae69a4 (patch) | |
tree | 210a6f5e45c5d515c7012bd11e283df9617469a0 /libdbusmenu-gtk | |
parent | 475110aa2fe3a47cf6331fbd5941f34a9461fd81 (diff) | |
download | libdbusmenu-ef2f1b8d2e827050e91b2bcdaf75ebc2cdae69a4.tar.gz libdbusmenu-ef2f1b8d2e827050e91b2bcdaf75ebc2cdae69a4.tar.bz2 libdbusmenu-ef2f1b8d2e827050e91b2bcdaf75ebc2cdae69a4.zip |
Check the string for mnemonic support when setting the value
Diffstat (limited to 'libdbusmenu-gtk')
-rw-r--r-- | libdbusmenu-gtk/genericmenuitem.c | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/libdbusmenu-gtk/genericmenuitem.c b/libdbusmenu-gtk/genericmenuitem.c index e9c8367..09e509f 100644 --- a/libdbusmenu-gtk/genericmenuitem.c +++ b/libdbusmenu-gtk/genericmenuitem.c @@ -216,6 +216,31 @@ get_text_color (GenericmenuitemDisposition disposition, GtkWidget * widget) return g_strdup(values[disposition].default_color); } +/* Check to see if we've got mnemonic stuff goin' on */ +static gboolean +has_mnemonic (const gchar * string, gboolean previous_underscore) +{ + if (string == NULL || string[0] == '\0') { + return FALSE; + } + + if (g_utf8_get_char(string) == '_') { + if (previous_underscore) { + return has_mnemonic(g_utf8_next_char(string), FALSE); + } else { + return has_mnemonic(g_utf8_next_char(string), TRUE); + } + } else { + if (previous_underscore) { + return TRUE; + } else { + return has_mnemonic(g_utf8_next_char(string), FALSE); + } + } + + return FALSE; +} + /* Set the label on the item */ static void set_label (GtkMenuItem * menu_item, const gchar * in_label) @@ -287,11 +312,15 @@ set_label (GtkMenuItem * menu_item, const gchar * in_label) if (labelw == NULL) { /* Build it */ labelw = GTK_LABEL(gtk_accel_label_new(local_label)); - gtk_label_set_use_underline(GTK_LABEL(labelw), TRUE); 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)); - gtk_label_set_markup_with_mnemonic(labelw, local_label); + + 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); + } + gtk_widget_show(GTK_WIDGET(labelw)); /* Check to see if it needs to be in the bin for this |