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
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2001-10-24 19:23:50 +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-10-24 19:23:50 +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-10-24 19:23:50 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#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"
|
|
|
|
#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"
|
2007-05-27 23:13:45 +08:00
|
|
|
#include "widgets/gimpcontainerview-utils.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"
|
2009-10-05 01:27:58 +08:00
|
|
|
#include "display/gimpdisplayshell.h"
|
2004-05-13 02:36:33 +08:00
|
|
|
|
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"
|
|
|
|
|
|
|
|
|
2007-05-22 00:32:52 +08:00
|
|
|
typedef struct
|
2004-10-18 19:29:58 +08:00
|
|
|
{
|
|
|
|
const gchar *name;
|
|
|
|
gboolean found;
|
2007-05-22 00:32:52 +08:00
|
|
|
} RaiseClosure;
|
2004-10-18 19:29:58 +08:00
|
|
|
|
|
|
|
|
2004-05-13 02:36:33 +08:00
|
|
|
/* local function prototypes */
|
|
|
|
|
2007-05-22 00:32:52 +08:00
|
|
|
static void documents_open_image (GtkWidget *editor,
|
|
|
|
GimpContext *context,
|
2004-10-18 19:29:58 +08:00
|
|
|
GimpImagefile *imagefile);
|
2007-05-22 00:32:52 +08:00
|
|
|
static void documents_raise_display (GimpDisplay *display,
|
|
|
|
RaiseClosure *closure);
|
|
|
|
|
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)))
|
|
|
|
{
|
2007-05-22 00:32:52 +08:00
|
|
|
documents_open_image (GTK_WIDGET (editor), context, imagefile);
|
2004-05-13 02:36:33 +08:00
|
|
|
}
|
|
|
|
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;
|
|
|
|
|
2009-09-01 04:47:18 +08:00
|
|
|
closure.name = gimp_object_get_name (imagefile);
|
2004-05-13 02:36:33 +08:00
|
|
|
closure.found = FALSE;
|
|
|
|
|
|
|
|
gimp_container_foreach (context->gimp->displays,
|
2007-05-22 00:32:52 +08:00
|
|
|
(GFunc) documents_raise_display,
|
2004-05-13 02:36:33 +08:00
|
|
|
&closure);
|
|
|
|
|
|
|
|
if (! closure.found)
|
2007-05-22 00:32:52 +08:00
|
|
|
documents_open_image (GTK_WIDGET (editor), context, imagefile);
|
2004-05-13 02:36:33 +08:00
|
|
|
}
|
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,
|
2009-09-01 04:47:18 +08:00
|
|
|
gimp_object_get_name (imagefile),
|
2004-05-13 02:36:33 +08:00
|
|
|
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,
|
2009-09-01 04:47:18 +08:00
|
|
|
gimp_object_get_name (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
|
|
|
{
|
2008-03-25 07:03:23 +08:00
|
|
|
GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (data);
|
|
|
|
GimpContext *context = gimp_container_view_get_context (editor->view);
|
2008-11-12 04:37:15 +08:00
|
|
|
GimpImagefile *imagefile = gimp_context_get_imagefile (context);
|
|
|
|
const gchar *uri;
|
2004-05-13 02:36:33 +08:00
|
|
|
|
2009-09-01 04:47:18 +08:00
|
|
|
uri = gimp_object_get_name (imagefile);
|
2008-03-24 19:53:05 +08:00
|
|
|
|
2008-11-12 04:37:15 +08:00
|
|
|
gtk_recent_manager_remove_item (gtk_recent_manager_get_default (), uri, NULL);
|
2008-03-25 01:56:27 +08:00
|
|
|
|
|
|
|
gimp_container_view_remove_active (editor->view);
|
2004-05-13 02:36:33 +08:00
|
|
|
}
|
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)
|
|
|
|
{
|
2008-03-25 07:03:23 +08:00
|
|
|
GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (data);
|
|
|
|
GimpContext *context = gimp_container_view_get_context (editor->view);
|
|
|
|
Gimp *gimp = context->gimp;
|
2008-11-12 04:37:15 +08:00
|
|
|
GtkWidget *dialog;
|
2005-06-21 03:28:49 +08:00
|
|
|
|
2008-11-12 04:37:15 +08: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-21 03:28:49 +08:00
|
|
|
|
2008-11-12 04:37:15 +08:00
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_STOCK_CLEAR, GTK_RESPONSE_OK,
|
2005-06-21 03:28:49 +08:00
|
|
|
|
2008-11-12 04:37:15 +08:00
|
|
|
NULL);
|
2005-06-21 03:28:49 +08:00
|
|
|
|
2008-11-12 04:37:15 +08:00
|
|
|
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
|
|
|
|
GTK_RESPONSE_OK,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
-1);
|
2005-06-21 03:28:49 +08:00
|
|
|
|
2008-11-12 04:37:15 +08:00
|
|
|
g_signal_connect_object (gtk_widget_get_toplevel (GTK_WIDGET (editor)),
|
|
|
|
"unmap",
|
|
|
|
G_CALLBACK (gtk_widget_destroy),
|
|
|
|
dialog, G_CONNECT_SWAPPED);
|
2005-06-21 03:28:49 +08:00
|
|
|
|
2008-11-12 04:37:15 +08:00
|
|
|
gimp_message_box_set_primary_text (GIMP_MESSAGE_DIALOG (dialog)->box,
|
|
|
|
_("Clear the Recent Documents list?"));
|
2005-06-21 06:15:41 +08:00
|
|
|
|
2008-11-12 04:37:15 +08:00
|
|
|
gimp_message_box_set_text (GIMP_MESSAGE_DIALOG (dialog)->box,
|
|
|
|
_("Clearing the document history will "
|
|
|
|
"permanently remove all images from "
|
|
|
|
"the recent documents list."));
|
2005-06-21 03:28:49 +08:00
|
|
|
|
2008-11-12 04:37:15 +08:00
|
|
|
if (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK)
|
|
|
|
{
|
|
|
|
GtkRecentManager *manager = gtk_recent_manager_get_default ();
|
|
|
|
GList *items;
|
|
|
|
GList *list;
|
2007-12-20 15:26:50 +08:00
|
|
|
|
2008-11-12 04:37:15 +08:00
|
|
|
items = gtk_recent_manager_get_items (manager);
|
2007-12-20 15:26:50 +08:00
|
|
|
|
2008-11-12 04:37:15 +08:00
|
|
|
for (list = items; list; list = list->next)
|
|
|
|
{
|
|
|
|
GtkRecentInfo *info = list->data;
|
2008-11-12 04:09:05 +08:00
|
|
|
|
2008-11-12 04:37:15 +08:00
|
|
|
if (gtk_recent_info_has_application (info,
|
|
|
|
"GNU Image Manipulation Program"))
|
2008-03-25 07:03:23 +08:00
|
|
|
{
|
2008-11-12 04:37:15 +08:00
|
|
|
gtk_recent_manager_remove_item (manager,
|
|
|
|
gtk_recent_info_get_uri (info),
|
|
|
|
NULL);
|
2008-03-25 07:03:23 +08:00
|
|
|
}
|
2008-11-12 04:37:15 +08:00
|
|
|
|
|
|
|
gtk_recent_info_unref (info);
|
2007-12-20 15:26:50 +08:00
|
|
|
}
|
2005-06-21 03:28:49 +08:00
|
|
|
|
2008-11-12 04:37:15 +08:00
|
|
|
g_list_free (items);
|
|
|
|
|
2008-03-25 07:03:23 +08:00
|
|
|
gimp_container_clear (gimp->documents);
|
|
|
|
}
|
2008-11-12 04:37:15 +08:00
|
|
|
|
|
|
|
gtk_widget_destroy (dialog);
|
2005-06-21 03:28:49 +08:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2009-09-01 04:47:18 +08:00
|
|
|
const gchar *uri = gimp_object_get_name (imagefile);
|
2008-03-24 19:53:05 +08:00
|
|
|
|
|
|
|
gtk_recent_manager_remove_item (gtk_recent_manager_get_default (), uri,
|
|
|
|
NULL);
|
2008-03-25 01:56:27 +08:00
|
|
|
|
|
|
|
gimp_container_remove (container, GIMP_OBJECT (imagefile));
|
2004-05-13 02:36:33 +08:00
|
|
|
}
|
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
|
2007-05-22 00:32:52 +08:00
|
|
|
documents_open_image (GtkWidget *editor,
|
|
|
|
GimpContext *context,
|
2004-05-13 02:36:33 +08:00
|
|
|
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;
|
|
|
|
|
2009-09-01 04:47:18 +08:00
|
|
|
uri = gimp_object_get_name (imagefile);
|
2004-05-13 02:36:33 +08:00
|
|
|
|
2007-04-17 23:54:01 +08:00
|
|
|
image = file_open_with_display (context->gimp, context, NULL, uri, FALSE,
|
|
|
|
&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
|
|
|
|
2007-05-22 00:32:52 +08:00
|
|
|
gimp_message (context->gimp, G_OBJECT (editor), GIMP_MESSAGE_ERROR,
|
2006-10-10 02:49:15 +08:00
|
|
|
_("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
|
2007-05-22 00:32:52 +08:00
|
|
|
documents_raise_display (GimpDisplay *display,
|
|
|
|
RaiseClosure *closure)
|
2004-10-18 19:29:58 +08:00
|
|
|
{
|
2009-10-07 01:20:44 +08:00
|
|
|
const gchar *uri = gimp_object_get_name (gimp_display_get_image (display));
|
2004-10-18 19:29:58 +08:00
|
|
|
|
|
|
|
if (uri && ! strcmp (closure->name, uri))
|
|
|
|
{
|
|
|
|
closure->found = TRUE;
|
2009-10-05 01:56:39 +08:00
|
|
|
gimp_display_shell_present (gimp_display_get_shell (display));
|
2004-10-18 19:29:58 +08:00
|
|
|
}
|
|
|
|
}
|