1
/* The GIMP -- an image manipulation program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
#include "libgimpwidgets/gimpwidgets.h"
25
#include "actions-types.h"
27
#include "core/gimpcontainer.h"
28
#include "core/gimpcontext.h"
29
#include "core/gimpdata.h"
30
#include "core/gimpdatafactory.h"
32
#include "widgets/gimpcontainerview.h"
33
#include "widgets/gimpdataeditor.h"
34
#include "widgets/gimpdatafactoryview.h"
35
#include "widgets/gimpdialogfactory.h"
36
#include "widgets/gimpmessagebox.h"
37
#include "widgets/gimpmessagedialog.h"
39
#include "dialogs/dialogs.h"
42
#include "data-commands.h"
44
#include "gimp-intl.h"
47
typedef struct _GimpDataDeleteData GimpDataDeleteData;
49
struct _GimpDataDeleteData
51
GimpDataFactory *factory;
56
/* local function prototypes */
58
static void data_delete_confirm_response (GtkWidget *dialog,
60
GimpDataDeleteData *delete_data);
63
/* public functions */
66
data_new_data_cmd_callback (GtkAction *action,
69
GimpDataFactoryView *view = GIMP_DATA_FACTORY_VIEW (user_data);
71
if (view->factory->data_new_func)
77
gimp_container_view_get_context (GIMP_CONTAINER_EDITOR (view)->view);
79
data = gimp_data_factory_data_new (view->factory, _("Untitled"));
83
gimp_context_set_by_type (context,
84
view->factory->container->children_type,
87
gtk_button_clicked (GTK_BUTTON (view->edit_button));
93
data_duplicate_data_cmd_callback (GtkAction *action,
96
GimpDataFactoryView *view = GIMP_DATA_FACTORY_VIEW (user_data);
100
context = gimp_container_view_get_context (GIMP_CONTAINER_EDITOR (view)->view);
103
gimp_context_get_by_type (context,
104
view->factory->container->children_type);
106
if (data && gimp_container_have (view->factory->container,
111
new_data = gimp_data_factory_data_duplicate (view->factory, data);
115
gimp_context_set_by_type (context,
116
view->factory->container->children_type,
117
GIMP_OBJECT (new_data));
119
gtk_button_clicked (GTK_BUTTON (view->edit_button));
125
data_delete_data_cmd_callback (GtkAction *action,
128
GimpDataFactoryView *view = GIMP_DATA_FACTORY_VIEW (user_data);
129
GimpContext *context;
132
context = gimp_container_view_get_context (GIMP_CONTAINER_EDITOR (view)->view);
135
gimp_context_get_by_type (context,
136
view->factory->container->children_type);
138
if (data && data->deletable && gimp_container_have (view->factory->container,
141
GimpDataDeleteData *delete_data;
144
delete_data = g_new0 (GimpDataDeleteData, 1);
146
delete_data->factory = view->factory;
147
delete_data->data = data;
149
dialog = gimp_message_dialog_new (_("Delete Object"), GIMP_STOCK_QUESTION,
150
GTK_WIDGET (view), 0,
151
gimp_standard_help_func, NULL,
153
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
154
GTK_STOCK_DELETE, GTK_RESPONSE_OK,
158
g_signal_connect_object (data, "disconnect",
159
G_CALLBACK (gtk_widget_destroy),
160
dialog, G_CONNECT_SWAPPED);
162
g_signal_connect (dialog, "response",
163
G_CALLBACK (data_delete_confirm_response),
166
gimp_message_box_set_primary_text (GIMP_MESSAGE_DIALOG (dialog)->box,
167
_("Are you sure you want to delete "
168
"'%s' from the list and from disk?"),
169
GIMP_OBJECT (data)->name);
170
gtk_widget_show (dialog);
175
data_refresh_data_cmd_callback (GtkAction *action,
178
GimpDataFactoryView *view = GIMP_DATA_FACTORY_VIEW (user_data);
180
gimp_data_factory_data_save (view->factory);
181
gimp_data_factory_data_init (view->factory, FALSE);
185
data_edit_data_cmd_callback (GtkAction *action,
189
GimpDataFactoryView *view = GIMP_DATA_FACTORY_VIEW (user_data);
190
GimpContext *context;
193
context = gimp_container_view_get_context (GIMP_CONTAINER_EDITOR (view)->view);
196
gimp_context_get_by_type (context,
197
view->factory->container->children_type);
199
if (data && gimp_container_have (view->factory->container,
202
GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (view));
205
dockable = gimp_dialog_factory_dialog_raise (global_dock_factory, screen,
208
gimp_data_editor_set_data (GIMP_DATA_EDITOR (GTK_BIN (dockable)->child),
214
/* private functions */
217
data_delete_confirm_response (GtkWidget *dialog,
219
GimpDataDeleteData *delete_data)
221
gtk_widget_destroy (dialog);
223
if (response_id == GTK_RESPONSE_OK)
225
GError *error = NULL;
227
if (! gimp_data_factory_data_delete (delete_data->factory,
231
g_message (error->message);
232
g_clear_error (&error);
236
g_free (delete_data);