diff options
author | Matthias Clasen <mclasen@redhat.com> | 2011-02-09 17:32:05 -0500 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2011-02-09 17:32:05 -0500 |
commit | 3f1c95de8d411b956c6e51aa3bcc9baed1ab4558 (patch) | |
tree | cca5c4440fe024c1d630d6fa23fdb9e4e188d8e0 /gtk/gtkaccellabel.c | |
parent | 981cadb578a0f60e941b2ed942c5f9df5d1faa58 (diff) | |
download | gtk+-3f1c95de8d411b956c6e51aa3bcc9baed1ab4558.tar.gz |
Don't try to modify readonly strings
This was an oversight in the recent accel label improvement.
When we get an untranslated string back from gettext(), it is
not ok to replace '_' by ' ' in-place. Instead, do it while
appending to the GString.
https://bugzilla.gnome.org/show_bug.cgi?id=641912
Diffstat (limited to 'gtk/gtkaccellabel.c')
-rw-r--r-- | gtk/gtkaccellabel.c | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/gtk/gtkaccellabel.c b/gtk/gtkaccellabel.c index 0b0e1bc780..e48933dc05 100644 --- a/gtk/gtkaccellabel.c +++ b/gtk/gtkaccellabel.c @@ -597,30 +597,34 @@ gtk_accel_label_get_string (GtkAccelLabel *accel_label) } /* Underscores in key names are better displayed as spaces - * E.g., Page_Up should be "Page Up" + * E.g., Page_Up should be "Page Up". + * + * Some keynames also have prefixes that are not suitable + * for display, e.g XF86AudioMute, so strip those out, too. + * + * This function is only called on untranslated keynames, + * so no need to be UTF-8 safe. */ static void -substitute_underscores (gchar *str) +append_without_underscores (GString *s, + gchar *str) { - char *p; + gchar *p; - for (p = str; *p; p++) - if (*p == '_') - *p = ' '; -} - -/* Some keynames have prefixes that are not suitable - * for display, e.g XF86AudioMute - */ -static gchar * -strip_prefix (gchar *str) -{ if (g_str_has_prefix (str, "XF86")) - return str + 4; + p = str + 4; else if (g_str_has_prefix (str, "ISO_")) - return str + 4; + p = str + 4; + else + p = str; - return str; + for ( ; *p; p++) + { + if (*p == '_') + g_string_append_c (s, ' '); + else + g_string_append_c (s, *p); + } } /* On Mac, if the key has symbolic representation (e.g. arrow keys), @@ -846,11 +850,7 @@ _gtk_accel_label_class_get_accelerator_label (GtkAccelLabelClass *klass, const gchar *str; str = g_dpgettext2 (GETTEXT_PACKAGE, "keyboard label", tmp); if (str == tmp) - { - substitute_underscores (tmp); - tmp = strip_prefix (tmp); - g_string_append (gstring, tmp); - } + append_without_underscores (gstring, tmp); else g_string_append (gstring, str); } |