diff options
author | Charles Kerr <charles.kerr@canonical.com> | 2012-04-11 11:41:17 -0500 |
---|---|---|
committer | Charles Kerr <charles.kerr@canonical.com> | 2012-04-11 11:41:17 -0500 |
commit | 02c40be3ab8f5c5ed9ba89911364628a255ae607 (patch) | |
tree | e60c7b76e5587825e530ae298d8ae70d72f09aea | |
parent | a217d86f8ad6f83b5604ef36a71f7752199f8d04 (diff) | |
parent | 1a2b0942da2b73c6338516144f0b77ac5696db74 (diff) | |
download | libdbusmenu-02c40be3ab8f5c5ed9ba89911364628a255ae607.tar.gz libdbusmenu-02c40be3ab8f5c5ed9ba89911364628a255ae607.tar.bz2 libdbusmenu-02c40be3ab8f5c5ed9ba89911364628a255ae607.zip |
merge lp:~ted/dbusmenu/lp903200 to be more explicit about what is and isn't a mnemonic.
-rw-r--r-- | libdbusmenu-gtk/genericmenuitem.c | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/libdbusmenu-gtk/genericmenuitem.c b/libdbusmenu-gtk/genericmenuitem.c index e9c8367..9effd82 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 @@ -309,7 +338,13 @@ set_label (GtkMenuItem * menu_item, const gchar * in_label) getting in. */ suppress_update = TRUE; } else { - 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); + } else { + gtk_label_set_markup(labelw, local_label); + } } } |