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
|
|
|
|
*
|
|
|
|
* 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-04 01:50:56 +08:00
|
|
|
#include <string.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"
|
|
|
|
#include "file/file-save.h"
|
2002-04-19 22:09:53 +08:00
|
|
|
#include "file/file-utils.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
|
|
|
|
2004-09-13 23:15:23 +08:00
|
|
|
#include "dialogs/dialogs.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 */
|
|
|
|
|
2004-09-14 03:33:07 +08:00
|
|
|
static void file_open_dialog_show (GtkWidget *parent,
|
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);
|
2006-03-29 01:08:36 +08:00
|
|
|
static void file_save_dialog_show (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
|
|
|
static void file_save_dialog_destroyed (GtkWidget *dialog,
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image);
|
2003-09-05 09:40:29 +08:00
|
|
|
static void file_new_template_callback (GtkWidget *widget,
|
|
|
|
const gchar *name,
|
|
|
|
gpointer data);
|
2004-10-13 23:27:00 +08:00
|
|
|
static void 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
|
|
|
|
|
|
|
|
|
|
|
/* 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
|
|
|
{
|
2005-01-14 01:41:48 +08:00
|
|
|
GimpImage *image;
|
|
|
|
GtkWidget *widget;
|
|
|
|
const gchar *uri = NULL;
|
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);
|
|
|
|
|
|
|
|
if (image)
|
|
|
|
uri = gimp_object_get_name (GIMP_OBJECT (image));
|
|
|
|
|
|
|
|
file_open_dialog_show (widget, NULL, uri, 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
|
|
|
{
|
2006-03-29 01:55:52 +08:00
|
|
|
GimpDisplay *display;
|
2004-09-21 20:08:30 +08:00
|
|
|
GtkWidget *widget;
|
2005-02-25 01:18:11 +08:00
|
|
|
GimpImage *image;
|
|
|
|
const gchar *uri;
|
2006-03-29 01:55:52 +08:00
|
|
|
return_if_no_display (display, data);
|
2004-09-21 20:08:30 +08:00
|
|
|
return_if_no_widget (widget, data);
|
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
image = display->image;
|
2005-02-25 01:18:11 +08:00
|
|
|
uri = gimp_object_get_name (GIMP_OBJECT (image));
|
|
|
|
|
|
|
|
file_open_dialog_show (widget, image, uri, 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);
|
|
|
|
|
2004-09-09 17:47:33 +08:00
|
|
|
gimp_dialog_factory_dialog_new (global_dialog_factory,
|
|
|
|
gtk_widget_get_screen (widget),
|
|
|
|
"gimp-file-open-location-dialog", -1, TRUE);
|
2004-05-31 22:40:10 +08:00
|
|
|
}
|
|
|
|
|
2001-06-30 03:25:03 +08:00
|
|
|
void
|
2004-04-29 20:52:29 +08:00
|
|
|
file_last_opened_cmd_callback (GtkAction *action,
|
|
|
|
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
|
|
|
|
|
|
|
num_entries = gimp_container_num_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
|
|
|
{
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image;
|
2003-03-05 19:25:59 +08:00
|
|
|
GimpPDBStatusType status;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
image = file_open_with_display (gimp, action_data_get_context (data),
|
2006-07-12 14:10:52 +08:00
|
|
|
NULL,
|
|
|
|
GIMP_OBJECT (imagefile)->name,
|
|
|
|
&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 =
|
|
|
|
file_utils_uri_display_name (GIMP_OBJECT (imagefile)->name);
|
2003-03-05 19:25:59 +08:00
|
|
|
|
2006-10-09 16:17:22 +08:00
|
|
|
gimp_message (gimp, NULL, GIMP_MESSAGE_ERROR,
|
|
|
|
_("Opening '%s' failed:\n\n%s"),
|
|
|
|
filename, error->message);
|
2003-03-05 19:25:59 +08:00
|
|
|
g_clear_error (&error);
|
|
|
|
|
|
|
|
g_free (filename);
|
|
|
|
}
|
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
|
|
|
{
|
2007-01-21 03:38:09 +08:00
|
|
|
GimpDisplay *display;
|
|
|
|
GimpImage *image;
|
|
|
|
GtkWidget *widget;
|
|
|
|
GimpSaveMode save_mode;
|
|
|
|
gboolean saved = FALSE;
|
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
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
image = display->image;
|
2005-02-14 02:05:43 +08:00
|
|
|
|
2007-01-21 03:38:09 +08:00
|
|
|
save_mode = (GimpSaveMode) value;
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
if (! gimp_image_active_drawable (image))
|
2004-10-24 03:13:17 +08:00
|
|
|
return;
|
2001-07-10 01:58:56 +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:
|
|
|
|
/* Only save if the image has been modified */
|
|
|
|
if (image->dirty ||
|
|
|
|
! GIMP_GUI_CONFIG (image->gimp->config)->trust_dirty_flag)
|
2004-07-01 00:01:05 +08:00
|
|
|
{
|
2007-01-21 03:38:09 +08:00
|
|
|
const gchar *uri;
|
|
|
|
GimpPlugInProcedure *save_proc = NULL;
|
2005-10-29 09:43:14 +08:00
|
|
|
|
2007-01-21 03:38:09 +08:00
|
|
|
uri = gimp_object_get_name (GIMP_OBJECT (image));
|
|
|
|
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)
|
|
|
|
save_proc =
|
|
|
|
file_utils_find_proc (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
|
|
|
{
|
2007-01-21 03:38:09 +08:00
|
|
|
GimpPDBStatusType status;
|
|
|
|
GError *error = NULL;
|
|
|
|
GList *list;
|
|
|
|
|
|
|
|
for (list = gimp_action_groups_from_name ("file");
|
|
|
|
list;
|
|
|
|
list = g_list_next (list))
|
|
|
|
{
|
|
|
|
gimp_action_group_set_action_sensitive (list->data,
|
|
|
|
"file-quit",
|
|
|
|
FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
status = file_save (image, action_data_get_context (data),
|
|
|
|
GIMP_PROGRESS (display),
|
|
|
|
uri, save_proc,
|
|
|
|
GIMP_RUN_WITH_LAST_VALS, FALSE, &error);
|
|
|
|
|
|
|
|
switch (status)
|
|
|
|
{
|
|
|
|
case GIMP_PDB_SUCCESS:
|
|
|
|
saved = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_PDB_CANCEL:
|
|
|
|
gimp_message (image->gimp, G_OBJECT (display),
|
|
|
|
GIMP_MESSAGE_INFO,
|
|
|
|
_("Saving canceled"));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
gchar *filename = file_utils_uri_display_name (uri);
|
|
|
|
|
|
|
|
gimp_message (image->gimp, G_OBJECT (display),
|
|
|
|
GIMP_MESSAGE_ERROR,
|
|
|
|
_("Saving '%s' failed:\n\n%s"),
|
|
|
|
filename, error->message);
|
|
|
|
g_free (filename);
|
|
|
|
g_clear_error (&error);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (list = gimp_action_groups_from_name ("file");
|
|
|
|
list;
|
|
|
|
list = g_list_next (list))
|
|
|
|
{
|
|
|
|
gimp_action_group_set_action_sensitive (list->data,
|
|
|
|
"file-quit",
|
|
|
|
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
|
|
|
|
{
|
|
|
|
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:
|
|
|
|
file_save_dialog_show (display->image, widget,
|
|
|
|
_("Save Image"), FALSE,
|
|
|
|
save_mode == GIMP_SAVE_MODE_SAVE_AND_CLOSE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_SAVE_MODE_SAVE_A_COPY:
|
|
|
|
file_save_dialog_show (display->image, widget,
|
|
|
|
_("Save a Copy of the Image"), TRUE,
|
|
|
|
FALSE);
|
|
|
|
break;
|
|
|
|
}
|
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 &&
|
|
|
|
saved && ! display->image->dirty)
|
|
|
|
{
|
|
|
|
gimp_display_delete (display);
|
|
|
|
}
|
2006-12-12 04:33:01 +08:00
|
|
|
}
|
|
|
|
|
2003-04-04 01:50:56 +08:00
|
|
|
void
|
2004-04-29 20:52:29 +08:00
|
|
|
file_save_template_cmd_callback (GtkAction *action,
|
2004-04-20 00:00:54 +08:00
|
|
|
gpointer data)
|
2003-04-04 01:50:56 +08:00
|
|
|
{
|
2006-03-29 01:55:52 +08:00
|
|
|
GimpDisplay *display;
|
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
|
|
|
|
2004-10-19 22:08:44 +08:00
|
|
|
dialog = gimp_query_string_box (_("Create New Template"),
|
2006-03-29 01:55:52 +08:00
|
|
|
display->shell,
|
2004-10-19 22:08:44 +08:00
|
|
|
gimp_standard_help_func,
|
|
|
|
GIMP_HELP_FILE_SAVE_AS_TEMPLATE,
|
|
|
|
_("Enter a name for this template"),
|
|
|
|
NULL,
|
2006-03-29 01:55:52 +08:00
|
|
|
G_OBJECT (display->image), "disconnect",
|
|
|
|
file_new_template_callback, display->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;
|
2002-04-14 22:38:55 +08:00
|
|
|
const gchar *uri;
|
2006-03-29 01:55:52 +08:00
|
|
|
return_if_no_display (display, data);
|
2001-07-10 01:58:56 +08:00
|
|
|
|
2006-08-09 05:06:36 +08:00
|
|
|
image = display->image;
|
2001-07-10 01:58:56 +08:00
|
|
|
|
2006-08-09 05:06:36 +08:00
|
|
|
uri = gimp_object_get_name (GIMP_OBJECT (image));
|
|
|
|
|
|
|
|
dialog = g_object_get_data (G_OBJECT (image), REVERT_DATA_KEY);
|
2001-07-10 01:58:56 +08:00
|
|
|
|
2002-04-14 22:38:55 +08:00
|
|
|
if (! uri)
|
2001-07-10 01:58:56 +08:00
|
|
|
{
|
2006-10-09 16:17:22 +08:00
|
|
|
gimp_message (image->gimp, G_OBJECT (display), GIMP_MESSAGE_ERROR,
|
2006-08-09 05:06:36 +08:00
|
|
|
_("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 =
|
|
|
|
gimp_message_dialog_new (_("Revert Image"), GIMP_STOCK_QUESTION,
|
2006-03-29 01:55:52 +08:00
|
|
|
display->shell, 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
|
|
|
|
2005-10-02 06:43:22 +08:00
|
|
|
basename = file_utils_uri_display_basename (uri);
|
|
|
|
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))
|
|
|
|
{
|
|
|
|
gimp_displays_delete (gimp);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
return_if_no_widget (widget, data);
|
|
|
|
|
|
|
|
gimp_dialog_factory_dialog_raise (global_dialog_factory,
|
|
|
|
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
|
|
|
{
|
2004-09-21 20:08:30 +08:00
|
|
|
file_open_dialog_show (parent, NULL, uri, FALSE);
|
2004-09-14 03:33:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
static void
|
|
|
|
file_open_dialog_show (GtkWidget *parent,
|
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;
|
|
|
|
|
|
|
|
dialog = gimp_dialog_factory_dialog_new (global_dialog_factory,
|
|
|
|
gtk_widget_get_screen (parent),
|
|
|
|
"gimp-file-open-dialog", -1, FALSE);
|
|
|
|
|
|
|
|
if (dialog)
|
|
|
|
{
|
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
|
|
|
|
2006-11-05 19:35:57 +08:00
|
|
|
if (open_as_layers)
|
2004-09-21 20:08:30 +08:00
|
|
|
{
|
2006-11-05 19:35:57 +08:00
|
|
|
gtk_window_set_title (GTK_WINDOW (dialog), _("Open Image as Layers"));
|
2006-03-29 01:08:36 +08:00
|
|
|
GIMP_FILE_DIALOG (dialog)->image = image;
|
2004-09-21 20:08:30 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_window_set_title (GTK_WINDOW (dialog), _("Open Image"));
|
2006-03-29 01:08:36 +08:00
|
|
|
GIMP_FILE_DIALOG (dialog)->image = NULL;
|
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))
|
|
|
|
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
|
2006-03-29 01:08:36 +08:00
|
|
|
file_save_dialog_show (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)
|
|
|
|
{
|
|
|
|
dialog = gimp_dialog_factory_dialog_new (global_dialog_factory,
|
|
|
|
gtk_widget_get_screen (parent),
|
|
|
|
"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);
|
|
|
|
|
2004-11-16 21:37:36 +08:00
|
|
|
gimp_file_dialog_set_image (GIMP_FILE_DIALOG (dialog),
|
2007-01-21 03:38:09 +08:00
|
|
|
image, save_a_copy, 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
|
|
|
|
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
|
|
|
{
|
2006-03-29 01:55:52 +08:00
|
|
|
GimpImage *old_image = display->image;
|
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
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
uri = gimp_object_get_name (GIMP_OBJECT (old_image));
|
2001-07-10 01:58:56 +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),
|
|
|
|
uri, uri, NULL,
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|