2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2001-07-09 05:44:52 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2001-07-09 05:44:52 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2001-07-09 05:44:52 +08:00
|
|
|
* (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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2001-07-09 05:44:52 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#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
|
|
|
|
2005-11-03 03:39:54 +08:00
|
|
|
#include "core/gimp.h"
|
2007-05-27 23:13:45 +08:00
|
|
|
#include "core/gimp-utils.h"
|
2004-05-12 00:05:21 +08:00
|
|
|
#include "core/gimpcontainer.h"
|
|
|
|
#include "core/gimpcontext.h"
|
|
|
|
#include "core/gimpdata.h"
|
|
|
|
#include "core/gimpdatafactory.h"
|
|
|
|
|
2005-01-14 04:22:53 +08:00
|
|
|
#include "file/file-open.h"
|
|
|
|
#include "file/file-utils.h"
|
|
|
|
|
2005-11-01 19:01:44 +08:00
|
|
|
#include "widgets/gimpclipboard.h"
|
2004-05-12 00:05:21 +08:00
|
|
|
#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"
|
2004-10-13 23:27:00 +08:00
|
|
|
#include "widgets/gimpmessagebox.h"
|
|
|
|
#include "widgets/gimpmessagedialog.h"
|
2004-09-27 18:45:49 +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
|
|
|
|
|
|
|
|
2004-09-27 20:30:04 +08:00
|
|
|
typedef struct _GimpDataDeleteData GimpDataDeleteData;
|
|
|
|
|
|
|
|
struct _GimpDataDeleteData
|
|
|
|
{
|
2007-05-27 23:13:45 +08:00
|
|
|
GimpContext *context;
|
2006-10-10 02:49:15 +08:00
|
|
|
GimpDataFactoryView *view;
|
|
|
|
GimpData *data;
|
2004-09-27 20:30:04 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* local function prototypes */
|
|
|
|
|
2004-10-13 23:27:00 +08:00
|
|
|
static void data_delete_confirm_response (GtkWidget *dialog,
|
|
|
|
gint response_id,
|
|
|
|
GimpDataDeleteData *delete_data);
|
2004-09-27 20:30:04 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
2005-01-14 04:22:53 +08:00
|
|
|
void
|
|
|
|
data_open_as_image_cmd_callback (GtkAction *action,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GimpDataFactoryView *view = GIMP_DATA_FACTORY_VIEW (user_data);
|
|
|
|
GimpContext *context;
|
|
|
|
GimpData *data;
|
|
|
|
|
2006-08-09 05:06:36 +08:00
|
|
|
context =
|
|
|
|
gimp_container_view_get_context (GIMP_CONTAINER_EDITOR (view)->view);
|
2005-01-14 04:22:53 +08:00
|
|
|
|
|
|
|
data = (GimpData *)
|
|
|
|
gimp_context_get_by_type (context,
|
2008-12-20 20:27:52 +08:00
|
|
|
gimp_data_factory_view_get_children_type (view));
|
2005-01-14 04:22:53 +08:00
|
|
|
|
2009-10-31 22:24:57 +08:00
|
|
|
if (data && gimp_data_get_filename (data))
|
2005-01-14 04:22:53 +08:00
|
|
|
{
|
2009-10-31 22:24:57 +08:00
|
|
|
gchar *uri = g_filename_to_uri (gimp_data_get_filename (data), NULL, NULL);
|
2005-01-14 04:22:53 +08:00
|
|
|
|
|
|
|
if (uri)
|
|
|
|
{
|
|
|
|
GimpImage *image;
|
|
|
|
GimpPDBStatusType status;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
2007-04-17 23:54:01 +08:00
|
|
|
image = file_open_with_display (context->gimp, context, NULL,
|
|
|
|
uri, FALSE,
|
2005-01-14 04:22:53 +08:00
|
|
|
&status, &error);
|
|
|
|
|
|
|
|
if (! image && status != GIMP_PDB_CANCEL)
|
|
|
|
{
|
2006-08-09 05:06:36 +08:00
|
|
|
gchar *filename = file_utils_uri_display_name (uri);
|
2005-01-14 04:22:53 +08:00
|
|
|
|
2006-10-10 02:49:15 +08:00
|
|
|
gimp_message (context->gimp, G_OBJECT (view),
|
|
|
|
GIMP_MESSAGE_ERROR,
|
|
|
|
_("Opening '%s' failed:\n\n%s"),
|
|
|
|
filename, error->message);
|
2005-01-14 04:22:53 +08:00
|
|
|
g_clear_error (&error);
|
|
|
|
|
|
|
|
g_free (filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (uri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-07-09 05:44:52 +08:00
|
|
|
void
|
2005-01-14 21:30:05 +08:00
|
|
|
data_new_cmd_callback (GtkAction *action,
|
|
|
|
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);
|
|
|
|
|
2008-12-20 20:27:52 +08:00
|
|
|
if (gimp_data_factory_view_has_data_new_func (view))
|
2004-05-12 00:05:21 +08:00
|
|
|
{
|
|
|
|
GimpContext *context;
|
|
|
|
GimpData *data;
|
|
|
|
|
|
|
|
context =
|
|
|
|
gimp_container_view_get_context (GIMP_CONTAINER_EDITOR (view)->view);
|
2001-07-09 05:44:52 +08:00
|
|
|
|
2008-12-20 20:08:28 +08:00
|
|
|
data = gimp_data_factory_data_new (gimp_data_factory_view_get_data_factory (view), _("Untitled"));
|
2004-05-12 00:05:21 +08:00
|
|
|
|
|
|
|
if (data)
|
2006-04-12 20:49:29 +08:00
|
|
|
{
|
|
|
|
gimp_context_set_by_type (context,
|
2008-12-20 20:27:52 +08:00
|
|
|
gimp_data_factory_view_get_children_type (view),
|
2006-04-12 20:49:29 +08:00
|
|
|
GIMP_OBJECT (data));
|
2004-05-12 00:05:21 +08:00
|
|
|
|
2008-12-20 20:08:28 +08:00
|
|
|
gtk_button_clicked (GTK_BUTTON (gimp_data_factory_view_get_edit_button (view)));
|
2006-04-12 20:49:29 +08:00
|
|
|
}
|
2004-05-12 00:05:21 +08:00
|
|
|
}
|
2001-07-09 05:44:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-01-14 21:30:05 +08:00
|
|
|
data_duplicate_cmd_callback (GtkAction *action,
|
|
|
|
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,
|
2008-12-20 20:27:52 +08:00
|
|
|
gimp_data_factory_view_get_children_type (view));
|
2001-07-09 05:44:52 +08:00
|
|
|
|
2008-12-20 20:27:52 +08:00
|
|
|
if (data && gimp_data_factory_view_have (view,
|
|
|
|
GIMP_OBJECT (data)))
|
2004-05-12 00:05:21 +08:00
|
|
|
{
|
|
|
|
GimpData *new_data;
|
|
|
|
|
2008-12-20 20:08:28 +08:00
|
|
|
new_data = gimp_data_factory_data_duplicate (gimp_data_factory_view_get_data_factory (view), data);
|
2004-05-12 00:05:21 +08:00
|
|
|
|
|
|
|
if (new_data)
|
2006-04-12 20:49:29 +08:00
|
|
|
{
|
|
|
|
gimp_context_set_by_type (context,
|
2008-12-20 20:27:52 +08:00
|
|
|
gimp_data_factory_view_get_children_type (view),
|
2006-04-12 20:49:29 +08:00
|
|
|
GIMP_OBJECT (new_data));
|
2004-05-12 00:05:21 +08:00
|
|
|
|
2008-12-20 20:08:28 +08:00
|
|
|
gtk_button_clicked (GTK_BUTTON (gimp_data_factory_view_get_edit_button (view)));
|
2006-04-12 20:49:29 +08:00
|
|
|
}
|
2004-05-12 00:05:21 +08:00
|
|
|
}
|
2001-07-09 05:44:52 +08:00
|
|
|
}
|
|
|
|
|
2005-10-31 20:00:25 +08:00
|
|
|
void
|
|
|
|
data_copy_location_cmd_callback (GtkAction *action,
|
|
|
|
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,
|
2008-12-20 20:27:52 +08:00
|
|
|
gimp_data_factory_view_get_children_type (view));
|
2005-10-31 20:00:25 +08:00
|
|
|
|
2009-10-31 22:24:57 +08:00
|
|
|
if (data)
|
2005-10-31 20:00:25 +08:00
|
|
|
{
|
2009-10-31 22:24:57 +08:00
|
|
|
const gchar *filename = gimp_data_get_filename (data);
|
2005-10-31 20:00:25 +08:00
|
|
|
|
2009-10-31 22:24:57 +08:00
|
|
|
if (filename && *filename)
|
2005-10-31 20:00:25 +08:00
|
|
|
{
|
2009-10-31 22:24:57 +08:00
|
|
|
gchar *uri = g_filename_to_uri (filename, NULL, NULL);
|
|
|
|
|
|
|
|
if (uri)
|
|
|
|
{
|
|
|
|
gimp_clipboard_set_text (context->gimp, uri);
|
|
|
|
g_free (uri);
|
|
|
|
}
|
2005-10-31 20:00:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-07-09 05:44:52 +08:00
|
|
|
void
|
2005-01-14 21:30:05 +08:00
|
|
|
data_delete_cmd_callback (GtkAction *action,
|
|
|
|
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;
|
|
|
|
|
2007-02-16 20:59:10 +08:00
|
|
|
context =
|
|
|
|
gimp_container_view_get_context (GIMP_CONTAINER_EDITOR (view)->view);
|
2004-05-12 00:05:21 +08:00
|
|
|
|
|
|
|
data = (GimpData *)
|
|
|
|
gimp_context_get_by_type (context,
|
2008-12-20 20:27:52 +08:00
|
|
|
gimp_data_factory_view_get_children_type (view));
|
2004-05-12 00:05:21 +08:00
|
|
|
|
2009-11-01 01:48:38 +08:00
|
|
|
if (data &&
|
|
|
|
gimp_data_is_deletable (data) &&
|
2008-12-20 20:27:52 +08:00
|
|
|
gimp_data_factory_view_have (view,
|
|
|
|
GIMP_OBJECT (data)))
|
2004-05-12 00:05:21 +08:00
|
|
|
{
|
|
|
|
GimpDataDeleteData *delete_data;
|
|
|
|
GtkWidget *dialog;
|
|
|
|
|
2007-05-22 18:43:48 +08:00
|
|
|
delete_data = g_slice_new0 (GimpDataDeleteData);
|
2004-05-12 00:05:21 +08:00
|
|
|
|
2007-05-27 23:13:45 +08:00
|
|
|
delete_data->context = context;
|
|
|
|
delete_data->view = view;
|
|
|
|
delete_data->data = data;
|
2004-05-12 00:05:21 +08:00
|
|
|
|
2007-09-25 22:03:33 +08:00
|
|
|
dialog = gimp_message_dialog_new (_("Delete Object"), GTK_STOCK_DELETE,
|
2004-10-13 23:27:00 +08:00
|
|
|
GTK_WIDGET (view), 0,
|
|
|
|
gimp_standard_help_func, NULL,
|
2004-05-12 00:05:21 +08:00
|
|
|
|
2004-10-13 23:27:00 +08:00
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_STOCK_DELETE, GTK_RESPONSE_OK,
|
2004-05-12 00:05:21 +08:00
|
|
|
|
2004-10-13 23:27:00 +08:00
|
|
|
NULL);
|
2004-05-12 00:05:21 +08:00
|
|
|
|
2005-09-28 02:51:44 +08:00
|
|
|
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
|
|
|
|
GTK_RESPONSE_OK,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
-1);
|
2005-02-10 19:00:46 +08:00
|
|
|
|
2004-10-13 23:27:00 +08:00
|
|
|
g_signal_connect_object (data, "disconnect",
|
|
|
|
G_CALLBACK (gtk_widget_destroy),
|
|
|
|
dialog, G_CONNECT_SWAPPED);
|
2001-07-09 05:44:52 +08:00
|
|
|
|
2004-10-13 23:27:00 +08:00
|
|
|
g_signal_connect (dialog, "response",
|
|
|
|
G_CALLBACK (data_delete_confirm_response),
|
|
|
|
delete_data);
|
|
|
|
|
|
|
|
gimp_message_box_set_primary_text (GIMP_MESSAGE_DIALOG (dialog)->box,
|
2007-02-16 20:59:10 +08:00
|
|
|
_("Delete '%s'?"),
|
2009-08-29 18:40:40 +08:00
|
|
|
gimp_object_get_name (data));
|
2007-02-16 20:59:10 +08:00
|
|
|
gimp_message_box_set_text(GIMP_MESSAGE_DIALOG (dialog)->box,
|
|
|
|
_("Are you sure you want to remove '%s' "
|
|
|
|
"from the list and delete it on disk?"),
|
2009-08-29 18:40:40 +08:00
|
|
|
gimp_object_get_name (data));
|
2007-02-16 20:59:10 +08:00
|
|
|
|
2004-05-12 00:05:21 +08:00
|
|
|
gtk_widget_show (dialog);
|
|
|
|
}
|
2001-07-09 05:44:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-01-14 21:30:05 +08:00
|
|
|
data_refresh_cmd_callback (GtkAction *action,
|
|
|
|
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);
|
2005-10-31 19:29:01 +08:00
|
|
|
Gimp *gimp;
|
|
|
|
return_if_no_gimp (gimp, user_data);
|
2001-07-09 05:44:52 +08:00
|
|
|
|
2005-10-31 19:29:01 +08:00
|
|
|
gimp_set_busy (gimp);
|
2008-12-20 20:08:28 +08:00
|
|
|
gimp_data_factory_data_refresh (gimp_data_factory_view_get_data_factory (view));
|
2005-10-31 19:29:01 +08:00
|
|
|
gimp_unset_busy (gimp);
|
2001-07-09 05:44:52 +08:00
|
|
|
}
|
2004-09-27 18:45:49 +08:00
|
|
|
|
|
|
|
void
|
2005-01-14 21:30:05 +08:00
|
|
|
data_edit_cmd_callback (GtkAction *action,
|
|
|
|
const gchar *value,
|
|
|
|
gpointer user_data)
|
2004-09-27 18:45:49 +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,
|
2008-12-20 20:27:52 +08:00
|
|
|
gimp_data_factory_view_get_children_type (view));
|
2004-09-27 18:45:49 +08:00
|
|
|
|
2008-12-20 20:27:52 +08:00
|
|
|
if (data && gimp_data_factory_view_have (view,
|
|
|
|
GIMP_OBJECT (data)))
|
2004-09-27 18:45:49 +08:00
|
|
|
{
|
|
|
|
GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (view));
|
|
|
|
GtkWidget *dockable;
|
|
|
|
|
2010-03-01 06:20:57 +08:00
|
|
|
dockable = gimp_dialog_factory_dialog_raise (gimp_dialog_factory_get_singleton (), screen,
|
2004-09-27 18:45:49 +08:00
|
|
|
value, -1);
|
|
|
|
|
2008-03-13 00:58:28 +08:00
|
|
|
gimp_data_editor_set_data (GIMP_DATA_EDITOR (gtk_bin_get_child (GTK_BIN (dockable))),
|
2004-09-27 18:45:49 +08:00
|
|
|
data);
|
|
|
|
}
|
|
|
|
}
|
2004-09-27 20:30:04 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
static void
|
2004-10-13 23:27:00 +08:00
|
|
|
data_delete_confirm_response (GtkWidget *dialog,
|
|
|
|
gint response_id,
|
|
|
|
GimpDataDeleteData *delete_data)
|
2004-09-27 20:30:04 +08:00
|
|
|
{
|
2004-10-13 23:27:00 +08:00
|
|
|
gtk_widget_destroy (dialog);
|
2004-09-27 20:30:04 +08:00
|
|
|
|
2004-10-13 23:27:00 +08:00
|
|
|
if (response_id == GTK_RESPONSE_OK)
|
2004-09-27 20:30:04 +08:00
|
|
|
{
|
2008-12-20 20:08:28 +08:00
|
|
|
GimpDataFactory *factory = gimp_data_factory_view_get_data_factory (delete_data->view);
|
2007-05-27 23:13:45 +08:00
|
|
|
GimpData *data = delete_data->data;
|
|
|
|
GimpObject *new_active;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
2008-12-20 05:58:17 +08:00
|
|
|
new_active = gimp_container_get_neighbor_of_active (gimp_data_factory_get_container (factory),
|
2007-05-27 23:13:45 +08:00
|
|
|
delete_data->context,
|
|
|
|
GIMP_OBJECT (data));
|
2004-09-27 20:30:04 +08:00
|
|
|
|
2007-05-27 23:13:45 +08:00
|
|
|
if (! gimp_data_factory_data_delete (factory, data, TRUE, &error))
|
2004-09-27 20:30:04 +08:00
|
|
|
{
|
2008-12-20 05:58:17 +08:00
|
|
|
gimp_message (gimp_data_factory_get_gimp (factory),
|
2006-10-10 02:49:15 +08:00
|
|
|
G_OBJECT (delete_data->view), GIMP_MESSAGE_ERROR,
|
|
|
|
"%s", error->message);
|
2004-09-27 20:30:04 +08:00
|
|
|
g_clear_error (&error);
|
|
|
|
}
|
2007-05-27 23:13:45 +08:00
|
|
|
|
|
|
|
if (new_active)
|
|
|
|
gimp_context_set_by_type (delete_data->context,
|
2008-12-20 05:58:17 +08:00
|
|
|
gimp_container_get_children_type (gimp_data_factory_get_container (factory)),
|
2007-05-27 23:13:45 +08:00
|
|
|
new_active);
|
2004-09-27 20:30:04 +08:00
|
|
|
}
|
2004-10-13 23:27:00 +08:00
|
|
|
|
2007-05-22 18:43:48 +08:00
|
|
|
g_slice_free (GimpDataDeleteData, delete_data);
|
2004-09-27 20:30:04 +08:00
|
|
|
}
|