2001-06-26 12:09:43 +00: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"
|
|
|
|
|
2003-04-03 17:50:56 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2001-06-26 12:09:43 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2001-07-09 17:58:56 +00:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
2004-04-20 13:25:55 +00:00
|
|
|
#include "actions-types.h"
|
2001-06-26 12:09:43 +00:00
|
|
|
|
2002-11-18 20:50:31 +00:00
|
|
|
#include "config/gimpguiconfig.h"
|
|
|
|
|
2001-10-17 11:33:43 +00:00
|
|
|
#include "core/gimp.h"
|
2001-10-23 16:23:32 +00:00
|
|
|
#include "core/gimpcontainer.h"
|
2001-10-17 11:33:43 +00:00
|
|
|
#include "core/gimpcontext.h"
|
2003-04-06 11:21:56 +00:00
|
|
|
#include "core/gimplist.h"
|
2001-07-09 17:58:56 +00:00
|
|
|
#include "core/gimpimage.h"
|
2003-04-03 17:50:56 +00:00
|
|
|
#include "core/gimptemplate.h"
|
2001-07-09 17:58:56 +00:00
|
|
|
|
2001-10-25 13:30:01 +00:00
|
|
|
#include "file/file-open.h"
|
|
|
|
#include "file/file-save.h"
|
2002-04-19 14:09:53 +00:00
|
|
|
#include "file/file-utils.h"
|
2001-10-25 13:30:01 +00:00
|
|
|
|
2004-01-31 20:23:53 +00:00
|
|
|
#include "widgets/gimpdock.h"
|
2003-08-21 15:54:47 +00:00
|
|
|
#include "widgets/gimphelp-ids.h"
|
2003-05-02 18:43:15 +00:00
|
|
|
#include "widgets/gimpdialogfactory.h"
|
2004-02-27 14:20:19 +00:00
|
|
|
#include "widgets/gimpfiledialog.h"
|
2003-05-02 18:43:15 +00:00
|
|
|
|
2001-09-25 23:23:09 +00:00
|
|
|
#include "display/gimpdisplay.h"
|
2001-10-13 12:52:30 +00:00
|
|
|
#include "display/gimpdisplay-foreach.h"
|
2001-10-31 21:20:09 +00:00
|
|
|
#include "display/gimpdisplayshell.h"
|
2001-09-25 23:23:09 +00:00
|
|
|
|
2004-04-20 13:25:55 +00:00
|
|
|
#include "gui/dialogs.h"
|
|
|
|
#include "gui/file-new-dialog.h"
|
|
|
|
#include "gui/file-open-dialog.h"
|
|
|
|
#include "gui/file-save-dialog.h"
|
|
|
|
#include "gui/menus.h"
|
|
|
|
|
2001-06-26 12:09:43 +00:00
|
|
|
#include "file-commands.h"
|
|
|
|
|
2003-03-25 16:38:19 +00:00
|
|
|
#include "gimp-intl.h"
|
2001-06-26 12:09:43 +00:00
|
|
|
|
|
|
|
|
2001-07-09 17:58:56 +00:00
|
|
|
#define REVERT_DATA_KEY "revert-confirm-dialog"
|
|
|
|
|
2002-12-10 16:38:16 +00:00
|
|
|
|
|
|
|
#define return_if_no_gimp(gimp,data) \
|
|
|
|
if (GIMP_IS_DISPLAY (data)) \
|
|
|
|
gimp = ((GimpDisplay *) data)->gimage->gimp; \
|
|
|
|
else if (GIMP_IS_GIMP (data)) \
|
|
|
|
gimp = data; \
|
2004-01-31 20:23:53 +00:00
|
|
|
else if (GIMP_IS_DOCK (data)) \
|
|
|
|
gimp = ((GimpDock *) data)->context->gimp; \
|
2002-12-10 16:38:16 +00:00
|
|
|
else \
|
|
|
|
gimp = NULL; \
|
|
|
|
if (! gimp) \
|
|
|
|
return
|
|
|
|
|
|
|
|
|
2001-10-29 11:47:11 +00:00
|
|
|
#define return_if_no_display(gdisp,data) \
|
2002-12-10 16:38:16 +00:00
|
|
|
if (GIMP_IS_DISPLAY (data)) \
|
|
|
|
gdisp = data; \
|
|
|
|
else if (GIMP_IS_GIMP (data)) \
|
|
|
|
gdisp = gimp_context_get_display (gimp_get_user_context (GIMP (data))); \
|
2004-01-31 20:23:53 +00:00
|
|
|
else if (GIMP_IS_DOCK (data)) \
|
|
|
|
gdisp = gimp_context_get_display (((GimpDock *) data)->context); \
|
2002-12-10 16:38:16 +00:00
|
|
|
else \
|
|
|
|
gdisp = NULL; \
|
|
|
|
if (! gdisp) \
|
|
|
|
return
|
2001-06-26 12:09:43 +00:00
|
|
|
|
|
|
|
|
2001-07-09 17:58:56 +00:00
|
|
|
/* local function prototypes */
|
|
|
|
|
2003-09-05 01:40:29 +00:00
|
|
|
static void file_new_template_callback (GtkWidget *widget,
|
|
|
|
const gchar *name,
|
|
|
|
gpointer data);
|
|
|
|
static void file_revert_confirm_callback (GtkWidget *widget,
|
|
|
|
gboolean revert,
|
|
|
|
gpointer data);
|
2001-07-09 17:58:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
2001-06-26 12:09:43 +00:00
|
|
|
void
|
|
|
|
file_new_cmd_callback (GtkWidget *widget,
|
|
|
|
gpointer data,
|
|
|
|
guint action)
|
|
|
|
{
|
2001-10-29 11:47:11 +00:00
|
|
|
Gimp *gimp;
|
2002-12-10 16:38:16 +00:00
|
|
|
GimpImage *gimage;
|
2003-05-02 18:43:15 +00:00
|
|
|
GtkWidget *dialog;
|
2002-12-10 16:38:16 +00:00
|
|
|
return_if_no_gimp (gimp, data);
|
2001-06-26 12:09:43 +00:00
|
|
|
|
2001-10-29 11:47:11 +00:00
|
|
|
/* if called from the image menu */
|
2001-06-26 12:09:43 +00:00
|
|
|
if (action)
|
2002-11-01 16:20:13 +00:00
|
|
|
gimage = gimp_context_get_image (gimp_get_user_context (gimp));
|
2003-11-08 15:29:47 +00:00
|
|
|
else
|
2002-12-10 16:38:16 +00:00
|
|
|
gimage = NULL;
|
2001-06-26 12:09:43 +00:00
|
|
|
|
2003-05-02 18:43:15 +00:00
|
|
|
dialog = gimp_dialog_factory_dialog_new (global_dialog_factory,
|
2003-11-08 15:29:47 +00:00
|
|
|
gtk_widget_get_screen (widget),
|
2003-05-02 18:43:15 +00:00
|
|
|
"gimp-file-new-dialog", -1);
|
|
|
|
|
|
|
|
if (dialog)
|
|
|
|
file_new_dialog_set (dialog, gimage, NULL);
|
2001-06-26 12:09:43 +00:00
|
|
|
}
|
|
|
|
|
2001-07-09 17:58:56 +00:00
|
|
|
void
|
2004-02-27 14:20:19 +00:00
|
|
|
file_type_cmd_callback (GtkWidget *widget,
|
2004-04-19 16:00:54 +00:00
|
|
|
gpointer data)
|
2003-01-10 17:55:53 +00:00
|
|
|
{
|
2004-02-27 14:20:19 +00:00
|
|
|
gimp_file_dialog_set_file_proc (GIMP_FILE_DIALOG (data),
|
|
|
|
g_object_get_data (G_OBJECT (widget),
|
|
|
|
"file-proc"));
|
2001-07-09 17:58:56 +00:00
|
|
|
}
|
|
|
|
|
2001-06-26 12:09:43 +00:00
|
|
|
void
|
|
|
|
file_open_cmd_callback (GtkWidget *widget,
|
2002-11-01 16:20:13 +00:00
|
|
|
gpointer data,
|
|
|
|
guint action)
|
2001-06-26 12:09:43 +00:00
|
|
|
{
|
2002-11-01 16:20:13 +00:00
|
|
|
Gimp *gimp;
|
2002-12-10 16:38:16 +00:00
|
|
|
GimpImage *gimage;
|
|
|
|
return_if_no_gimp (gimp, data);
|
2002-11-01 16:20:13 +00:00
|
|
|
|
|
|
|
/* if called from the image menu */
|
|
|
|
if (action)
|
|
|
|
gimage = gimp_context_get_image (gimp_get_user_context (gimp));
|
2002-12-10 16:38:16 +00:00
|
|
|
else
|
|
|
|
gimage = NULL;
|
2002-11-01 16:20:13 +00:00
|
|
|
|
2003-11-09 22:05:37 +00:00
|
|
|
file_open_dialog_show (gimp, gimage, NULL, global_menu_factory, widget);
|
2001-06-26 12:09:43 +00:00
|
|
|
}
|
|
|
|
|
2001-06-29 19:25:03 +00:00
|
|
|
void
|
|
|
|
file_last_opened_cmd_callback (GtkWidget *widget,
|
|
|
|
gpointer data,
|
|
|
|
guint action)
|
|
|
|
{
|
2001-10-29 11:47:11 +00:00
|
|
|
Gimp *gimp;
|
2001-10-23 16:23:32 +00:00
|
|
|
GimpImagefile *imagefile;
|
|
|
|
guint num_entries;
|
2002-12-10 16:38:16 +00:00
|
|
|
return_if_no_gimp (gimp, data);
|
2001-10-29 11:47:11 +00:00
|
|
|
|
|
|
|
num_entries = gimp_container_num_children (gimp->documents);
|
2001-06-29 19:25:03 +00:00
|
|
|
|
|
|
|
if (action >= num_entries)
|
|
|
|
return;
|
|
|
|
|
2001-10-23 16:23:32 +00:00
|
|
|
imagefile = (GimpImagefile *)
|
2001-10-29 11:47:11 +00:00
|
|
|
gimp_container_get_child_by_index (gimp->documents, action);
|
2001-06-29 19:25:03 +00:00
|
|
|
|
2001-10-23 16:23:32 +00:00
|
|
|
if (imagefile)
|
2001-06-29 19:25:03 +00:00
|
|
|
{
|
2003-03-05 11:25:59 +00:00
|
|
|
GimpImage *gimage;
|
|
|
|
GimpPDBStatusType status;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
2004-04-14 23:37:34 +00:00
|
|
|
gimage = file_open_with_display (gimp, gimp_get_user_context (gimp),
|
|
|
|
GIMP_OBJECT (imagefile)->name,
|
2003-03-05 11:25:59 +00:00
|
|
|
&status, &error);
|
|
|
|
|
|
|
|
if (! gimage && status != GIMP_PDB_CANCEL)
|
|
|
|
{
|
|
|
|
gchar *filename;
|
2002-04-19 14:09:53 +00:00
|
|
|
|
2003-03-05 11:25:59 +00:00
|
|
|
filename =
|
|
|
|
file_utils_uri_to_utf8_filename (GIMP_OBJECT (imagefile)->name);
|
|
|
|
|
|
|
|
g_message (_("Opening '%s' failed:\n\n%s"),
|
|
|
|
filename, error->message);
|
|
|
|
g_clear_error (&error);
|
|
|
|
|
|
|
|
g_free (filename);
|
|
|
|
}
|
2001-06-29 19:25:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-26 12:09:43 +00:00
|
|
|
void
|
|
|
|
file_save_cmd_callback (GtkWidget *widget,
|
2004-04-19 16:00:54 +00:00
|
|
|
gpointer data)
|
2001-06-26 12:09:43 +00:00
|
|
|
{
|
2001-10-17 11:33:43 +00:00
|
|
|
GimpDisplay *gdisp;
|
2001-10-29 11:47:11 +00:00
|
|
|
return_if_no_display (gdisp, data);
|
2001-07-09 17:58:56 +00:00
|
|
|
|
2003-07-08 08:34:18 +00:00
|
|
|
g_return_if_fail (gimp_image_active_drawable (gdisp->gimage));
|
2001-07-09 17:58:56 +00:00
|
|
|
|
|
|
|
/* Only save if the gimage has been modified */
|
2002-11-18 20:50:31 +00:00
|
|
|
if (gdisp->gimage->dirty ||
|
|
|
|
! GIMP_GUI_CONFIG (gdisp->gimage->gimp->config)->trust_dirty_flag)
|
2001-07-09 17:58:56 +00:00
|
|
|
{
|
2002-04-14 14:38:55 +00:00
|
|
|
const gchar *uri;
|
2001-07-09 17:58:56 +00:00
|
|
|
|
2002-04-14 14:38:55 +00:00
|
|
|
uri = gimp_object_get_name (GIMP_OBJECT (gdisp->gimage));
|
2001-07-09 17:58:56 +00:00
|
|
|
|
2002-04-14 14:38:55 +00:00
|
|
|
if (! uri)
|
2001-07-09 17:58:56 +00:00
|
|
|
{
|
2004-04-19 16:00:54 +00:00
|
|
|
file_save_as_cmd_callback (widget, data);
|
2001-07-09 17:58:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-03-05 11:25:59 +00:00
|
|
|
GimpPDBStatusType status;
|
|
|
|
GError *error = NULL;
|
2001-07-09 17:58:56 +00:00
|
|
|
|
2004-04-14 23:37:34 +00:00
|
|
|
status = file_save (gdisp->gimage,
|
|
|
|
gimp_get_user_context (gdisp->gimage->gimp),
|
|
|
|
GIMP_RUN_WITH_LAST_VALS, &error);
|
2001-07-09 17:58:56 +00:00
|
|
|
|
|
|
|
if (status != GIMP_PDB_SUCCESS &&
|
|
|
|
status != GIMP_PDB_CANCEL)
|
|
|
|
{
|
2003-03-04 10:32:35 +00:00
|
|
|
gchar *filename;
|
|
|
|
|
2003-03-05 11:25:59 +00:00
|
|
|
filename = file_utils_uri_to_utf8_filename (uri);
|
2003-03-04 10:32:35 +00:00
|
|
|
|
2003-03-05 11:25:59 +00:00
|
|
|
g_message (_("Saving '%s' failed:\n\n%s"),
|
|
|
|
filename, error->message);
|
|
|
|
g_clear_error (&error);
|
2003-03-04 10:32:35 +00:00
|
|
|
|
|
|
|
g_free (filename);
|
2001-07-09 17:58:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-06-26 12:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
file_save_as_cmd_callback (GtkWidget *widget,
|
2004-04-19 16:00:54 +00:00
|
|
|
gpointer data)
|
2001-06-26 12:09:43 +00:00
|
|
|
{
|
2001-10-17 11:33:43 +00:00
|
|
|
GimpDisplay *gdisp;
|
2001-10-29 11:47:11 +00:00
|
|
|
return_if_no_display (gdisp, data);
|
2001-07-09 17:58:56 +00:00
|
|
|
|
2003-11-09 22:05:37 +00:00
|
|
|
file_save_dialog_show (gdisp->gimage, global_menu_factory, widget);
|
2001-06-26 12:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-09-01 07:44:29 +00:00
|
|
|
file_save_a_copy_cmd_callback (GtkWidget *widget,
|
2004-04-19 16:00:54 +00:00
|
|
|
gpointer data)
|
2001-06-26 12:09:43 +00:00
|
|
|
{
|
2001-10-17 11:33:43 +00:00
|
|
|
GimpDisplay *gdisp;
|
2001-10-29 11:47:11 +00:00
|
|
|
return_if_no_display (gdisp, data);
|
2001-07-09 17:58:56 +00:00
|
|
|
|
2003-11-09 22:05:37 +00:00
|
|
|
file_save_a_copy_dialog_show (gdisp->gimage, global_menu_factory, widget);
|
2001-06-26 12:09:43 +00:00
|
|
|
}
|
|
|
|
|
2003-04-03 17:50:56 +00:00
|
|
|
void
|
|
|
|
file_save_template_cmd_callback (GtkWidget *widget,
|
2004-04-19 16:00:54 +00:00
|
|
|
gpointer data)
|
2003-04-03 17:50:56 +00:00
|
|
|
{
|
|
|
|
GimpDisplay *gdisp;
|
|
|
|
GtkWidget *qbox;
|
|
|
|
return_if_no_display (gdisp, data);
|
|
|
|
|
|
|
|
qbox = gimp_query_string_box (_("Create New Template"),
|
2003-11-08 15:29:47 +00:00
|
|
|
gdisp->shell,
|
2003-04-03 17:50:56 +00:00
|
|
|
gimp_standard_help_func,
|
2003-08-21 15:54:47 +00:00
|
|
|
GIMP_HELP_FILE_SAVE_AS_TEMPLATE,
|
2003-04-03 17:50:56 +00:00
|
|
|
_("Enter a name for this template"),
|
|
|
|
NULL,
|
|
|
|
G_OBJECT (gdisp->gimage), "disconnect",
|
|
|
|
file_new_template_callback, gdisp->gimage);
|
|
|
|
gtk_widget_show (qbox);
|
|
|
|
}
|
|
|
|
|
2001-06-26 12:09:43 +00:00
|
|
|
void
|
|
|
|
file_revert_cmd_callback (GtkWidget *widget,
|
2004-04-19 16:00:54 +00:00
|
|
|
gpointer data)
|
2001-06-26 12:09:43 +00:00
|
|
|
{
|
2001-10-17 11:33:43 +00:00
|
|
|
GimpDisplay *gdisp;
|
2001-07-09 17:58:56 +00:00
|
|
|
GtkWidget *query_box;
|
2002-04-14 14:38:55 +00:00
|
|
|
const gchar *uri;
|
2001-10-29 11:47:11 +00:00
|
|
|
return_if_no_display (gdisp, data);
|
2001-07-09 17:58:56 +00:00
|
|
|
|
2002-04-14 14:38:55 +00:00
|
|
|
uri = gimp_object_get_name (GIMP_OBJECT (gdisp->gimage));
|
2001-07-09 17:58:56 +00:00
|
|
|
|
2001-08-14 16:33:28 +00:00
|
|
|
query_box = g_object_get_data (G_OBJECT (gdisp->gimage), REVERT_DATA_KEY);
|
2001-07-09 17:58:56 +00:00
|
|
|
|
2002-04-14 14:38:55 +00:00
|
|
|
if (! uri)
|
2001-07-09 17:58:56 +00:00
|
|
|
{
|
2003-11-14 15:33:40 +00:00
|
|
|
g_message (_("Revert failed. No file name associated with this image."));
|
2001-07-09 17:58:56 +00:00
|
|
|
}
|
|
|
|
else if (query_box)
|
|
|
|
{
|
2002-10-25 01:11:24 +00:00
|
|
|
gtk_window_present (GTK_WINDOW (query_box->window));
|
2001-07-09 17:58:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-08-29 17:48:28 +00:00
|
|
|
gchar *basename;
|
2001-07-09 17:58:56 +00:00
|
|
|
gchar *text;
|
|
|
|
|
2002-04-14 14:38:55 +00:00
|
|
|
basename = g_path_get_basename (uri);
|
2001-08-29 17:48:28 +00:00
|
|
|
|
2001-11-26 17:12:29 +00:00
|
|
|
text = g_strdup_printf (_("Revert '%s' to\n"
|
2002-02-28 10:36:06 +00:00
|
|
|
"'%s'?\n\n"
|
2003-03-20 14:34:16 +00:00
|
|
|
"You will lose all your changes, "
|
|
|
|
"including all undo information."),
|
2002-04-14 14:38:55 +00:00
|
|
|
basename, uri);
|
2001-08-29 17:48:28 +00:00
|
|
|
|
|
|
|
g_free (basename);
|
2001-07-09 17:58:56 +00:00
|
|
|
|
2001-11-26 17:12:29 +00:00
|
|
|
query_box = gimp_query_boolean_box (_("Revert Image"),
|
2003-11-08 15:29:47 +00:00
|
|
|
gdisp->shell,
|
2001-07-09 17:58:56 +00:00
|
|
|
gimp_standard_help_func,
|
2003-08-21 15:54:47 +00:00
|
|
|
GIMP_HELP_FILE_REVERT,
|
2003-03-06 16:47:34 +00:00
|
|
|
GIMP_STOCK_QUESTION,
|
2001-07-09 17:58:56 +00:00
|
|
|
text,
|
2001-07-30 17:17:36 +00:00
|
|
|
GTK_STOCK_YES, GTK_STOCK_NO,
|
2001-08-11 21:10:44 +00:00
|
|
|
G_OBJECT (gdisp->gimage),
|
|
|
|
"disconnect",
|
2001-07-09 17:58:56 +00:00
|
|
|
file_revert_confirm_callback,
|
|
|
|
gdisp->gimage);
|
|
|
|
|
|
|
|
g_free (text);
|
|
|
|
|
2001-08-14 16:33:28 +00:00
|
|
|
g_object_set_data (G_OBJECT (gdisp->gimage), REVERT_DATA_KEY,
|
|
|
|
query_box);
|
2001-07-09 17:58:56 +00:00
|
|
|
|
2003-03-20 14:34:16 +00:00
|
|
|
gtk_window_set_transient_for (GTK_WINDOW (query_box),
|
|
|
|
GTK_WINDOW (gdisp->shell));
|
|
|
|
|
2001-07-09 17:58:56 +00:00
|
|
|
gtk_widget_show (query_box);
|
|
|
|
}
|
2001-06-26 12:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
file_close_cmd_callback (GtkWidget *widget,
|
2004-04-19 16:00:54 +00:00
|
|
|
gpointer data)
|
2001-06-26 12:09:43 +00:00
|
|
|
{
|
2001-10-17 11:33:43 +00:00
|
|
|
GimpDisplay *gdisp;
|
2001-10-29 11:47:11 +00:00
|
|
|
return_if_no_display (gdisp, data);
|
2001-06-26 12:09:43 +00:00
|
|
|
|
2001-10-31 21:20:09 +00:00
|
|
|
gimp_display_shell_close (GIMP_DISPLAY_SHELL (gdisp->shell), FALSE);
|
2001-06-26 12:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
file_quit_cmd_callback (GtkWidget *widget,
|
2004-04-19 16:00:54 +00:00
|
|
|
gpointer data)
|
2001-06-26 12:09:43 +00:00
|
|
|
{
|
2002-12-10 16:38:16 +00:00
|
|
|
Gimp *gimp;
|
|
|
|
return_if_no_gimp (gimp, data);
|
|
|
|
|
|
|
|
gimp_exit (gimp, FALSE);
|
2001-06-26 12:09:43 +00:00
|
|
|
}
|
2001-07-09 17:58:56 +00:00
|
|
|
|
2003-01-10 17:55:53 +00:00
|
|
|
void
|
|
|
|
file_file_open_dialog (Gimp *gimp,
|
2003-11-09 22:05:37 +00:00
|
|
|
const gchar *uri,
|
|
|
|
GtkWidget *parent)
|
2003-01-10 17:55:53 +00:00
|
|
|
{
|
2003-11-09 22:05:37 +00:00
|
|
|
file_open_dialog_show (gimp, NULL, uri, global_menu_factory, parent);
|
2003-01-10 17:55:53 +00:00
|
|
|
}
|
2001-07-09 17:58:56 +00:00
|
|
|
|
2003-04-03 17:50:56 +00:00
|
|
|
|
2001-07-09 17:58:56 +00:00
|
|
|
/* private functions */
|
|
|
|
|
2003-04-03 17:50:56 +00:00
|
|
|
static void
|
2003-09-05 01:40:29 +00:00
|
|
|
file_new_template_callback (GtkWidget *widget,
|
|
|
|
const gchar *name,
|
|
|
|
gpointer data)
|
2003-04-03 17:50:56 +00:00
|
|
|
{
|
|
|
|
GimpTemplate *template;
|
|
|
|
GimpImage *gimage;
|
|
|
|
|
|
|
|
gimage = (GimpImage *) data;
|
|
|
|
|
|
|
|
if (! (name && strlen (name)))
|
|
|
|
name = _("(Unnamed Template)");
|
|
|
|
|
|
|
|
template = gimp_template_new (name);
|
|
|
|
gimp_template_set_from_image (template, gimage);
|
|
|
|
|
2003-04-06 11:21:56 +00:00
|
|
|
gimp_list_uniquefy_name (GIMP_LIST (gimage->gimp->templates),
|
|
|
|
GIMP_OBJECT (template), TRUE);
|
2003-04-03 17:50:56 +00:00
|
|
|
gimp_container_add (gimage->gimp->templates,
|
|
|
|
GIMP_OBJECT (template));
|
|
|
|
g_object_unref (template);
|
|
|
|
}
|
|
|
|
|
2001-07-09 17:58:56 +00:00
|
|
|
static void
|
|
|
|
file_revert_confirm_callback (GtkWidget *widget,
|
|
|
|
gboolean revert,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GimpImage *old_gimage;
|
|
|
|
|
|
|
|
old_gimage = (GimpImage *) data;
|
|
|
|
|
2001-08-14 16:33:28 +00:00
|
|
|
g_object_set_data (G_OBJECT (old_gimage), REVERT_DATA_KEY, NULL);
|
2001-07-09 17:58:56 +00:00
|
|
|
|
|
|
|
if (revert)
|
|
|
|
{
|
2003-05-17 16:34:30 +00:00
|
|
|
Gimp *gimp;
|
2001-10-29 11:47:11 +00:00
|
|
|
GimpImage *new_gimage;
|
2002-04-14 14:38:55 +00:00
|
|
|
const gchar *uri;
|
2001-10-29 11:47:11 +00:00
|
|
|
GimpPDBStatusType status;
|
2002-04-19 14:09:53 +00:00
|
|
|
GError *error = NULL;
|
2001-07-09 17:58:56 +00:00
|
|
|
|
2003-05-17 16:34:30 +00:00
|
|
|
gimp = old_gimage->gimp;
|
|
|
|
|
2002-04-14 14:38:55 +00:00
|
|
|
uri = gimp_object_get_name (GIMP_OBJECT (old_gimage));
|
2001-07-09 17:58:56 +00:00
|
|
|
|
2004-04-14 23:37:34 +00:00
|
|
|
new_gimage = file_open_image (gimp, gimp_get_user_context (gimp),
|
|
|
|
uri, uri, NULL,
|
2001-12-19 00:13:16 +00:00
|
|
|
GIMP_RUN_INTERACTIVE,
|
2003-05-17 16:34:30 +00:00
|
|
|
&status, &error);
|
2001-07-09 17:58:56 +00:00
|
|
|
|
2002-04-19 14:09:53 +00:00
|
|
|
if (new_gimage)
|
2001-07-09 17:58:56 +00:00
|
|
|
{
|
2003-05-17 16:34:30 +00:00
|
|
|
GList *contexts = NULL;
|
|
|
|
GList *list;
|
2001-10-31 21:20:09 +00:00
|
|
|
|
2003-05-17 16:34:30 +00:00
|
|
|
/* remember which contexts refer to old_gimage */
|
|
|
|
for (list = gimp->context_list; list; list = g_list_next (list))
|
|
|
|
{
|
|
|
|
GimpContext *context = list->data;
|
2001-10-31 21:20:09 +00:00
|
|
|
|
2003-05-17 16:34:30 +00:00
|
|
|
if (gimp_context_get_image (context) == old_gimage)
|
|
|
|
contexts = g_list_prepend (contexts, list->data);
|
|
|
|
}
|
2001-10-31 21:20:09 +00:00
|
|
|
|
2003-05-17 16:34:30 +00:00
|
|
|
gimp_displays_reconnect (gimp, old_gimage, new_gimage);
|
2002-05-08 17:48:24 +00:00
|
|
|
gimp_image_flush (new_gimage);
|
2003-05-17 16:34:30 +00:00
|
|
|
|
|
|
|
/* set the new_gimage on the remembered contexts (in reverse
|
|
|
|
* order, since older contexts are usually the parents of
|
|
|
|
* newer ones)
|
|
|
|
*/
|
|
|
|
g_list_foreach (contexts, (GFunc) gimp_context_set_image, new_gimage);
|
|
|
|
g_list_free (contexts);
|
|
|
|
|
|
|
|
/* the displays own the image now */
|
|
|
|
g_object_unref (new_gimage);
|
2001-07-09 17:58:56 +00:00
|
|
|
}
|
|
|
|
else if (status != GIMP_PDB_CANCEL)
|
|
|
|
{
|
2002-04-19 14:09:53 +00:00
|
|
|
gchar *filename;
|
|
|
|
|
|
|
|
filename = file_utils_uri_to_utf8_filename (uri);
|
|
|
|
|
2003-03-05 11:25:59 +00:00
|
|
|
g_message (_("Reverting to '%s' failed:\n\n%s"),
|
2002-04-19 14:09:53 +00:00
|
|
|
filename, error->message);
|
2003-03-05 11:25:59 +00:00
|
|
|
g_clear_error (&error);
|
2002-04-19 14:09:53 +00:00
|
|
|
|
|
|
|
g_free (filename);
|
2001-07-09 17:58:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|