mirror of
https://gitlab.gnome.org/GNOME/gimp
synced 2024-10-20 19:43:01 +00:00
f36a63f68c
2003-08-09 Henrik Brix Andersen <brix@gimp.org> * gimp/app/widgets/gimpwidgets-utils.[ch]: removed function gimp_menu_path_strip_uline() ... * gimp/libgimpbase/gimputils.[ch]: ... and added it here under the name gimp_strip_uline() * gimp/devel-docs/libgimpbase/libgimpbase-sections.txt: added gimp_strip_uline to gimputils section * gimp/app/plug-in/plug-in.c * gimp/app/widgets/gimpitemfactory.c * gimp/app/widgets/gimptoolbox. * gimp/app/gui/plug-in-menus.c: changed accordingly * gimp/plug-ins/script-fu/script-fu-scripts.c (script_fu_interface): use gimp_strip_uline() to strip mnemonics from script-fu menu paths * gimp/app/gui/vectors-menu.c * gimp/app/gui/templates-menu.c * gimp/app/gui/qmask-menu.c * gimp/app/gui/palettes-menu.c * gimp/app/gui/palette-editor-menu.c * gimp/app/gui/images-menu.c * gimp/app/gui/gradients-menu.c * gimp/app/gui/gradient-editor-menu.c * gimp/app/gui/documents-menu.c * gimp/app/gui/dialogs-menu.c * gimp/app/gui/colormap-editor-menu.c * gimp/app/gui/channels-menu.c * gimp/app/gui/buffers-menu.c * gimp/app/gui/brushes-menu.c * gimp/app/gui/layers-menu.c * gimp/plug-ins/pygimp/plug-ins/clothify.py * gimp/plug-ins/pygimp/plug-ins/shadow_bevel.py * gimp/plug-ins/pygimp/plug-ins/whirlpinch.py * gimp/plug-ins/pygimp/plug-ins/foggify.py * gimp/plug-ins/script-fu/scripts/*.scm * gimp/plug-ins/script-fu/script-fu.c: added mnemonics fixing more of bug #106991 * gimp/app/gui/error-console-menu.c (error_console_menu_update): updated menu item names, added mnemonics * gimp/plug-ins/common/animoptimize.c * gimp/plug-ins/common/animationplay.c: don't prepend every menu entry with "Animation"
186 lines
4.5 KiB
C
186 lines
4.5 KiB
C
/* LIBGIMP - The GIMP Library
|
|
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
|
|
*
|
|
* gimputils.c
|
|
*
|
|
* Copyright (C) 2003 Sven Neumann <sven@gimp.org>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
*/
|
|
|
|
#include "config.h"
|
|
|
|
#include <string.h>
|
|
|
|
#include <glib.h>
|
|
|
|
#include "gimputils.h"
|
|
|
|
#include "libgimp/libgimp-intl.h"
|
|
|
|
|
|
/**
|
|
* gimp_utf8_strtrim:
|
|
* @str: an UTF-8 encoded string (or %NULL)
|
|
* @max_chars: the maximum number of characters before the string get
|
|
* trimmed
|
|
*
|
|
* Creates a (possibly trimmed) copy of @str. The string is cut if it
|
|
* exceeds @max_chars characters or on the first newline. The fact
|
|
* that the string was trimmed is indicated by appending an ellipsis.
|
|
*
|
|
* Returns: A (possibly trimmed) copy of @str which should be freed
|
|
* using g_free() when it is not needed any longer.
|
|
**/
|
|
gchar *
|
|
gimp_utf8_strtrim (const gchar *str,
|
|
gint max_chars)
|
|
{
|
|
/* FIXME: should we make this translatable? */
|
|
static const gchar *ellipsis = "...";
|
|
static const gint e_len = 3;
|
|
|
|
if (str)
|
|
{
|
|
const gchar *p;
|
|
const gchar *newline = NULL;
|
|
gint chars = 0;
|
|
gunichar unichar;
|
|
|
|
for (p = str; *p; p = g_utf8_next_char (p))
|
|
{
|
|
if (++chars > max_chars)
|
|
break;
|
|
|
|
unichar = g_utf8_get_char (p);
|
|
|
|
switch (g_unichar_break_type (unichar))
|
|
{
|
|
case G_UNICODE_BREAK_MANDATORY:
|
|
case G_UNICODE_BREAK_LINE_FEED:
|
|
newline = p;
|
|
break;
|
|
default:
|
|
continue;
|
|
}
|
|
|
|
break;
|
|
}
|
|
|
|
if (*p)
|
|
{
|
|
gsize len = p - str;
|
|
gchar *trimmed = g_new (gchar, len + e_len + 2);
|
|
|
|
memcpy (trimmed, str, len);
|
|
if (newline)
|
|
trimmed[len++] = ' ';
|
|
|
|
g_strlcpy (trimmed + len, ellipsis, e_len + 1);
|
|
|
|
return trimmed;
|
|
}
|
|
|
|
return g_strdup (str);
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
/**
|
|
* gimp_memsize_to_string:
|
|
* @memsize: A memory size in bytes.
|
|
*
|
|
* This function returns a human readable, translated representation
|
|
* of the passed @memsize. Large values are rounded to the closest
|
|
* reasonable memsize unit, e.g.: "3456" becomes "3456 Bytes", "4100"
|
|
* becomes "4 KB" and so on.
|
|
*
|
|
* Return value: A human-readable, translated string.
|
|
**/
|
|
gchar *
|
|
gimp_memsize_to_string (gulong memsize)
|
|
{
|
|
if (memsize < 4096)
|
|
{
|
|
return g_strdup_printf (_("%d Bytes"), (gint) memsize);
|
|
}
|
|
else if (memsize < 1024 * 10)
|
|
{
|
|
return g_strdup_printf (_("%.2f KB"), (gdouble) memsize / 1024.0);
|
|
}
|
|
else if (memsize < 1024 * 100)
|
|
{
|
|
return g_strdup_printf (_("%.1f KB"), (gdouble) memsize / 1024.0);
|
|
}
|
|
else if (memsize < 1024 * 1024)
|
|
{
|
|
return g_strdup_printf (_("%d KB"), (gint) memsize / 1024);
|
|
}
|
|
else if (memsize < 1024 * 1024 * 10)
|
|
{
|
|
memsize /= 1024;
|
|
return g_strdup_printf (_("%.2f MB"), (gdouble) memsize / 1024.0);
|
|
}
|
|
else
|
|
{
|
|
memsize /= 1024;
|
|
return g_strdup_printf (_("%.1f MB"), (gdouble) memsize / 1024.0);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* gimp_strip_uline:
|
|
* @str: Underline infested string (or %NULL)
|
|
*
|
|
* This function returns a copy of @str stripped of underline
|
|
* characters. This comes in handy when needing to strip mnemonics
|
|
* from menu paths etc.
|
|
*
|
|
* Return value: A (possibly stripped) copy of @str which should be
|
|
* freed using g_free() when it is not needed any longer.
|
|
**/
|
|
gchar *
|
|
gimp_strip_uline (const gchar *str)
|
|
{
|
|
gchar *escaped;
|
|
gchar *p;
|
|
|
|
if (! str)
|
|
return NULL;
|
|
|
|
p = escaped = g_strdup (str);
|
|
|
|
while (*str)
|
|
{
|
|
if (*str == '_')
|
|
{
|
|
/* "__" means a literal "_" in the menu path */
|
|
if (str[1] == '_')
|
|
*p++ = *str++;
|
|
|
|
str++;
|
|
}
|
|
else
|
|
{
|
|
*p++ = *str++;
|
|
}
|
|
}
|
|
|
|
*p = '\0';
|
|
|
|
return escaped;
|
|
}
|