Commit 85adefe7 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

app/core/Makefile.am app/core/core-types.h added filter functionality for

2003-09-04  Sven Neumann  <sven@gimp.org>

	* app/core/Makefile.am
	* app/core/core-types.h
	* app/core/gimpcontainer-filter.[ch]: added filter functionality
	for GimpContainers.

	* tools/pdbgen/pdb/brushes.pdb
	* tools/pdbgen/pdb/fonts.pdb
	* tools/pdbgen/pdb/gradients.pdb
	* tools/pdbgen/pdb/palettes.pdb
	* tools/pdbgen/pdb/patterns.pdb: made the gimp_foo_get_list()
	PDB function somewhat useful by adding a filter parameter that
	allows to specify a regular expression to be used on the list.

	* app/pdb/Makefile.am: had to uglify the ugly hack even more :(

	* app/pdb/brushes_cmds.c
	* app/pdb/fonts_cmds.c
	* app/pdb/gradients_cmds.c
	* app/pdb/palettes_cmds.c
	* app/pdb/patterns_cmds.c
	* libgimp/gimpbrushes_pdb.[ch]
	* libgimp/gimpfonts_pdb.[ch]
	* libgimp/gimpgradients_pdb.[ch]
	* libgimp/gimppalettes_pdb.[ch]
	* libgimp/gimppatterns_pdb.[ch]: regenerated.

	* plug-ins/gflare/gflare.c
	* plug-ins/pygimp/gimpmodule.c: changed accordingly.

	* plug-ins/script-fu/scripts/font-map.scm: replaced the font list
	parameter with a more useful regexp filter on the available fonts.
parent e6ab3106
2003-09-04 Sven Neumann <sven@gimp.org>
* app/core/Makefile.am
* app/core/core-types.h
* app/core/gimpcontainer-filter.[ch]: added filter functionality
for GimpContainers.
* tools/pdbgen/pdb/brushes.pdb
* tools/pdbgen/pdb/fonts.pdb
* tools/pdbgen/pdb/gradients.pdb
* tools/pdbgen/pdb/palettes.pdb
* tools/pdbgen/pdb/patterns.pdb: made the gimp_foo_get_list()
PDB function somewhat useful by adding a filter parameter that
allows to specify a regular expression to be used on the list.
* app/pdb/Makefile.am: had to uglify the ugly hack even more :(
* app/pdb/brushes_cmds.c
* app/pdb/fonts_cmds.c
* app/pdb/gradients_cmds.c
* app/pdb/palettes_cmds.c
* app/pdb/patterns_cmds.c
* libgimp/gimpbrushes_pdb.[ch]
* libgimp/gimpfonts_pdb.[ch]
* libgimp/gimpgradients_pdb.[ch]
* libgimp/gimppalettes_pdb.[ch]
* libgimp/gimppatterns_pdb.[ch]: regenerated.
* plug-ins/gflare/gflare.c
* plug-ins/pygimp/gimpmodule.c: changed accordingly.
* plug-ins/script-fu/scripts/font-map.scm: replaced the font list
parameter with a more useful regexp filter on the available fonts.
2003-09-04 Sven Neumann <sven@gimp.org>
* app/core/gimpcontainer.[ch] (gimp_container_get_name_array):
......@@ -47,6 +47,8 @@ libappcore_a_sources = \
gimpchannel-combine.h \
gimpcontainer.c \
gimpcontainer.h \
gimpcontainer-filter.c \
gimpcontainer-filter.h \
gimpcontext.c \
gimpcontext.h \
gimpdata.c \
......
......@@ -143,6 +143,9 @@ typedef void (* GimpInitStatusFunc) (const gchar *text1,
typedef GimpData * (* GimpDataObjectLoaderFunc) (const gchar *filename);
typedef gboolean (* GimpObjectFilterFunc) (const GimpObject *object,
gpointer user_data);
typedef gboolean (* GimpUndoPopFunc) (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum);
......
/* The GIMP -- an image manipulation program
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
*
* gimpcontainer-filter.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 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 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-object.h>
#ifdef HAVE_GLIBC_REGEX
#include <regex.h>
#else
#include "regexrepl/regex.h"
#endif
#include "core-types.h"
#include "gimpcontainer.h"
#include "gimpcontainer-filter.h"
#include "gimplist.h"
typedef struct
{
GimpObjectFilterFunc filter;
GimpContainer *container;
gpointer user_data;
} GimpContainerFilterContext;
static void
gimp_container_filter_foreach_func (GimpObject *object,
GimpContainerFilterContext *context)
{
if (context->filter (object, context->user_data))
gimp_container_add (context->container, object);
}
/**
* gimp_container_filter:
* @container: a #GimpContainer to filter
* @filter: a #GimpObjectFilterFunc
* @user_data: a pointer passed to @filter
*
* Calls the supplied @filter function on each object in @container.
* A return value of %TRUE is interpreted as a match.
*
* Returns: a weak #GimpContainer filled with matching objects.
**/
GimpContainer *
gimp_container_filter (const GimpContainer *container,
GimpObjectFilterFunc filter,
gpointer user_data)
{
GimpContainer *result;
GimpContainerFilterContext context;
g_return_val_if_fail (GIMP_IS_CONTAINER (container), NULL);
g_return_val_if_fail (filter != NULL, NULL);
result =
g_object_new (G_TYPE_FROM_INSTANCE (container),
"children_type", gimp_container_children_type (container),
"policy", GIMP_CONTAINER_POLICY_WEAK,
NULL);
context.filter = filter;
context.container = result;
context.user_data = user_data;
gimp_container_foreach (container,
(GFunc) gimp_container_filter_foreach_func,
&context);
/* This is somewhat ugly, but it keeps lists in the same order. */
if (GIMP_IS_LIST (result))
gimp_list_reverse (GIMP_LIST (result));
return result;
}
static gboolean
gimp_object_filter_by_name (const GimpObject *object,
const regex_t *regex)
{
return (regexec (regex,
gimp_object_get_name (object), 0, NULL, 0) != REG_NOMATCH);
}
/**
* gimp_container_filter_by_name:
* @container: a #GimpContainer to filter
* @regexp: a regular expression (as a %NULL-terminated string)
* @error: error location to report errors or %NULL
*
* This function performs a case-insensitive regular expression search
* on the names of the GimpObjects in @container.
*
* Returns: a weak #GimpContainer filled with matching objects.
**/
GimpContainer *
gimp_container_filter_by_name (const GimpContainer *container,
const gchar *regexp,
GError **error)
{
GimpContainer *result;
gint ret;
regex_t regex;
g_return_val_if_fail (GIMP_IS_CONTAINER (container), NULL);
g_return_val_if_fail (regexp != NULL, NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
ret = regcomp (&regex, regexp, REG_ICASE | REG_NOSUB);
if (ret)
{
gsize error_len;
gchar *error_buf;
error_len = regerror (ret, &regex, NULL, 0);
error_buf = g_new (gchar, error_len);
regerror (ret, &regex, error_buf, error_len);
g_set_error (error, 0, 0, error_buf);
g_free (error_buf);
regfree (&regex);
return NULL;
}
result =
gimp_container_filter (container,
(GimpObjectFilterFunc) gimp_object_filter_by_name,
&regex);
regfree (&regex);
return result;
}
gchar **
gimp_container_get_filtered_name_array (const GimpContainer *container,
const gchar *regexp,
gint *length)
{
GimpContainer *weak;
GError *error = NULL;
g_return_val_if_fail (GIMP_IS_CONTAINER (container), NULL);
g_return_val_if_fail (length != NULL, NULL);
if (regexp == NULL || strlen (regexp) == 0)
return (gimp_container_get_name_array (container, length));
weak = gimp_container_filter_by_name (container, regexp, &error);
if (weak)
{
gchar **retval = gimp_container_get_name_array (weak, length);
g_object_unref (weak);
return retval;
}
else
{
g_warning (error->message);
g_error_free (error);
*length = 0;
return NULL;
}
}
/* The GIMP -- an image manipulation program
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
*
* gimpcontainer-filter.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 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 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.
*/
#ifndef __GIMP_CONTAINER_FILTER_H__
#define __GIMP_CONTAINER_FILTER_H__
GimpContainer * gimp_container_filter (const GimpContainer *container,
GimpObjectFilterFunc filter,
gpointer user_data);
GimpContainer * gimp_container_filter_by_name (const GimpContainer *container,
const gchar *regexp,
GError **error);
gchar ** gimp_container_get_filtered_name_array
(const GimpContainer *container,
const gchar *regexp,
gint *length);
#endif /* __GIMP_CONTAINER_FILTER_H__ */
......@@ -49,7 +49,7 @@ libapppdb_a_SOURCES = \
unit_cmds.c
## This is a truly ugly hack
libapppdb_a_LIBADD = ../gui/pattern-select.o ../gui/brush-select.o ../gui/font-select.o
libapppdb_a_LIBADD = ../core/gimpcontainer-filter.o ../gui/pattern-select.o ../gui/brush-select.o ../gui/font-select.o
AM_CPPFLAGS = \
-DG_LOG_DOMAIN=\"Gimp-PDB\" \
......
......@@ -32,6 +32,7 @@
#include "base/temp-buf.h"
#include "core/gimp.h"
#include "core/gimpbrush.h"
#include "core/gimpcontainer-filter.h"
#include "core/gimpcontext.h"
#include "core/gimpdatafactory.h"
#include "core/gimplist.h"
......@@ -102,20 +103,39 @@ static Argument *
brushes_get_list_invoker (Gimp *gimp,
Argument *args)
{
gboolean success = TRUE;
Argument *return_args;
gchar *filter;
gint32 num_brushes;
gchar **brush_list;
brush_list = gimp_container_get_name_array (gimp->brush_factory->container, &num_brushes);
filter = (gchar *) args[0].value.pdb_pointer;
if (filter && !g_utf8_validate (filter, -1, NULL))
success = FALSE;
if (success)
brush_list = gimp_container_get_filtered_name_array (gimp->brush_factory->container, filter, &num_brushes);
return_args = procedural_db_return_args (&brushes_get_list_proc, TRUE);
return_args = procedural_db_return_args (&brushes_get_list_proc, success);
return_args[1].value.pdb_int = num_brushes;
return_args[2].value.pdb_pointer = brush_list;
if (success)
{
return_args[1].value.pdb_int = num_brushes;
return_args[2].value.pdb_pointer = brush_list;
}
return return_args;
}
static ProcArg brushes_get_list_inargs[] =
{
{
GIMP_PDB_STRING,
"filter",
"An optional regular expression used to filter the list"
}
};
static ProcArg brushes_get_list_outargs[] =
{
{
......@@ -139,8 +159,8 @@ static ProcRecord brushes_get_list_proc =
"Spencer Kimball & Peter Mattis",
"1995-1996",
GIMP_INTERNAL,
0,
NULL,
1,
brushes_get_list_inargs,
2,
brushes_get_list_outargs,
{ { brushes_get_list_invoker } }
......
......@@ -29,6 +29,7 @@
#include "procedural_db.h"
#include "core/gimp.h"
#include "core/gimpcontainer-filter.h"
#include "core/gimpcontainer.h"
#include "text/gimpfonts.h"
......@@ -70,20 +71,39 @@ static Argument *
fonts_get_list_invoker (Gimp *gimp,
Argument *args)
{
gboolean success = TRUE;
Argument *return_args;
gchar *filter;
gint32 num_fonts;
gchar **font_list;
font_list = gimp_container_get_name_array (gimp->fonts, &num_fonts);
filter = (gchar *) args[0].value.pdb_pointer;
if (filter && !g_utf8_validate (filter, -1, NULL))
success = FALSE;
return_args = procedural_db_return_args (&fonts_get_list_proc, TRUE);
if (success)
font_list = gimp_container_get_filtered_name_array (gimp->fonts, filter, &num_fonts);
return_args[1].value.pdb_int = num_fonts;
return_args[2].value.pdb_pointer = font_list;
return_args = procedural_db_return_args (&fonts_get_list_proc, success);
if (success)
{
return_args[1].value.pdb_int = num_fonts;
return_args[2].value.pdb_pointer = font_list;
}
return return_args;
}
static ProcArg fonts_get_list_inargs[] =
{
{
GIMP_PDB_STRING,
"filter",
"An optional regular expression used to filter the list"
}
};
static ProcArg fonts_get_list_outargs[] =
{
{
......@@ -107,8 +127,8 @@ static ProcRecord fonts_get_list_proc =
"Sven Neumann",
"2003",
GIMP_INTERNAL,
0,
NULL,
1,
fonts_get_list_inargs,
2,
fonts_get_list_outargs,
{ { fonts_get_list_invoker } }
......
......@@ -30,6 +30,7 @@
#include "procedural_db.h"
#include "core/gimp.h"
#include "core/gimpcontainer-filter.h"
#include "core/gimpcontainer.h"
#include "core/gimpcontext.h"
#include "core/gimpdatafactory.h"
......@@ -85,20 +86,39 @@ static Argument *
gradients_get_list_invoker (Gimp *gimp,
Argument *args)
{
gboolean success = TRUE;
Argument *return_args;
gchar *filter;
gint32 num_gradients;
gchar **gradient_list;
gradient_list = gimp_container_get_name_array (gimp->gradient_factory->container, &num_gradients);
filter = (gchar *) args[0].value.pdb_pointer;
if (filter && !g_utf8_validate (filter, -1, NULL))
success = FALSE;
if (success)
gradient_list = gimp_container_get_filtered_name_array (gimp->gradient_factory->container, filter, &num_gradients);
return_args = procedural_db_return_args (&gradients_get_list_proc, TRUE);
return_args = procedural_db_return_args (&gradients_get_list_proc, success);
return_args[1].value.pdb_int = num_gradients;
return_args[2].value.pdb_pointer = gradient_list;
if (success)
{
return_args[1].value.pdb_int = num_gradients;
return_args[2].value.pdb_pointer = gradient_list;
}
return return_args;
}
static ProcArg gradients_get_list_inargs[] =
{
{
GIMP_PDB_STRING,
"filter",
"An optional regular expression used to filter the list"
}
};
static ProcArg gradients_get_list_outargs[] =
{
{
......@@ -122,8 +142,8 @@ static ProcRecord gradients_get_list_proc =
"Federico Mena Quintero",
"1997",
GIMP_INTERNAL,
0,
NULL,
1,
gradients_get_list_inargs,
2,
gradients_get_list_outargs,
{ { gradients_get_list_invoker } }
......
......@@ -30,6 +30,7 @@
#include "procedural_db.h"
#include "core/gimp.h"
#include "core/gimpcontainer-filter.h"
#include "core/gimpcontext.h"
#include "core/gimpdatafactory.h"
#include "core/gimplist.h"
......@@ -91,20 +92,39 @@ static Argument *
palettes_get_list_invoker (Gimp *gimp,
Argument *args)
{
gboolean success = TRUE;
Argument *return_args;
gchar *filter;
gint32 num_palettes;
gchar **palette_list;
palette_list = gimp_container_get_name_array (gimp->palette_factory->container, &num_palettes);
filter = (gchar *) args[0].value.pdb_pointer;
if (filter && !g_utf8_validate (filter, -1, NULL))
success = FALSE;
if (success)
palette_list = gimp_container_get_filtered_name_array (gimp->palette_factory->container, filter, &num_palettes);
return_args = procedural_db_return_args (&palettes_get_list_proc, TRUE);
return_args = procedural_db_return_args (&palettes_get_list_proc, success);
return_args[1].value.pdb_int = num_palettes;
return_args[2].value.pdb_pointer = palette_list;
if (success)
{
return_args[1].value.pdb_int = num_palettes;
return_args[2].value.pdb_pointer = palette_list;
}
return return_args;
}
static ProcArg palettes_get_list_inargs[] =
{
{
GIMP_PDB_STRING,
"filter",
"An optional regular expression used to filter the list"
}
};
static ProcArg palettes_get_list_outargs[] =
{
{
......@@ -128,8 +148,8 @@ static ProcRecord palettes_get_list_proc =
"Nathan Summers",
"2001",
GIMP_INTERNAL,
0,
NULL,
1,
palettes_get_list_inargs,
2,
palettes_get_list_outargs,
{ { palettes_get_list_invoker } }
......
......@@ -31,6 +31,7 @@
#include "base/temp-buf.h"
#include "core/gimp.h"
#include "core/gimpcontainer-filter.h"
#include "core/gimpcontext.h"
#include "core/gimpdatafactory.h"
#include "core/gimplist.h"
......@@ -81,20 +82,39 @@ static Argument *
patterns_get_list_invoker (Gimp *gimp,
Argument *args)
{
gboolean success = TRUE;
Argument *return_args;
gchar *filter;
gint32 num_patterns;
gchar **pattern_list;
pattern_list = gimp_container_get_name_array (gimp->pattern_factory->container, &num_patterns);
filter = (gchar *) args[0].value.pdb_pointer;
if (filter && !g_utf8_validate (filter, -1, NULL))
success = FALSE;
if (success)
pattern_list = gimp_container_get_filtered_name_array (gimp->pattern_factory->container, filter, &num_patterns);
return_args = procedural_db_return_args (&patterns_get_list_proc, TRUE);
return_args = procedural_db_return_args (&patterns_get_list_proc, success);
return_args[1].value.pdb_int = num_patterns;
return_args[2].value.pdb_pointer = pattern_list;
if (success)
{
return_args[1].value.pdb_int = num_patterns;
return_args[2].value.pdb_pointer = pattern_list;
}
return return_args;
}
static ProcArg patterns_get_list_inargs[] =
{
{
GIMP_PDB_STRING,
"filter",
"An optional regular expression used to filter the list"
}
};
static ProcArg patterns_get_list_outargs[] =
{
{
......@@ -118,8 +138,8 @@ static ProcRecord patterns_get_list_proc =
"Spencer Kimball & Peter Mattis",
"1995-1996",
GIMP_INTERNAL,
0,
NULL,
1,
patterns_get_list_inargs,
2,
patterns_get_list_outargs,
{ { patterns_get_list_invoker } }
......
2003-09-04 Sven Neumann <sven@gimp.org>
* libgimp/tmpl/gimpbrushes.sgml
* libgimp/tmpl/gimpfonts.sgml
* libgimp/tmpl/gimpgradients.sgml
* libgimp/tmpl/gimppalettes.sgml
* libgimp/tmpl/gimppatterns.sgml: updated after API change.
2003-09-04 Sven Neumann <sven@gimp.org>
* libgimp/libgimp-docs.sgml
......
......@@ -27,6 +27,7 @@ Functions related to getting and setting brushes.
</para>
@filter:
@num_brushes:
@Returns:
......
......@@ -27,6 +27,7 @@ Operations related to fonts.
</para>
@filter:
@num_fonts:
@Returns:
......
......@@ -28,6 +28,7 @@ Operations related to gradients.
</para>
@filter:
@num_gradients:
@Returns:
......
......@@ -27,6 +27,7 @@ gimppalettes
</para>
@filter:
@num_palettes:
@Returns:
......
......@@ -28,6 +28,7 @@ Functions relating to patterns.
</para>
@filter:
@num_patterns:
@Returns:
......
......@@ -57,6 +57,7 @@ gimp_brushes_refresh (void)
/**
* gimp_brushes_get_list:
* @filter: An optional regular expression used to filter the list.
* @num_brushes: The number of brushes in the brush list.
*
* Retrieve a complete listing of the available brushes.
......@@ -68,7 +69,8 @@ gimp_brushes_refresh (void)
* Returns: The list of brush names.
*/
gchar **
gimp_brushes_get_list (gint *num_brushes)
gimp_brushes_get_list (const gchar *filter,
gint *num_brushes)
{
GimpParam *return_vals;
gint nreturn_vals;
......@@ -77,6 +79,7 @@ gimp_brushes_get_list (gint *num_brushes)
return_vals = gimp_run_procedure ("gimp_brushes_get_list",
&nreturn_vals,
GIMP_PDB_STRING, filter,
GIMP_PDB_END);
*num_brushes = 0;
......
......@@ -30,7 +30,8 @@ G_BEGIN_DECLS
gboolean gimp_brushes_refresh (void);
gchar** gimp_brushes_get_list (gint *num_brushes);
gchar** gimp_brushes_get_list (const gchar *filter,
gint *num_brushes);
gchar* gimp_brushes_get_brush (gint *width,
gint *height,
gint *spacing);
......
......@@ -55,6 +55,7 @@ gimp_fonts_refresh (void)
/**
* gimp_fonts_get_list:
* @filter: An optional regular expression used to filter the list.
* @num_fonts: The number of available fonts.
*
* Retrieve the list of loaded fonts.
......@@ -65,7 +66,8 @@ gimp_fonts_refresh (void)
* Returns: The list of font names.
*/
gchar **
gimp_fonts_get_list (gint *num_fonts)
gimp_fonts_get_list (const gchar *filter,
gint *num_fonts)
{
GimpParam *return_vals;
gint nreturn_vals;
......@@ -74,6 +76,7 @@ gimp_fonts_get_list (gint *num_fonts)
return_vals = gimp_run_procedure ("gimp_fonts_get_list",
&nreturn_vals,
GIMP_PDB_STRING, filter,
GIMP_PDB_END);
*num_fonts = 0;
......
......@@ -30,7 +30,8 @@ G_BEGIN_DECLS
gboolean gimp_fonts_refresh (void);
gchar** gimp_fonts_get_list (gint *num_fonts);
gchar** gimp_fonts_get_list (const gchar *filter,
gint *num_fonts);
G_END_DECLS
......