Commit 9827ceac authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

added gimp_list_uniquefy_name() utility function.

2003-04-06  Michael Natterer  <mitch@gimp.org>

	* app/core/gimplist.[ch]: added gimp_list_uniquefy_name() utility
	function.

	* app/core/gimpdatalist.c
	* app/core/gimpitem.c: use it here instead of duplicating almost
	the same code.

	* app/widgets/Makefile.am
	* app/widgets/widgets-types.h
	* app/widgets/gimptemplateview.[ch]: new widget for editing the
	template list.

	* app/gui/dialogs-constructors.c: use it.

	* app/gui/Makefile.am
	* app/gui/templates-commands.[ch]
	* app/gui/templates-menu.[ch]: new files implementing the context
	menu for the template list.

	* app/gui/menus.c: register the new menu with the menu factory.

	* app/gui/file-commands.c (file_new_template_callback): uniquefy
	the new template's name.

	* app/gui/documents-commands.c: fixed typo.
parent b0defba6
2003-04-06 Michael Natterer <mitch@gimp.org>
* app/core/gimplist.[ch]: added gimp_list_uniquefy_name() utility
function.
* app/core/gimpdatalist.c
* app/core/gimpitem.c: use it here instead of duplicating almost
the same code.
* app/widgets/Makefile.am
* app/widgets/widgets-types.h
* app/widgets/gimptemplateview.[ch]: new widget for editing the
template list.
* app/gui/dialogs-constructors.c: use it.
* app/gui/Makefile.am
* app/gui/templates-commands.[ch]
* app/gui/templates-menu.[ch]: new files implementing the context
menu for the template list.
* app/gui/menus.c: register the new menu with the menu factory.
* app/gui/file-commands.c (file_new_template_callback): uniquefy
the new template's name.
* app/gui/documents-commands.c: fixed typo.
2003-04-06 Michael Natterer <mitch@gimp.org>
 
* app/core/gimpgradient.c (gimp_gradient_get_color_at): fixed bug
......@@ -29,7 +29,7 @@
#include "documents-commands.h"
/* public functionss */
/* public functions */
void
documents_open_document_cmd_callback (GtkWidget *widget,
......
......@@ -31,6 +31,7 @@
#include "core/gimp.h"
#include "core/gimpcontainer.h"
#include "core/gimpcontext.h"
#include "core/gimplist.h"
#include "core/gimpimage.h"
#include "core/gimpimage-undo.h"
#include "core/gimptemplate.h"
......@@ -397,6 +398,8 @@ 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));
g_object_unref (template);
......
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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 <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
#include "gui-types.h"
#include "widgets/gimptemplateview.h"
#include "templates-commands.h"
/* public functions */
void
templates_new_template_cmd_callback (GtkWidget *widget,
gpointer data)
{
GimpTemplateView *view;
view = GIMP_TEMPLATE_VIEW (data);
gtk_button_clicked (GTK_BUTTON (view->new_button));
}
void
templates_duplicate_template_cmd_callback (GtkWidget *widget,
gpointer data)
{
GimpTemplateView *view;
view = GIMP_TEMPLATE_VIEW (data);
gtk_button_clicked (GTK_BUTTON (view->duplicate_button));
}
void
templates_create_image_cmd_callback (GtkWidget *widget,
gpointer data)
{
GimpTemplateView *view;
view = GIMP_TEMPLATE_VIEW (data);
gtk_button_clicked (GTK_BUTTON (view->create_button));
}
void
templates_delete_template_cmd_callback (GtkWidget *widget,
gpointer data)
{
GimpTemplateView *view;
view = GIMP_TEMPLATE_VIEW (data);
gtk_button_clicked (GTK_BUTTON (view->delete_button));
}
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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 __TEMPLATES_COMMANDS_H__
#define __TEMPLATES_COMMANDS_H__
void templates_new_template_cmd_callback (GtkWidget *widget,
gpointer data);
void templates_duplicate_template_cmd_callback (GtkWidget *widget,
gpointer data);
void templates_create_image_cmd_callback (GtkWidget *widget,
gpointer data);
void templates_delete_template_cmd_callback (GtkWidget *widget,
gpointer data);
#endif /* __TEMPLATES_COMMANDS_H__ */
......@@ -43,8 +43,6 @@ static void gimp_data_list_add (GimpContainer *container,
static void gimp_data_list_remove (GimpContainer *container,
GimpObject *object);
static void gimp_data_list_uniquefy_data_name (GimpDataList *data_list,
GimpObject *object);
static void gimp_data_list_object_renamed_callback (GimpObject *object,
GimpDataList *data_list);
static gint gimp_data_list_data_compare_func (gconstpointer first,
......@@ -108,7 +106,7 @@ gimp_data_list_add (GimpContainer *container,
list = GIMP_LIST (container);
gimp_data_list_uniquefy_data_name (GIMP_DATA_LIST (container), object);
gimp_list_uniquefy_name (GIMP_LIST (container), object, TRUE);
list->list = g_list_insert_sorted (list->list, object,
gimp_data_list_data_compare_func);
......@@ -149,129 +147,43 @@ gimp_data_list_new (GType children_type)
}
static void
gimp_data_list_uniquefy_data_name (GimpDataList *data_list,
GimpObject *object)
gimp_data_list_object_renamed_callback (GimpObject *object,
GimpDataList *data_list)
{
GList *base_list;
GList *list;
GList *list2;
GimpObject *object2;
gint unique_ext = 0;
gchar *new_name = NULL;
gchar *ext;
gboolean have;
g_return_if_fail (GIMP_IS_DATA_LIST (data_list));
g_return_if_fail (GIMP_IS_OBJECT (object));
base_list = GIMP_LIST (data_list)->list;
have = gimp_container_have (GIMP_CONTAINER (data_list), object);
for (list = base_list; list; list = g_list_next (list))
{
object2 = GIMP_OBJECT (list->data);
if (object != object2 &&
strcmp (gimp_object_get_name (GIMP_OBJECT (object)),
gimp_object_get_name (GIMP_OBJECT (object2))) == 0)
{
ext = strrchr (object->name, '#');
if (ext)
{
gchar *ext_str;
unique_ext = atoi (ext + 1);
ext_str = g_strdup_printf ("%d", unique_ext);
/* check if the extension really is of the form "#<n>" */
if (! strcmp (ext_str, ext + 1))
{
*ext = '\0';
}
else
{
unique_ext = 0;
}
g_free (ext_str);
}
else
{
unique_ext = 0;
}
do
{
unique_ext++;
GimpList *gimp_list;
GList *list;
gint old_index;
gint new_index = 0;
g_free (new_name);
gimp_list = GIMP_LIST (data_list);
new_name = g_strdup_printf ("%s#%d", object->name, unique_ext);
g_signal_handlers_block_by_func (object,
gimp_data_list_object_renamed_callback,
data_list);
for (list2 = base_list; list2; list2 = g_list_next (list2))
{
object2 = GIMP_OBJECT (list2->data);
gimp_list_uniquefy_name (gimp_list, object, TRUE);
if (object == object2)
continue;
g_signal_handlers_unblock_by_func (object,
gimp_data_list_object_renamed_callback,
data_list);
if (! strcmp (object2->name, new_name))
break;
}
}
while (list2);
old_index = g_list_index (gimp_list->list, object);
if (have)
g_signal_handlers_block_by_func (object,
gimp_data_list_object_renamed_callback,
data_list);
gimp_object_set_name (object, new_name);
if (have)
g_signal_handlers_unblock_by_func (object,
gimp_data_list_object_renamed_callback,
data_list);
g_free (new_name);
break;
}
}
if (have)
for (list = gimp_list->list; list; list = g_list_next (list))
{
gint old_index;
gint new_index = 0;
old_index = g_list_index (base_list, object);
GimpObject *object2 = GIMP_OBJECT (list->data);
for (list2 = base_list; list2; list2 = g_list_next (list2))
{
object2 = GIMP_OBJECT (list2->data);
if (object == object2)
continue;
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);
if (gimp_data_list_data_compare_func (object, object2) > 0)
new_index++;
else
break;
}
}
static void
gimp_data_list_object_renamed_callback (GimpObject *object,
GimpDataList *data_list)
{
gimp_data_list_uniquefy_data_name (data_list, object);
if (new_index != old_index)
gimp_container_reorder (GIMP_CONTAINER (data_list), object, new_index);
}
static gint
......
......@@ -169,13 +169,7 @@ static void
gimp_item_name_changed (GimpObject *object)
{
GimpItem *item;
GimpItem *item2;
GList *list, *list2, *base_list;
gint unique_ext = 0;
gchar *ext;
gchar *new_name = NULL;
g_return_if_fail (GIMP_IS_ITEM (object));
GimpList *list = NULL;
item = GIMP_ITEM (object);
......@@ -184,83 +178,14 @@ gimp_item_name_changed (GimpObject *object)
return;
if (GIMP_IS_LAYER (item))
base_list = GIMP_LIST (item->gimage->layers)->list;
list = GIMP_LIST (item->gimage->layers);
else if (GIMP_IS_CHANNEL (item))
base_list = GIMP_LIST (item->gimage->channels)->list;
list = GIMP_LIST (item->gimage->channels);
else if (GIMP_IS_VECTORS (item))
base_list = GIMP_LIST (item->gimage->vectors)->list;
else
base_list = NULL;
list = GIMP_LIST (item->gimage->vectors);
for (list = base_list;
list;
list = g_list_next (list))
{
item2 = GIMP_ITEM (list->data);
if (item != item2 &&
strcmp (gimp_object_get_name (GIMP_OBJECT (item)),
gimp_object_get_name (GIMP_OBJECT (item2))) == 0)
{
ext = strrchr (GIMP_OBJECT (item)->name, '#');
if (ext)
{
gchar *ext_str;
unique_ext = atoi (ext + 1);
ext_str = g_strdup_printf ("%d", unique_ext);
/* check if the extension really is of the form "#<n>" */
if (! strcmp (ext_str, ext + 1))
{
*ext = '\0';
}
else
{
unique_ext = 0;
}
g_free (ext_str);
}
else
{
unique_ext = 0;
}
do
{
unique_ext++;
g_free (new_name);
new_name = g_strdup_printf ("%s#%d",
GIMP_OBJECT (item)->name,
unique_ext);
for (list2 = base_list; list2; list2 = g_list_next (list2))
{
item2 = GIMP_ITEM (list2->data);
if (item == item2)
continue;
if (! strcmp (GIMP_OBJECT (item2)->name, new_name))
{
break;
}
}
}
while (list2);
g_free (GIMP_OBJECT (item)->name);
GIMP_OBJECT (item)->name = new_name;
break;
}
}
if (list)
gimp_list_uniquefy_name (list, object, FALSE);
}
static gsize
......
......@@ -21,6 +21,7 @@
#include "config.h"
#include <stdlib.h>
#include <string.h> /* strcmp */
#include <glib-object.h>
......@@ -322,3 +323,90 @@ gimp_list_sort (GimpList *list,
gimp_container_thaw (GIMP_CONTAINER (list));
}
}
void
gimp_list_uniquefy_name (GimpList *gimp_list,
GimpObject *object,
gboolean use_set_name)
{
GList *list;
GList *list2;
GimpObject *object2;
gint unique_ext = 0;
gchar *new_name = NULL;
gchar *ext;
g_return_if_fail (GIMP_IS_LIST (gimp_list));
g_return_if_fail (GIMP_IS_OBJECT (object));
for (list = gimp_list->list; list; list = g_list_next (list))
{
object2 = GIMP_OBJECT (list->data);
if (object != object2 &&
strcmp (gimp_object_get_name (GIMP_OBJECT (object)),
gimp_object_get_name (GIMP_OBJECT (object2))) == 0)
{
ext = strrchr (object->name, '#');
if (ext)
{
gchar *ext_str;
unique_ext = atoi (ext + 1);
ext_str = g_strdup_printf ("%d", unique_ext);
/* check if the extension really is of the form "#<n>" */
if (! strcmp (ext_str, ext + 1))
{
*ext = '\0';
}
else
{
unique_ext = 0;
}
g_free (ext_str);
}
else
{
unique_ext = 0;
}
do
{
unique_ext++;
g_free (new_name);
new_name = g_strdup_printf ("%s#%d", object->name, unique_ext);
for (list2 = gimp_list->list; list2; list2 = g_list_next (list2))
{
object2 = GIMP_OBJECT (list2->data);
if (object == object2)
continue;
if (! strcmp (object2->name, new_name))
break;
}
}
while (list2);
if (use_set_name)
{
gimp_object_set_name (object, new_name);
g_free (new_name);
}
else
{
g_free (object->name);
object->name = new_name;
}
break;
}
}
}
......@@ -49,13 +49,16 @@ struct _GimpListClass
};
GType gimp_list_get_type (void) G_GNUC_CONST;
GType gimp_list_get_type (void) G_GNUC_CONST;
GimpContainer * gimp_list_new (GType children_type,
GimpContainerPolicy policy);
void gimp_list_reverse (GimpList *list);
void gimp_list_sort (GimpList *list,
GCompareFunc compare_func);
GimpContainer * gimp_list_new (GType children_type,
GimpContainerPolicy policy);
void gimp_list_reverse (GimpList *list);
void gimp_list_sort (GimpList *list,
GCompareFunc compare_func);
void gimp_list_uniquefy_name (GimpList *gimp_list,
GimpObject *object,
gboolean use_set_name);
#endif /* __GIMP_LIST_H__ */
......@@ -58,6 +58,7 @@
#include "widgets/gimppaletteeditor.h"
#include "widgets/gimppreview.h"
#include "widgets/gimpselectioneditor.h"
#include "widgets/gimptemplateview.h"
#include "widgets/gimptoolbox.h"
#include "widgets/gimptoolbox-color-area.h"
#include "widgets/gimpundoeditor.h"
......@@ -908,17 +909,18 @@ dialogs_template_list_new (GimpDialogFactory *factory,
{
GtkWidget *view;
view = gimp_container_tree_view_new (context->gimp->templates,
context,
preview_size,
TRUE,
5, 3);
view = gimp_template_view_new (GIMP_VIEW_TYPE_LIST,
context->gimp->templates,
context,
preview_size,
5, 3,
factory->menu_factory);
return dialogs_dockable_new (view,
_("List of Templates"), _("Templates"),
GIMP_STOCK_TEMPLATE,
dialogs_stock_text_tab_func,
dialogs_set_view_context_func);
dialogs_set_editor_context_func);
}
......
......@@ -53,6 +53,10 @@ dialogs_sources = \
resize-dialog.h \
resolution-calibrate-dialog.c \
resolution-calibrate-dialog.h \
templates-commands.c \
templates-commands.h \
templates-menu.c \
templates-menu.h \
tips-dialog.c \
tips-dialog.h \
tips-parser.c \
......