2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2001-06-26 20:09:43 +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-06-26 20:09:43 +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-06-26 20:09:43 +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-06-26 20:09:43 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2003-04-04 01:50:56 +08:00
|
|
|
#include <string.h>
|
|
|
|
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.h>
|
2001-06-26 20:09:43 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2001-07-10 01:58:56 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
2004-04-20 21:25:55 +08:00
|
|
|
#include "actions-types.h"
|
2001-06-26 20:09:43 +08:00
|
|
|
|
2002-11-19 04:50:31 +08:00
|
|
|
#include "config/gimpguiconfig.h"
|
|
|
|
|
2001-10-17 19:33:43 +08:00
|
|
|
#include "core/gimp.h"
|
2001-10-24 00:23:32 +08:00
|
|
|
#include "core/gimpcontainer.h"
|
2001-07-10 01:58:56 +08:00
|
|
|
#include "core/gimpimage.h"
|
2004-08-11 02:47:21 +08:00
|
|
|
#include "core/gimpprogress.h"
|
2003-04-04 01:50:56 +08:00
|
|
|
#include "core/gimptemplate.h"
|
2001-07-10 01:58:56 +08:00
|
|
|
|
2006-04-29 06:26:51 +08:00
|
|
|
#include "plug-in/gimppluginmanager.h"
|
|
|
|
|
2001-10-25 21:30:01 +08:00
|
|
|
#include "file/file-open.h"
|
2007-05-12 02:50:35 +08:00
|
|
|
#include "file/file-procedure.h"
|
2001-10-25 21:30:01 +08:00
|
|
|
#include "file/file-save.h"
|
2002-04-19 22:09:53 +08:00
|
|
|
#include "file/file-utils.h"
|
2009-05-01 15:03:13 +08:00
|
|
|
#include "file/gimp-file.h"
|
2001-10-25 21:30:01 +08:00
|
|
|
|
2005-10-29 09:43:14 +08:00
|
|
|
#include "widgets/gimpactiongroup.h"
|
2004-09-09 17:47:33 +08:00
|
|
|
#include "widgets/gimpdialogfactory.h"
|
2004-09-14 00:01:52 +08:00
|
|
|
#include "widgets/gimpfiledialog.h"
|
2003-08-21 23:54:47 +08:00
|
|
|
#include "widgets/gimphelp-ids.h"
|
2004-10-13 23:27:00 +08:00
|
|
|
#include "widgets/gimpmessagebox.h"
|
|
|
|
#include "widgets/gimpmessagedialog.h"
|
2003-05-03 02:43:15 +08:00
|
|
|
|
2001-09-26 07:23:09 +08:00
|
|
|
#include "display/gimpdisplay.h"
|
2001-10-13 20:52:30 +08:00
|
|
|
#include "display/gimpdisplay-foreach.h"
|
2001-09-26 07:23:09 +08:00
|
|
|
|
2009-05-02 21:58:32 +08:00
|
|
|
#include "dialogs/file-save-dialog.h"
|
2004-04-20 21:25:55 +08:00
|
|
|
|
2004-05-03 22:03:51 +08:00
|
|
|
#include "actions.h"
|
2001-06-26 20:09:43 +08:00
|
|
|
#include "file-commands.h"
|
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2001-06-26 20:09:43 +08:00
|
|
|
|
|
|
|
|
2001-07-10 01:58:56 +08:00
|
|
|
#define REVERT_DATA_KEY "revert-confirm-dialog"
|
|
|
|
|
2002-12-11 00:38:16 +08:00
|
|
|
|
2001-07-10 01:58:56 +08:00
|
|
|
/* local function prototypes */
|
|
|
|
|
2009-04-26 23:22:56 +08:00
|
|
|
static void file_open_dialog_show (Gimp *gimp,
|
|
|
|
GtkWidget *parent,
|
|
|
|
const gchar *title,
|
|
|
|
GimpImage *image,
|
|
|
|
const gchar *uri,
|
|
|
|
gboolean open_as_layers);
|
2009-05-01 18:22:41 +08:00
|
|
|
static void file_save_dialog_show (Gimp *gimp,
|
|
|
|
GimpImage *image,
|
2009-04-26 23:22:56 +08:00
|
|
|
GtkWidget *parent,
|
|
|
|
const gchar *title,
|
|
|
|
gboolean save_a_copy,
|
|
|
|
gboolean close_after_saving);
|
2009-04-25 16:54:56 +08:00
|
|
|
static void file_export_dialog_show (Gimp *gimp,
|
|
|
|
GimpImage *image,
|
|
|
|
GtkWidget *parent);
|
2009-04-26 23:22:56 +08:00
|
|
|
static void file_save_dialog_destroyed (GtkWidget *dialog,
|
|
|
|
GimpImage *image);
|
2009-04-25 16:54:56 +08:00
|
|
|
static void file_export_dialog_destroyed (GtkWidget *dialog,
|
|
|
|
GimpImage *image);
|
2009-04-26 23:22:56 +08:00
|
|
|
static void file_new_template_callback (GtkWidget *widget,
|
|
|
|
const gchar *name,
|
|
|
|
gpointer data);
|
|
|
|
static void file_revert_confirm_response (GtkWidget *dialog,
|
|
|
|
gint response_id,
|
|
|
|
GimpDisplay *display);
|
|
|
|
|
2001-07-10 01:58:56 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
2007-01-16 03:48:36 +08:00
|
|
|
|
2001-06-26 20:09:43 +08:00
|
|
|
void
|
2004-05-25 20:02:54 +08:00
|
|
|
file_open_cmd_callback (GtkAction *action,
|
2004-07-01 00:01:05 +08:00
|
|
|
gpointer data)
|
2001-06-26 20:09:43 +08:00
|
|
|
{
|
2008-07-30 22:53:09 +08:00
|
|
|
Gimp *gimp;
|
2005-01-14 01:41:48 +08:00
|
|
|
GtkWidget *widget;
|
2008-10-05 23:21:02 +08:00
|
|
|
GimpImage *image;
|
2008-07-30 22:53:09 +08:00
|
|
|
return_if_no_gimp (gimp, data);
|
2004-04-29 20:52:29 +08:00
|
|
|
return_if_no_widget (widget, data);
|
2002-11-02 00:20:13 +08:00
|
|
|
|
2005-01-14 01:41:48 +08:00
|
|
|
image = action_data_get_image (data);
|
|
|
|
|
2008-10-05 23:21:02 +08:00
|
|
|
file_open_dialog_show (gimp, widget,
|
|
|
|
_("Open Image"),
|
|
|
|
image, NULL, FALSE);
|
2004-09-21 20:08:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-11-05 19:35:57 +08:00
|
|
|
file_open_as_layers_cmd_callback (GtkAction *action,
|
|
|
|
gpointer data)
|
2004-09-21 20:08:30 +08:00
|
|
|
{
|
2008-07-30 22:53:09 +08:00
|
|
|
Gimp *gimp;
|
2004-09-21 20:08:30 +08:00
|
|
|
GtkWidget *widget;
|
2008-10-05 23:21:02 +08:00
|
|
|
GimpDisplay *display;
|
|
|
|
GimpImage *image = NULL;
|
2008-07-30 22:53:09 +08:00
|
|
|
return_if_no_gimp (gimp, data);
|
2004-09-21 20:08:30 +08:00
|
|
|
return_if_no_widget (widget, data);
|
|
|
|
|
2008-10-05 23:21:02 +08:00
|
|
|
display = action_data_get_display (data);
|
|
|
|
|
|
|
|
if (display)
|
2009-10-07 01:20:44 +08:00
|
|
|
image = gimp_display_get_image (display);
|
2005-02-25 01:18:11 +08:00
|
|
|
|
2008-10-05 23:21:02 +08:00
|
|
|
file_open_dialog_show (gimp, widget,
|
|
|
|
_("Open Image as Layers"),
|
|
|
|
image, NULL, TRUE);
|
2001-06-26 20:09:43 +08:00
|
|
|
}
|
|
|
|
|
2004-05-31 22:40:10 +08:00
|
|
|
void
|
|
|
|
file_open_location_cmd_callback (GtkAction *action,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
return_if_no_widget (widget, data);
|
|
|
|
|
2010-03-01 06:20:57 +08:00
|
|
|
gimp_dialog_factory_dialog_new (gimp_dialog_factory_get_singleton (),
|
2004-09-09 17:47:33 +08:00
|
|
|
gtk_widget_get_screen (widget),
|
2010-05-16 18:19:18 +08:00
|
|
|
NULL /*ui_manager*/,
|
2004-09-09 17:47:33 +08:00
|
|
|
"gimp-file-open-location-dialog", -1, TRUE);
|
2004-05-31 22:40:10 +08:00
|
|
|
}
|
|
|
|
|
2001-06-30 03:25:03 +08:00
|
|
|
void
|
2008-03-25 17:33:28 +08:00
|
|
|
file_open_recent_cmd_callback (GtkAction *action,
|
2004-04-29 20:52:29 +08:00
|
|
|
gint value,
|
2004-07-01 00:01:05 +08:00
|
|
|
gpointer data)
|
2001-06-30 03:25:03 +08:00
|
|
|
{
|
2001-10-29 19:47:11 +08:00
|
|
|
Gimp *gimp;
|
2001-10-24 00:23:32 +08:00
|
|
|
GimpImagefile *imagefile;
|
2004-04-29 20:52:29 +08:00
|
|
|
gint num_entries;
|
2002-12-11 00:38:16 +08:00
|
|
|
return_if_no_gimp (gimp, data);
|
2001-10-29 19:47:11 +08:00
|
|
|
|
2008-11-21 06:45:19 +08:00
|
|
|
num_entries = gimp_container_get_n_children (gimp->documents);
|
2001-06-30 03:25:03 +08:00
|
|
|
|
2004-04-29 20:52:29 +08:00
|
|
|
if (value >= num_entries)
|
2001-06-30 03:25:03 +08:00
|
|
|
return;
|
|
|
|
|
2001-10-24 00:23:32 +08:00
|
|
|
imagefile = (GimpImagefile *)
|
2004-04-29 20:52:29 +08:00
|
|
|
gimp_container_get_child_by_index (gimp->documents, value);
|
2001-06-30 03:25:03 +08:00
|
|
|
|
2001-10-24 00:23:32 +08:00
|
|
|
if (imagefile)
|
2001-06-30 03:25:03 +08:00
|
|
|
{
|
2008-03-25 17:33:28 +08:00
|
|
|
GimpDisplay *display;
|
|
|
|
GimpProgress *progress;
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image;
|
2003-03-05 19:25:59 +08:00
|
|
|
GimpPDBStatusType status;
|
|
|
|
GError *error = NULL;
|
2008-03-25 17:33:28 +08:00
|
|
|
return_if_no_display (display, data);
|
|
|
|
|
2008-10-21 15:51:08 +08:00
|
|
|
g_object_ref (display);
|
|
|
|
g_object_ref (imagefile);
|
|
|
|
|
2009-10-07 01:20:44 +08:00
|
|
|
progress = gimp_display_get_image (display) ?
|
|
|
|
NULL : GIMP_PROGRESS (display);
|
2003-03-05 19:25:59 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
image = file_open_with_display (gimp, action_data_get_context (data),
|
2008-03-25 17:33:28 +08:00
|
|
|
progress,
|
2009-08-29 18:40:40 +08:00
|
|
|
gimp_object_get_name (imagefile), FALSE,
|
2006-07-12 14:10:52 +08:00
|
|
|
&status, &error);
|
2003-03-05 19:25:59 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
if (! image && status != GIMP_PDB_CANCEL)
|
2003-03-05 19:25:59 +08:00
|
|
|
{
|
2005-10-02 06:43:22 +08:00
|
|
|
gchar *filename =
|
2009-08-29 18:40:40 +08:00
|
|
|
file_utils_uri_display_name (gimp_object_get_name (imagefile));
|
2003-03-05 19:25:59 +08:00
|
|
|
|
2008-03-25 17:33:28 +08:00
|
|
|
gimp_message (gimp, G_OBJECT (display), GIMP_MESSAGE_ERROR,
|
2006-10-09 16:17:22 +08:00
|
|
|
_("Opening '%s' failed:\n\n%s"),
|
|
|
|
filename, error->message);
|
2003-03-05 19:25:59 +08:00
|
|
|
g_clear_error (&error);
|
|
|
|
|
|
|
|
g_free (filename);
|
|
|
|
}
|
2008-10-21 15:51:08 +08:00
|
|
|
|
|
|
|
g_object_unref (imagefile);
|
|
|
|
g_object_unref (display);
|
2001-06-30 03:25:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-26 20:09:43 +08:00
|
|
|
void
|
2004-04-29 20:52:29 +08:00
|
|
|
file_save_cmd_callback (GtkAction *action,
|
2007-01-21 03:38:09 +08:00
|
|
|
gint value,
|
2004-07-01 00:01:05 +08:00
|
|
|
gpointer data)
|
2001-06-26 20:09:43 +08:00
|
|
|
{
|
2009-05-01 18:22:41 +08:00
|
|
|
Gimp *gimp;
|
2007-01-21 03:38:09 +08:00
|
|
|
GimpDisplay *display;
|
|
|
|
GimpImage *image;
|
|
|
|
GtkWidget *widget;
|
|
|
|
GimpSaveMode save_mode;
|
2008-08-15 15:38:32 +08:00
|
|
|
const gchar *uri;
|
2007-01-21 03:38:09 +08:00
|
|
|
gboolean saved = FALSE;
|
2009-05-01 18:22:41 +08:00
|
|
|
return_if_no_gimp (gimp, data);
|
2006-03-29 01:55:52 +08:00
|
|
|
return_if_no_display (display, data);
|
2007-01-21 03:38:09 +08:00
|
|
|
return_if_no_widget (widget, data);
|
2001-07-10 01:58:56 +08:00
|
|
|
|
2009-10-07 01:20:44 +08:00
|
|
|
image = gimp_display_get_image (display);
|
2005-02-14 02:05:43 +08:00
|
|
|
|
2007-01-21 03:38:09 +08:00
|
|
|
save_mode = (GimpSaveMode) value;
|
|
|
|
|
2007-07-19 22:59:51 +08:00
|
|
|
if (! gimp_image_get_active_drawable (image))
|
2004-10-24 03:13:17 +08:00
|
|
|
return;
|
2001-07-10 01:58:56 +08:00
|
|
|
|
2011-01-26 15:19:39 +08:00
|
|
|
uri = gimp_image_get_uri (image);
|
2008-08-15 15:38:32 +08:00
|
|
|
|
2007-01-21 03:38:09 +08:00
|
|
|
switch (save_mode)
|
2001-07-10 01:58:56 +08:00
|
|
|
{
|
2007-01-21 03:38:09 +08:00
|
|
|
case GIMP_SAVE_MODE_SAVE:
|
|
|
|
case GIMP_SAVE_MODE_SAVE_AND_CLOSE:
|
2008-08-15 15:38:32 +08:00
|
|
|
/* Only save if the image has been modified, or if it is new. */
|
2009-07-04 03:11:21 +08:00
|
|
|
if ((gimp_image_is_dirty (image) ||
|
2008-08-15 15:38:32 +08:00
|
|
|
! GIMP_GUI_CONFIG (image->gimp->config)->trust_dirty_flag) ||
|
|
|
|
uri == NULL)
|
2004-07-01 00:01:05 +08:00
|
|
|
{
|
2008-08-15 15:38:32 +08:00
|
|
|
GimpPlugInProcedure *save_proc = gimp_image_get_save_proc (image);
|
2001-07-10 01:58:56 +08:00
|
|
|
|
2007-01-21 03:38:09 +08:00
|
|
|
if (uri && ! save_proc)
|
2008-08-15 15:38:32 +08:00
|
|
|
{
|
|
|
|
save_proc =
|
|
|
|
file_procedure_find (image->gimp->plug_in_manager->save_procs,
|
|
|
|
uri, NULL);
|
|
|
|
}
|
2001-07-10 01:58:56 +08:00
|
|
|
|
2007-01-21 03:38:09 +08:00
|
|
|
if (uri && save_proc)
|
2006-10-09 16:17:22 +08:00
|
|
|
{
|
2009-05-02 21:58:32 +08:00
|
|
|
saved = file_save_dialog_save_image (GIMP_PROGRESS (display),
|
|
|
|
gimp, image, uri,
|
|
|
|
save_proc,
|
|
|
|
GIMP_RUN_WITH_LAST_VALS,
|
2009-05-16 17:28:53 +08:00
|
|
|
TRUE, FALSE, TRUE);
|
2006-10-09 16:17:22 +08:00
|
|
|
break;
|
2004-07-01 00:01:05 +08:00
|
|
|
}
|
2005-10-29 09:43:14 +08:00
|
|
|
|
2007-01-21 03:38:09 +08:00
|
|
|
/* fall thru */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-11-04 20:33:09 +08:00
|
|
|
gimp_message_literal (image->gimp,
|
|
|
|
G_OBJECT (display), GIMP_MESSAGE_INFO,
|
|
|
|
_("No changes need to be saved"));
|
2007-01-21 03:38:09 +08:00
|
|
|
saved = TRUE;
|
|
|
|
break;
|
2004-07-01 00:01:05 +08:00
|
|
|
}
|
2006-12-12 04:33:01 +08:00
|
|
|
|
2007-01-21 03:38:09 +08:00
|
|
|
case GIMP_SAVE_MODE_SAVE_AS:
|
2009-10-07 01:20:44 +08:00
|
|
|
file_save_dialog_show (gimp, image, widget,
|
2007-01-21 03:38:09 +08:00
|
|
|
_("Save Image"), FALSE,
|
|
|
|
save_mode == GIMP_SAVE_MODE_SAVE_AND_CLOSE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_SAVE_MODE_SAVE_A_COPY:
|
2009-10-07 01:20:44 +08:00
|
|
|
file_save_dialog_show (gimp, image, widget,
|
2007-01-21 03:38:09 +08:00
|
|
|
_("Save a Copy of the Image"), TRUE,
|
|
|
|
FALSE);
|
|
|
|
break;
|
2009-04-24 00:59:40 +08:00
|
|
|
|
|
|
|
case GIMP_SAVE_MODE_EXPORT:
|
2009-10-07 01:20:44 +08:00
|
|
|
file_export_dialog_show (gimp, image, widget);
|
2009-04-25 16:54:56 +08:00
|
|
|
break;
|
|
|
|
|
2009-04-24 00:59:40 +08:00
|
|
|
case GIMP_SAVE_MODE_EXPORT_TO:
|
2009-04-26 23:44:10 +08:00
|
|
|
{
|
|
|
|
const gchar *uri;
|
|
|
|
GimpPlugInProcedure *export_proc;
|
|
|
|
|
2011-01-27 03:45:32 +08:00
|
|
|
uri = gimp_image_get_exported_uri (image);
|
2009-07-05 15:09:12 +08:00
|
|
|
|
|
|
|
if (!uri)
|
2011-01-27 03:45:32 +08:00
|
|
|
uri = gimp_image_get_imported_uri (image);
|
2009-07-05 15:09:12 +08:00
|
|
|
|
2009-04-26 23:44:10 +08:00
|
|
|
if (uri)
|
|
|
|
{
|
|
|
|
export_proc =
|
|
|
|
file_procedure_find (image->gimp->plug_in_manager->export_procs,
|
|
|
|
uri, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (uri && export_proc)
|
|
|
|
{
|
2011-05-07 08:21:30 +08:00
|
|
|
char *uri_copy;
|
|
|
|
|
|
|
|
/* The memory that 'uri' points to can be freed by
|
|
|
|
file_save_dialog_save_image(), when it eventually calls
|
|
|
|
gimp_image_set_imported_uri() to reset the imported uri,
|
|
|
|
resulting in garbage. So make a duplicate of it here. */
|
|
|
|
|
|
|
|
uri_copy = g_strdup (uri);
|
|
|
|
|
2009-04-26 23:44:10 +08:00
|
|
|
saved = file_save_dialog_save_image (GIMP_PROGRESS (display),
|
2011-05-07 08:21:30 +08:00
|
|
|
gimp, image, uri_copy,
|
2009-04-26 23:44:10 +08:00
|
|
|
export_proc,
|
|
|
|
GIMP_RUN_WITH_LAST_VALS,
|
2009-05-16 17:28:53 +08:00
|
|
|
FALSE, TRUE, TRUE);
|
2011-05-07 08:21:30 +08:00
|
|
|
g_free (uri_copy);
|
2009-04-26 23:44:10 +08:00
|
|
|
}
|
|
|
|
}
|
2009-04-24 00:59:40 +08:00
|
|
|
break;
|
2007-01-21 03:38:09 +08:00
|
|
|
}
|
2006-12-12 04:33:01 +08:00
|
|
|
|
2007-01-21 03:38:09 +08:00
|
|
|
if (save_mode == GIMP_SAVE_MODE_SAVE_AND_CLOSE &&
|
2009-07-04 03:11:21 +08:00
|
|
|
saved &&
|
2009-10-07 01:20:44 +08:00
|
|
|
! gimp_image_is_dirty (image))
|
2007-01-21 03:38:09 +08:00
|
|
|
{
|
2008-04-06 04:32:24 +08:00
|
|
|
gimp_display_close (display);
|
2007-01-21 03:38:09 +08:00
|
|
|
}
|
2006-12-12 04:33:01 +08:00
|
|
|
}
|
|
|
|
|
2003-04-04 01:50:56 +08:00
|
|
|
void
|
2009-04-26 14:24:02 +08:00
|
|
|
file_create_template_cmd_callback (GtkAction *action,
|
|
|
|
gpointer data)
|
2003-04-04 01:50:56 +08:00
|
|
|
{
|
2006-03-29 01:55:52 +08:00
|
|
|
GimpDisplay *display;
|
2009-10-07 01:20:44 +08:00
|
|
|
GimpImage *image;
|
2004-10-19 22:08:44 +08:00
|
|
|
GtkWidget *dialog;
|
2006-03-29 01:55:52 +08:00
|
|
|
return_if_no_display (display, data);
|
2003-04-04 01:50:56 +08:00
|
|
|
|
2009-10-07 01:20:44 +08:00
|
|
|
image = gimp_display_get_image (display);
|
|
|
|
|
2004-10-19 22:08:44 +08:00
|
|
|
dialog = gimp_query_string_box (_("Create New Template"),
|
2009-10-06 01:58:03 +08:00
|
|
|
GTK_WIDGET (gimp_display_get_shell (display)),
|
2004-10-19 22:08:44 +08:00
|
|
|
gimp_standard_help_func,
|
2009-04-26 14:24:02 +08:00
|
|
|
GIMP_HELP_FILE_CREATE_TEMPLATE,
|
2004-10-19 22:08:44 +08:00
|
|
|
_("Enter a name for this template"),
|
|
|
|
NULL,
|
2009-10-07 01:20:44 +08:00
|
|
|
G_OBJECT (image), "disconnect",
|
|
|
|
file_new_template_callback, image);
|
2004-10-19 22:08:44 +08:00
|
|
|
gtk_widget_show (dialog);
|
2003-04-04 01:50:56 +08:00
|
|
|
}
|
|
|
|
|
2001-06-26 20:09:43 +08:00
|
|
|
void
|
2004-04-29 20:52:29 +08:00
|
|
|
file_revert_cmd_callback (GtkAction *action,
|
2004-07-01 00:01:05 +08:00
|
|
|
gpointer data)
|
2001-06-26 20:09:43 +08:00
|
|
|
{
|
2006-03-29 01:55:52 +08:00
|
|
|
GimpDisplay *display;
|
2006-08-09 05:06:36 +08:00
|
|
|
GimpImage *image;
|
2004-10-13 23:27:00 +08:00
|
|
|
GtkWidget *dialog;
|
2009-04-26 19:00:25 +08:00
|
|
|
const gchar *uri = NULL;
|
|
|
|
const gchar *source = NULL;
|
2006-03-29 01:55:52 +08:00
|
|
|
return_if_no_display (display, data);
|
2001-07-10 01:58:56 +08:00
|
|
|
|
2009-10-07 01:20:44 +08:00
|
|
|
image = gimp_display_get_image (display);
|
2001-07-10 01:58:56 +08:00
|
|
|
|
2011-01-26 15:19:39 +08:00
|
|
|
uri = gimp_image_get_uri (image);
|
2006-08-09 05:06:36 +08:00
|
|
|
|
2009-04-26 19:00:25 +08:00
|
|
|
if (! uri)
|
|
|
|
{
|
2011-01-27 03:45:32 +08:00
|
|
|
uri = gimp_image_get_imported_uri (image);
|
2009-04-26 19:00:25 +08:00
|
|
|
source = uri;
|
|
|
|
}
|
|
|
|
|
2006-08-09 05:06:36 +08:00
|
|
|
dialog = g_object_get_data (G_OBJECT (image), REVERT_DATA_KEY);
|
2001-07-10 01:58:56 +08:00
|
|
|
|
2009-04-26 19:00:25 +08:00
|
|
|
if (! uri && ! source)
|
2001-07-10 01:58:56 +08:00
|
|
|
{
|
2008-11-04 20:33:09 +08:00
|
|
|
gimp_message_literal (image->gimp,
|
|
|
|
G_OBJECT (display), GIMP_MESSAGE_ERROR,
|
|
|
|
_("Revert failed. "
|
|
|
|
"No file name associated with this image."));
|
2001-07-10 01:58:56 +08:00
|
|
|
}
|
2004-10-13 23:27:00 +08:00
|
|
|
else if (dialog)
|
2001-07-10 01:58:56 +08:00
|
|
|
{
|
2004-10-13 23:27:00 +08:00
|
|
|
gtk_window_present (GTK_WINDOW (dialog));
|
2001-07-10 01:58:56 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-08-30 01:48:28 +08:00
|
|
|
gchar *basename;
|
2004-10-14 07:03:12 +08:00
|
|
|
gchar *filename;
|
2001-07-10 01:58:56 +08:00
|
|
|
|
2004-10-13 23:27:00 +08:00
|
|
|
dialog =
|
2007-09-25 22:03:33 +08:00
|
|
|
gimp_message_dialog_new (_("Revert Image"), GTK_STOCK_REVERT_TO_SAVED,
|
2009-10-06 01:58:03 +08:00
|
|
|
GTK_WIDGET (gimp_display_get_shell (display)),
|
|
|
|
0,
|
2004-10-13 23:27:00 +08:00
|
|
|
gimp_standard_help_func, GIMP_HELP_FILE_REVERT,
|
2001-08-30 01:48:28 +08:00
|
|
|
|
2004-10-13 23:27:00 +08:00
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_STOCK_REVERT_TO_SAVED, GTK_RESPONSE_OK,
|
2001-08-30 01:48:28 +08:00
|
|
|
|
2004-10-13 23:27:00 +08:00
|
|
|
NULL);
|
2001-07-10 01:58:56 +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
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
g_signal_connect_object (display, "disconnect",
|
2004-10-13 23:27:00 +08:00
|
|
|
G_CALLBACK (gtk_widget_destroy),
|
|
|
|
dialog, G_CONNECT_SWAPPED);
|
2004-07-17 05:24:39 +08:00
|
|
|
|
2004-10-13 23:27:00 +08:00
|
|
|
g_signal_connect (dialog, "response",
|
|
|
|
G_CALLBACK (file_revert_confirm_response),
|
2006-03-29 01:55:52 +08:00
|
|
|
display);
|
2004-07-01 00:01:05 +08:00
|
|
|
|
2009-04-26 19:00:25 +08:00
|
|
|
if (! source)
|
|
|
|
basename = file_utils_uri_display_basename (uri);
|
|
|
|
else
|
2011-01-26 14:55:14 +08:00
|
|
|
basename = g_strdup (gimp_image_get_uri_or_untitled (image));
|
2009-04-26 19:00:25 +08:00
|
|
|
|
2005-10-02 06:43:22 +08:00
|
|
|
filename = file_utils_uri_display_name (uri);
|
2004-10-14 07:03:12 +08:00
|
|
|
|
2004-10-13 23:27:00 +08:00
|
|
|
gimp_message_box_set_primary_text (GIMP_MESSAGE_DIALOG (dialog)->box,
|
|
|
|
_("Revert '%s' to '%s'?"),
|
2004-10-14 07:03:12 +08:00
|
|
|
basename, filename);
|
|
|
|
g_free (filename);
|
2004-10-13 23:27:00 +08:00
|
|
|
g_free (basename);
|
|
|
|
|
|
|
|
gimp_message_box_set_text (GIMP_MESSAGE_DIALOG (dialog)->box,
|
|
|
|
_("By reverting the image to the state saved "
|
|
|
|
"on disk, you will lose all changes, "
|
|
|
|
"including all undo information."));
|
2004-07-17 05:24:39 +08:00
|
|
|
|
2006-08-09 05:06:36 +08:00
|
|
|
g_object_set_data (G_OBJECT (image), REVERT_DATA_KEY, dialog);
|
2004-07-17 05:24:39 +08:00
|
|
|
|
2004-10-13 23:27:00 +08:00
|
|
|
gtk_widget_show (dialog);
|
2001-07-10 01:58:56 +08:00
|
|
|
}
|
2001-06-26 20:09:43 +08:00
|
|
|
}
|
|
|
|
|
2005-09-25 03:30:08 +08:00
|
|
|
void
|
|
|
|
file_close_all_cmd_callback (GtkAction *action,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
Gimp *gimp;
|
|
|
|
return_if_no_gimp (gimp, data);
|
|
|
|
|
|
|
|
if (! gimp_displays_dirty (gimp))
|
|
|
|
{
|
2008-04-06 04:32:24 +08:00
|
|
|
gimp_displays_close (gimp);
|
2005-09-25 03:30:08 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
return_if_no_widget (widget, data);
|
|
|
|
|
2010-03-01 06:20:57 +08:00
|
|
|
gimp_dialog_factory_dialog_raise (gimp_dialog_factory_get_singleton (),
|
2005-09-25 03:30:08 +08:00
|
|
|
gtk_widget_get_screen (widget),
|
|
|
|
"gimp-close-all-dialog", -1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-26 20:09:43 +08:00
|
|
|
void
|
2004-04-29 20:52:29 +08:00
|
|
|
file_quit_cmd_callback (GtkAction *action,
|
2004-07-01 00:01:05 +08:00
|
|
|
gpointer data)
|
2001-06-26 20:09:43 +08:00
|
|
|
{
|
2002-12-11 00:38:16 +08:00
|
|
|
Gimp *gimp;
|
|
|
|
return_if_no_gimp (gimp, data);
|
|
|
|
|
|
|
|
gimp_exit (gimp, FALSE);
|
2001-06-26 20:09:43 +08:00
|
|
|
}
|
2001-07-10 01:58:56 +08:00
|
|
|
|
2003-01-11 01:55:53 +08:00
|
|
|
void
|
|
|
|
file_file_open_dialog (Gimp *gimp,
|
2003-11-10 06:05:37 +08:00
|
|
|
const gchar *uri,
|
|
|
|
GtkWidget *parent)
|
2004-09-14 03:33:07 +08:00
|
|
|
{
|
2008-10-05 23:21:02 +08:00
|
|
|
file_open_dialog_show (gimp, parent,
|
|
|
|
_("Open Image"),
|
|
|
|
NULL, uri, FALSE);
|
2004-09-14 03:33:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
static void
|
2008-10-05 23:21:02 +08:00
|
|
|
file_open_dialog_show (Gimp *gimp,
|
|
|
|
GtkWidget *parent,
|
|
|
|
const gchar *title,
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image,
|
2004-09-21 20:08:30 +08:00
|
|
|
const gchar *uri,
|
2006-11-05 19:35:57 +08:00
|
|
|
gboolean open_as_layers)
|
2003-01-11 01:55:53 +08:00
|
|
|
{
|
2004-09-14 00:01:52 +08:00
|
|
|
GtkWidget *dialog;
|
|
|
|
|
2010-03-01 06:20:57 +08:00
|
|
|
dialog = gimp_dialog_factory_dialog_new (gimp_dialog_factory_get_singleton (),
|
2004-09-14 00:01:52 +08:00
|
|
|
gtk_widget_get_screen (parent),
|
2010-05-16 18:19:18 +08:00
|
|
|
NULL /*ui_manager*/,
|
2004-09-14 00:01:52 +08:00
|
|
|
"gimp-file-open-dialog", -1, FALSE);
|
|
|
|
|
|
|
|
if (dialog)
|
|
|
|
{
|
2008-10-05 23:21:02 +08:00
|
|
|
if (! uri && image)
|
2011-01-26 15:19:39 +08:00
|
|
|
uri = gimp_image_get_uri (image);
|
2008-10-05 23:21:02 +08:00
|
|
|
|
2008-07-30 22:53:09 +08:00
|
|
|
if (! uri)
|
2009-05-01 01:53:19 +08:00
|
|
|
uri = g_object_get_data (G_OBJECT (gimp), GIMP_FILE_OPEN_LAST_URI_KEY);
|
2008-07-30 22:53:09 +08:00
|
|
|
|
2005-01-14 01:41:48 +08:00
|
|
|
if (uri)
|
|
|
|
gtk_file_chooser_set_uri (GTK_FILE_CHOOSER (dialog), uri);
|
2004-09-14 00:01:52 +08:00
|
|
|
|
2008-10-05 23:21:02 +08:00
|
|
|
gimp_file_dialog_set_open_image (GIMP_FILE_DIALOG (dialog),
|
|
|
|
image, open_as_layers);
|
2004-09-21 20:08:30 +08:00
|
|
|
|
2007-01-16 20:55:00 +08:00
|
|
|
parent = gtk_widget_get_toplevel (parent);
|
|
|
|
|
|
|
|
if (GTK_IS_WINDOW (parent))
|
2008-10-05 23:21:02 +08:00
|
|
|
gtk_window_set_transient_for (GTK_WINDOW (dialog),
|
|
|
|
GTK_WINDOW (parent));
|
2005-05-19 05:01:51 +08:00
|
|
|
|
2004-09-14 00:01:52 +08:00
|
|
|
gtk_window_present (GTK_WINDOW (dialog));
|
|
|
|
}
|
2003-01-11 01:55:53 +08:00
|
|
|
}
|
2001-07-10 01:58:56 +08:00
|
|
|
|
2004-09-14 03:33:07 +08:00
|
|
|
static void
|
2009-05-01 18:22:41 +08:00
|
|
|
file_save_dialog_show (Gimp *gimp,
|
|
|
|
GimpImage *image,
|
2004-09-14 03:33:07 +08:00
|
|
|
GtkWidget *parent,
|
|
|
|
const gchar *title,
|
2007-01-21 03:38:09 +08:00
|
|
|
gboolean save_a_copy,
|
|
|
|
gboolean close_after_saving)
|
2004-09-14 03:33:07 +08:00
|
|
|
{
|
|
|
|
GtkWidget *dialog;
|
2003-04-04 01:50:56 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
dialog = g_object_get_data (G_OBJECT (image), "gimp-file-save-dialog");
|
2004-09-14 03:33:07 +08:00
|
|
|
|
|
|
|
if (! dialog)
|
|
|
|
{
|
2010-03-01 06:20:57 +08:00
|
|
|
dialog = gimp_dialog_factory_dialog_new (gimp_dialog_factory_get_singleton (),
|
2004-09-14 03:33:07 +08:00
|
|
|
gtk_widget_get_screen (parent),
|
2010-05-16 18:19:18 +08:00
|
|
|
NULL /*ui_manager*/,
|
2004-09-14 03:33:07 +08:00
|
|
|
"gimp-file-save-dialog",
|
|
|
|
-1, FALSE);
|
|
|
|
|
|
|
|
if (dialog)
|
|
|
|
{
|
2005-05-19 05:01:51 +08:00
|
|
|
gtk_window_set_transient_for (GTK_WINDOW (dialog),
|
|
|
|
GTK_WINDOW (parent));
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
g_object_set_data_full (G_OBJECT (image),
|
2004-09-14 03:33:07 +08:00
|
|
|
"gimp-file-save-dialog", dialog,
|
|
|
|
(GDestroyNotify) gtk_widget_destroy);
|
|
|
|
g_signal_connect (dialog, "destroy",
|
|
|
|
G_CALLBACK (file_save_dialog_destroyed),
|
2006-03-29 01:08:36 +08:00
|
|
|
image);
|
2004-09-14 03:33:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dialog)
|
|
|
|
{
|
|
|
|
gtk_window_set_title (GTK_WINDOW (dialog), title);
|
|
|
|
|
2008-10-05 23:21:02 +08:00
|
|
|
gimp_file_dialog_set_save_image (GIMP_FILE_DIALOG (dialog),
|
2009-04-25 16:51:07 +08:00
|
|
|
gimp, image, save_a_copy, FALSE,
|
2009-05-01 18:22:41 +08:00
|
|
|
close_after_saving);
|
2004-09-14 03:33:07 +08:00
|
|
|
|
|
|
|
gtk_window_present (GTK_WINDOW (dialog));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
file_save_dialog_destroyed (GtkWidget *dialog,
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image)
|
2004-09-14 03:33:07 +08:00
|
|
|
{
|
2006-03-29 01:08:36 +08:00
|
|
|
if (GIMP_FILE_DIALOG (dialog)->image == image)
|
|
|
|
g_object_set_data (G_OBJECT (image), "gimp-file-save-dialog", NULL);
|
2004-09-14 03:33:07 +08:00
|
|
|
}
|
2001-07-10 01:58:56 +08:00
|
|
|
|
2009-04-25 16:54:56 +08:00
|
|
|
static void
|
|
|
|
file_export_dialog_show (Gimp *gimp,
|
|
|
|
GimpImage *image,
|
|
|
|
GtkWidget *parent)
|
|
|
|
{
|
|
|
|
GtkWidget *dialog;
|
|
|
|
|
|
|
|
dialog = g_object_get_data (G_OBJECT (image), "gimp-file-export-dialog");
|
|
|
|
|
|
|
|
if (! dialog)
|
|
|
|
{
|
2010-03-01 06:20:57 +08:00
|
|
|
dialog = gimp_dialog_factory_dialog_new (gimp_dialog_factory_get_singleton (),
|
2009-04-25 16:54:56 +08:00
|
|
|
gtk_widget_get_screen (parent),
|
2010-05-16 18:19:18 +08:00
|
|
|
NULL /*ui_manager*/,
|
2009-04-25 16:54:56 +08:00
|
|
|
"gimp-file-export-dialog",
|
|
|
|
-1, FALSE);
|
|
|
|
|
|
|
|
if (dialog)
|
|
|
|
{
|
|
|
|
gtk_window_set_transient_for (GTK_WINDOW (dialog),
|
|
|
|
GTK_WINDOW (parent));
|
|
|
|
|
|
|
|
g_object_set_data_full (G_OBJECT (image),
|
|
|
|
"gimp-file-export-dialog", dialog,
|
|
|
|
(GDestroyNotify) gtk_widget_destroy);
|
|
|
|
g_signal_connect (dialog, "destroy",
|
|
|
|
G_CALLBACK (file_export_dialog_destroyed),
|
|
|
|
image);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dialog)
|
|
|
|
{
|
|
|
|
gimp_file_dialog_set_save_image (GIMP_FILE_DIALOG (dialog),
|
|
|
|
gimp,
|
|
|
|
image,
|
|
|
|
FALSE,
|
|
|
|
TRUE,
|
|
|
|
FALSE);
|
|
|
|
|
|
|
|
gtk_window_present (GTK_WINDOW (dialog));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
file_export_dialog_destroyed (GtkWidget *dialog,
|
|
|
|
GimpImage *image)
|
|
|
|
{
|
|
|
|
if (GIMP_FILE_DIALOG (dialog)->image == image)
|
|
|
|
g_object_set_data (G_OBJECT (image), "gimp-file-export-dialog", NULL);
|
|
|
|
}
|
|
|
|
|
2003-04-04 01:50:56 +08:00
|
|
|
static void
|
2003-09-05 09:40:29 +08:00
|
|
|
file_new_template_callback (GtkWidget *widget,
|
|
|
|
const gchar *name,
|
|
|
|
gpointer data)
|
2003-04-04 01:50:56 +08:00
|
|
|
{
|
|
|
|
GimpTemplate *template;
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image;
|
2003-04-04 01:50:56 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
image = (GimpImage *) data;
|
2003-04-04 01:50:56 +08:00
|
|
|
|
|
|
|
if (! (name && strlen (name)))
|
|
|
|
name = _("(Unnamed Template)");
|
|
|
|
|
|
|
|
template = gimp_template_new (name);
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_template_set_from_image (template, image);
|
|
|
|
gimp_container_add (image->gimp->templates, GIMP_OBJECT (template));
|
2003-04-04 01:50:56 +08:00
|
|
|
g_object_unref (template);
|
|
|
|
}
|
|
|
|
|
2001-07-10 01:58:56 +08:00
|
|
|
static void
|
2004-10-13 23:27:00 +08:00
|
|
|
file_revert_confirm_response (GtkWidget *dialog,
|
|
|
|
gint response_id,
|
2006-03-29 01:55:52 +08:00
|
|
|
GimpDisplay *display)
|
2001-07-10 01:58:56 +08:00
|
|
|
{
|
2009-10-07 01:20:44 +08:00
|
|
|
GimpImage *old_image = gimp_display_get_image (display);
|
2004-10-13 23:27:00 +08:00
|
|
|
|
|
|
|
gtk_widget_destroy (dialog);
|
2001-07-10 01:58:56 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
g_object_set_data (G_OBJECT (old_image), REVERT_DATA_KEY, NULL);
|
2001-07-10 01:58:56 +08:00
|
|
|
|
2004-10-13 23:27:00 +08:00
|
|
|
if (response_id == GTK_RESPONSE_OK)
|
2001-07-10 01:58:56 +08:00
|
|
|
{
|
2006-03-29 01:08:36 +08:00
|
|
|
Gimp *gimp = old_image->gimp;
|
|
|
|
GimpImage *new_image;
|
2002-04-14 22:38:55 +08:00
|
|
|
const gchar *uri;
|
2001-10-29 19:47:11 +08:00
|
|
|
GimpPDBStatusType status;
|
2002-04-19 22:09:53 +08:00
|
|
|
GError *error = NULL;
|
2001-07-10 01:58:56 +08:00
|
|
|
|
2011-01-26 15:19:39 +08:00
|
|
|
uri = gimp_image_get_uri (old_image);
|
2001-07-10 01:58:56 +08:00
|
|
|
|
2009-04-26 19:00:25 +08:00
|
|
|
if (! uri)
|
2011-01-27 03:45:32 +08:00
|
|
|
uri = gimp_image_get_imported_uri (old_image);
|
2009-04-26 19:00:25 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
new_image = file_open_image (gimp, gimp_get_user_context (gimp),
|
2006-07-12 14:10:52 +08:00
|
|
|
GIMP_PROGRESS (display),
|
2007-04-17 23:54:01 +08:00
|
|
|
uri, uri, FALSE, NULL,
|
2006-07-12 14:10:52 +08:00
|
|
|
GIMP_RUN_INTERACTIVE,
|
|
|
|
&status, NULL, &error);
|
2001-07-10 01:58:56 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
if (new_image)
|
2004-07-01 00:01:05 +08:00
|
|
|
{
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_displays_reconnect (gimp, old_image, new_image);
|
|
|
|
gimp_image_flush (new_image);
|
2003-05-18 00:34:30 +08:00
|
|
|
|
|
|
|
/* the displays own the image now */
|
2006-03-29 01:08:36 +08:00
|
|
|
g_object_unref (new_image);
|
2004-07-01 00:01:05 +08:00
|
|
|
}
|
2001-07-10 01:58:56 +08:00
|
|
|
else if (status != GIMP_PDB_CANCEL)
|
2004-07-01 00:01:05 +08:00
|
|
|
{
|
2006-03-07 01:35:40 +08:00
|
|
|
gchar *filename = file_utils_uri_display_name (uri);
|
2002-04-19 22:09:53 +08:00
|
|
|
|
2006-10-09 16:17:22 +08:00
|
|
|
gimp_message (gimp, G_OBJECT (display), GIMP_MESSAGE_ERROR,
|
2006-08-09 05:06:36 +08:00
|
|
|
_("Reverting to '%s' failed:\n\n%s"),
|
|
|
|
filename, error->message);
|
2003-03-05 19:25:59 +08:00
|
|
|
g_clear_error (&error);
|
2002-04-19 22:09:53 +08:00
|
|
|
|
|
|
|
g_free (filename);
|
2004-07-01 00:01:05 +08:00
|
|
|
}
|
2001-07-10 01:58:56 +08:00
|
|
|
}
|
|
|
|
}
|