diff --git a/ChangeLog b/ChangeLog index 9cc8ec299e..1e278cdb6b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2004-04-29 Michael Natterer + + * libgimpbase/gimputils.[ch] (gimp_escape_uline): new function + which does the opposite of gimp_strip_uline(). + + * app/actions/file-actions.c (file_actions_last_opened_update): + escape ulines in filenames so they don't end up as mnemonics. + Spotted by Pedro Gimeno. + 2004-04-29 Manish Singh * plug-ins/pygimp/plug-ins/py-slice.py: Quick fix to make uppercase diff --git a/app/actions/file-actions.c b/app/actions/file-actions.c index febbce6323..8d061a6c59 100644 --- a/app/actions/file-actions.c +++ b/app/actions/file-actions.c @@ -20,6 +20,7 @@ #include +#include "libgimpbase/gimpbase.h" #include "libgimpwidgets/gimpwidgets.h" #include "actions-types.h" @@ -240,20 +241,25 @@ file_actions_last_opened_update (GimpContainer *container, const gchar *uri; gchar *filename; gchar *basename; + gchar *escaped; uri = gimp_object_get_name (GIMP_OBJECT (imagefile)); filename = file_utils_uri_to_utf8_filename (uri); basename = file_utils_uri_to_utf8_basename (uri); + escaped = gimp_escape_uline (basename); + + g_free (basename); + g_object_set (G_OBJECT (action), - "label", basename, + "label", escaped, "tooltip", filename, "visible", TRUE, NULL); g_free (filename); - g_free (basename); + g_free (escaped); g_object_set_data (G_OBJECT (action), "gimp-imagefile", imagefile); diff --git a/libgimpbase/gimputils.c b/libgimpbase/gimputils.c index 53136d6fce..30f494009a 100644 --- a/libgimpbase/gimputils.c +++ b/libgimpbase/gimputils.c @@ -331,3 +331,44 @@ gimp_strip_uline (const gchar *str) return escaped; } + +/** + * gimp_escape_uline: + * @str: Underline infested string (or %NULL) + * + * This function returns a copy of @str with all underline converted + * to two adjacent underlines. This comes in handy when needing to display + * strings with underlines (like filenames) in a place that would convert + * them to mnemonics. + * + * Return value: A (possibly escaped) copy of @str which should be + * freed using g_free() when it is not needed any longer. + **/ +gchar * +gimp_escape_uline (const gchar *str) +{ + gchar *escaped; + gchar *p; + gint n_ulines = 0; + + if (! str) + return NULL; + + for (p = (gchar *) str; *p; p++) + if (*p == '_') + n_ulines++; + + p = escaped = g_malloc (strlen (str) + n_ulines + 1); + + while (*str) + { + if (*str == '_') + *p++ = '_'; + + *p++ = *str++; + } + + *p = '\0'; + + return escaped; +} diff --git a/libgimpbase/gimputils.h b/libgimpbase/gimputils.h index 1bb457344f..b607e2cfc5 100644 --- a/libgimpbase/gimputils.h +++ b/libgimpbase/gimputils.h @@ -32,6 +32,7 @@ const gchar * gimp_filename_to_utf8 (const gchar *filename); gchar * gimp_memsize_to_string (guint64 memsize); gchar * gimp_strip_uline (const gchar *str); +gchar * gimp_escape_uline (const gchar *str); #endif /* __GIMP_UTILS_H__ */