libgimpbase/Makefile.am added new files that hold the new

2003-02-05  Sven Neumann  <sven@gimp.org>

	* libgimpbase/Makefile.am
	* libgimpbase/gimputils.[ch]: added new files that hold the new
	gimp_utf8_strtrim() routine; it might be useful in more places.

	* libgimpbase/gimpdatafiles.c (gimp_datafiles_read_directories):
	silently ignore directories in the path that can't be opened.

	* app/core/gimpobject.c (gimp_object_set_name_safe): use
	gimp_utf8_strtrim().

	* app/widgets/gimpwidgets-utils.[ch]
	* app/tools/gimptextoptions.c: try to make the text tool options
	look more like all other tool options. Still needs work; I'll
	leave this up to Mitch ...

        This byte --> <-- is the millionth in this file!
This commit is contained in:
Sven Neumann 2003-02-05 22:15:39 +00:00 committed by Sven Neumann
parent 83f2738a3b
commit 7aaff76971
16 changed files with 257 additions and 136 deletions

View File

@ -1,3 +1,22 @@
2003-02-05 Sven Neumann <sven@gimp.org>
* libgimpbase/Makefile.am
* libgimpbase/gimputils.[ch]: added new files that hold the new
gimp_utf8_strtrim() routine; it might be useful in more places.
* libgimpbase/gimpdatafiles.c (gimp_datafiles_read_directories):
silently ignore directories in the path that can't be opened.
* app/core/gimpobject.c (gimp_object_set_name_safe): use
gimp_utf8_strtrim().
* app/widgets/gimpwidgets-utils.[ch]
* app/tools/gimptextoptions.c: try to make the text tool options
look more like all other tool options. Still needs work; I'll
leave this up to Mitch ...
This byte --> <-- is the millionth in this file!
2003-02-05 Manish Singh <yosh@gimp.org>
* plug-ins/common/jpeg.c (run): if the quality level is close to zero

View File

@ -22,6 +22,8 @@
#include <glib-object.h>
#include "libgimpbase/gimputils.h"
#include "core-types.h"
#include "gimpobject.h"
@ -240,63 +242,21 @@ gimp_object_set_name (GimpObject *object,
/* A safe version of gimp_object_set_name() that takes care
* of newlines and overly long names.
*/
#define MAX_NAME_LEN 30
void
gimp_object_set_name_safe (GimpObject *object,
const gchar *name)
{
/* FIXME: should to make this translatable */
static const gchar *ellipsis = "...";
static const gint e_len = 3;
g_return_if_fail (GIMP_IS_OBJECT (object));
if (name)
{
const gchar *p;
const gchar *newline = NULL;
gint chars = 0;
gunichar unichar;
for (p = name; p && !newline; p = g_utf8_next_char (p))
{
if (++chars > MAX_NAME_LEN)
break;
if ((!object->name && !name) ||
(object->name && name && !strcmp (object->name, name)))
return;
unichar = g_utf8_get_char (p);
g_free (object->name);
switch (g_unichar_break_type (unichar))
{
case G_UNICODE_BREAK_MANDATORY:
case G_UNICODE_BREAK_LINE_FEED:
newline = p;
break;
default:
break;
}
}
object->name = gimp_utf8_strtrim (name, 30);
if (p)
{
gchar safe_name[MAX_NAME_LEN * 6 + e_len + 1];
gsize len;
len = p - name;
memcpy (safe_name, name, len);
if (newline)
safe_name[len-1] = ' ';
g_strlcpy (safe_name + len, ellipsis, e_len + 1);
gimp_object_set_name (object, safe_name);
return;
}
}
gimp_object_set_name (object, name);
gimp_object_name_changed (object);
}
const gchar *

View File

@ -122,7 +122,7 @@ gimp_text_options_gui (GimpToolOptions *tool_options)
"font");
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
_("Font:"), 1.0, 0.5,
font_selection, 2, FALSE);
font_selection, 3, FALSE);
digits = gimp_unit_get_digits (options->text->font_size_unit);
spinbutton = gimp_prop_spin_button_new (G_OBJECT (options->text),
@ -130,39 +130,40 @@ gimp_text_options_gui (GimpToolOptions *tool_options)
1.0, 10.0, digits);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 1,
_("Size:"), 1.0, 0.5,
spinbutton, 1, FALSE);
spinbutton, 2, FALSE);
unit_menu = gimp_prop_unit_menu_new (G_OBJECT (options->text),
"font-size-unit", "%a");
g_object_set_data (G_OBJECT (unit_menu), "set_digits", spinbutton);
gtk_table_attach (GTK_TABLE (table), unit_menu, 2, 3, 1, 2,
gtk_table_attach (GTK_TABLE (table), unit_menu, 3, 4, 1, 2,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
gtk_widget_show (unit_menu);
button = gimp_prop_color_button_new (G_OBJECT (options->text),
"color", _("Text Color"),
48, 24, GIMP_COLOR_AREA_FLAT);
-1, 24, GIMP_COLOR_AREA_FLAT);
gimp_color_panel_set_context (GIMP_COLOR_PANEL (button),
GIMP_CONTEXT (options));
gimp_table_attach_aligned (GTK_TABLE (table), 0, 2,
_("Color:"), 1.0, 0.5, button, 2, TRUE);
_("Color:"), 1.0, 0.5, button, 1, FALSE);
box = gimp_prop_enum_stock_box_new (G_OBJECT (options->text),
"justify", "gtk-justify", 0, 0);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 3,
_("Justify:"), 1.0, 0.5, box, 2, TRUE);
_("Justify:"), 1.0, 0.5, box, 3, TRUE);
spinbutton = gimp_prop_spin_button_new (G_OBJECT (options->text),
"indent", 1.0, 10.0, 1);
gtk_entry_set_width_chars (GTK_ENTRY (spinbutton), 5);
gimp_table_attach_stock (GTK_TABLE (table), 0, 4,
_("Indentation"), spinbutton);
gimp_table_attach_stock (GTK_TABLE (table), 4,
_("Indent:"), 0.5, spinbutton, NULL);
spinbutton = gimp_prop_spin_button_new (G_OBJECT (options->text),
"line-spacing", 1.0, 10.0, 1);
gtk_entry_set_width_chars (GTK_ENTRY (spinbutton), 5);
gimp_table_attach_stock (GTK_TABLE (table), 0, 5,
GIMP_STOCK_LINE_SPACING, spinbutton);
gimp_table_attach_stock (GTK_TABLE (table), 5,
_("Line\nSpacing:"), 0.0, spinbutton,
GIMP_STOCK_LINE_SPACING);
}
static void

View File

@ -30,6 +30,8 @@
#include <gtk/gtk.h>
#include <pango/pangoft2.h>
#include "libgimpwidgets/gimpwidgets.h"
#include "widgets-types.h"
#include "core/gimpmarshal.h"
@ -165,6 +167,10 @@ gimp_font_selection_init (GimpFontSelection *fontsel)
gtk_box_pack_end (GTK_BOX (fontsel), button, FALSE, FALSE, 0);
gtk_widget_show (button);
gimp_help_set_help_data (button,
_("Click to open the Font Selection Dialog"),
"dialogs/font_selection.html");
image = gtk_image_new_from_stock (GTK_STOCK_SELECT_FONT, GTK_ICON_SIZE_MENU);
gtk_container_add (GTK_CONTAINER (button), image);
gtk_widget_show (image);

View File

@ -242,49 +242,46 @@ gimp_menu_position (GtkMenu *menu,
void
gimp_table_attach_stock (GtkTable *table,
gint column,
gint row,
const gchar *stock_id,
GtkWidget *widget)
const gchar *label_text,
gdouble yalign,
GtkWidget *widget,
const gchar *stock_id)
{
GtkStockItem item;
GtkWidget *label;
GtkWidget *image;
GtkWidget *image;
GtkWidget *label;
g_return_if_fail (GTK_IS_TABLE (table));
g_return_if_fail (stock_id != NULL);
g_return_if_fail (label_text != NULL);
if (gtk_stock_lookup (stock_id, &item))
{
image = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_BUTTON);
label = gtk_label_new_with_mnemonic (item.label);
}
else
{
image = gtk_image_new_from_stock (GTK_STOCK_MISSING_IMAGE,
GTK_ICON_SIZE_BUTTON);
label = gtk_label_new_with_mnemonic (stock_id);
}
label = gtk_label_new_with_mnemonic (label_text);
gtk_table_attach (table, image, column, column + 1, row, row + 1,
GTK_SHRINK, GTK_SHRINK, 0, 0);
gtk_widget_show (image);
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_table_attach (table, label, column + 1, column + 2, row, row + 1,
GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
gtk_misc_set_alignment (GTK_MISC (label), 1.0, yalign);
gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_RIGHT);
gtk_table_attach (table, label, 0, 1, row, row + 1,
GTK_FILL, GTK_FILL, 0, 0);
gtk_widget_show (label);
if (!widget)
return;
if (widget)
{
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (GTK_IS_WIDGET (widget));
gtk_table_attach (table, widget, 1, 3, row, row + 1,
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_widget_show (widget);
gtk_table_attach (table, widget, column + 2, column + 3, row, row + 1,
GTK_SHRINK, GTK_SHRINK, 0, 0);
gtk_widget_show (widget);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
}
gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
image = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_BUTTON);
if (image)
{
gtk_misc_set_alignment (GTK_MISC (image), 0.0, 0.5);
gtk_table_attach (table, image, 3, 4, row, row + 1,
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_widget_show (image);
}
}

View File

@ -37,10 +37,11 @@ void gimp_menu_position (GtkMenu *menu,
guint32 *activate_time);
void gimp_table_attach_stock (GtkTable *table,
gint column,
gint row,
const gchar *stock_id,
GtkWidget *widget);
gint row,
const gchar *label_text,
gdouble yalign,
GtkWidget *widget,
const gchar *stock_id);
const gchar * gimp_get_mod_name_shift (void);
const gchar * gimp_get_mod_name_control (void);

View File

@ -1,3 +1,9 @@
2003-02-05 Sven Neumann <sven@gimp.org>
* devel-docs/libgimpbase/libgimpbase-docs.sgml
* devel-docs/libgimpbase/libgimpbase-sections.txt
* devel-docs/libgimpbase/tmpl/gimputils.sgml: added new file.
2003-01-31 Sven Neumann <sven@gimp.org>
* libgimpwidgets/Makefile.am (HTML_IMAGES)

View File

@ -7,6 +7,7 @@
<!entity GimpParasiteIO SYSTEM "sgml/gimpparasiteio.sgml">
<!entity GimpSignal SYSTEM "sgml/gimpsignal.sgml">
<!entity GimpUnit SYSTEM "sgml/gimpunit.sgml">
<!entity GimpUtils SYSTEM "sgml/gimputils.sgml">
<!entity GimpVersion SYSTEM "sgml/gimpversion.sgml">
<!entity GimpProtocol SYSTEM "sgml/gimpprotocol.sgml">
<!entity GimpWire SYSTEM "sgml/gimpwire.sgml">
@ -27,6 +28,7 @@
&GimpParasiteIO;
&GimpSignal;
&GimpUnit;
&GimpUtils;
&GimpProtocol;
&GimpWire;
</chapter>

View File

@ -122,6 +122,11 @@ gimp_unit_get_singular
gimp_unit_get_plural
</SECTION>
<SECTION>
<FILE>gimputils</FILE>
gimp_utf8_strtrim
</SECTION>
<SECTION>
<FILE>gimpwire</FILE>
WireMessage

View File

@ -0,0 +1,28 @@
<!-- ##### SECTION Title ##### -->
gimputils
<!-- ##### SECTION Short_Description ##### -->
<!-- ##### SECTION Long_Description ##### -->
<para>
</para>
<!-- ##### SECTION See_Also ##### -->
<para>
</para>
<!-- ##### FUNCTION gimp_utf8_strtrim ##### -->
<para>
</para>
@str:
@max_chars:
@Returns:

View File

@ -83,6 +83,8 @@ libgimpbase_1_3_la_SOURCES = \
gimpprotocol.h \
gimpsignal.c \
gimpsignal.h \
gimputils.c \
gimputils.h \
gimpwire.c \
gimpwire.h
@ -91,6 +93,7 @@ libgimpbaseinclude_HEADERS = \
gimpbasetypes.h \
gimplimits.h \
gimpunit.h \
gimputils.h \
gimpversion.h \
\
gimpdatafiles.h \

View File

@ -28,6 +28,7 @@
#include <libgimpbase/gimplimits.h>
#include <libgimpbase/gimpparasite.h>
#include <libgimpbase/gimpunit.h>
#include <libgimpbase/gimputils.h>
#include <libgimpbase/gimpversion.h>
#ifndef G_OS_WIN32

View File

@ -151,12 +151,7 @@ gimp_datafiles_read_directories (const gchar *path_str,
{
dir = g_dir_open ((gchar *) list->data, 0, NULL);
if (! dir)
{
g_message ("error reading datafiles directory \"%s\"",
(gchar *) list->data);
}
else
if (dir)
{
while ((dir_ent = g_dir_read_name (dir)))
{

97
libgimpbase/gimputils.c Normal file
View File

@ -0,0 +1,97 @@
/* 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"
/**
* 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;
}

28
libgimpbase/gimputils.h Normal file
View File

@ -0,0 +1,28 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* This library 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 library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __GIMP_UTILS_H__
#define __GIMP_UTILS_H__
gchar * gimp_utf8_strtrim (const gchar *str,
gint max_chars);
#endif /* __GIMP_UTILS_H__ */

View File

@ -27,6 +27,8 @@
#include <glib-object.h>
#include "libgimpbase/gimputils.h"
#include "core-types.h"
#include "gimpobject.h"
@ -245,51 +247,21 @@ gimp_object_set_name (GimpObject *object,
/* A safe version of gimp_object_set_name() that takes care
* of newlines and overly long names.
*/
#define MAX_NAME_LEN 32
void
gimp_object_set_name_safe (GimpObject *object,
const gchar *name)
{
gchar *newline;
gsize len;
g_return_if_fail (GIMP_IS_OBJECT (object));
if (name)
{
newline = strchr (name, '\n');
if (newline)
len = newline - name + 1;
else
len = strlen (name);
if ((!object->name && !name) ||
(object->name && name && !strcmp (object->name, name)))
return;
if (len > MAX_NAME_LEN)
newline = NULL;
g_free (object->name);
if (newline || len > MAX_NAME_LEN)
{
gchar *safe_name;
len = MIN (len, MAX_NAME_LEN);
object->name = gimp_utf8_strtrim (name, 30);
safe_name = g_new (gchar, len + 4);
memcpy (safe_name, name, len);
if (newline)
safe_name[len-1] = ' ';
g_strlcpy (safe_name + len, "...", 4);
gimp_object_set_name (object, safe_name);
g_free (safe_name);
return;
}
}
gimp_object_set_name (object, name);
gimp_object_name_changed (object);
}
const gchar *