templates-commands.c 7.82 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/* 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"

Michael Natterer's avatar
Michael Natterer committed
25
#include "actions-types.h"
26

27
#include "config/gimpconfig.h"
28
#include "config/gimpconfig-utils.h"
29
#include "config/gimpcoreconfig.h"
30 31 32 33 34 35

#include "core/gimp.h"
#include "core/gimpcontext.h"
#include "core/gimplist.h"
#include "core/gimptemplate.h"

36
#include "widgets/gimpdialogfactory.h"
37
#include "widgets/gimphelp-ids.h"
38
#include "widgets/gimptemplateeditor.h"
39
#include "widgets/gimptemplateview.h"
40
#include "widgets/gimpviewabledialog.h"
41

Michael Natterer's avatar
Michael Natterer committed
42 43 44
#include "gui/dialogs.h"
#include "gui/file-new-dialog.h"

45 46
#include "templates-commands.h"

47 48
#include "gimp-intl.h"

49 50 51 52

/*  public functions */

void
53
templates_new_template_cmd_callback (GtkAction *action,
54 55
                                     gpointer   data)
{
56
  GimpTemplateView *view = GIMP_TEMPLATE_VIEW (data);
57 58 59 60 61

  gtk_button_clicked (GTK_BUTTON (view->new_button));
}

void
62
templates_duplicate_template_cmd_callback (GtkAction *action,
63 64
                                           gpointer   data)
{
65
  GimpTemplateView *view = GIMP_TEMPLATE_VIEW (data);
66 67 68 69

  gtk_button_clicked (GTK_BUTTON (view->duplicate_button));
}

70
void
71
templates_edit_template_cmd_callback (GtkAction *action,
72 73 74 75 76 77 78
                                      gpointer   data)
{
  GimpTemplateView *view = GIMP_TEMPLATE_VIEW (data);

  gtk_button_clicked (GTK_BUTTON (view->edit_button));
}

79
void
80
templates_create_image_cmd_callback (GtkAction *action,
81 82
                                     gpointer   data)
{
83
  GimpTemplateView *view = GIMP_TEMPLATE_VIEW (data);
84 85 86 87 88

  gtk_button_clicked (GTK_BUTTON (view->create_button));
}

void
89
templates_delete_template_cmd_callback (GtkAction *action,
90 91
                                        gpointer   data)
{
92
  GimpTemplateView *view = GIMP_TEMPLATE_VIEW (data);
93 94 95

  gtk_button_clicked (GTK_BUTTON (view->delete_button));
}
96 97

static void
98 99 100
templates_new_template_response (GtkWidget *widget,
                                 gint       response_id,
                                 GtkWidget *dialog)
101
{
102 103 104 105
  if (response_id == GTK_RESPONSE_OK)
    {
      GimpTemplate *template;
      Gimp         *gimp;
106

107 108
      template = g_object_get_data (G_OBJECT (dialog), "gimp-template");
      gimp     = g_object_get_data (G_OBJECT (dialog), "gimp");
109

110 111 112
      gimp_container_add (gimp->templates, GIMP_OBJECT (template));
      gimp_context_set_template (gimp_get_user_context (gimp), template);
    }
113 114 115 116 117

  gtk_widget_destroy (dialog);
}

void
118
templates_new_template_dialog (Gimp         *gimp,
119 120
                               GimpTemplate *unused,
                               GtkWidget    *parent)
121 122 123 124 125 126
{
  GimpTemplate *template;
  GtkWidget    *dialog;
  GtkWidget    *main_vbox;
  GtkWidget    *editor;

127
  dialog = gimp_viewable_dialog_new (NULL,
128
                                     _("New Template"), "gimp-template-new",
129 130
                                     GIMP_STOCK_TEMPLATE,
                                     _("Create a New Template"),
131
                                     parent,
132 133
                                     gimp_standard_help_func,
                                     GIMP_HELP_TEMPLATE_NEW,
134

135 136
                                     GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                                     GTK_STOCK_OK,     GTK_RESPONSE_OK,
137

138
                                     NULL);
139

140 141 142
  g_signal_connect (dialog, "response",
                    G_CALLBACK (templates_new_template_response),
                    dialog);
143

144 145
  main_vbox = gtk_vbox_new (FALSE, 12);
  gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
146 147 148 149
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), main_vbox,
                      TRUE, TRUE, 0);
  gtk_widget_show (main_vbox);

150 151
  template = gimp_config_duplicate (GIMP_CONFIG (gimp->config->default_image));
  gimp_object_set_name (GIMP_OBJECT (template), _("Unnamed"));
152

153
  editor = gimp_template_editor_new (template, gimp, TRUE);
154

155 156 157 158
  g_object_unref (template);

  g_object_set_data (G_OBJECT (dialog), "gimp",          gimp);
  g_object_set_data (G_OBJECT (dialog), "gimp-template", template);
159

160 161
  gtk_box_pack_start (GTK_BOX (main_vbox), editor, FALSE, FALSE, 0);
  gtk_widget_show (editor);
162 163 164 165 166

  gtk_widget_show (dialog);
}

static void
167 168 169
templates_edit_template_response (GtkWidget *widget,
                                  gint       response_id,
                                  GtkWidget *dialog)
170
{
171 172 173 174 175
  if (response_id == GTK_RESPONSE_OK)
    {
      GimpTemplateEditor *editor;
      GimpTemplate       *template;
      Gimp               *gimp;
176

177 178 179
      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");
180

181 182
      gimp_config_sync (GIMP_CONFIG (editor->template),
                        GIMP_CONFIG (template), 0);
183

184 185 186
      gimp_list_uniquefy_name (GIMP_LIST (gimp->templates),
                               GIMP_OBJECT (template), TRUE);
    }
187 188 189 190 191 192

  gtk_widget_destroy (dialog);
}

void
templates_edit_template_dialog (Gimp         *gimp,
193 194
                                GimpTemplate *template,
                                GtkWidget    *parent)
195 196 197 198 199
{
  GtkWidget *dialog;
  GtkWidget *main_vbox;
  GtkWidget *editor;

200
  dialog = gimp_viewable_dialog_new (GIMP_VIEWABLE (template),
201
                                     _("Edit Template"), "gimp-template-edit",
202 203
                                     GIMP_STOCK_EDIT,
                                     _("Edit Template"),
204
                                     parent,
205 206
                                     gimp_standard_help_func,
                                     GIMP_HELP_TEMPLATE_EDIT,
207

208 209
                                     GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                                     GTK_STOCK_OK,     GTK_RESPONSE_OK,
210

211
                                     NULL);
212

213 214 215
  g_signal_connect (dialog, "response",
                    G_CALLBACK (templates_edit_template_response),
                    dialog);
216

217 218
  main_vbox = gtk_vbox_new (FALSE, 12);
  gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
219 220 221 222
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), main_vbox,
                      TRUE, TRUE, 0);
  gtk_widget_show (main_vbox);

223 224 225 226 227 228 229 230 231
  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);

232 233 234 235 236 237 238 239 240 241
  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,
242 243
                           GimpTemplate *template,
                           GtkWidget    *parent)
244
{
245 246 247
  GtkWidget *dialog;

  dialog = gimp_dialog_factory_dialog_new (global_dialog_factory,
248
                                           gtk_widget_get_screen (parent),
249 250 251 252
                                           "gimp-file-new-dialog", -1);

  if (dialog)
    file_new_dialog_set (dialog, NULL, template);
253
}