gimp/app/actions/templates-commands.c

249 lines
7.8 KiB
C
Raw Normal View History

/* 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 "config/gimpconfig-utils.h"
#include "core/gimp.h"
#include "core/gimpcontext.h"
#include "core/gimplist.h"
#include "core/gimptemplate.h"
added new function gimp_dialog_factory_add_foreign() which adds a dialog 2003-05-02 Michael Natterer <mitch@gimp.org> * app/widgets/gimpdialogfactory.[ch]: added new function gimp_dialog_factory_add_foreign() which adds a dialog that was not created by the factory itself. Its identifier however must be registered with the factory. Connect to all toplevel dialogs' "configure_event" and remember the resulting window geometry so we get session management for *all* dialogs, not only for those which were open on exit. * app/gui/dialogs.c: added the "File New" dialog. Added foreign entries (without constructor) for all dialogs opened by tools. * app/gui/dialogs-constructors.[ch]: added a constructor for the file_new dialog. * app/gui/file-new-dialog.[ch]: renamed file_new_dialog_create() to file_new_dialog_new() and removed the gimage and template paramaters. Adder new function file_new_dialog_set() to set gimage and template after creation. * app/gui/file-commands.c * app/gui/templates-commands.c: changed accordingly. * app/tools/gimpimagemaptool.[ch] * app/tools/gimptransformtool.[ch]: added "const gchar *shell_identifier" to the tool structs. Register the tool dialogs using gimp_dialog_factory_add_foreign(). * app/tools/gimpbrightnesscontrasttool.c * app/tools/gimpcolorbalancetool.c * app/tools/gimpcurvestool.c * app/tools/gimphuesaturationtool.c * app/tools/gimplevelstool.c * app/tools/gimpperspectivetool.c * app/tools/gimpposterizetool.c * app/tools/gimprotatetool.c * app/tools/gimpscaletool.c * app/tools/gimpsheartool.c * app/tools/gimpthresholdtool.c: set "shell_identifier" so the dialogs become session managed. Fixes bug #61091. * app/tools/gimpcroptool.c: register the crop dialog with the dialog factory. Fixes bug #52849. * app/tools/gimpcolorpickertool.c: ditto. Unrelated: * app/tools/gimptool.c: no need to cast the return value of g_object_new().
2003-05-03 02:43:15 +08:00
#include "widgets/gimpdialogfactory.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimptemplateeditor.h"
#include "widgets/gimptemplateview.h"
#include "widgets/gimpviewabledialog.h"
added new function gimp_dialog_factory_add_foreign() which adds a dialog 2003-05-02 Michael Natterer <mitch@gimp.org> * app/widgets/gimpdialogfactory.[ch]: added new function gimp_dialog_factory_add_foreign() which adds a dialog that was not created by the factory itself. Its identifier however must be registered with the factory. Connect to all toplevel dialogs' "configure_event" and remember the resulting window geometry so we get session management for *all* dialogs, not only for those which were open on exit. * app/gui/dialogs.c: added the "File New" dialog. Added foreign entries (without constructor) for all dialogs opened by tools. * app/gui/dialogs-constructors.[ch]: added a constructor for the file_new dialog. * app/gui/file-new-dialog.[ch]: renamed file_new_dialog_create() to file_new_dialog_new() and removed the gimage and template paramaters. Adder new function file_new_dialog_set() to set gimage and template after creation. * app/gui/file-commands.c * app/gui/templates-commands.c: changed accordingly. * app/tools/gimpimagemaptool.[ch] * app/tools/gimptransformtool.[ch]: added "const gchar *shell_identifier" to the tool structs. Register the tool dialogs using gimp_dialog_factory_add_foreign(). * app/tools/gimpbrightnesscontrasttool.c * app/tools/gimpcolorbalancetool.c * app/tools/gimpcurvestool.c * app/tools/gimphuesaturationtool.c * app/tools/gimplevelstool.c * app/tools/gimpperspectivetool.c * app/tools/gimpposterizetool.c * app/tools/gimprotatetool.c * app/tools/gimpscaletool.c * app/tools/gimpsheartool.c * app/tools/gimpthresholdtool.c: set "shell_identifier" so the dialogs become session managed. Fixes bug #61091. * app/tools/gimpcroptool.c: register the crop dialog with the dialog factory. Fixes bug #52849. * app/tools/gimpcolorpickertool.c: ditto. Unrelated: * app/tools/gimptool.c: no need to cast the return value of g_object_new().
2003-05-03 02:43:15 +08:00
#include "dialogs.h"
#include "file-new-dialog.h"
#include "templates-commands.h"
#include "gimp-intl.h"
/* public functions */
void
templates_new_template_cmd_callback (GtkWidget *widget,
gpointer data)
{
GimpTemplateView *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 = 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 = GIMP_TEMPLATE_VIEW (data);
gtk_button_clicked (GTK_BUTTON (view->create_button));
}
void
templates_delete_template_cmd_callback (GtkWidget *widget,
gpointer 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,
GIMP_HELP_TEMPLATE_NEW,
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,
GIMP_HELP_TEMPLATE_EDIT,
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)
{
added new function gimp_dialog_factory_add_foreign() which adds a dialog 2003-05-02 Michael Natterer <mitch@gimp.org> * app/widgets/gimpdialogfactory.[ch]: added new function gimp_dialog_factory_add_foreign() which adds a dialog that was not created by the factory itself. Its identifier however must be registered with the factory. Connect to all toplevel dialogs' "configure_event" and remember the resulting window geometry so we get session management for *all* dialogs, not only for those which were open on exit. * app/gui/dialogs.c: added the "File New" dialog. Added foreign entries (without constructor) for all dialogs opened by tools. * app/gui/dialogs-constructors.[ch]: added a constructor for the file_new dialog. * app/gui/file-new-dialog.[ch]: renamed file_new_dialog_create() to file_new_dialog_new() and removed the gimage and template paramaters. Adder new function file_new_dialog_set() to set gimage and template after creation. * app/gui/file-commands.c * app/gui/templates-commands.c: changed accordingly. * app/tools/gimpimagemaptool.[ch] * app/tools/gimptransformtool.[ch]: added "const gchar *shell_identifier" to the tool structs. Register the tool dialogs using gimp_dialog_factory_add_foreign(). * app/tools/gimpbrightnesscontrasttool.c * app/tools/gimpcolorbalancetool.c * app/tools/gimpcurvestool.c * app/tools/gimphuesaturationtool.c * app/tools/gimplevelstool.c * app/tools/gimpperspectivetool.c * app/tools/gimpposterizetool.c * app/tools/gimprotatetool.c * app/tools/gimpscaletool.c * app/tools/gimpsheartool.c * app/tools/gimpthresholdtool.c: set "shell_identifier" so the dialogs become session managed. Fixes bug #61091. * app/tools/gimpcroptool.c: register the crop dialog with the dialog factory. Fixes bug #52849. * app/tools/gimpcolorpickertool.c: ditto. Unrelated: * app/tools/gimptool.c: no need to cast the return value of g_object_new().
2003-05-03 02:43:15 +08:00
GtkWidget *dialog;
dialog = gimp_dialog_factory_dialog_new (global_dialog_factory,
"gimp-file-new-dialog", -1);
if (dialog)
file_new_dialog_set (dialog, NULL, template);
}