2003-04-06 19:21:56 +08:00
|
|
|
/* 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"
|
|
|
|
|
2004-04-20 21:25:55 +08:00
|
|
|
#include "actions-types.h"
|
2003-04-06 19:21:56 +08:00
|
|
|
|
2003-10-11 22:30:18 +08:00
|
|
|
#include "config/gimpconfig.h"
|
2003-04-14 00:25:14 +08:00
|
|
|
#include "config/gimpconfig-utils.h"
|
2003-10-14 23:20:59 +08:00
|
|
|
#include "config/gimpcoreconfig.h"
|
2003-04-14 00:25:14 +08:00
|
|
|
|
|
|
|
#include "core/gimp.h"
|
|
|
|
#include "core/gimpcontext.h"
|
|
|
|
#include "core/gimplist.h"
|
|
|
|
#include "core/gimptemplate.h"
|
|
|
|
|
2003-05-03 02:43:15 +08:00
|
|
|
#include "widgets/gimpdialogfactory.h"
|
2003-08-22 09:42:57 +08:00
|
|
|
#include "widgets/gimphelp-ids.h"
|
2003-04-14 00:25:14 +08:00
|
|
|
#include "widgets/gimptemplateeditor.h"
|
2003-04-06 19:21:56 +08:00
|
|
|
#include "widgets/gimptemplateview.h"
|
2003-04-14 00:25:14 +08:00
|
|
|
#include "widgets/gimpviewabledialog.h"
|
2003-04-06 19:21:56 +08:00
|
|
|
|
2004-04-20 21:25:55 +08:00
|
|
|
#include "gui/dialogs.h"
|
|
|
|
#include "gui/file-new-dialog.h"
|
|
|
|
|
2003-04-06 19:21:56 +08:00
|
|
|
#include "templates-commands.h"
|
|
|
|
|
2003-04-14 00:25:14 +08:00
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
2003-04-06 19:21:56 +08:00
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
|
|
|
void
|
2004-04-29 20:52:29 +08:00
|
|
|
templates_new_template_cmd_callback (GtkAction *action,
|
2003-04-06 19:21:56 +08:00
|
|
|
gpointer data)
|
|
|
|
{
|
2003-04-14 00:25:14 +08:00
|
|
|
GimpTemplateView *view = GIMP_TEMPLATE_VIEW (data);
|
2003-04-06 19:21:56 +08:00
|
|
|
|
|
|
|
gtk_button_clicked (GTK_BUTTON (view->new_button));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-04-29 20:52:29 +08:00
|
|
|
templates_duplicate_template_cmd_callback (GtkAction *action,
|
2003-04-06 19:21:56 +08:00
|
|
|
gpointer data)
|
|
|
|
{
|
2003-04-14 00:25:14 +08:00
|
|
|
GimpTemplateView *view = GIMP_TEMPLATE_VIEW (data);
|
2003-04-06 19:21:56 +08:00
|
|
|
|
|
|
|
gtk_button_clicked (GTK_BUTTON (view->duplicate_button));
|
|
|
|
}
|
|
|
|
|
2003-04-14 00:25:14 +08:00
|
|
|
void
|
2004-04-29 20:52:29 +08:00
|
|
|
templates_edit_template_cmd_callback (GtkAction *action,
|
2003-04-14 00:25:14 +08:00
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GimpTemplateView *view = GIMP_TEMPLATE_VIEW (data);
|
|
|
|
|
|
|
|
gtk_button_clicked (GTK_BUTTON (view->edit_button));
|
|
|
|
}
|
|
|
|
|
2003-04-06 19:21:56 +08:00
|
|
|
void
|
2004-04-29 20:52:29 +08:00
|
|
|
templates_create_image_cmd_callback (GtkAction *action,
|
2003-04-06 19:21:56 +08:00
|
|
|
gpointer data)
|
|
|
|
{
|
2003-04-14 00:25:14 +08:00
|
|
|
GimpTemplateView *view = GIMP_TEMPLATE_VIEW (data);
|
2003-04-06 19:21:56 +08:00
|
|
|
|
|
|
|
gtk_button_clicked (GTK_BUTTON (view->create_button));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-04-29 20:52:29 +08:00
|
|
|
templates_delete_template_cmd_callback (GtkAction *action,
|
2003-04-06 19:21:56 +08:00
|
|
|
gpointer data)
|
|
|
|
{
|
2003-04-14 00:25:14 +08:00
|
|
|
GimpTemplateView *view = GIMP_TEMPLATE_VIEW (data);
|
2003-04-06 19:21:56 +08:00
|
|
|
|
|
|
|
gtk_button_clicked (GTK_BUTTON (view->delete_button));
|
|
|
|
}
|
2003-04-14 00:25:14 +08:00
|
|
|
|
|
|
|
static void
|
2003-11-06 23:27:05 +08:00
|
|
|
templates_new_template_response (GtkWidget *widget,
|
|
|
|
gint response_id,
|
|
|
|
GtkWidget *dialog)
|
2003-04-14 00:25:14 +08:00
|
|
|
{
|
2003-11-06 23:27:05 +08:00
|
|
|
if (response_id == GTK_RESPONSE_OK)
|
|
|
|
{
|
|
|
|
GimpTemplate *template;
|
|
|
|
Gimp *gimp;
|
2003-04-14 00:25:14 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
template = g_object_get_data (G_OBJECT (dialog), "gimp-template");
|
|
|
|
gimp = g_object_get_data (G_OBJECT (dialog), "gimp");
|
2003-04-14 00:25:14 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
gimp_container_add (gimp->templates, GIMP_OBJECT (template));
|
|
|
|
gimp_context_set_template (gimp_get_user_context (gimp), template);
|
|
|
|
}
|
2003-04-14 00:25:14 +08:00
|
|
|
|
|
|
|
gtk_widget_destroy (dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-10-19 01:06:43 +08:00
|
|
|
templates_new_template_dialog (Gimp *gimp,
|
2003-11-08 23:29:47 +08:00
|
|
|
GimpTemplate *unused,
|
|
|
|
GtkWidget *parent)
|
2003-04-14 00:25:14 +08:00
|
|
|
{
|
|
|
|
GimpTemplate *template;
|
|
|
|
GtkWidget *dialog;
|
|
|
|
GtkWidget *main_vbox;
|
|
|
|
GtkWidget *editor;
|
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
dialog = gimp_viewable_dialog_new (NULL,
|
2003-11-08 01:29:02 +08:00
|
|
|
_("New Template"), "gimp-template-new",
|
2003-11-06 23:27:05 +08:00
|
|
|
GIMP_STOCK_TEMPLATE,
|
|
|
|
_("Create a New Template"),
|
2003-11-08 23:29:47 +08:00
|
|
|
parent,
|
2003-11-06 23:27:05 +08:00
|
|
|
gimp_standard_help_func,
|
|
|
|
GIMP_HELP_TEMPLATE_NEW,
|
2003-04-14 00:25:14 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_STOCK_OK, GTK_RESPONSE_OK,
|
2003-04-14 00:25:14 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
NULL);
|
2003-04-14 00:25:14 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
g_signal_connect (dialog, "response",
|
|
|
|
G_CALLBACK (templates_new_template_response),
|
|
|
|
dialog);
|
2003-04-14 00:25:14 +08:00
|
|
|
|
2004-05-04 22:21:13 +08:00
|
|
|
main_vbox = gtk_vbox_new (FALSE, 12);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
|
2003-04-14 00:25:14 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), main_vbox,
|
|
|
|
TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (main_vbox);
|
|
|
|
|
2003-10-14 23:20:59 +08:00
|
|
|
template = gimp_config_duplicate (GIMP_CONFIG (gimp->config->default_image));
|
|
|
|
gimp_object_set_name (GIMP_OBJECT (template), _("Unnamed"));
|
2003-04-14 00:25:14 +08:00
|
|
|
|
2003-10-14 23:20:59 +08:00
|
|
|
editor = gimp_template_editor_new (template, gimp, TRUE);
|
2003-04-14 00:25:14 +08:00
|
|
|
|
2003-10-14 23:20:59 +08:00
|
|
|
g_object_unref (template);
|
|
|
|
|
|
|
|
g_object_set_data (G_OBJECT (dialog), "gimp", gimp);
|
|
|
|
g_object_set_data (G_OBJECT (dialog), "gimp-template", template);
|
2003-04-14 00:25:14 +08:00
|
|
|
|
2003-10-14 23:20:59 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (main_vbox), editor, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (editor);
|
2003-04-14 00:25:14 +08:00
|
|
|
|
|
|
|
gtk_widget_show (dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-11-06 23:27:05 +08:00
|
|
|
templates_edit_template_response (GtkWidget *widget,
|
|
|
|
gint response_id,
|
|
|
|
GtkWidget *dialog)
|
2003-04-14 00:25:14 +08:00
|
|
|
{
|
2003-11-06 23:27:05 +08:00
|
|
|
if (response_id == GTK_RESPONSE_OK)
|
|
|
|
{
|
|
|
|
GimpTemplateEditor *editor;
|
|
|
|
GimpTemplate *template;
|
|
|
|
Gimp *gimp;
|
2003-04-14 00:25:14 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
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");
|
2003-04-14 00:25:14 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
gimp_config_sync (GIMP_CONFIG (editor->template),
|
|
|
|
GIMP_CONFIG (template), 0);
|
2003-10-14 23:20:59 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
gimp_list_uniquefy_name (GIMP_LIST (gimp->templates),
|
|
|
|
GIMP_OBJECT (template), TRUE);
|
|
|
|
}
|
2003-04-14 00:25:14 +08:00
|
|
|
|
|
|
|
gtk_widget_destroy (dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
templates_edit_template_dialog (Gimp *gimp,
|
2003-11-08 23:29:47 +08:00
|
|
|
GimpTemplate *template,
|
|
|
|
GtkWidget *parent)
|
2003-04-14 00:25:14 +08:00
|
|
|
{
|
|
|
|
GtkWidget *dialog;
|
|
|
|
GtkWidget *main_vbox;
|
|
|
|
GtkWidget *editor;
|
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
dialog = gimp_viewable_dialog_new (GIMP_VIEWABLE (template),
|
2003-11-08 01:29:02 +08:00
|
|
|
_("Edit Template"), "gimp-template-edit",
|
2003-11-06 23:27:05 +08:00
|
|
|
GIMP_STOCK_EDIT,
|
|
|
|
_("Edit Template"),
|
2003-11-08 23:29:47 +08:00
|
|
|
parent,
|
2003-11-06 23:27:05 +08:00
|
|
|
gimp_standard_help_func,
|
|
|
|
GIMP_HELP_TEMPLATE_EDIT,
|
2003-04-14 00:25:14 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_STOCK_OK, GTK_RESPONSE_OK,
|
2003-04-14 00:25:14 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
NULL);
|
2003-04-14 00:25:14 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
g_signal_connect (dialog, "response",
|
|
|
|
G_CALLBACK (templates_edit_template_response),
|
|
|
|
dialog);
|
2003-04-14 00:25:14 +08:00
|
|
|
|
2004-05-04 22:21:13 +08:00
|
|
|
main_vbox = gtk_vbox_new (FALSE, 12);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
|
2003-04-14 00:25:14 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), main_vbox,
|
|
|
|
TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (main_vbox);
|
|
|
|
|
2003-10-14 23:20:59 +08:00
|
|
|
g_object_set_data (G_OBJECT (dialog), "gimp", gimp);
|
|
|
|
g_object_set_data (G_OBJECT (dialog), "gimp-template", template);
|
|
|
|
|
|
|
|
template = gimp_config_duplicate (GIMP_CONFIG (template));
|
|
|
|
|
|
|
|
editor = gimp_template_editor_new (template, gimp, TRUE);
|
|
|
|
|
|
|
|
g_object_unref (template);
|
|
|
|
|
2003-04-14 00:25:14 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (main_vbox), editor, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (editor);
|
|
|
|
|
|
|
|
g_object_set_data (G_OBJECT (dialog), "gimp-template-editor", editor);
|
|
|
|
|
|
|
|
gtk_widget_show (dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
templates_file_new_dialog (Gimp *gimp,
|
2003-11-08 23:29:47 +08:00
|
|
|
GimpTemplate *template,
|
|
|
|
GtkWidget *parent)
|
2003-04-14 00:25:14 +08:00
|
|
|
{
|
2003-05-03 02:43:15 +08:00
|
|
|
GtkWidget *dialog;
|
|
|
|
|
|
|
|
dialog = gimp_dialog_factory_dialog_new (global_dialog_factory,
|
2003-11-08 23:29:47 +08:00
|
|
|
gtk_widget_get_screen (parent),
|
2003-05-03 02:43:15 +08:00
|
|
|
"gimp-file-new-dialog", -1);
|
|
|
|
|
|
|
|
if (dialog)
|
|
|
|
file_new_dialog_set (dialog, NULL, template);
|
2003-04-14 00:25:14 +08:00
|
|
|
}
|