2001-07-09 05:44:52 +08:00
|
|
|
/* 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>
|
|
|
|
|
2004-05-12 00:05:21 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
2004-04-20 21:25:55 +08:00
|
|
|
#include "actions-types.h"
|
2001-07-09 05:44:52 +08:00
|
|
|
|
2004-05-12 00:05:21 +08:00
|
|
|
#include "core/gimpcontainer.h"
|
|
|
|
#include "core/gimpcontext.h"
|
|
|
|
#include "core/gimpdata.h"
|
|
|
|
#include "core/gimpdatafactory.h"
|
|
|
|
|
|
|
|
#include "widgets/gimpcontainerview.h"
|
2004-09-27 18:45:49 +08:00
|
|
|
#include "widgets/gimpdataeditor.h"
|
2001-07-09 05:44:52 +08:00
|
|
|
#include "widgets/gimpdatafactoryview.h"
|
2004-09-27 18:45:49 +08:00
|
|
|
#include "widgets/gimpdialogfactory.h"
|
|
|
|
|
|
|
|
#include "dialogs/dialogs.h"
|
2001-07-09 05:44:52 +08:00
|
|
|
|
2004-05-12 00:05:21 +08:00
|
|
|
#include "actions.h"
|
2001-07-09 05:44:52 +08:00
|
|
|
#include "data-commands.h"
|
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2001-07-09 05:44:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
void
|
2004-04-29 20:52:29 +08:00
|
|
|
data_new_data_cmd_callback (GtkAction *action,
|
2004-05-12 00:05:21 +08:00
|
|
|
gpointer user_data)
|
2001-07-09 05:44:52 +08:00
|
|
|
{
|
2004-05-12 00:05:21 +08:00
|
|
|
GimpDataFactoryView *view = GIMP_DATA_FACTORY_VIEW (user_data);
|
|
|
|
|
|
|
|
if (view->factory->data_new_func)
|
|
|
|
{
|
|
|
|
GimpContext *context;
|
|
|
|
GimpData *data;
|
|
|
|
|
|
|
|
context =
|
|
|
|
gimp_container_view_get_context (GIMP_CONTAINER_EDITOR (view)->view);
|
2001-07-09 05:44:52 +08:00
|
|
|
|
2004-05-12 00:05:21 +08:00
|
|
|
data = gimp_data_factory_data_new (view->factory, _("Untitled"));
|
|
|
|
|
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
gimp_context_set_by_type (context,
|
|
|
|
view->factory->container->children_type,
|
|
|
|
GIMP_OBJECT (data));
|
|
|
|
|
|
|
|
gtk_button_clicked (GTK_BUTTON (view->edit_button));
|
|
|
|
}
|
|
|
|
}
|
2001-07-09 05:44:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-04-29 20:52:29 +08:00
|
|
|
data_duplicate_data_cmd_callback (GtkAction *action,
|
2004-05-12 00:05:21 +08:00
|
|
|
gpointer user_data)
|
2001-07-09 05:44:52 +08:00
|
|
|
{
|
2004-05-12 00:05:21 +08:00
|
|
|
GimpDataFactoryView *view = GIMP_DATA_FACTORY_VIEW (user_data);
|
|
|
|
GimpContext *context;
|
|
|
|
GimpData *data;
|
|
|
|
|
|
|
|
context = gimp_container_view_get_context (GIMP_CONTAINER_EDITOR (view)->view);
|
|
|
|
|
|
|
|
data = (GimpData *)
|
|
|
|
gimp_context_get_by_type (context,
|
|
|
|
view->factory->container->children_type);
|
2001-07-09 05:44:52 +08:00
|
|
|
|
2004-05-12 00:05:21 +08:00
|
|
|
if (data && gimp_container_have (view->factory->container,
|
|
|
|
GIMP_OBJECT (data)))
|
|
|
|
{
|
|
|
|
GimpData *new_data;
|
|
|
|
|
|
|
|
new_data = gimp_data_factory_data_duplicate (view->factory, data);
|
|
|
|
|
|
|
|
if (new_data)
|
|
|
|
{
|
|
|
|
gimp_context_set_by_type (context,
|
|
|
|
view->factory->container->children_type,
|
|
|
|
GIMP_OBJECT (new_data));
|
|
|
|
|
|
|
|
gtk_button_clicked (GTK_BUTTON (view->edit_button));
|
|
|
|
}
|
|
|
|
}
|
2001-07-09 05:44:52 +08:00
|
|
|
}
|
|
|
|
|
2004-05-12 00:05:21 +08:00
|
|
|
typedef struct _GimpDataDeleteData GimpDataDeleteData;
|
|
|
|
|
|
|
|
struct _GimpDataDeleteData
|
2001-07-09 05:44:52 +08:00
|
|
|
{
|
2004-05-12 00:05:21 +08:00
|
|
|
GimpDataFactory *factory;
|
|
|
|
GimpData *data;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
data_delete_callback (GtkWidget *widget,
|
|
|
|
gboolean delete,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GimpDataDeleteData *delete_data = data;
|
|
|
|
|
2004-06-02 05:37:36 +08:00
|
|
|
if (delete)
|
2004-05-12 00:05:21 +08:00
|
|
|
{
|
2004-06-02 05:37:36 +08:00
|
|
|
GError *error = NULL;
|
2001-07-09 05:44:52 +08:00
|
|
|
|
2004-06-02 05:37:36 +08:00
|
|
|
if (! gimp_data_factory_data_delete (delete_data->factory,
|
|
|
|
delete_data->data,
|
|
|
|
TRUE, &error))
|
2004-05-12 00:05:21 +08:00
|
|
|
{
|
2004-06-02 05:37:36 +08:00
|
|
|
g_message (error->message);
|
|
|
|
g_clear_error (&error);
|
2004-05-12 00:05:21 +08:00
|
|
|
}
|
|
|
|
}
|
2001-07-09 05:44:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-04-29 20:52:29 +08:00
|
|
|
data_delete_data_cmd_callback (GtkAction *action,
|
2004-05-12 00:05:21 +08:00
|
|
|
gpointer user_data)
|
2001-07-09 05:44:52 +08:00
|
|
|
{
|
2004-05-12 00:05:21 +08:00
|
|
|
GimpDataFactoryView *view = GIMP_DATA_FACTORY_VIEW (user_data);
|
|
|
|
GimpContext *context;
|
|
|
|
GimpData *data;
|
|
|
|
|
|
|
|
context = gimp_container_view_get_context (GIMP_CONTAINER_EDITOR (view)->view);
|
|
|
|
|
|
|
|
data = (GimpData *)
|
|
|
|
gimp_context_get_by_type (context,
|
|
|
|
view->factory->container->children_type);
|
|
|
|
|
|
|
|
if (data && data->deletable && gimp_container_have (view->factory->container,
|
|
|
|
GIMP_OBJECT (data)))
|
|
|
|
{
|
|
|
|
GimpDataDeleteData *delete_data;
|
|
|
|
GtkWidget *dialog;
|
|
|
|
gchar *str;
|
|
|
|
|
|
|
|
delete_data = g_new0 (GimpDataDeleteData, 1);
|
|
|
|
|
|
|
|
delete_data->factory = view->factory;
|
|
|
|
delete_data->data = data;
|
|
|
|
|
|
|
|
str = g_strdup_printf (_("Are you sure you want to delete '%s' "
|
|
|
|
"from the list and from disk?"),
|
|
|
|
GIMP_OBJECT (data)->name);
|
|
|
|
|
|
|
|
dialog = gimp_query_boolean_box (_("Delete Data Object"),
|
|
|
|
GTK_WIDGET (view),
|
|
|
|
gimp_standard_help_func, NULL,
|
|
|
|
GIMP_STOCK_QUESTION,
|
|
|
|
str,
|
|
|
|
GTK_STOCK_DELETE, GTK_STOCK_CANCEL,
|
|
|
|
G_OBJECT (data),
|
|
|
|
"disconnect",
|
|
|
|
data_delete_callback,
|
|
|
|
delete_data);
|
|
|
|
|
|
|
|
g_object_weak_ref (G_OBJECT (dialog), (GWeakNotify) g_free, delete_data);
|
|
|
|
|
|
|
|
g_free (str);
|
2001-07-09 05:44:52 +08:00
|
|
|
|
2004-05-12 00:05:21 +08:00
|
|
|
gtk_widget_show (dialog);
|
|
|
|
}
|
2001-07-09 05:44:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-04-29 20:52:29 +08:00
|
|
|
data_refresh_data_cmd_callback (GtkAction *action,
|
2004-05-12 00:05:21 +08:00
|
|
|
gpointer user_data)
|
2001-07-09 05:44:52 +08:00
|
|
|
{
|
2004-05-12 00:05:21 +08:00
|
|
|
GimpDataFactoryView *view = GIMP_DATA_FACTORY_VIEW (user_data);
|
2001-07-09 05:44:52 +08:00
|
|
|
|
2004-05-12 00:05:21 +08:00
|
|
|
gimp_data_factory_data_save (view->factory);
|
|
|
|
gimp_data_factory_data_init (view->factory, FALSE);
|
2001-07-09 05:44:52 +08:00
|
|
|
}
|
2004-09-27 18:45:49 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
data_edit_data_cmd_callback (GtkAction *action,
|
|
|
|
const gchar *value,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GimpDataFactoryView *view = GIMP_DATA_FACTORY_VIEW (user_data);
|
|
|
|
GimpContext *context;
|
|
|
|
GimpData *data;
|
|
|
|
|
|
|
|
context = gimp_container_view_get_context (GIMP_CONTAINER_EDITOR (view)->view);
|
|
|
|
|
|
|
|
data = (GimpData *)
|
|
|
|
gimp_context_get_by_type (context,
|
|
|
|
view->factory->container->children_type);
|
|
|
|
|
|
|
|
if (data && gimp_container_have (view->factory->container,
|
|
|
|
GIMP_OBJECT (data)))
|
|
|
|
{
|
|
|
|
GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (view));
|
|
|
|
GtkWidget *dockable;
|
|
|
|
|
|
|
|
dockable = gimp_dialog_factory_dialog_raise (global_dock_factory, screen,
|
|
|
|
value, -1);
|
|
|
|
|
|
|
|
gimp_data_editor_set_data (GIMP_DATA_EDITOR (GTK_BIN (dockable)->child),
|
|
|
|
data);
|
|
|
|
}
|
|
|
|
}
|