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