Close the display after "Save as" when invoked via the "Close Without

2007-01-20  Michael Natterer  <mitch@gimp.org>

	Close the display after "Save as" when invoked via the "Close
	Without Saving" dialog. Fixes bug #383700.

	* app/actions/actions-types.h: added enum GimpSaveMode { SAVE,
	SAVE_AS, SAVE_A_COPY, SAVE_AND_CLOSE }.

	* app/actions/file-actions.c: changed the 4 save actions into
	GimpEnumActions with above enum as values.

	* app/actions/file-commands.[ch]: merged the save callbacks into
	one and pass a "close_after_saving" boolean to
	file_save_dialog_show().

	* app/widgets/gimpfiledialog.[ch]: added "gboolean
	close_after_saving" parameter to gimp_file_dialog_set_image() and
	to the GimpFileDialog struct.

	* app/dialogs/file-save-dialog.c: if the file was saved
	successfully and close_after_saving is TRUE, close the display if
	the image has not become dirty again in the meantime.


svn path=/trunk/; revision=21743
This commit is contained in:
Michael Natterer 2007-01-20 19:38:09 +00:00 committed by Michael Natterer
parent 5b45b7321f
commit a4863593ec
8 changed files with 212 additions and 148 deletions

View file

@ -1,3 +1,26 @@
2007-01-20 Michael Natterer <mitch@gimp.org>
Close the display after "Save as" when invoked via the "Close
Without Saving" dialog. Fixes bug #383700.
* app/actions/actions-types.h: added enum GimpSaveMode { SAVE,
SAVE_AS, SAVE_A_COPY, SAVE_AND_CLOSE }.
* app/actions/file-actions.c: changed the 4 save actions into
GimpEnumActions with above enum as values.
* app/actions/file-commands.[ch]: merged the save callbacks into
one and pass a "close_after_saving" boolean to
file_save_dialog_show().
* app/widgets/gimpfiledialog.[ch]: added "gboolean
close_after_saving" parameter to gimp_file_dialog_set_image() and
to the GimpFileDialog struct.
* app/dialogs/file-save-dialog.c: if the file was saved
successfully and close_after_saving is TRUE, close the display if
the image has not become dirty again in the meantime.
2007-01-20 Sven Neumann <sven@gimp.org>
* HACKING: removed obsolete paragraph about authorsgen.

View file

@ -39,5 +39,13 @@ typedef enum
GIMP_ACTION_SELECT_PERCENT_NEXT = -10
} GimpActionSelectType;
typedef enum
{
GIMP_SAVE_MODE_SAVE,
GIMP_SAVE_MODE_SAVE_AS,
GIMP_SAVE_MODE_SAVE_A_COPY,
GIMP_SAVE_MODE_SAVE_AND_CLOSE
} GimpSaveMode;
#endif /* __ACTIONS_TYPES_H__ */

View file

@ -80,26 +80,6 @@ static const GimpActionEntry file_actions[] =
G_CALLBACK (file_open_location_cmd_callback),
GIMP_HELP_FILE_OPEN_LOCATION },
{ "file-save", GTK_STOCK_SAVE,
N_("_Save"), "<control>S", NULL,
G_CALLBACK (file_save_cmd_callback),
GIMP_HELP_FILE_SAVE },
{ "file-save-as", GTK_STOCK_SAVE_AS,
N_("Save _As..."), "<control><shift>S", NULL,
G_CALLBACK (file_save_as_cmd_callback),
GIMP_HELP_FILE_SAVE_AS },
{ "file-save-a-copy", NULL,
N_("Save a Cop_y..."), NULL, NULL,
G_CALLBACK (file_save_a_copy_cmd_callback),
GIMP_HELP_FILE_SAVE_A_COPY },
{ "file-save-and-close", NULL,
N_("Save and Close..."), NULL, NULL,
G_CALLBACK (file_save_and_close_cmd_callback),
GIMP_HELP_FILE_SAVE },
{ "file-save-as-template", NULL,
N_("Save as _Template..."), NULL,
N_("Create a new template from this image"),
@ -125,6 +105,28 @@ static const GimpActionEntry file_actions[] =
GIMP_HELP_FILE_QUIT }
};
static const GimpEnumActionEntry file_save_actions[] =
{
{ "file-save", GTK_STOCK_SAVE,
N_("_Save"), "<control>S", NULL,
GIMP_SAVE_MODE_SAVE, FALSE,
GIMP_HELP_FILE_SAVE },
{ "file-save-as", GTK_STOCK_SAVE_AS,
N_("Save _As..."), "<control><shift>S", NULL,
GIMP_SAVE_MODE_SAVE_AS, FALSE,
GIMP_HELP_FILE_SAVE_AS },
{ "file-save-a-copy", NULL,
N_("Save a Cop_y..."), NULL, NULL,
GIMP_SAVE_MODE_SAVE_A_COPY, FALSE,
GIMP_HELP_FILE_SAVE_A_COPY },
{ "file-save-and-close", NULL,
N_("Save and Close..."), NULL, NULL,
GIMP_SAVE_MODE_SAVE_AND_CLOSE, FALSE,
GIMP_HELP_FILE_SAVE }
};
void
file_actions_setup (GimpActionGroup *group)
@ -137,6 +139,11 @@ file_actions_setup (GimpActionGroup *group)
file_actions,
G_N_ELEMENTS (file_actions));
gimp_action_group_add_enum_actions (group,
file_save_actions,
G_N_ELEMENTS (file_save_actions),
G_CALLBACK (file_save_cmd_callback));
n_entries = GIMP_GUI_CONFIG (group->gimp->config)->last_opened_size;
entries = g_new0 (GimpEnumActionEntry, n_entries);

View file

@ -70,7 +70,8 @@ static void file_open_dialog_show (GtkWidget *parent,
static void file_save_dialog_show (GimpImage *image,
GtkWidget *parent,
const gchar *title,
gboolean save_a_copy);
gboolean save_a_copy,
gboolean close_after_saving);
static void file_save_dialog_destroyed (GtkWidget *dialog,
GimpImage *image);
static void file_new_template_callback (GtkWidget *widget,
@ -176,134 +177,127 @@ file_last_opened_cmd_callback (GtkAction *action,
void
file_save_cmd_callback (GtkAction *action,
gint value,
gpointer data)
{
GimpDisplay *display;
GimpImage *image;
GimpDisplay *display;
GimpImage *image;
GtkWidget *widget;
GimpSaveMode save_mode;
gboolean saved = FALSE;
return_if_no_display (display, data);
return_if_no_widget (widget, data);
image = display->image;
save_mode = (GimpSaveMode) value;
if (! gimp_image_active_drawable (image))
return;
/* Only save if the image has been modified */
if (image->dirty ||
! GIMP_GUI_CONFIG (image->gimp->config)->trust_dirty_flag)
switch (save_mode)
{
const gchar *uri;
GimpPlugInProcedure *save_proc = NULL;
uri = gimp_object_get_name (GIMP_OBJECT (image));
save_proc = gimp_image_get_save_proc (image);
if (uri && ! save_proc)
save_proc =
file_utils_find_proc (image->gimp->plug_in_manager->save_procs,
uri, NULL);
if (! (uri && save_proc))
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)
{
file_save_as_cmd_callback (action, data);
const gchar *uri;
GimpPlugInProcedure *save_proc = NULL;
uri = gimp_object_get_name (GIMP_OBJECT (image));
save_proc = gimp_image_get_save_proc (image);
if (uri && ! save_proc)
save_proc =
file_utils_find_proc (image->gimp->plug_in_manager->save_procs,
uri, NULL);
if (uri && save_proc)
{
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);
}
break;
}
/* fall thru */
}
else
{
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:
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);
}
saved = TRUE;
break;
}
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;
}
}
void
file_save_as_cmd_callback (GtkAction *action,
gpointer data)
{
GimpDisplay *display;
GtkWidget *widget;
return_if_no_display (display, data);
return_if_no_widget (widget, data);
if (! gimp_image_active_drawable (display->image))
return;
file_save_dialog_show (display->image, widget,
_("Save Image"), FALSE);
}
void
file_save_a_copy_cmd_callback (GtkAction *action,
gpointer data)
{
GimpDisplay *display;
GtkWidget *widget;
return_if_no_display (display, data);
return_if_no_widget (widget, data);
if (! gimp_image_active_drawable (display->image))
return;
file_save_dialog_show (display->image, widget,
_("Save a Copy of the Image"), TRUE);
}
void
file_save_and_close_cmd_callback (GtkAction *action,
gpointer data)
{
GimpDisplay *display;
return_if_no_display (display, data);
file_save_cmd_callback (action, data);
if (! display->image->dirty)
gimp_display_delete (display);
if (save_mode == GIMP_SAVE_MODE_SAVE_AND_CLOSE &&
saved && ! display->image->dirty)
{
gimp_display_delete (display);
}
}
void
@ -483,7 +477,8 @@ static void
file_save_dialog_show (GimpImage *image,
GtkWidget *parent,
const gchar *title,
gboolean save_a_copy)
gboolean save_a_copy,
gboolean close_after_saving)
{
GtkWidget *dialog;
@ -515,7 +510,7 @@ file_save_dialog_show (GimpImage *image,
gtk_window_set_title (GTK_WINDOW (dialog), title);
gimp_file_dialog_set_image (GIMP_FILE_DIALOG (dialog),
image, save_a_copy);
image, save_a_copy, close_after_saving);
gtk_window_present (GTK_WINDOW (dialog));
}

View file

@ -31,12 +31,7 @@ void file_last_opened_cmd_callback (GtkAction *action,
gpointer data);
void file_save_cmd_callback (GtkAction *action,
gpointer data);
void file_save_as_cmd_callback (GtkAction *action,
gpointer data);
void file_save_a_copy_cmd_callback (GtkAction *action,
gpointer data);
void file_save_and_close_cmd_callback (GtkAction *action,
gint value,
gpointer data);
void file_save_template_cmd_callback (GtkAction *action,
gpointer data);

View file

@ -43,6 +43,9 @@
#include "widgets/gimpmessagebox.h"
#include "widgets/gimpmessagedialog.h"
#include "display/gimpdisplay.h"
#include "display/gimpdisplayshell.h"
#include "file-save-dialog.h"
#include "gimp-intl.h"
@ -64,7 +67,8 @@ static gboolean file_save_dialog_save_image (GtkWidget *save_dial
GimpImage *image,
const gchar *uri,
GimpPlugInProcedure *save_proc,
gboolean save_a_copy);
gboolean save_a_copy,
gboolean *file_saved);
/* public functions */
@ -128,14 +132,36 @@ file_save_dialog_response (GtkWidget *save_dialog,
if (file_save_dialog_check_uri (save_dialog, gimp,
&uri, &basename, &save_proc))
{
gboolean file_saved = FALSE;
if (file_save_dialog_save_image (save_dialog,
dialog->image,
uri,
save_proc,
dialog->save_a_copy))
dialog->save_a_copy,
&file_saved))
{
if (dialog)
gtk_widget_hide (save_dialog);
{
gtk_widget_hide (save_dialog);
if (file_saved && dialog->close_after_saving)
{
GtkWindow *parent;
parent = gtk_window_get_transient_for (GTK_WINDOW (dialog));
if (GIMP_IS_DISPLAY_SHELL (parent))
{
GimpDisplay *display;
display = GIMP_DISPLAY_SHELL (parent)->display;
if (! display->image->dirty)
gimp_display_delete (display);
}
}
}
}
g_free (uri);
@ -472,7 +498,8 @@ file_save_dialog_save_image (GtkWidget *save_dialog,
GimpImage *image,
const gchar *uri,
GimpPlugInProcedure *save_proc,
gboolean save_a_copy)
gboolean save_a_copy,
gboolean *file_saved)
{
GimpPDBStatusType status;
GError *error = NULL;
@ -499,9 +526,14 @@ file_save_dialog_save_image (GtkWidget *save_dialog,
g_object_unref (image);
*file_saved = FALSE;
switch (status)
{
case GIMP_PDB_SUCCESS:
*file_saved = TRUE;
/* fallthru */
case GIMP_PDB_CANCEL:
break;

View file

@ -392,7 +392,8 @@ gimp_file_dialog_set_file_proc (GimpFileDialog *dialog,
void
gimp_file_dialog_set_image (GimpFileDialog *dialog,
GimpImage *image,
gboolean save_a_copy)
gboolean save_a_copy,
gboolean close_after_saving)
{
const gchar *uri = NULL;
gchar *dirname;
@ -401,8 +402,9 @@ gimp_file_dialog_set_image (GimpFileDialog *dialog,
g_return_if_fail (GIMP_IS_FILE_DIALOG (dialog));
g_return_if_fail (GIMP_IS_IMAGE (image));
dialog->image = image;
dialog->save_a_copy = save_a_copy;
dialog->image = image;
dialog->save_a_copy = save_a_copy;
dialog->close_after_saving = close_after_saving;
if (save_a_copy)
uri = g_object_get_data (G_OBJECT (image), "gimp-image-save-a-copy");

View file

@ -43,6 +43,7 @@ struct _GimpFileDialog
GimpImage *image;
gboolean save_a_copy;
gboolean close_after_saving;
GtkWidget *thumb_box;
GtkWidget *proc_expander;
@ -76,7 +77,8 @@ void gimp_file_dialog_set_file_proc (GimpFileDialog *dialog,
void gimp_file_dialog_set_image (GimpFileDialog *dialog,
GimpImage *image,
gboolean save_a_copy);
gboolean save_a_copy,
gboolean close_after_saving);
G_END_DECLS