1
/* The GIMP -- an image manipulation program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
* gimpdatafactoryview.c
5
* Copyright (C) 2001-2003 Michael Natterer <mitch@gimp.org>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28
#include "libgimpwidgets/gimpwidgets.h"
30
#include "widgets-types.h"
32
#include "config/gimpbaseconfig.h"
34
#include "core/gimp.h"
35
#include "core/gimpcontainer.h"
36
#include "core/gimpcontext.h"
37
#include "core/gimpdata.h"
38
#include "core/gimpdatafactory.h"
39
#include "core/gimpmarshal.h"
41
#include "gimpcontainerview.h"
42
#include "gimpdatafactoryview.h"
43
#include "gimpcontainergridview.h"
44
#include "gimpcontainertreeview.h"
46
#include "gimpviewrenderer.h"
47
#include "gimpuimanager.h"
48
#include "gimpwidgets-utils.h"
50
#include "gimp-intl.h"
53
static void gimp_data_factory_view_class_init (GimpDataFactoryViewClass *klass);
54
static void gimp_data_factory_view_init (GimpDataFactoryView *view);
56
static void gimp_data_factory_view_activate_item (GimpContainerEditor *editor,
57
GimpViewable *viewable);
58
static void gimp_data_factory_view_tree_name_edited (GtkCellRendererText *cell,
61
GimpDataFactoryView *view);
64
static GimpContainerEditorClass *parent_class = NULL;
68
gimp_data_factory_view_get_type (void)
70
static GType view_type = 0;
74
static const GTypeInfo view_info =
76
sizeof (GimpDataFactoryViewClass),
78
NULL, /* base_finalize */
79
(GClassInitFunc) gimp_data_factory_view_class_init,
80
NULL, /* class_finalize */
81
NULL, /* class_data */
82
sizeof (GimpDataFactoryView),
84
(GInstanceInitFunc) gimp_data_factory_view_init,
87
view_type = g_type_register_static (GIMP_TYPE_CONTAINER_EDITOR,
88
"GimpDataFactoryView",
96
gimp_data_factory_view_class_init (GimpDataFactoryViewClass *klass)
98
GimpContainerEditorClass *editor_class = GIMP_CONTAINER_EDITOR_CLASS (klass);
100
parent_class = g_type_class_peek_parent (klass);
102
editor_class->activate_item = gimp_data_factory_view_activate_item;
106
gimp_data_factory_view_init (GimpDataFactoryView *view)
108
view->edit_button = NULL;
109
view->new_button = NULL;
110
view->duplicate_button = NULL;
111
view->delete_button = NULL;
112
view->refresh_button = NULL;
116
gimp_data_factory_view_new (GimpViewType view_type,
117
GimpDataFactory *factory,
118
GimpContext *context,
120
gint preview_border_width,
121
GimpMenuFactory *menu_factory,
122
const gchar *menu_identifier,
123
const gchar *ui_identifier,
124
const gchar *action_group)
126
GimpDataFactoryView *factory_view;
128
factory_view = g_object_new (GIMP_TYPE_DATA_FACTORY_VIEW, NULL);
130
if (! gimp_data_factory_view_construct (factory_view,
135
preview_border_width,
141
g_object_unref (factory_view);
145
return GTK_WIDGET (factory_view);
149
gimp_data_factory_view_construct (GimpDataFactoryView *factory_view,
150
GimpViewType view_type,
151
GimpDataFactory *factory,
152
GimpContext *context,
154
gint preview_border_width,
155
GimpMenuFactory *menu_factory,
156
const gchar *menu_identifier,
157
const gchar *ui_identifier,
158
const gchar *action_group)
160
GimpContainerEditor *editor;
163
g_return_val_if_fail (GIMP_IS_DATA_FACTORY_VIEW (factory_view), FALSE);
164
g_return_val_if_fail (GIMP_IS_DATA_FACTORY (factory), FALSE);
165
g_return_val_if_fail (preview_size > 0 &&
166
preview_size <= GIMP_VIEWABLE_MAX_PREVIEW_SIZE, FALSE);
167
g_return_val_if_fail (preview_border_width >= 0 &&
168
preview_border_width <= GIMP_VIEW_MAX_BORDER_WIDTH,
171
factory_view->factory = factory;
173
if (! gimp_container_editor_construct (GIMP_CONTAINER_EDITOR (factory_view),
175
factory->container, context,
176
preview_size, preview_border_width,
177
menu_factory, menu_identifier,
183
editor = GIMP_CONTAINER_EDITOR (factory_view);
185
if (GIMP_IS_CONTAINER_TREE_VIEW (editor->view))
187
GimpContainerTreeView *tree_view;
189
tree_view = GIMP_CONTAINER_TREE_VIEW (editor->view);
191
tree_view->name_cell->mode = GTK_CELL_RENDERER_MODE_EDITABLE;
192
GTK_CELL_RENDERER_TEXT (tree_view->name_cell)->editable = TRUE;
194
tree_view->editable_cells = g_list_prepend (tree_view->editable_cells,
195
tree_view->name_cell);
197
g_signal_connect (tree_view->name_cell, "edited",
198
G_CALLBACK (gimp_data_factory_view_tree_name_edited),
202
str = g_strdup_printf ("%s-edit", action_group);
203
factory_view->edit_button =
204
gimp_editor_add_action_button (GIMP_EDITOR (editor->view), action_group,
208
if (factory_view->factory->data_new_func)
210
str = g_strdup_printf ("%s-new", action_group);
211
factory_view->new_button =
212
gimp_editor_add_action_button (GIMP_EDITOR (editor->view), action_group,
217
str = g_strdup_printf ("%s-duplicate", action_group);
218
factory_view->duplicate_button =
219
gimp_editor_add_action_button (GIMP_EDITOR (editor->view), action_group,
223
str = g_strdup_printf ("%s-delete", action_group);
224
factory_view->delete_button =
225
gimp_editor_add_action_button (GIMP_EDITOR (editor->view), action_group,
229
str = g_strdup_printf ("%s-refresh", action_group);
230
factory_view->refresh_button =
231
gimp_editor_add_action_button (GIMP_EDITOR (editor->view), action_group,
235
gimp_container_view_enable_dnd (editor->view,
236
GTK_BUTTON (factory_view->edit_button),
237
factory->container->children_type);
238
gimp_container_view_enable_dnd (editor->view,
239
GTK_BUTTON (factory_view->duplicate_button),
240
factory->container->children_type);
241
gimp_container_view_enable_dnd (editor->view,
242
GTK_BUTTON (factory_view->delete_button),
243
factory->container->children_type);
245
gimp_ui_manager_update (GIMP_EDITOR (editor->view)->ui_manager, editor);
251
gimp_data_factory_view_activate_item (GimpContainerEditor *editor,
252
GimpViewable *viewable)
254
GimpDataFactoryView *view = GIMP_DATA_FACTORY_VIEW (editor);
255
GimpData *data = GIMP_DATA (viewable);
257
if (GIMP_CONTAINER_EDITOR_CLASS (parent_class)->activate_item)
258
GIMP_CONTAINER_EDITOR_CLASS (parent_class)->activate_item (editor, viewable);
260
if (data && gimp_container_have (view->factory->container,
263
if (view->edit_button && GTK_WIDGET_SENSITIVE (view->edit_button))
264
gtk_button_clicked (GTK_BUTTON (view->edit_button));
269
gimp_data_factory_view_tree_name_edited (GtkCellRendererText *cell,
270
const gchar *path_str,
271
const gchar *new_name,
272
GimpDataFactoryView *view)
274
GimpContainerTreeView *tree_view;
278
tree_view = GIMP_CONTAINER_TREE_VIEW (GIMP_CONTAINER_EDITOR (view)->view);
280
path = gtk_tree_path_new_from_string (path_str);
282
if (gtk_tree_model_get_iter (tree_view->model, &iter, path))
284
GimpViewRenderer *renderer;
286
const gchar *old_name;
288
gtk_tree_model_get (tree_view->model, &iter,
289
tree_view->model_column_renderer, &renderer,
292
data = GIMP_DATA (renderer->viewable);
294
old_name = gimp_object_get_name (GIMP_OBJECT (data));
296
if (! old_name) old_name = "";
297
if (! new_name) new_name = "";
299
if (data->writable && strcmp (old_name, new_name))
301
gimp_object_set_name (GIMP_OBJECT (data), new_name);
305
gchar *name = gimp_viewable_get_description (renderer->viewable, NULL);
307
gtk_list_store_set (GTK_LIST_STORE (tree_view->model), &iter,
308
tree_view->model_column_name, name,
313
g_object_unref (renderer);
316
gtk_tree_path_free (path);