Commit 6663cee5 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

invalidate the preview when the stock_id changes.

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

	* app/core/gimptemplate.c (gimp_template_notify): invalidate
	the preview when the stock_id changes.

	* app/widgets/gimptemplateeditor.[ch]: added an optional entry
	to edit the template's name.

	* app/widgets/gimptemplateview.[ch]: added a "duplicate" button and
	function pointers for creating templates, editing templates and
	creating images from templates.

	* app/gui/file-new-dialog.[ch] (file_new_dialog_create): added an
	optional template parameter.

	* app/gui/file-commands.c: pass template == NULL.

	* app/gui/templates-menu.c: added a "Duplicate Template" menu entry.

	* app/gui/templates-commands.[ch]: added the callback for the
	duplicate menu item. Added "New Template" and "Edit Template"
	dialogs. Added a function which opens a file_new_dialog with
	a template preselected.

	* app/gui/dialogs-constructors.c: let GimpTemplateView know
	about the functions.
parent c16bc592
2003-04-13 Michael Natterer <mitch@gimp.org>
* app/core/gimptemplate.c (gimp_template_notify): invalidate
the preview when the stock_id changes.
* app/widgets/gimptemplateeditor.[ch]: added an optional entry
to edit the template's name.
* app/widgets/gimptemplateview.[ch]: added a "duplicate" button and
function pointers for creating templates, editing templates and
creating images from templates.
* app/gui/file-new-dialog.[ch] (file_new_dialog_create): added an
optional template parameter.
* app/gui/file-commands.c: pass template == NULL.
* app/gui/templates-menu.c: added a "Duplicate Template" menu entry.
* app/gui/templates-commands.[ch]: added the callback for the
duplicate menu item. Added "New Template" and "Edit Template"
dialogs. Added a function which opens a file_new_dialog with
a template preselected.
* app/gui/dialogs-constructors.c: let GimpTemplateView know
about the functions.
2003-04-13 Sven Neumann <sven@gimp.org>
 
* app/paint/gimppaintoptions.c: changed the "fade-length" and
......@@ -105,7 +105,7 @@ file_new_cmd_callback (GtkWidget *widget,
else
gimage = NULL;
file_new_dialog_create (gimp, gimage);
file_new_dialog_create (gimp, gimage, NULL);
}
void
......
......@@ -24,10 +24,22 @@
#include "gui-types.h"
#include "config/gimpconfig-utils.h"
#include "core/gimp.h"
#include "core/gimpcontext.h"
#include "core/gimplist.h"
#include "core/gimptemplate.h"
#include "widgets/gimptemplateeditor.h"
#include "widgets/gimptemplateview.h"
#include "widgets/gimpviewabledialog.h"
#include "file-new-dialog.h"
#include "templates-commands.h"
#include "gimp-intl.h"
/* public functions */
......@@ -35,9 +47,7 @@ void
templates_new_template_cmd_callback (GtkWidget *widget,
gpointer data)
{
GimpTemplateView *view;
view = GIMP_TEMPLATE_VIEW (data);
GimpTemplateView *view = GIMP_TEMPLATE_VIEW (data);
gtk_button_clicked (GTK_BUTTON (view->new_button));
}
......@@ -46,20 +56,25 @@ void
templates_duplicate_template_cmd_callback (GtkWidget *widget,
gpointer data)
{
GimpTemplateView *view;
view = GIMP_TEMPLATE_VIEW (data);
GimpTemplateView *view = GIMP_TEMPLATE_VIEW (data);
gtk_button_clicked (GTK_BUTTON (view->duplicate_button));
}
void
templates_edit_template_cmd_callback (GtkWidget *widget,
gpointer data)
{
GimpTemplateView *view = GIMP_TEMPLATE_VIEW (data);
gtk_button_clicked (GTK_BUTTON (view->edit_button));
}
void
templates_create_image_cmd_callback (GtkWidget *widget,
gpointer data)
{
GimpTemplateView *view;
view = GIMP_TEMPLATE_VIEW (data);
GimpTemplateView *view = GIMP_TEMPLATE_VIEW (data);
gtk_button_clicked (GTK_BUTTON (view->create_button));
}
......@@ -68,9 +83,157 @@ void
templates_delete_template_cmd_callback (GtkWidget *widget,
gpointer data)
{
GimpTemplateView *view;
view = GIMP_TEMPLATE_VIEW (data);
GimpTemplateView *view = GIMP_TEMPLATE_VIEW (data);
gtk_button_clicked (GTK_BUTTON (view->delete_button));
}
static void
templates_new_template_ok_callback (GtkWidget *widget,
GtkWidget *dialog)
{
GimpTemplateEditor *editor;
GimpTemplate *template;
Gimp *gimp;
editor = g_object_get_data (G_OBJECT (dialog), "gimp-template-editor");
template = g_object_get_data (G_OBJECT (dialog), "gimp-template");
gimp = g_object_get_data (G_OBJECT (dialog), "gimp");
gimp_config_copy_properties (G_OBJECT (editor->template),
G_OBJECT (template));
gimp_list_uniquefy_name (GIMP_LIST (gimp->templates),
GIMP_OBJECT (template), TRUE);
gimp_container_add (gimp->templates, GIMP_OBJECT (template));
gimp_context_set_template (gimp_get_user_context (gimp), template);
gtk_widget_destroy (dialog);
}
void
templates_new_template_dialog (Gimp *gimp,
GimpTemplate *template_template)
{
GimpTemplate *template;
GtkWidget *dialog;
GtkWidget *main_vbox;
GtkWidget *editor;
template = gimp_template_new (_("Unnamed"));
gimp_template_set_from_config (template, gimp->config);
dialog =
gimp_viewable_dialog_new (NULL,
_("New Template"), "new_template",
GIMP_STOCK_TEMPLATE,
_("Create a New Template"),
gimp_standard_help_func,
"dialogs/new_template.html",
GTK_STOCK_CANCEL, gtk_widget_destroy,
NULL, (gpointer) 1, NULL, FALSE, TRUE,
GTK_STOCK_OK,
G_CALLBACK (templates_new_template_ok_callback),
NULL, NULL, NULL, TRUE, FALSE,
NULL);
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
main_vbox = gtk_vbox_new (FALSE, 4);
gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 4);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), main_vbox,
TRUE, TRUE, 0);
gtk_widget_show (main_vbox);
editor = gimp_template_editor_new (gimp, TRUE);
gtk_box_pack_start (GTK_BOX (main_vbox), editor, FALSE, FALSE, 0);
gtk_widget_show (editor);
gimp_template_editor_set_template (GIMP_TEMPLATE_EDITOR (editor),
template);
g_object_set_data (G_OBJECT (dialog), "gimp-template-editor", editor);
g_object_set_data (G_OBJECT (dialog), "gimp", gimp);
g_object_set_data_full (G_OBJECT (dialog), "gimp-template", template,
(GDestroyNotify) g_object_unref);
gtk_widget_show (dialog);
}
static void
templates_edit_template_ok_callback (GtkWidget *widget,
GtkWidget *dialog)
{
GimpTemplateEditor *editor;
GimpTemplate *template;
Gimp *gimp;
editor = g_object_get_data (G_OBJECT (dialog), "gimp-template-editor");
template = g_object_get_data (G_OBJECT (dialog), "gimp-template");
gimp = g_object_get_data (G_OBJECT (dialog), "gimp");
gimp_config_copy_properties (G_OBJECT (editor->template),
G_OBJECT (template));
gimp_list_uniquefy_name (GIMP_LIST (gimp->templates),
GIMP_OBJECT (template), TRUE);
gtk_widget_destroy (dialog);
}
void
templates_edit_template_dialog (Gimp *gimp,
GimpTemplate *template)
{
GtkWidget *dialog;
GtkWidget *main_vbox;
GtkWidget *editor;
dialog =
gimp_viewable_dialog_new (GIMP_VIEWABLE (template),
_("Edit Template"), "edit_template",
GIMP_STOCK_EDIT,
_("Edit Template"),
gimp_standard_help_func,
"dialogs/edit_template.html",
GTK_STOCK_CANCEL, gtk_widget_destroy,
NULL, (gpointer) 1, NULL, FALSE, TRUE,
GTK_STOCK_OK,
G_CALLBACK (templates_edit_template_ok_callback),
NULL, NULL, NULL, TRUE, FALSE,
NULL);
main_vbox = gtk_vbox_new (FALSE, 4);
gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 4);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), main_vbox,
TRUE, TRUE, 0);
gtk_widget_show (main_vbox);
editor = gimp_template_editor_new (gimp, TRUE);
gtk_box_pack_start (GTK_BOX (main_vbox), editor, FALSE, FALSE, 0);
gtk_widget_show (editor);
gimp_template_editor_set_template (GIMP_TEMPLATE_EDITOR (editor),
template);
g_object_set_data (G_OBJECT (dialog), "gimp-template-editor", editor);
g_object_set_data (G_OBJECT (dialog), "gimp-template", template);
g_object_set_data (G_OBJECT (dialog), "gimp", gimp);
gtk_widget_show (dialog);
}
void
templates_file_new_dialog (Gimp *gimp,
GimpTemplate *template)
{
file_new_dialog_create (gimp, NULL, template);
}
......@@ -20,14 +20,22 @@
#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);
void templates_new_template_cmd_callback (GtkWidget *widget,
gpointer data);
void templates_duplicate_template_cmd_callback (GtkWidget *widget,
gpointer data);
void templates_edit_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);
void templates_new_template_dialog (Gimp *gimp,
GimpTemplate *template);
void templates_edit_template_dialog (Gimp *gimp,
GimpTemplate *template);
void templates_file_new_dialog (Gimp *gimp,
GimpTemplate *template);
#endif /* __TEMPLATES_COMMANDS_H__ */
......@@ -21,6 +21,8 @@
#include "config.h"
#include <string.h>
#include <glib-object.h>
#include "libgimpbase/gimpbase.h"
......@@ -336,6 +338,9 @@ gimp_template_notify (GObject *object,
template->initial_size = (gulong) size;
template->initial_size_too_large = FALSE;
}
if (! strcmp (pspec->name, "stock-id"))
gimp_viewable_invalidate_preview (GIMP_VIEWABLE (object));
}
static gboolean
......
......@@ -84,6 +84,7 @@
#include "module-browser.h"
#include "paths-dialog.h"
#include "preferences-dialog.h"
#include "templates-commands.h"
#include "tips-dialog.h"
#include "tool-options-dialog.h"
#include "vectors-commands.h"
......@@ -896,7 +897,8 @@ dialogs_template_list_new (GimpDialogFactory *factory,
GimpContext *context,
gint preview_size)
{
GtkWidget *view;
GtkWidget *view;
GimpTemplateView *template_view;
view = gimp_template_view_new (GIMP_VIEW_TYPE_LIST,
context->gimp->templates,
......@@ -904,6 +906,12 @@ dialogs_template_list_new (GimpDialogFactory *factory,
preview_size, 0,
factory->menu_factory);
template_view = GIMP_TEMPLATE_VIEW (view);
template_view->new_template_func = templates_new_template_dialog;
template_view->edit_template_func = templates_edit_template_dialog;
template_view->create_image_func = templates_file_new_dialog;
return dialogs_dockable_new (view,
_("List of Templates"), _("Templates"),
GIMP_STOCK_TEMPLATE,
......
......@@ -77,17 +77,18 @@ static void file_new_create_image (FileNewDialog *dialog);
/* public functions */
void
file_new_dialog_create (Gimp *gimp,
GimpImage *gimage)
file_new_dialog_create (Gimp *gimp,
GimpImage *gimage,
GimpTemplate *template)
{
FileNewDialog *dialog;
GimpTemplate *template;
GtkWidget *main_vbox;
GtkWidget *table;
GtkWidget *optionmenu;
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (gimage == NULL || GIMP_IS_IMAGE (gimage));
g_return_if_fail (template == NULL || GIMP_IS_TEMPLATE (template));
dialog = g_new0 (FileNewDialog, 1);
......@@ -145,7 +146,7 @@ file_new_dialog_create (Gimp *gimp,
dialog);
/* Template editor */
dialog->editor = gimp_template_editor_new (gimp, TRUE);
dialog->editor = gimp_template_editor_new (gimp, FALSE);
gtk_box_pack_start (GTK_BOX (main_vbox), dialog->editor, FALSE, FALSE, 0);
gtk_widget_show (dialog->editor);
......@@ -153,10 +154,18 @@ file_new_dialog_create (Gimp *gimp,
G_CALLBACK (file_new_template_notify),
dialog);
template = gimp_image_new_get_last_template (gimp, gimage);
gimp_template_editor_set_template (GIMP_TEMPLATE_EDITOR (dialog->editor),
template);
g_object_unref (template);
if (template)
{
gimp_container_menu_select_item (GIMP_CONTAINER_MENU (dialog->template_menu),
GIMP_VIEWABLE (template));
}
else
{
template = gimp_image_new_get_last_template (gimp, gimage);
gimp_template_editor_set_template (GIMP_TEMPLATE_EDITOR (dialog->editor),
template);
g_object_unref (template);
}
gimp_size_entry_grab_focus (GIMP_SIZE_ENTRY (GIMP_TEMPLATE_EDITOR (dialog->editor)->size_se));
......
......@@ -20,8 +20,9 @@
#define __FILE_NEW_DIALOG_H__
void file_new_dialog_create (Gimp *gimp,
GimpImage *gimage);
void file_new_dialog_create (Gimp *gimp,
GimpImage *gimage,
GimpTemplate *template);
#endif /* __FILE_NEW_DIALOG_H__ */
......@@ -84,6 +84,7 @@
#include "module-browser.h"
#include "paths-dialog.h"
#include "preferences-dialog.h"
#include "templates-commands.h"
#include "tips-dialog.h"
#include "tool-options-dialog.h"
#include "vectors-commands.h"
......@@ -896,7 +897,8 @@ dialogs_template_list_new (GimpDialogFactory *factory,
GimpContext *context,
gint preview_size)
{
GtkWidget *view;
GtkWidget *view;
GimpTemplateView *template_view;
view = gimp_template_view_new (GIMP_VIEW_TYPE_LIST,
context->gimp->templates,
......@@ -904,6 +906,12 @@ dialogs_template_list_new (GimpDialogFactory *factory,
preview_size, 0,
factory->menu_factory);
template_view = GIMP_TEMPLATE_VIEW (view);
template_view->new_template_func = templates_new_template_dialog;
template_view->edit_template_func = templates_edit_template_dialog;
template_view->create_image_func = templates_file_new_dialog;
return dialogs_dockable_new (view,
_("List of Templates"), _("Templates"),
GIMP_STOCK_TEMPLATE,
......
......@@ -105,7 +105,7 @@ file_new_cmd_callback (GtkWidget *widget,
else
gimage = NULL;
file_new_dialog_create (gimp, gimage);
file_new_dialog_create (gimp, gimage, NULL);
}
void
......
......@@ -77,17 +77,18 @@ static void file_new_create_image (FileNewDialog *dialog);
/* public functions */
void
file_new_dialog_create (Gimp *gimp,
GimpImage *gimage)
file_new_dialog_create (Gimp *gimp,
GimpImage *gimage,
GimpTemplate *template)
{
FileNewDialog *dialog;
GimpTemplate *template;
GtkWidget *main_vbox;
GtkWidget *table;
GtkWidget *optionmenu;
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (gimage == NULL || GIMP_IS_IMAGE (gimage));
g_return_if_fail (template == NULL || GIMP_IS_TEMPLATE (template));
dialog = g_new0 (FileNewDialog, 1);
......@@ -145,7 +146,7 @@ file_new_dialog_create (Gimp *gimp,
dialog);
/* Template editor */
dialog->editor = gimp_template_editor_new (gimp, TRUE);
dialog->editor = gimp_template_editor_new (gimp, FALSE);
gtk_box_pack_start (GTK_BOX (main_vbox), dialog->editor, FALSE, FALSE, 0);
gtk_widget_show (dialog->editor);
......@@ -153,10 +154,18 @@ file_new_dialog_create (Gimp *gimp,
G_CALLBACK (file_new_template_notify),
dialog);
template = gimp_image_new_get_last_template (gimp, gimage);
gimp_template_editor_set_template (GIMP_TEMPLATE_EDITOR (dialog->editor),
template);
g_object_unref (template);
if (template)
{
gimp_container_menu_select_item (GIMP_CONTAINER_MENU (dialog->template_menu),
GIMP_VIEWABLE (template));
}
else
{
template = gimp_image_new_get_last_template (gimp, gimage);
gimp_template_editor_set_template (GIMP_TEMPLATE_EDITOR (dialog->editor),
template);
g_object_unref (template);
}
gimp_size_entry_grab_focus (GIMP_SIZE_ENTRY (GIMP_TEMPLATE_EDITOR (dialog->editor)->size_se));
......
......@@ -20,8 +20,9 @@
#define __FILE_NEW_DIALOG_H__
void file_new_dialog_create (Gimp *gimp,
GimpImage *gimage);
void file_new_dialog_create (Gimp *gimp,
GimpImage *gimage,
GimpTemplate *template);
#endif /* __FILE_NEW_DIALOG_H__ */
......@@ -24,10 +24,22 @@
#include "gui-types.h"
#include "config/gimpconfig-utils.h"
#include "core/gimp.h"
#include "core/gimpcontext.h"
#include "core/gimplist.h"
#include "core/gimptemplate.h"
#include "widgets/gimptemplateeditor.h"
#include "widgets/gimptemplateview.h"
#include "widgets/gimpviewabledialog.h"
#include "file-new-dialog.h"
#include "templates-commands.h"
#include "gimp-intl.h"
/* public functions */
......@@ -35,9 +47,7 @@ void
templates_new_template_cmd_callback (GtkWidget *widget,
gpointer data)
{
GimpTemplateView *view;
view = GIMP_TEMPLATE_VIEW (data);
GimpTemplateView *view = GIMP_TEMPLATE_VIEW (data);
gtk_button_clicked (GTK_BUTTON (view->new_button));
}
......@@ -46,20 +56,25 @@ void
templates_duplicate_template_cmd_callback (GtkWidget *widget,
gpointer data)
{
GimpTemplateView *view;
view = GIMP_TEMPLATE_VIEW (data);
GimpTemplateView *view = GIMP_TEMPLATE_VIEW (data);
gtk_button_clicked (GTK_BUTTON (view->duplicate_button));
}
void
templates_edit_template_cmd_callback (GtkWidget *widget,
gpointer data)
{
GimpTemplateView *view = GIMP_TEMPLATE_VIEW (data);
gtk_button_clicked (GTK_BUTTON (view->edit_button));
}
void
templates_create_image_cmd_callback (GtkWidget *widget,
gpointer data)
{
GimpTemplateView *view;
view = GIMP_TEMPLATE_VIEW (data);
GimpTemplateView *view = GIMP_TEMPLATE_VIEW (data);
gtk_button_clicked (GTK_BUTTON (view->create_button));
}
......@@ -68,9 +83,157 @@ void
templates_delete_template_cmd_callback (GtkWidget *widget,
gpointer data)
{
GimpTemplateView *view;
view = GIMP_TEMPLATE_VIEW (data);
GimpTemplateView *view = GIMP_TEMPLATE_VIEW (data);
gtk_button_clicked (GTK_BUTTON (view->delete_button));
}
static void
templates_new_template_ok_callback (GtkWidget *widget,
GtkWidget *dialog)
{
GimpTemplateEditor *editor;
GimpTemplate *template;
Gimp *gimp;
editor = g_object_get_data (G_OBJECT (dialog), "gimp-template-editor");
template = g_object_get_data (G_OBJECT (dialog), "gimp-template");
gimp = g_object_get_data (G_OBJECT (dialog), "gimp");
gimp_config_copy_properties (G_OBJECT (editor->template),
G_OBJECT (template));