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.
This commit is contained in:
Michael Natterer 2003-04-06 11:21:56 +00:00 committed by Michael Natterer
parent b0defba66a
commit 9827ceac0e
24 changed files with 988 additions and 224 deletions

View File

@ -1,3 +1,31 @@
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

View File

@ -29,7 +29,7 @@
#include "documents-commands.h"
/* public functionss */
/* public functions */
void
documents_open_document_cmd_callback (GtkWidget *widget,

View File

@ -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);

View File

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

View File

@ -0,0 +1,33 @@
/* 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__ */

View File

@ -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);
@ -148,130 +146,44 @@ gimp_data_list_new (GType children_type)
return GIMP_CONTAINER (list);
}
static void
gimp_data_list_uniquefy_data_name (GimpDataList *data_list,
GimpObject *object)
{
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++;
g_free (new_name);
new_name = g_strdup_printf ("%s#%d", object->name, unique_ext);
for (list2 = base_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 (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)
{
gint old_index;
gint new_index = 0;
old_index = g_list_index (base_list, object);
for (list2 = base_list; list2; list2 = g_list_next (list2))
{
object2 = GIMP_OBJECT (list2->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 void
gimp_data_list_object_renamed_callback (GimpObject *object,
GimpDataList *data_list)
{
gimp_data_list_uniquefy_data_name (data_list, object);
GimpList *gimp_list;
GList *list;
gint old_index;
gint new_index = 0;
gimp_list = GIMP_LIST (data_list);
g_signal_handlers_block_by_func (object,
gimp_data_list_object_renamed_callback,
data_list);
gimp_list_uniquefy_name (gimp_list, object, TRUE);
g_signal_handlers_unblock_by_func (object,
gimp_data_list_object_renamed_callback,
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

View File

@ -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

View File

@ -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;
}
}
}

View File

@ -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__ */

View File

@ -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);
}

View File

@ -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 \

View File

@ -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);
}

View File

@ -29,7 +29,7 @@
#include "documents-commands.h"
/* public functionss */
/* public functions */
void
documents_open_document_cmd_callback (GtkWidget *widget,

View File

@ -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);

View File

@ -56,6 +56,7 @@
#include "paths-dialog.h"
#include "patterns-menu.h"
#include "qmask-menu.h"
#include "templates-menu.h"
#include "toolbox-menu.h"
#include "vectors-menu.h"
@ -198,6 +199,12 @@ menus_init (Gimp *gimp)
n_documents_menu_entries,
documents_menu_entries);
gimp_menu_factory_menu_register (global_menu_factory,
"<Templates>", "templates",
NULL, templates_menu_update, TRUE,
n_templates_menu_entries,
templates_menu_entries);
gimp_menu_factory_menu_register (global_menu_factory,
"<Images>", "images",
NULL, images_menu_update, TRUE,

View File

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

View File

@ -0,0 +1,33 @@
/* 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__ */

83
app/gui/templates-menu.c Normal file
View File

@ -0,0 +1,83 @@
/* 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 "core/gimpcontext.h"
#include "widgets/gimpcontainereditor.h"
#include "widgets/gimpcontainerview.h"
#include "widgets/gimpitemfactory.h"
#include "templates-commands.h"
#include "templates-menu.h"
#include "menus.h"
#include "gimp-intl.h"
GimpItemFactoryEntry templates_menu_entries[] =
{
{ { N_("/New Template"), "",
templates_new_template_cmd_callback, 0,
"<StockItem>", GTK_STOCK_NEW },
NULL, NULL, NULL },
{ { N_("/Duplicate Template"), "",
templates_duplicate_template_cmd_callback, 0,
"<StockItem>", GIMP_STOCK_DUPLICATE },
NULL, NULL, NULL },
{ { N_("/Create Image from Template"), "",
templates_create_image_cmd_callback, 0,
"<StockItem>", GIMP_STOCK_IMAGE },
NULL, NULL, NULL },
{ { N_("/Delete Template..."), "",
templates_delete_template_cmd_callback, 0,
"<StockItem>", GTK_STOCK_DELETE },
NULL, NULL, NULL }
};
gint n_templates_menu_entries = G_N_ELEMENTS (templates_menu_entries);
void
templates_menu_update (GtkItemFactory *factory,
gpointer data)
{
GimpContainerEditor *editor;
GimpTemplate *template;
editor = GIMP_CONTAINER_EDITOR (data);
template = gimp_context_get_template (editor->view->context);
#define SET_SENSITIVE(menu,condition) \
gimp_item_factory_set_sensitive (factory, menu, (condition) != 0)
SET_SENSITIVE ("/New Template", TRUE);
SET_SENSITIVE ("/Duplicate Template", template);
SET_SENSITIVE ("/Create Image from Template", template);
SET_SENSITIVE ("/Delete Template...", template);
#undef SET_SENSITIVE
}

31
app/gui/templates-menu.h Normal file
View File

@ -0,0 +1,31 @@
/* 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_MENU_H__
#define __TEMPLATES_MENU_H__
extern GimpItemFactoryEntry templates_menu_entries[];
extern gint n_templates_menu_entries;
void templates_menu_update (GtkItemFactory *factory,
gpointer data);
#endif /* __TEMPLATES_MENU_H__ */

View File

@ -56,6 +56,7 @@
#include "paths-dialog.h"
#include "patterns-menu.h"
#include "qmask-menu.h"
#include "templates-menu.h"
#include "toolbox-menu.h"
#include "vectors-menu.h"
@ -198,6 +199,12 @@ menus_init (Gimp *gimp)
n_documents_menu_entries,
documents_menu_entries);
gimp_menu_factory_menu_register (global_menu_factory,
"<Templates>", "templates",
NULL, templates_menu_update, TRUE,
n_templates_menu_entries,
templates_menu_entries);
gimp_menu_factory_menu_register (global_menu_factory,
"<Images>", "images",
NULL, images_menu_update, TRUE,

View File

@ -139,6 +139,8 @@ libappwidgets_a_sources = \
gimppropwidgets.h \
gimpselectioneditor.c \
gimpselectioneditor.h \
gimptemplateview.c \
gimptemplateview.h \
gimptexteditor.c \
gimptexteditor.h \
gimptoolbox.c \

View File

@ -0,0 +1,379 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimptemplateview.c
* Copyright (C) 2003 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 <string.h>
#include <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
#include "widgets-types.h"
#include "config/gimpconfig.h"
#include "core/gimp.h"
#include "core/gimpcontainer.h"
#include "core/gimpcontext.h"
#include "core/gimplist.h"
#include "core/gimpimage.h"
#include "core/gimptemplate.h"
#include "gimpcontainerview.h"
#include "gimptemplateview.h"
#include "gimpdnd.h"
#include "gimpwidgets-utils.h"
#include "gimp-intl.h"
static void gimp_template_view_class_init (GimpTemplateViewClass *klass);
static void gimp_template_view_init (GimpTemplateView *view);
static void gimp_template_view_new_clicked (GtkWidget *widget,
GimpTemplateView *view);
static void gimp_template_view_duplicate_clicked (GtkWidget *widget,
GimpTemplateView *view);
static void gimp_template_view_create_clicked (GtkWidget *widget,
GimpTemplateView *view);
static void gimp_template_view_delete_clicked (GtkWidget *widget,
GimpTemplateView *view);
static void gimp_template_view_select_item (GimpContainerEditor *editor,
GimpViewable *viewable);
static void gimp_template_view_activate_item (GimpContainerEditor *editor,
GimpViewable *viewable);
static GimpContainerEditorClass *parent_class = NULL;
GType
gimp_template_view_get_type (void)
{
static GType view_type = 0;
if (! view_type)
{
static const GTypeInfo view_info =
{
sizeof (GimpTemplateViewClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) gimp_template_view_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpTemplateView),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_template_view_init,
};
view_type = g_type_register_static (GIMP_TYPE_CONTAINER_EDITOR,
"GimpTemplateView",
&view_info, 0);
}
return view_type;
}
static void
gimp_template_view_class_init (GimpTemplateViewClass *klass)
{
GimpContainerEditorClass *editor_class;
editor_class = GIMP_CONTAINER_EDITOR_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
editor_class->select_item = gimp_template_view_select_item;
editor_class->activate_item = gimp_template_view_activate_item;
}
static void
gimp_template_view_init (GimpTemplateView *view)
{
view->new_button = NULL;
view->create_button = NULL;
view->delete_button = NULL;
}
GtkWidget *
gimp_template_view_new (GimpViewType view_type,
GimpContainer *container,
GimpContext *context,
gint preview_size,
gint min_items_x,
gint min_items_y,
GimpMenuFactory *menu_factory)
{
GimpTemplateView *template_view;
GimpContainerEditor *editor;
template_view = g_object_new (GIMP_TYPE_TEMPLATE_VIEW, NULL);
if (! gimp_container_editor_construct (GIMP_CONTAINER_EDITOR (template_view),
view_type,
container,
context,
preview_size,
TRUE, /* reorderable */
min_items_x,
min_items_y,
menu_factory, "<Templates>"))
{
g_object_unref (template_view);
return NULL;
}
editor = GIMP_CONTAINER_EDITOR (template_view);
template_view->new_button =
gimp_editor_add_button (GIMP_EDITOR (editor->view),
GTK_STOCK_NEW,
_("Create a new template"), NULL,
G_CALLBACK (gimp_template_view_new_clicked),
NULL,
editor);
template_view->duplicate_button =
gimp_editor_add_button (GIMP_EDITOR (editor->view),
GIMP_STOCK_DUPLICATE,
_("Duplicate the selected template"), NULL,
G_CALLBACK (gimp_template_view_duplicate_clicked),
NULL,
editor);
template_view->create_button =
gimp_editor_add_button (GIMP_EDITOR (editor->view),
GIMP_STOCK_IMAGE,
_("Create a new image from the selected template"),
NULL,
G_CALLBACK (gimp_template_view_create_clicked),
NULL,
editor);
template_view->delete_button =
gimp_editor_add_button (GIMP_EDITOR (editor->view),
GTK_STOCK_DELETE,
_("Delete the selected template"), NULL,
G_CALLBACK (gimp_template_view_delete_clicked),
NULL,
editor);
/* set button sensitivity */
if (GIMP_CONTAINER_EDITOR_GET_CLASS (editor)->select_item)
GIMP_CONTAINER_EDITOR_GET_CLASS (editor)->select_item
(editor, (GimpViewable *) gimp_context_get_template (context));
gimp_container_view_enable_dnd (editor->view,
GTK_BUTTON (template_view->duplicate_button),
GIMP_TYPE_TEMPLATE);
gimp_container_view_enable_dnd (editor->view,
GTK_BUTTON (template_view->create_button),
GIMP_TYPE_TEMPLATE);
gimp_container_view_enable_dnd (editor->view,
GTK_BUTTON (template_view->delete_button),
GIMP_TYPE_TEMPLATE);
return GTK_WIDGET (template_view);
}
static void
gimp_template_view_new_clicked (GtkWidget *widget,
GimpTemplateView *view)
{
GimpContainerEditor *editor;
GimpTemplate *template;
editor = GIMP_CONTAINER_EDITOR (view);
template = gimp_context_get_template (editor->view->context);
if (template && gimp_container_have (editor->view->container,
GIMP_OBJECT (template)))
{
}
}
static void
gimp_template_view_duplicate_clicked (GtkWidget *widget,
GimpTemplateView *view)
{
GimpContainerEditor *editor;
GimpTemplate *template;
editor = GIMP_CONTAINER_EDITOR (view);
template = gimp_context_get_template (editor->view->context);
if (template && gimp_container_have (editor->view->container,
GIMP_OBJECT (template)))
{
GimpTemplate *new_template;
new_template = GIMP_TEMPLATE (gimp_config_duplicate (G_OBJECT (template)));
gimp_list_uniquefy_name (GIMP_LIST (editor->view->container),
GIMP_OBJECT (new_template), TRUE);
gimp_container_add (editor->view->container, GIMP_OBJECT (new_template));
gimp_context_set_by_type (editor->view->context,
editor->view->container->children_type,
GIMP_OBJECT (new_template));
g_object_unref (new_template);
}
}
static void
gimp_template_view_create_clicked (GtkWidget *widget,
GimpTemplateView *view)
{
GimpContainerEditor *editor;
GimpTemplate *template;
editor = GIMP_CONTAINER_EDITOR (view);
template = gimp_context_get_template (editor->view->context);
if (template && gimp_container_have (editor->view->container,
GIMP_OBJECT (template)))
{
gimp_template_create_image (editor->view->context->gimp, template);
}
}
typedef struct _GimpTemplateDeleteData GimpTemplateDeleteData;
struct _GimpTemplateDeleteData
{
GimpContainer *container;
GimpTemplate *template;
};
static void
gimp_template_view_delete_callback (GtkWidget *widget,
gboolean delete,
gpointer data)
{
GimpTemplateDeleteData *delete_data;
delete_data = (GimpTemplateDeleteData *) data;
if (! delete)
return;
if (gimp_container_have (delete_data->container,
GIMP_OBJECT (delete_data->template)))
{
gimp_container_remove (delete_data->container,
GIMP_OBJECT (delete_data->template));
}
}
static void
gimp_template_view_delete_clicked (GtkWidget *widget,
GimpTemplateView *view)
{
GimpContainerEditor *editor;
GimpTemplate *template;
editor = GIMP_CONTAINER_EDITOR (view);
template = gimp_context_get_template (editor->view->context);
if (template && gimp_container_have (editor->view->container,
GIMP_OBJECT (template)))
{
GimpTemplateDeleteData *delete_data;
GtkWidget *dialog;
gchar *str;
delete_data = g_new0 (GimpTemplateDeleteData, 1);
delete_data->container = editor->view->container;
delete_data->template = template;
str = g_strdup_printf (_("Are you sure you want to delete\n"
"template \"%s\" from the list?"),
GIMP_OBJECT (template)->name);
dialog = gimp_query_boolean_box (_("Delete Template"),
gimp_standard_help_func, NULL,
GIMP_STOCK_QUESTION,
str,
GTK_STOCK_DELETE, GTK_STOCK_CANCEL,
G_OBJECT (template),
"disconnect",
gimp_template_view_delete_callback,
delete_data);
g_object_weak_ref (G_OBJECT (dialog), (GWeakNotify) g_free, delete_data);
g_free (str);
gtk_widget_show (dialog);
}
}
static void
gimp_template_view_select_item (GimpContainerEditor *editor,
GimpViewable *viewable)
{
GimpTemplateView *view;
gboolean create_sensitive = FALSE;
gboolean delete_sensitive = FALSE;
if (GIMP_CONTAINER_EDITOR_CLASS (parent_class)->select_item)
GIMP_CONTAINER_EDITOR_CLASS (parent_class)->select_item (editor, viewable);
view = GIMP_TEMPLATE_VIEW (editor);
if (viewable && gimp_container_have (editor->view->container,
GIMP_OBJECT (viewable)))
{
create_sensitive = TRUE;
delete_sensitive = TRUE;
}
gtk_widget_set_sensitive (view->create_button, create_sensitive);
gtk_widget_set_sensitive (view->delete_button, delete_sensitive);
}
static void
gimp_template_view_activate_item (GimpContainerEditor *editor,
GimpViewable *viewable)
{
GimpTemplateView *view;
if (GIMP_CONTAINER_EDITOR_CLASS (parent_class)->activate_item)
GIMP_CONTAINER_EDITOR_CLASS (parent_class)->activate_item (editor, viewable);
view = GIMP_TEMPLATE_VIEW (editor);
if (viewable && gimp_container_have (editor->view->container,
GIMP_OBJECT (viewable)))
{
gimp_template_create_image (editor->view->context->gimp,
GIMP_TEMPLATE (viewable));
}
}

View File

@ -0,0 +1,66 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimptemplateview.h
* Copyright (C) 2003 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_TEMPLATE_VIEW_H__
#define __GIMP_TEMPLATE_VIEW_H__
#include "gimpcontainereditor.h"
#define GIMP_TYPE_TEMPLATE_VIEW (gimp_template_view_get_type ())
#define GIMP_TEMPLATE_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_TEMPLATE_VIEW, GimpTemplateView))
#define GIMP_TEMPLATE_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_TEMPLATE_VIEW, GimpTemplateViewClass))
#define GIMP_IS_TEMPLATE_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_TEMPLATE_VIEW))
#define GIMP_IS_TEMPLATE_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_TEMPLATE_VIEW))
#define GIMP_TEMPLATE_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_TEMPLATE_VIEW, GimpTemplateViewClass))
typedef struct _GimpTemplateViewClass GimpTemplateViewClass;
struct _GimpTemplateView
{
GimpContainerEditor parent_instance;
GtkWidget *new_button;
GtkWidget *duplicate_button;
GtkWidget *create_button;
GtkWidget *delete_button;
};
struct _GimpTemplateViewClass
{
GimpContainerEditorClass parent_class;
};
GType gimp_template_view_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_template_view_new (GimpViewType view_type,
GimpContainer *container,
GimpContext *context,
gint preview_size,
gint min_items_x,
gint min_items_y,
GimpMenuFactory *menu_factory);
#endif /* __GIMP_TEMPLATE_VIEW_H__ */

View File

@ -85,6 +85,7 @@ typedef struct _GimpContainerEditor GimpContainerEditor;
typedef struct _GimpBufferView GimpBufferView;
typedef struct _GimpDocumentView GimpDocumentView;
typedef struct _GimpImageView GimpImageView;
typedef struct _GimpTemplateView GimpTemplateView;
typedef struct _GimpDataFactoryView GimpDataFactoryView;
typedef struct _GimpBrushFactoryView GimpBrushFactoryView;