2006-12-09 21:33:38 +00:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2001-10-24 11:23:50 +00:00
|
|
|
* 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"
|
|
|
|
|
2004-05-12 18:36:33 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2001-10-24 11:23:50 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2004-05-12 18:36:33 +00:00
|
|
|
#include "libgimpthumb/gimpthumb.h"
|
2001-10-24 11:23:50 +00:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
2004-04-20 13:25:55 +00:00
|
|
|
#include "actions-types.h"
|
2001-10-24 11:23:50 +00:00
|
|
|
|
2004-10-11 12:28:58 +00:00
|
|
|
#include "config/gimpcoreconfig.h"
|
|
|
|
|
2004-05-12 18:36:33 +00:00
|
|
|
#include "core/gimp.h"
|
|
|
|
#include "core/gimpcontainer.h"
|
|
|
|
#include "core/gimpcontext.h"
|
|
|
|
#include "core/gimpimagefile.h"
|
|
|
|
|
|
|
|
#include "file/file-open.h"
|
|
|
|
#include "file/file-utils.h"
|
|
|
|
|
2005-11-01 11:01:44 +00:00
|
|
|
#include "widgets/gimpclipboard.h"
|
2004-05-12 18:36:33 +00:00
|
|
|
#include "widgets/gimpcontainerview.h"
|
2007-05-27 15:13:45 +00:00
|
|
|
#include "widgets/gimpcontainerview-utils.h"
|
2001-10-24 11:23:50 +00:00
|
|
|
#include "widgets/gimpdocumentview.h"
|
2005-06-20 19:28:49 +00:00
|
|
|
#include "widgets/gimpmessagebox.h"
|
|
|
|
#include "widgets/gimpmessagedialog.h"
|
2001-10-24 11:23:50 +00:00
|
|
|
|
2004-05-12 18:36:33 +00:00
|
|
|
#include "display/gimpdisplay.h"
|
|
|
|
#include "display/gimpdisplay-foreach.h"
|
|
|
|
|
2001-10-24 11:23:50 +00:00
|
|
|
#include "documents-commands.h"
|
2004-05-12 18:36:33 +00:00
|
|
|
#include "file-commands.h"
|
|
|
|
|
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
|
|
|
|
2007-05-21 16:32:52 +00:00
|
|
|
typedef struct
|
2004-10-18 11:29:58 +00:00
|
|
|
{
|
|
|
|
const gchar *name;
|
|
|
|
gboolean found;
|
2007-05-21 16:32:52 +00:00
|
|
|
} RaiseClosure;
|
2004-10-18 11:29:58 +00:00
|
|
|
|
|
|
|
|
2004-05-12 18:36:33 +00:00
|
|
|
/* local function prototypes */
|
|
|
|
|
2007-05-21 16:32:52 +00:00
|
|
|
static void documents_open_image (GtkWidget *editor,
|
|
|
|
GimpContext *context,
|
2004-10-18 11:29:58 +00:00
|
|
|
GimpImagefile *imagefile);
|
2007-05-21 16:32:52 +00:00
|
|
|
static void documents_raise_display (GimpDisplay *display,
|
|
|
|
RaiseClosure *closure);
|
|
|
|
|
2001-10-24 11:23:50 +00:00
|
|
|
|
|
|
|
|
2003-04-06 11:21:56 +00:00
|
|
|
/* public functions */
|
2001-10-24 11:23:50 +00:00
|
|
|
|
|
|
|
void
|
2005-01-14 13:30:05 +00:00
|
|
|
documents_open_cmd_callback (GtkAction *action,
|
|
|
|
gpointer data)
|
2001-10-24 11:23:50 +00:00
|
|
|
{
|
2004-05-12 18:36:33 +00:00
|
|
|
GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (data);
|
|
|
|
GimpContext *context;
|
|
|
|
GimpContainer *container;
|
|
|
|
GimpImagefile *imagefile;
|
|
|
|
|
|
|
|
context = gimp_container_view_get_context (editor->view);
|
|
|
|
container = gimp_container_view_get_container (editor->view);
|
|
|
|
|
|
|
|
imagefile = gimp_context_get_imagefile (context);
|
|
|
|
|
|
|
|
if (imagefile && gimp_container_have (container, GIMP_OBJECT (imagefile)))
|
|
|
|
{
|
2007-05-21 16:32:52 +00:00
|
|
|
documents_open_image (GTK_WIDGET (editor), context, imagefile);
|
2004-05-12 18:36:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
file_file_open_dialog (context->gimp, NULL, GTK_WIDGET (editor));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-24 11:23:50 +00:00
|
|
|
void
|
2005-01-14 13:30:05 +00:00
|
|
|
documents_raise_or_open_cmd_callback (GtkAction *action,
|
|
|
|
gpointer data)
|
2001-10-24 11:23:50 +00:00
|
|
|
{
|
2004-05-12 18:36:33 +00:00
|
|
|
GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (data);
|
|
|
|
GimpContext *context;
|
|
|
|
GimpContainer *container;
|
|
|
|
GimpImagefile *imagefile;
|
2001-10-24 11:23:50 +00:00
|
|
|
|
2004-05-12 18:36:33 +00:00
|
|
|
context = gimp_container_view_get_context (editor->view);
|
|
|
|
container = gimp_container_view_get_container (editor->view);
|
|
|
|
|
|
|
|
imagefile = gimp_context_get_imagefile (context);
|
|
|
|
|
|
|
|
if (imagefile && gimp_container_have (container, GIMP_OBJECT (imagefile)))
|
|
|
|
{
|
|
|
|
RaiseClosure closure;
|
|
|
|
|
|
|
|
closure.name = gimp_object_get_name (GIMP_OBJECT (imagefile));
|
|
|
|
closure.found = FALSE;
|
|
|
|
|
|
|
|
gimp_container_foreach (context->gimp->displays,
|
2007-05-21 16:32:52 +00:00
|
|
|
(GFunc) documents_raise_display,
|
2004-05-12 18:36:33 +00:00
|
|
|
&closure);
|
|
|
|
|
|
|
|
if (! closure.found)
|
2007-05-21 16:32:52 +00:00
|
|
|
documents_open_image (GTK_WIDGET (editor), context, imagefile);
|
2004-05-12 18:36:33 +00:00
|
|
|
}
|
2001-10-24 11:23:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-04-29 12:52:29 +00:00
|
|
|
documents_file_open_dialog_cmd_callback (GtkAction *action,
|
2001-10-24 11:23:50 +00:00
|
|
|
gpointer data)
|
|
|
|
{
|
2004-05-12 18:36:33 +00:00
|
|
|
GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (data);
|
|
|
|
GimpContext *context;
|
|
|
|
GimpContainer *container;
|
|
|
|
GimpImagefile *imagefile;
|
|
|
|
|
|
|
|
context = gimp_container_view_get_context (editor->view);
|
|
|
|
container = gimp_container_view_get_container (editor->view);
|
2001-10-24 11:23:50 +00:00
|
|
|
|
2004-05-12 18:36:33 +00:00
|
|
|
imagefile = gimp_context_get_imagefile (context);
|
|
|
|
|
|
|
|
if (imagefile && gimp_container_have (container, GIMP_OBJECT (imagefile)))
|
|
|
|
{
|
|
|
|
file_file_open_dialog (context->gimp,
|
|
|
|
gimp_object_get_name (GIMP_OBJECT (imagefile)),
|
|
|
|
GTK_WIDGET (editor));
|
|
|
|
}
|
2001-10-24 11:23:50 +00:00
|
|
|
}
|
|
|
|
|
2005-07-07 21:49:35 +00:00
|
|
|
void
|
|
|
|
documents_copy_location_cmd_callback (GtkAction *action,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (data);
|
|
|
|
GimpContext *context;
|
|
|
|
GimpImagefile *imagefile;
|
|
|
|
|
|
|
|
context = gimp_container_view_get_context (editor->view);
|
|
|
|
imagefile = gimp_context_get_imagefile (context);
|
|
|
|
|
|
|
|
if (imagefile)
|
2005-11-02 12:03:37 +00:00
|
|
|
gimp_clipboard_set_text (context->gimp,
|
|
|
|
gimp_object_get_name (GIMP_OBJECT (imagefile)));
|
2005-07-07 21:49:35 +00:00
|
|
|
}
|
|
|
|
|
2001-10-24 11:23:50 +00:00
|
|
|
void
|
2005-01-14 13:30:05 +00:00
|
|
|
documents_remove_cmd_callback (GtkAction *action,
|
|
|
|
gpointer data)
|
2001-10-24 11:23:50 +00:00
|
|
|
{
|
2008-03-24 23:03:23 +00:00
|
|
|
GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (data);
|
|
|
|
GimpContext *context = gimp_container_view_get_context (editor->view);
|
2004-05-12 18:36:33 +00:00
|
|
|
|
2008-03-24 23:03:23 +00:00
|
|
|
if (context->gimp->config->save_document_history)
|
|
|
|
{
|
|
|
|
GimpImagefile *imagefile = gimp_context_get_imagefile (context);
|
|
|
|
const gchar *uri = gimp_object_get_name (GIMP_OBJECT (imagefile));
|
2008-03-24 11:53:05 +00:00
|
|
|
|
2008-03-24 23:03:23 +00:00
|
|
|
gtk_recent_manager_remove_item (gtk_recent_manager_get_default (),
|
|
|
|
uri, NULL);
|
|
|
|
}
|
2008-03-24 17:56:27 +00:00
|
|
|
|
|
|
|
gimp_container_view_remove_active (editor->view);
|
2004-05-12 18:36:33 +00:00
|
|
|
}
|
2001-10-24 11:23:50 +00:00
|
|
|
|
2005-06-20 19:28:49 +00:00
|
|
|
void
|
|
|
|
documents_clear_cmd_callback (GtkAction *action,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2008-03-24 23:03:23 +00:00
|
|
|
GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (data);
|
|
|
|
GimpContext *context = gimp_container_view_get_context (editor->view);
|
|
|
|
Gimp *gimp = context->gimp;
|
2005-06-20 19:28:49 +00:00
|
|
|
|
2008-03-24 23:03:23 +00:00
|
|
|
if (gimp->config->save_document_history)
|
|
|
|
{
|
|
|
|
GtkWidget *dialog;
|
2005-06-20 19:28:49 +00:00
|
|
|
|
2008-03-24 23:03:23 +00:00
|
|
|
dialog = gimp_message_dialog_new (_("Clear Document History"),
|
|
|
|
GTK_STOCK_CLEAR,
|
|
|
|
GTK_WIDGET (editor),
|
|
|
|
GTK_DIALOG_MODAL |
|
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
gimp_standard_help_func, NULL,
|
2005-06-20 19:28:49 +00:00
|
|
|
|
2008-03-24 23:03:23 +00:00
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_STOCK_CLEAR, GTK_RESPONSE_OK,
|
2005-06-20 19:28:49 +00:00
|
|
|
|
2008-03-24 23:03:23 +00:00
|
|
|
NULL);
|
2005-06-20 19:28:49 +00:00
|
|
|
|
2008-03-24 23:03:23 +00:00
|
|
|
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
|
|
|
|
GTK_RESPONSE_OK,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
-1);
|
2005-06-20 19:28:49 +00:00
|
|
|
|
2008-03-24 23:03:23 +00:00
|
|
|
g_signal_connect_object (gtk_widget_get_toplevel (GTK_WIDGET (editor)),
|
|
|
|
"unmap",
|
|
|
|
G_CALLBACK (gtk_widget_destroy),
|
|
|
|
dialog, G_CONNECT_SWAPPED);
|
2005-06-20 19:28:49 +00:00
|
|
|
|
2008-03-24 23:03:23 +00:00
|
|
|
gimp_message_box_set_primary_text (GIMP_MESSAGE_DIALOG (dialog)->box,
|
|
|
|
_("Clear the Recent Documents list?"));
|
2005-06-20 22:15:41 +00:00
|
|
|
|
2008-03-24 23:03:23 +00:00
|
|
|
gimp_message_box_set_text (GIMP_MESSAGE_DIALOG (dialog)->box,
|
|
|
|
_("Clearing the document history will "
|
|
|
|
"permanently remove all items from "
|
|
|
|
"the recent documents list in all "
|
|
|
|
"applications."));
|
2005-06-20 19:28:49 +00:00
|
|
|
|
2008-03-24 23:03:23 +00:00
|
|
|
if (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK)
|
|
|
|
{
|
|
|
|
GError *error = NULL;
|
2007-12-20 07:26:50 +00:00
|
|
|
|
2008-03-24 23:03:23 +00:00
|
|
|
gimp_container_clear (gimp->documents);
|
2007-12-20 07:26:50 +00:00
|
|
|
|
2008-11-11 20:09:05 +00:00
|
|
|
gtk_recent_manager_purge_items (gtk_recent_manager_get_default (),
|
|
|
|
&error);
|
|
|
|
|
|
|
|
if (error)
|
2008-03-24 23:03:23 +00:00
|
|
|
{
|
2008-11-04 12:33:09 +00:00
|
|
|
gimp_message_literal (gimp, G_OBJECT (dialog), GIMP_MESSAGE_ERROR,
|
|
|
|
error->message);
|
2008-03-24 23:03:23 +00:00
|
|
|
g_clear_error (&error);
|
|
|
|
}
|
2007-12-20 07:26:50 +00:00
|
|
|
}
|
2005-06-20 19:28:49 +00:00
|
|
|
|
2008-03-24 23:03:23 +00:00
|
|
|
gtk_widget_destroy (dialog);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gimp_container_clear (gimp->documents);
|
|
|
|
}
|
2005-06-20 19:28:49 +00:00
|
|
|
}
|
|
|
|
|
2001-10-24 11:23:50 +00:00
|
|
|
void
|
2004-04-29 12:52:29 +00:00
|
|
|
documents_recreate_preview_cmd_callback (GtkAction *action,
|
2002-04-28 23:10:42 +00:00
|
|
|
gpointer data)
|
2001-10-24 11:23:50 +00:00
|
|
|
{
|
2004-05-12 18:36:33 +00:00
|
|
|
GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (data);
|
|
|
|
GimpContext *context;
|
|
|
|
GimpContainer *container;
|
|
|
|
GimpImagefile *imagefile;
|
|
|
|
|
|
|
|
context = gimp_container_view_get_context (editor->view);
|
|
|
|
container = gimp_container_view_get_container (editor->view);
|
|
|
|
|
|
|
|
imagefile = gimp_context_get_imagefile (context);
|
2001-10-24 11:23:50 +00:00
|
|
|
|
2004-05-12 18:36:33 +00:00
|
|
|
if (imagefile && gimp_container_have (container, GIMP_OBJECT (imagefile)))
|
|
|
|
{
|
2004-10-23 15:30:39 +00:00
|
|
|
gimp_imagefile_create_thumbnail (imagefile,
|
|
|
|
context, NULL,
|
|
|
|
imagefile->gimp->config->thumbnail_size,
|
|
|
|
FALSE);
|
2004-05-12 18:36:33 +00:00
|
|
|
}
|
2001-10-24 11:23:50 +00:00
|
|
|
}
|
|
|
|
|
2002-04-28 23:10:42 +00:00
|
|
|
void
|
2004-04-29 12:52:29 +00:00
|
|
|
documents_reload_previews_cmd_callback (GtkAction *action,
|
2002-04-28 23:10:42 +00:00
|
|
|
gpointer data)
|
|
|
|
{
|
2004-05-12 18:36:33 +00:00
|
|
|
GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (data);
|
|
|
|
GimpContainer *container;
|
|
|
|
|
|
|
|
container = gimp_container_view_get_container (editor->view);
|
2002-04-28 23:10:42 +00:00
|
|
|
|
2004-05-12 18:36:33 +00:00
|
|
|
gimp_container_foreach (container,
|
|
|
|
(GFunc) gimp_imagefile_update,
|
|
|
|
editor->view);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-01-14 13:30:05 +00:00
|
|
|
documents_remove_dangling_foreach (GimpImagefile *imagefile,
|
2004-05-12 18:36:33 +00:00
|
|
|
GimpContainer *container)
|
|
|
|
{
|
|
|
|
if (gimp_thumbnail_peek_image (imagefile->thumbnail) ==
|
|
|
|
GIMP_THUMB_STATE_NOT_FOUND)
|
|
|
|
{
|
2008-03-24 11:53:05 +00:00
|
|
|
const gchar *uri = gimp_object_get_name (GIMP_OBJECT (imagefile));
|
|
|
|
|
|
|
|
gtk_recent_manager_remove_item (gtk_recent_manager_get_default (), uri,
|
|
|
|
NULL);
|
2008-03-24 17:56:27 +00:00
|
|
|
|
|
|
|
gimp_container_remove (container, GIMP_OBJECT (imagefile));
|
2004-05-12 18:36:33 +00:00
|
|
|
}
|
2002-04-28 23:10:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-01-14 13:30:05 +00:00
|
|
|
documents_remove_dangling_cmd_callback (GtkAction *action,
|
|
|
|
gpointer data)
|
2002-04-28 23:10:42 +00:00
|
|
|
{
|
2004-05-12 18:36:33 +00:00
|
|
|
GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (data);
|
|
|
|
GimpContainer *container;
|
|
|
|
|
|
|
|
container = gimp_container_view_get_container (editor->view);
|
|
|
|
|
|
|
|
gimp_container_foreach (container,
|
2005-01-14 13:30:05 +00:00
|
|
|
(GFunc) documents_remove_dangling_foreach,
|
2004-05-12 18:36:33 +00:00
|
|
|
container);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
static void
|
2007-05-21 16:32:52 +00:00
|
|
|
documents_open_image (GtkWidget *editor,
|
|
|
|
GimpContext *context,
|
2004-05-12 18:36:33 +00:00
|
|
|
GimpImagefile *imagefile)
|
|
|
|
{
|
|
|
|
const gchar *uri;
|
2006-03-28 17:08:36 +00:00
|
|
|
GimpImage *image;
|
2004-05-12 18:36:33 +00:00
|
|
|
GimpPDBStatusType status;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
uri = gimp_object_get_name (GIMP_OBJECT (imagefile));
|
|
|
|
|
2007-04-17 15:54:01 +00:00
|
|
|
image = file_open_with_display (context->gimp, context, NULL, uri, FALSE,
|
|
|
|
&status, &error);
|
2004-05-12 18:36:33 +00:00
|
|
|
|
2006-03-28 17:08:36 +00:00
|
|
|
if (! image && status != GIMP_PDB_CANCEL)
|
2004-05-12 18:36:33 +00:00
|
|
|
{
|
2006-08-08 21:06:36 +00:00
|
|
|
gchar *filename = file_utils_uri_display_name (uri);
|
2004-05-12 18:36:33 +00:00
|
|
|
|
2007-05-21 16:32:52 +00:00
|
|
|
gimp_message (context->gimp, G_OBJECT (editor), GIMP_MESSAGE_ERROR,
|
2006-10-09 18:49:15 +00:00
|
|
|
_("Opening '%s' failed:\n\n%s"),
|
|
|
|
filename, error->message);
|
2004-05-12 18:36:33 +00:00
|
|
|
g_clear_error (&error);
|
2002-04-28 23:10:42 +00:00
|
|
|
|
2004-05-12 18:36:33 +00:00
|
|
|
g_free (filename);
|
|
|
|
}
|
2002-04-28 23:10:42 +00:00
|
|
|
}
|
2004-10-18 11:29:58 +00:00
|
|
|
|
|
|
|
static void
|
2007-05-21 16:32:52 +00:00
|
|
|
documents_raise_display (GimpDisplay *display,
|
|
|
|
RaiseClosure *closure)
|
2004-10-18 11:29:58 +00:00
|
|
|
{
|
2007-05-21 16:32:52 +00:00
|
|
|
const gchar *uri = gimp_object_get_name (GIMP_OBJECT (display->image));
|
2004-10-18 11:29:58 +00:00
|
|
|
|
|
|
|
if (uri && ! strcmp (closure->name, uri))
|
|
|
|
{
|
|
|
|
closure->found = TRUE;
|
2006-03-28 17:55:52 +00:00
|
|
|
gtk_window_present (GTK_WINDOW (display->shell));
|
2004-10-18 11:29:58 +00:00
|
|
|
}
|
|
|
|
}
|