~ubuntu-branches/ubuntu/breezy/gimp/breezy

« back to all changes in this revision

Viewing changes to app/actions/data-commands.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2005-10-04 19:04:46 UTC
  • Revision ID: james.westby@ubuntu.com-20051004190446-ukh32kwk56s4sjhu
Tags: upstream-2.2.8
ImportĀ upstreamĀ versionĀ 2.2.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* The GIMP -- an image manipulation program
 
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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.
 
17
 */
 
18
 
 
19
#include "config.h"
 
20
 
 
21
#include <gtk/gtk.h>
 
22
 
 
23
#include "libgimpwidgets/gimpwidgets.h"
 
24
 
 
25
#include "actions-types.h"
 
26
 
 
27
#include "core/gimpcontainer.h"
 
28
#include "core/gimpcontext.h"
 
29
#include "core/gimpdata.h"
 
30
#include "core/gimpdatafactory.h"
 
31
 
 
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"
 
38
 
 
39
#include "dialogs/dialogs.h"
 
40
 
 
41
#include "actions.h"
 
42
#include "data-commands.h"
 
43
 
 
44
#include "gimp-intl.h"
 
45
 
 
46
 
 
47
typedef struct _GimpDataDeleteData GimpDataDeleteData;
 
48
 
 
49
struct _GimpDataDeleteData
 
50
{
 
51
  GimpDataFactory *factory;
 
52
  GimpData        *data;
 
53
};
 
54
 
 
55
 
 
56
/*  local function prototypes  */
 
57
 
 
58
static void  data_delete_confirm_response (GtkWidget          *dialog,
 
59
                                           gint                response_id,
 
60
                                           GimpDataDeleteData *delete_data);
 
61
 
 
62
 
 
63
/*  public functions  */
 
64
 
 
65
void
 
66
data_new_data_cmd_callback (GtkAction *action,
 
67
                            gpointer   user_data)
 
68
{
 
69
  GimpDataFactoryView *view = GIMP_DATA_FACTORY_VIEW (user_data);
 
70
 
 
71
  if (view->factory->data_new_func)
 
72
    {
 
73
      GimpContext *context;
 
74
      GimpData    *data;
 
75
 
 
76
      context =
 
77
        gimp_container_view_get_context (GIMP_CONTAINER_EDITOR (view)->view);
 
78
 
 
79
      data = gimp_data_factory_data_new (view->factory, _("Untitled"));
 
80
 
 
81
      if (data)
 
82
        {
 
83
          gimp_context_set_by_type (context,
 
84
                                    view->factory->container->children_type,
 
85
                                    GIMP_OBJECT (data));
 
86
 
 
87
          gtk_button_clicked (GTK_BUTTON (view->edit_button));
 
88
        }
 
89
    }
 
90
}
 
91
 
 
92
void
 
93
data_duplicate_data_cmd_callback (GtkAction *action,
 
94
                                  gpointer   user_data)
 
95
{
 
96
  GimpDataFactoryView *view = GIMP_DATA_FACTORY_VIEW (user_data);
 
97
  GimpContext         *context;
 
98
  GimpData            *data;
 
99
 
 
100
  context = gimp_container_view_get_context (GIMP_CONTAINER_EDITOR (view)->view);
 
101
 
 
102
  data = (GimpData *)
 
103
    gimp_context_get_by_type (context,
 
104
                              view->factory->container->children_type);
 
105
 
 
106
  if (data && gimp_container_have (view->factory->container,
 
107
                                   GIMP_OBJECT (data)))
 
108
    {
 
109
      GimpData *new_data;
 
110
 
 
111
      new_data = gimp_data_factory_data_duplicate (view->factory, data);
 
112
 
 
113
      if (new_data)
 
114
        {
 
115
          gimp_context_set_by_type (context,
 
116
                                    view->factory->container->children_type,
 
117
                                    GIMP_OBJECT (new_data));
 
118
 
 
119
          gtk_button_clicked (GTK_BUTTON (view->edit_button));
 
120
        }
 
121
    }
 
122
}
 
123
 
 
124
void
 
125
data_delete_data_cmd_callback (GtkAction *action,
 
126
                               gpointer   user_data)
 
127
{
 
128
  GimpDataFactoryView *view = GIMP_DATA_FACTORY_VIEW (user_data);
 
129
  GimpContext         *context;
 
130
  GimpData            *data;
 
131
 
 
132
  context = gimp_container_view_get_context (GIMP_CONTAINER_EDITOR (view)->view);
 
133
 
 
134
  data = (GimpData *)
 
135
    gimp_context_get_by_type (context,
 
136
                              view->factory->container->children_type);
 
137
 
 
138
  if (data && data->deletable && gimp_container_have (view->factory->container,
 
139
                                                      GIMP_OBJECT (data)))
 
140
    {
 
141
      GimpDataDeleteData *delete_data;
 
142
      GtkWidget          *dialog;
 
143
 
 
144
      delete_data = g_new0 (GimpDataDeleteData, 1);
 
145
 
 
146
      delete_data->factory = view->factory;
 
147
      delete_data->data    = data;
 
148
 
 
149
      dialog = gimp_message_dialog_new (_("Delete Object"), GIMP_STOCK_QUESTION,
 
150
                                        GTK_WIDGET (view), 0,
 
151
                                        gimp_standard_help_func, NULL,
 
152
 
 
153
                                        GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
 
154
                                        GTK_STOCK_DELETE, GTK_RESPONSE_OK,
 
155
 
 
156
                                        NULL);
 
157
 
 
158
      g_signal_connect_object (data, "disconnect",
 
159
                               G_CALLBACK (gtk_widget_destroy),
 
160
                               dialog, G_CONNECT_SWAPPED);
 
161
 
 
162
      g_signal_connect (dialog, "response",
 
163
                        G_CALLBACK (data_delete_confirm_response),
 
164
                        delete_data);
 
165
 
 
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);
 
171
    }
 
172
}
 
173
 
 
174
void
 
175
data_refresh_data_cmd_callback (GtkAction *action,
 
176
                                gpointer   user_data)
 
177
{
 
178
  GimpDataFactoryView *view = GIMP_DATA_FACTORY_VIEW (user_data);
 
179
 
 
180
  gimp_data_factory_data_save (view->factory);
 
181
  gimp_data_factory_data_init (view->factory, FALSE);
 
182
}
 
183
 
 
184
void
 
185
data_edit_data_cmd_callback (GtkAction   *action,
 
186
                             const gchar *value,
 
187
                             gpointer     user_data)
 
188
{
 
189
  GimpDataFactoryView *view = GIMP_DATA_FACTORY_VIEW (user_data);
 
190
  GimpContext         *context;
 
191
  GimpData            *data;
 
192
 
 
193
  context = gimp_container_view_get_context (GIMP_CONTAINER_EDITOR (view)->view);
 
194
 
 
195
  data = (GimpData *)
 
196
    gimp_context_get_by_type (context,
 
197
                              view->factory->container->children_type);
 
198
 
 
199
  if (data && gimp_container_have (view->factory->container,
 
200
                                   GIMP_OBJECT (data)))
 
201
    {
 
202
      GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (view));
 
203
      GtkWidget *dockable;
 
204
 
 
205
      dockable = gimp_dialog_factory_dialog_raise (global_dock_factory, screen,
 
206
                                                   value, -1);
 
207
 
 
208
      gimp_data_editor_set_data (GIMP_DATA_EDITOR (GTK_BIN (dockable)->child),
 
209
                                 data);
 
210
    }
 
211
}
 
212
 
 
213
 
 
214
/*  private functions  */
 
215
 
 
216
static void
 
217
data_delete_confirm_response (GtkWidget          *dialog,
 
218
                              gint                response_id,
 
219
                              GimpDataDeleteData *delete_data)
 
220
{
 
221
  gtk_widget_destroy (dialog);
 
222
 
 
223
  if (response_id == GTK_RESPONSE_OK)
 
224
    {
 
225
      GError *error = NULL;
 
226
 
 
227
      if (! gimp_data_factory_data_delete (delete_data->factory,
 
228
                                           delete_data->data,
 
229
                                           TRUE, &error))
 
230
        {
 
231
          g_message (error->message);
 
232
          g_clear_error (&error);
 
233
        }
 
234
    }
 
235
 
 
236
  g_free (delete_data);
 
237
}