Commit 1c62ddef authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

Long overdue core container cleanup:

2004-05-24  Michael Natterer  <mitch@gimp.org>

	Long overdue core container cleanup:

	* app/core/gimplist.[ch]: added "unique-names" and "sort-func"
	properties and merged the resp. code from GimpDataList into
	GimpList. Removed "policy" parameters from gimp_list_new() and
	added "unique_names". Added new constructor gimp_list_new_weak().
	Made public function gimp_list_uniquefy_name() private.

	* app/core/Makefile.am
	* app/core/core-types.h
	* app/core/gimpdatalist.[ch]: removed. Its functionality is
	entirely in GimpList now.

	* app/core/gimpdata.[ch]: added gimp_data_name_compare() which
	used to live in GimpDataList.

	* app/core/gimp.c
	* app/core/gimpdatafactory.c
	* app/core/gimpimage.c
	* app/core/gimptoolinfo.c
	* app/core/gimpundostack.c
	* app/paint/gimp-paint.c
	* app/tools/gimp-tools.c
	* app/widgets/gimpdevices.c
	* app/widgets/gimptemplateeditor.c
	* app/widgets/gimpundoeditor.c: changed list creation accordingly.

	Made gimp->templates, gimp->named_buffers, tool_info->presets and
	the image's lists of layers, channels and vectors automatically
	ensure unique names.

	* app/widgets/gimptemplateview.c
	* app/actions/file-commands.c
	* app/actions/templates-commands.c
	* app/actions/tool-options-commands.c: removed calls to
	gimp_list_uniquefy_name().

	* app/core/gimpitem.c: removed major insanity where the items
	themselves where ensuring their unique names. Bah!

	* app/core/gimplayer.c (gimp_layer_name_changed): chain up
	conditionally.

	* app/core/gimplayermask.c (gimp_layer_mask_name_changed): removed
	because there is no need any more to keep the parent
	implementation from being invoked.
parent d3c7f3fd
2004-05-24 Michael Natterer <mitch@gimp.org>
Long overdue core container cleanup:
* app/core/gimplist.[ch]: added "unique-names" and "sort-func"
properties and merged the resp. code from GimpDataList into
GimpList. Removed "policy" parameters from gimp_list_new() and
added "unique_names". Added new constructor gimp_list_new_weak().
Made public function gimp_list_uniquefy_name() private.
* app/core/Makefile.am
* app/core/core-types.h
* app/core/gimpdatalist.[ch]: removed. Its functionality is
entirely in GimpList now.
* app/core/gimpdata.[ch]: added gimp_data_name_compare() which
used to live in GimpDataList.
* app/core/gimp.c
* app/core/gimpdatafactory.c
* app/core/gimpimage.c
* app/core/gimptoolinfo.c
* app/core/gimpundostack.c
* app/paint/gimp-paint.c
* app/tools/gimp-tools.c
* app/widgets/gimpdevices.c
* app/widgets/gimptemplateeditor.c
* app/widgets/gimpundoeditor.c: changed list creation accordingly.
Made gimp->templates, gimp->named_buffers, tool_info->presets and
the image's lists of layers, channels and vectors automatically
ensure unique names.
* app/widgets/gimptemplateview.c
* app/actions/file-commands.c
* app/actions/templates-commands.c
* app/actions/tool-options-commands.c: removed calls to
gimp_list_uniquefy_name().
* app/core/gimpitem.c: removed major insanity where the items
themselves where ensuring their unique names. Bah!
* app/core/gimplayer.c (gimp_layer_name_changed): chain up
conditionally.
* app/core/gimplayermask.c (gimp_layer_mask_name_changed): removed
because there is no need any more to keep the parent
implementation from being invoked.
2004-05-23 Sven Neumann <sven@gimp.org>
More fixes for bug #142996:
......
......@@ -31,7 +31,6 @@
#include "core/gimp.h"
#include "core/gimpcontainer.h"
#include "core/gimpcontext.h"
#include "core/gimplist.h"
#include "core/gimpimage.h"
#include "core/gimptemplate.h"
......@@ -344,11 +343,7 @@ file_new_template_callback (GtkWidget *widget,
template = gimp_template_new (name);
gimp_template_set_from_image (template, gimage);
gimp_list_uniquefy_name (GIMP_LIST (gimage->gimp->templates),
GIMP_OBJECT (template), TRUE);
gimp_container_add (gimage->gimp->templates,
GIMP_OBJECT (template));
gimp_container_add (gimage->gimp->templates, GIMP_OBJECT (template));
g_object_unref (template);
}
......
......@@ -29,8 +29,8 @@
#include "config/gimpcoreconfig.h"
#include "core/gimp.h"
#include "core/gimpcontainer.h"
#include "core/gimpcontext.h"
#include "core/gimplist.h"
#include "core/gimptemplate.h"
#include "widgets/gimpcontainerview.h"
......@@ -111,8 +111,6 @@ templates_duplicate_template_cmd_callback (GtkAction *action,
new_template = gimp_config_duplicate (GIMP_CONFIG (template));
gimp_list_uniquefy_name (GIMP_LIST (container),
GIMP_OBJECT (new_template), TRUE);
gimp_container_add (container, GIMP_OBJECT (new_template));
gimp_context_set_by_type (context, container->children_type,
......@@ -306,9 +304,6 @@ templates_edit_template_response (GtkWidget *widget,
gimp_config_sync (GIMP_CONFIG (editor->template),
GIMP_CONFIG (template), 0);
gimp_list_uniquefy_name (GIMP_LIST (gimp->templates),
GIMP_OBJECT (template), TRUE);
}
gtk_widget_destroy (dialog);
......
......@@ -241,8 +241,6 @@ tool_options_save_callback (GtkWidget *widget,
copy = gimp_config_duplicate (GIMP_CONFIG (tool_info->tool_options));
gimp_object_set_name (GIMP_OBJECT (copy), name);
gimp_list_uniquefy_name (GIMP_LIST (tool_info->options_presets),
GIMP_OBJECT (copy), TRUE);
gimp_container_insert (tool_info->options_presets, GIMP_OBJECT (copy), -1);
g_object_unref (copy);
......@@ -259,6 +257,4 @@ tool_options_rename_callback (GtkWidget *widget,
name = _("Saved Options");
gimp_object_set_name (GIMP_OBJECT (options), name);
gimp_list_uniquefy_name (GIMP_LIST (options->tool_info->options_presets),
GIMP_OBJECT (options), TRUE);
}
......@@ -65,8 +65,6 @@ libappcore_a_sources = \
gimpdata.h \
gimpdatafactory.c \
gimpdatafactory.h \
gimpdatalist.c \
gimpdatalist.h \
gimpdocumentlist.c \
gimpdocumentlist.h \
gimpdrawable.c \
......
......@@ -58,7 +58,6 @@ typedef struct _GimpParasiteList GimpParasiteList;
typedef struct _GimpContainer GimpContainer;
typedef struct _GimpList GimpList;
typedef struct _GimpDataList GimpDataList;
typedef struct _GimpDataFactory GimpDataFactory;
......
......@@ -257,8 +257,7 @@ gimp_init (Gimp *gimp)
gimp->plug_in_debug = NULL;
gimp->images = gimp_list_new (GIMP_TYPE_IMAGE,
GIMP_CONTAINER_POLICY_WEAK);
gimp->images = gimp_list_new_weak (GIMP_TYPE_IMAGE, FALSE);
gimp_object_set_name (GIMP_OBJECT (gimp->images), "images");
gimp->next_image_ID = 1;
......@@ -268,15 +267,13 @@ gimp_init (Gimp *gimp)
gimp->next_item_ID = 1;
gimp->item_table = g_hash_table_new (g_direct_hash, NULL);
gimp->displays = gimp_list_new (GIMP_TYPE_OBJECT,
GIMP_CONTAINER_POLICY_WEAK);
gimp->displays = gimp_list_new_weak (GIMP_TYPE_OBJECT, FALSE);
gimp_object_set_name (GIMP_OBJECT (gimp->displays), "displays");
gimp->next_display_ID = 1;
gimp->global_buffer = NULL;
gimp->named_buffers = gimp_list_new (GIMP_TYPE_BUFFER,
GIMP_CONTAINER_POLICY_STRONG);
gimp->named_buffers = gimp_list_new (GIMP_TYPE_BUFFER, TRUE);
gimp_object_set_name (GIMP_OBJECT (gimp->named_buffers), "named buffers");
gimp->fonts = NULL;
......@@ -292,16 +289,15 @@ gimp_init (Gimp *gimp)
xcf_init (gimp);
gimp->tool_info_list = gimp_list_new (GIMP_TYPE_TOOL_INFO,
GIMP_CONTAINER_POLICY_STRONG);
gimp->tool_info_list = gimp_list_new (GIMP_TYPE_TOOL_INFO, FALSE);
gimp_object_set_name (GIMP_OBJECT (gimp->tool_info_list), "tool infos");
gimp->standard_tool_info = NULL;
gimp->documents = gimp_document_list_new (gimp);
gimp->templates = gimp_list_new (GIMP_TYPE_TEMPLATE,
GIMP_CONTAINER_POLICY_STRONG);
gimp->templates = gimp_list_new (GIMP_TYPE_TEMPLATE, TRUE);
gimp->image_new_last_template = NULL;
gimp->have_current_cut_buffer = FALSE;
......
......@@ -384,6 +384,18 @@ gimp_data_make_internal (GimpData *data)
data->deletable = FALSE;
}
gint
gimp_data_name_compare (GimpData *data1,
GimpData *data2)
{
/* move the internal objects (like the FG -> BG) gradient) to the top */
if (data1->internal != data2->internal)
return data1->internal ? -1 : 1;
return gimp_object_name_collate ((GimpObject *) data1,
(GimpObject *) data2);
}
GQuark
gimp_data_error_quark (void)
{
......
......@@ -68,7 +68,7 @@ struct _GimpDataClass
GError **error);
gchar * (* get_extension) (GimpData *data);
GimpData * (* duplicate) (GimpData *data,
gboolean stingy_memory_use);
gboolean stingy_memory_use);
};
......@@ -95,6 +95,8 @@ GimpData * gimp_data_duplicate (GimpData *data,
void gimp_data_make_internal (GimpData *data);
gint gimp_data_name_compare (GimpData *data1,
GimpData *data2);
#define GIMP_DATA_ERROR (gimp_data_error_quark ())
......
......@@ -37,7 +37,7 @@
#include "gimpcontext.h"
#include "gimpdata.h"
#include "gimpdatafactory.h"
#include "gimpdatalist.h"
#include "gimplist.h"
#include "gimp-intl.h"
......@@ -92,11 +92,8 @@ gimp_data_factory_get_type (void)
static void
gimp_data_factory_class_init (GimpDataFactoryClass *klass)
{
GObjectClass *object_class;
GimpObjectClass *gimp_object_class;
object_class = G_OBJECT_CLASS (klass);
gimp_object_class = GIMP_OBJECT_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
......@@ -121,9 +118,7 @@ gimp_data_factory_init (GimpDataFactory *factory)
static void
gimp_data_factory_finalize (GObject *object)
{
GimpDataFactory *factory;
factory = GIMP_DATA_FACTORY (object);
GimpDataFactory *factory = GIMP_DATA_FACTORY (object);
if (factory->container)
{
......@@ -150,11 +145,9 @@ static gint64
gimp_data_factory_get_memsize (GimpObject *object,
gint64 *gui_size)
{
GimpDataFactory *factory;
GimpDataFactory *factory = GIMP_DATA_FACTORY (object);
gint64 memsize = 0;
factory = GIMP_DATA_FACTORY (object);
memsize += gimp_object_get_memsize (GIMP_OBJECT (factory->container),
gui_size);
......@@ -184,7 +177,9 @@ gimp_data_factory_new (Gimp *gimp,
factory = g_object_new (GIMP_TYPE_DATA_FACTORY, NULL);
factory->gimp = gimp;
factory->container = gimp_data_list_new (data_type);
factory->container = gimp_list_new (data_type, TRUE);
gimp_list_set_sort_func (GIMP_LIST (factory->container),
(GCompareFunc) gimp_data_name_compare);
factory->path_property_name = g_strdup (path_property_name);
factory->writable_property_name = g_strdup (writable_property_name);
......
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpdatalist.c
* Copyright (C) 2001 Michael Natterer <mitch@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 <glib-object.h>
#include "core-types.h"
#include "gimpdata.h"
#include "gimpdatalist.h"
static void gimp_data_list_class_init (GimpDataListClass *klass);
static void gimp_data_list_init (GimpDataList *list);
static void gimp_data_list_add (GimpContainer *container,
GimpObject *object);
static void gimp_data_list_remove (GimpContainer *container,
GimpObject *object);
static void gimp_data_list_object_renamed (GimpObject *object,
GimpDataList *data_list);
static gint gimp_data_list_data_compare_func (gconstpointer first,
gconstpointer second);
static GimpListClass *parent_class = NULL;
GType
gimp_data_list_get_type (void)
{
static GType list_type = 0;
if (! list_type)
{
static const GTypeInfo list_info =
{
sizeof (GimpDataListClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_data_list_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpDataList),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_data_list_init,
};
list_type = g_type_register_static (GIMP_TYPE_LIST,
"GimpDataList",
&list_info, 0);
}
return list_type;
}
static void
gimp_data_list_class_init (GimpDataListClass *klass)
{
GimpContainerClass *container_class = GIMP_CONTAINER_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
container_class->add = gimp_data_list_add;
container_class->remove = gimp_data_list_remove;
}
static void
gimp_data_list_init (GimpDataList *list)
{
}
static void
gimp_data_list_add (GimpContainer *container,
GimpObject *object)
{
GimpList *list = GIMP_LIST (container);
gimp_list_uniquefy_name (GIMP_LIST (container), object, TRUE);
g_signal_connect (object, "name_changed",
G_CALLBACK (gimp_data_list_object_renamed),
container);
list->list = g_list_insert_sorted (list->list, object,
gimp_data_list_data_compare_func);
}
static void
gimp_data_list_remove (GimpContainer *container,
GimpObject *object)
{
GimpList *list = GIMP_LIST (container);
g_signal_handlers_disconnect_by_func (object,
gimp_data_list_object_renamed,
container);
list->list = g_list_remove (list->list, object);
}
GimpContainer *
gimp_data_list_new (GType children_type)
{
GimpDataList *list;
g_return_val_if_fail (g_type_is_a (children_type, GIMP_TYPE_DATA), NULL);
list = g_object_new (GIMP_TYPE_DATA_LIST,
"children_type", children_type,
"policy", GIMP_CONTAINER_POLICY_STRONG,
NULL);
return GIMP_CONTAINER (list);
}
static void
gimp_data_list_object_renamed (GimpObject *object,
GimpDataList *data_list)
{
GimpList *gimp_list = GIMP_LIST (data_list);
GList *list;
gint old_index;
gint new_index = 0;
g_signal_handlers_block_by_func (object,
gimp_data_list_object_renamed,
data_list);
gimp_list_uniquefy_name (gimp_list, object, TRUE);
g_signal_handlers_unblock_by_func (object,
gimp_data_list_object_renamed,
data_list);
old_index = g_list_index (gimp_list->list, object);
for (list = gimp_list->list; list; list = g_list_next (list))
{
GimpObject *object2 = GIMP_OBJECT (list->data);
if (object == object2)
continue;
if (gimp_data_list_data_compare_func (object, object2) > 0)
new_index++;
else
break;
}
if (new_index != old_index)
gimp_container_reorder (GIMP_CONTAINER (data_list), object, new_index);
}
static gint
gimp_data_list_data_compare_func (gconstpointer first,
gconstpointer second)
{
GimpData *first_data = (GimpData *) first;
GimpData *second_data = (GimpData *) second;
/* move the internal objects (like the FG -> BG) gradient) to the top */
if (first_data->internal != second_data->internal)
return first_data->internal ? -1 : 1;
return gimp_object_name_collate ((GimpObject *) first,
(GimpObject *) second);
}
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpdatalist.h
* Copyright (C) 2001 Michael Natterer <mitch@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_DATA_LIST_H__
#define __GIMP_DATA_LIST_H__
#include "gimplist.h"
#define GIMP_TYPE_DATA_LIST (gimp_data_list_get_type ())
#define GIMP_DATA_LIST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_DATA_LIST, GimpDataList))
#define GIMP_DATA_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_DATA_LIST, GimpDataListClass))
#define GIMP_IS_DATA_LIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_DATA_LIST))
#define GIMP_IS_DATA_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_DATA_LIST))
#define GIMP_DATA_LIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_DATA_LIST, GimpDataListClass))
typedef struct _GimpDataListClass GimpDataListClass;
struct _GimpDataList
{
GimpList parent_instance;
};
struct _GimpDataListClass
{
GimpListClass parent_class;
};
GType gimp_data_list_get_type (void) G_GNUC_CONST;
GimpContainer * gimp_data_list_new (GType children_type);
#endif /* __GIMP_DATA_LIST_H__ */
......@@ -492,12 +492,9 @@ gimp_image_init (GimpImage *gimage)
gimage->grid = NULL;
gimage->layers = gimp_list_new (GIMP_TYPE_LAYER,
GIMP_CONTAINER_POLICY_STRONG);
gimage->channels = gimp_list_new (GIMP_TYPE_CHANNEL,
GIMP_CONTAINER_POLICY_STRONG);
gimage->vectors = gimp_list_new (GIMP_TYPE_VECTORS,
GIMP_CONTAINER_POLICY_STRONG);
gimage->layers = gimp_list_new (GIMP_TYPE_LAYER, TRUE);
gimage->channels = gimp_list_new (GIMP_TYPE_CHANNEL, TRUE);
gimage->vectors = gimp_list_new (GIMP_TYPE_VECTORS, TRUE);
gimage->layer_stack = NULL;
gimage->layer_update_handler =
......
......@@ -29,21 +29,18 @@
#include "gimp.h"
#include "gimp-parasites.h"
#include "gimpchannel.h"
#include "gimpdrawable.h"
#include "gimpimage.h"
#include "gimpimage-undo.h"
#include "gimpimage-undo-push.h"
#include "gimpitem.h"
#include "gimpitem-preview.h"
#include "gimplayer.h"
#include "gimplist.h"
#include "gimpmarshal.h"
#include "gimppaintinfo.h"
#include "gimpparasitelist.h"
#include "gimpstrokeoptions.h"
#include "vectors/gimpvectors.h"
#include "gimp-intl.h"
......@@ -63,7 +60,6 @@ static void gimp_item_init (GimpItem *item);
static void gimp_item_finalize (GObject *object);
static void gimp_item_name_changed (GimpObject *object);
static gint64 gimp_item_get_memsize (GimpObject *object,
gint64 *gui_size);
......@@ -174,7 +170,6 @@ gimp_item_class_init (GimpItemClass *klass)
object_class->finalize = gimp_item_finalize;
gimp_object_class->name_changed = gimp_item_name_changed;
gimp_object_class->get_memsize = gimp_item_get_memsize;
viewable_class->get_preview_size = gimp_item_get_preview_size;
......@@ -244,27 +239,6 @@ gimp_item_finalize (GObject *object)
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gimp_item_name_changed (GimpObject *object)
{
GimpItem *item = GIMP_ITEM (object);
GimpList *list = NULL;
/* if no other items to check name against */
if (item->gimage == NULL)
return;
if (GIMP_IS_LAYER (item))
list = GIMP_LIST (item->gimage->layers);
else if (GIMP_IS_CHANNEL (item))
list = GIMP_LIST (item->gimage->channels);
else if (GIMP_IS_VECTORS (item))
list = GIMP_LIST (item->gimage->vectors);
if (list)
gimp_list_uniquefy_name (list, object, FALSE);
}
static gint64
gimp_item_get_memsize (GimpObject *object,
gint64 *gui_size)
......@@ -505,12 +479,7 @@ gimp_item_convert (GimpItem *item,
new_type, add_alpha);
if (dest_image != item->gimage)
{
gimp_item_set_image (new_item, dest_image);
/* force a unique name */
gimp_object_name_changed (GIMP_OBJECT (new_item));
}
gimp_item_set_image (new_item, dest_image);
return new_item;