2006-12-09 21:33:38 +00:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2004-10-22 18:13:46 +00:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-17 22:28:01 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2004-10-22 18:13:46 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-17 22:28:01 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2004-10-22 18:13:46 +00:00
|
|
|
* (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
|
2018-07-11 23:27:07 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2004-10-22 18:13:46 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2012-03-29 19:19:01 +02:00
|
|
|
#include <gegl.h>
|
2004-10-22 18:13:46 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2005-01-25 19:11:26 +00:00
|
|
|
#include "libgimpconfig/gimpconfig.h"
|
2004-10-22 18:13:46 +00:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
|
|
|
#include "dialogs-types.h"
|
|
|
|
|
|
|
|
#include "config/gimpcoreconfig.h"
|
|
|
|
|
|
|
|
#include "core/gimp.h"
|
2006-09-01 11:26:54 +00:00
|
|
|
#include "core/gimpcontext.h"
|
2004-10-22 18:13:46 +00:00
|
|
|
#include "core/gimptemplate.h"
|
|
|
|
|
|
|
|
#include "widgets/gimptemplateeditor.h"
|
|
|
|
#include "widgets/gimpviewabledialog.h"
|
|
|
|
|
|
|
|
#include "template-options-dialog.h"
|
|
|
|
|
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
|
|
|
|
2016-10-30 20:54:47 +01:00
|
|
|
typedef struct _TemplateOptionsDialog TemplateOptionsDialog;
|
|
|
|
|
|
|
|
struct _TemplateOptionsDialog
|
|
|
|
{
|
|
|
|
GimpTemplate *template;
|
|
|
|
GimpContext *context;
|
|
|
|
GimpTemplateOptionsCallback callback;
|
|
|
|
gpointer user_data;
|
|
|
|
|
|
|
|
GtkWidget *editor;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-10-27 21:26:07 +02:00
|
|
|
/* local function prototypes */
|
|
|
|
|
2016-10-30 20:54:47 +01:00
|
|
|
static void template_options_dialog_free (TemplateOptionsDialog *private);
|
|
|
|
static void template_options_dialog_response (GtkWidget *dialog,
|
|
|
|
gint response_id,
|
|
|
|
TemplateOptionsDialog *private);
|
2007-05-23 20:08:27 +00:00
|
|
|
|
2004-10-22 18:13:46 +00:00
|
|
|
|
2016-10-27 21:26:07 +02:00
|
|
|
/* public function */
|
|
|
|
|
2016-10-30 20:54:47 +01:00
|
|
|
GtkWidget *
|
2006-09-01 11:26:54 +00:00
|
|
|
template_options_dialog_new (GimpTemplate *template,
|
|
|
|
GimpContext *context,
|
2004-10-22 18:13:46 +00:00
|
|
|
GtkWidget *parent,
|
|
|
|
const gchar *title,
|
|
|
|
const gchar *role,
|
2014-05-07 15:30:38 +02:00
|
|
|
const gchar *icon_name,
|
2004-10-22 18:13:46 +00:00
|
|
|
const gchar *desc,
|
2016-10-30 20:54:47 +01:00
|
|
|
const gchar *help_id,
|
|
|
|
GimpTemplateOptionsCallback callback,
|
|
|
|
gpointer user_data)
|
2004-10-22 18:13:46 +00:00
|
|
|
{
|
2016-10-30 20:54:47 +01:00
|
|
|
TemplateOptionsDialog *private;
|
|
|
|
GtkWidget *dialog;
|
2004-10-22 18:13:46 +00:00
|
|
|
GimpViewable *viewable = NULL;
|
|
|
|
GtkWidget *vbox;
|
|
|
|
|
|
|
|
g_return_val_if_fail (template == NULL || GIMP_IS_TEMPLATE (template), NULL);
|
2006-09-01 11:26:54 +00:00
|
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
|
2004-10-22 18:13:46 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_WIDGET (parent), NULL);
|
|
|
|
g_return_val_if_fail (title != NULL, NULL);
|
|
|
|
g_return_val_if_fail (role != NULL, NULL);
|
2014-05-07 15:30:38 +02:00
|
|
|
g_return_val_if_fail (icon_name != NULL, NULL);
|
2004-10-22 18:13:46 +00:00
|
|
|
g_return_val_if_fail (desc != NULL, NULL);
|
|
|
|
g_return_val_if_fail (help_id != NULL, NULL);
|
2016-10-30 20:54:47 +01:00
|
|
|
g_return_val_if_fail (callback != NULL, NULL);
|
2004-10-22 18:13:46 +00:00
|
|
|
|
2016-10-30 20:54:47 +01:00
|
|
|
private = g_slice_new0 (TemplateOptionsDialog);
|
2004-10-22 18:13:46 +00:00
|
|
|
|
2016-10-30 20:54:47 +01:00
|
|
|
private->template = template;
|
|
|
|
private->context = context;
|
|
|
|
private->callback = callback;
|
|
|
|
private->user_data = user_data;
|
2004-10-22 18:13:46 +00:00
|
|
|
|
|
|
|
if (template)
|
|
|
|
{
|
|
|
|
viewable = GIMP_VIEWABLE (template);
|
|
|
|
template = gimp_config_duplicate (GIMP_CONFIG (template));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
template =
|
2016-10-30 20:54:47 +01:00
|
|
|
gimp_config_duplicate (GIMP_CONFIG (context->gimp->config->default_image));
|
2011-09-05 18:27:34 +02:00
|
|
|
viewable = GIMP_VIEWABLE (template);
|
2006-04-07 10:51:22 +00:00
|
|
|
|
|
|
|
gimp_object_set_static_name (GIMP_OBJECT (template), _("Unnamed"));
|
2004-10-22 18:13:46 +00:00
|
|
|
}
|
|
|
|
|
2020-05-02 01:42:04 +02:00
|
|
|
dialog = gimp_viewable_dialog_new (g_list_prepend (NULL, viewable), context,
|
2016-10-30 20:54:47 +01:00
|
|
|
title, role, icon_name, desc,
|
|
|
|
parent,
|
|
|
|
gimp_standard_help_func, help_id,
|
2004-10-22 18:13:46 +00:00
|
|
|
|
2017-02-12 16:06:34 +01:00
|
|
|
_("_Cancel"), GTK_RESPONSE_CANCEL,
|
|
|
|
_("_OK"), GTK_RESPONSE_OK,
|
2004-10-22 18:13:46 +00:00
|
|
|
|
2016-10-30 20:54:47 +01:00
|
|
|
NULL);
|
2004-10-22 18:13:46 +00:00
|
|
|
|
2018-05-10 17:04:37 +02:00
|
|
|
gimp_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
|
2005-02-08 20:40:33 +00:00
|
|
|
GTK_RESPONSE_OK,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
-1);
|
|
|
|
|
2016-10-30 20:54:47 +01:00
|
|
|
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
|
|
|
|
|
|
|
|
g_object_weak_ref (G_OBJECT (dialog),
|
|
|
|
(GWeakNotify) template_options_dialog_free, private);
|
|
|
|
|
|
|
|
g_signal_connect (dialog, "response",
|
|
|
|
G_CALLBACK (template_options_dialog_response),
|
|
|
|
private);
|
2004-10-22 18:13:46 +00:00
|
|
|
|
2011-09-30 11:29:11 +02:00
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
|
2004-10-22 18:13:46 +00:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
|
2016-10-30 20:54:47 +01:00
|
|
|
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
|
2010-10-30 14:56:00 +02:00
|
|
|
vbox, TRUE, TRUE, 0);
|
2004-10-22 18:13:46 +00:00
|
|
|
gtk_widget_show (vbox);
|
|
|
|
|
2016-10-30 20:54:47 +01:00
|
|
|
private->editor = gimp_template_editor_new (template, context->gimp, TRUE);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), private->editor, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (private->editor);
|
2004-10-22 18:13:46 +00:00
|
|
|
|
|
|
|
g_object_unref (template);
|
|
|
|
|
2016-10-30 20:54:47 +01:00
|
|
|
return dialog;
|
2004-10-22 18:13:46 +00:00
|
|
|
}
|
2007-05-23 20:08:27 +00:00
|
|
|
|
2016-10-27 21:26:07 +02:00
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
2007-05-23 20:08:27 +00:00
|
|
|
static void
|
2016-10-30 20:54:47 +01:00
|
|
|
template_options_dialog_free (TemplateOptionsDialog *private)
|
2007-05-23 20:08:27 +00:00
|
|
|
{
|
2016-10-30 20:54:47 +01:00
|
|
|
g_slice_free (TemplateOptionsDialog, private);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
template_options_dialog_response (GtkWidget *dialog,
|
|
|
|
gint response_id,
|
|
|
|
TemplateOptionsDialog *private)
|
|
|
|
{
|
|
|
|
if (response_id == GTK_RESPONSE_OK)
|
|
|
|
{
|
|
|
|
GimpTemplateEditor *editor = GIMP_TEMPLATE_EDITOR (private->editor);
|
|
|
|
|
|
|
|
private->callback (dialog,
|
|
|
|
private->template,
|
|
|
|
gimp_template_editor_get_template (editor),
|
|
|
|
private->context,
|
|
|
|
private->user_data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_widget_destroy (dialog);
|
|
|
|
}
|
2007-05-23 20:08:27 +00:00
|
|
|
}
|