added new function file_save_as() which always uses the uri and file_proc

2003-03-04  Michael Natterer  <mitch@gimp.org>

	* app/file/file-save.[ch]: added new function file_save_as() which
	always uses the uri and file_proc parameters passed and never
	looks at the image's uri and file_proc. Renamed "gboolean set_uri"
	to "set_uri_and_proc" and always set them both if the save
	succeeded.  Fixes bug #97835.  Removed most parameters from
	file_save() and made it a small wrapper around file_save_as().

	* app/gui/file-commands.c (file_save_cmd_callback): changed
	accordingly.

	* app/gui/file-save-dialog.c: call file_save_as(), renamed
	"set_uri" variables to "set_uri_and_proc".
This commit is contained in:
Michael Natterer
2003-03-04 10:32:35 +00:00
committed by Michael Natterer
parent c860d8054c
commit a53f1ba4ca
7 changed files with 132 additions and 96 deletions

View File

@ -1,3 +1,18 @@
2003-03-04 Michael Natterer <mitch@gimp.org>
* app/file/file-save.[ch]: added new function file_save_as() which
always uses the uri and file_proc parameters passed and never
looks at the image's uri and file_proc. Renamed "gboolean set_uri"
to "set_uri_and_proc" and always set them both if the save
succeeded. Fixes bug #97835. Removed most parameters from
file_save() and made it a small wrapper around file_save_as().
* app/gui/file-commands.c (file_save_cmd_callback): changed
accordingly.
* app/gui/file-save-dialog.c: call file_save_as(), renamed
"set_uri" variables to "set_uri_and_proc".
2003-03-03 Michael Natterer <mitch@gimp.org> 2003-03-03 Michael Natterer <mitch@gimp.org>
* app/paint/gimppaintcore-stroke.c * app/paint/gimppaintcore-stroke.c

View File

@ -206,18 +206,19 @@ file_save_cmd_callback (GtkWidget *widget,
{ {
GimpPDBStatusType status; GimpPDBStatusType status;
status = file_save (gdisp->gimage, status = file_save (gdisp->gimage, GIMP_RUN_WITH_LAST_VALS);
uri,
uri,
NULL,
GIMP_RUN_WITH_LAST_VALS,
TRUE);
if (status != GIMP_PDB_SUCCESS && if (status != GIMP_PDB_SUCCESS &&
status != GIMP_PDB_CANCEL) status != GIMP_PDB_CANCEL)
{ {
gchar *filename;
filename = file_utils_uri_to_utf8_basename (uri);
/* Error message should be added. --bex */ /* Error message should be added. --bex */
g_message (_("Saving '%s' failed."), uri); g_message (_("Saving '%s' failed."), filename);
g_free (filename);
} }
} }
} }

View File

@ -70,14 +70,14 @@ static void file_save_dialog_save_image (GtkWidget *save_dialog,
const gchar *uri, const gchar *uri,
const gchar *raw_filename, const gchar *raw_filename,
PlugInProcDef *save_proc, PlugInProcDef *save_proc,
gboolean set_uri); gboolean set_uri_and_proc);
static GtkWidget *filesave = NULL; static GtkWidget *filesave = NULL;
static PlugInProcDef *save_file_proc = NULL; static PlugInProcDef *save_file_proc = NULL;
static GimpImage *the_gimage = NULL; static GimpImage *the_gimage = NULL;
static gboolean set_uri = TRUE; static gboolean set_uri_and_proc = TRUE;
/* public functions */ /* public functions */
@ -104,8 +104,8 @@ file_save_dialog_show (GimpImage *gimage,
if (! gimp_image_active_drawable (gimage)) if (! gimp_image_active_drawable (gimage))
return; return;
the_gimage = gimage; the_gimage = gimage;
set_uri = TRUE; set_uri_and_proc = TRUE;
if (! filesave) if (! filesave)
filesave = file_save_dialog_create (gimage->gimp, menu_factory); filesave = file_save_dialog_create (gimage->gimp, menu_factory);
@ -151,8 +151,8 @@ file_save_a_copy_dialog_show (GimpImage *gimage,
if (! gimp_image_active_drawable (gimage)) if (! gimp_image_active_drawable (gimage))
return; return;
the_gimage = gimage; the_gimage = gimage;
set_uri = FALSE; set_uri_and_proc = FALSE;
uri = gimp_object_get_name (GIMP_OBJECT (gimage)); uri = gimp_object_get_name (GIMP_OBJECT (gimage));
@ -292,7 +292,7 @@ file_save_ok_callback (GtkWidget *widget,
uri, uri,
raw_filename, raw_filename,
save_file_proc, save_file_proc,
set_uri); set_uri_and_proc);
gtk_widget_set_sensitive (GTK_WIDGET (fs), TRUE); gtk_widget_set_sensitive (GTK_WIDGET (fs), TRUE);
} }
@ -314,7 +314,8 @@ file_save_overwrite (GtkWidget *save_dialog,
{ {
OverwriteData *overwrite_data; OverwriteData *overwrite_data;
GtkWidget *query_box; GtkWidget *query_box;
gchar *overwrite_text; gchar *filename;
gchar *message;
overwrite_data = g_new0 (OverwriteData, 1); overwrite_data = g_new0 (OverwriteData, 1);
@ -322,20 +323,24 @@ file_save_overwrite (GtkWidget *save_dialog,
overwrite_data->uri = g_strdup (uri); overwrite_data->uri = g_strdup (uri);
overwrite_data->raw_filename = g_strdup (raw_filename); overwrite_data->raw_filename = g_strdup (raw_filename);
overwrite_text = g_strdup_printf (_("File '%s' exists.\n" filename = file_utils_uri_to_utf8_filename (uri);
"Overwrite it?"), uri);
message = g_strdup_printf (_("File '%s' exists.\n"
"Overwrite it?"), filename);
g_free (filename);
query_box = gimp_query_boolean_box (_("File Exists!"), query_box = gimp_query_boolean_box (_("File Exists!"),
gimp_standard_help_func, gimp_standard_help_func,
"save/file_exists.html", "save/file_exists.html",
GTK_STOCK_DIALOG_QUESTION, GTK_STOCK_DIALOG_QUESTION,
overwrite_text, message,
GTK_STOCK_YES, GTK_STOCK_NO, GTK_STOCK_YES, GTK_STOCK_NO,
NULL, NULL, NULL, NULL,
file_save_overwrite_callback, file_save_overwrite_callback,
overwrite_data); overwrite_data);
g_free (overwrite_text); g_free (message);
gtk_widget_show (query_box); gtk_widget_show (query_box);
@ -358,7 +363,7 @@ file_save_overwrite_callback (GtkWidget *widget,
overwrite_data->uri, overwrite_data->uri,
overwrite_data->raw_filename, overwrite_data->raw_filename,
save_file_proc, save_file_proc,
set_uri); set_uri_and_proc);
} }
gtk_widget_set_sensitive (overwrite_data->save_dialog, TRUE); gtk_widget_set_sensitive (overwrite_data->save_dialog, TRUE);
@ -374,16 +379,16 @@ file_save_dialog_save_image (GtkWidget *save_dialog,
const gchar *uri, const gchar *uri,
const gchar *raw_filename, const gchar *raw_filename,
PlugInProcDef *save_proc, PlugInProcDef *save_proc,
gboolean set_uri) gboolean set_uri_and_proc)
{ {
GimpPDBStatusType status; GimpPDBStatusType status;
status = file_save (gimage, status = file_save_as (gimage,
uri, uri,
raw_filename, raw_filename,
save_proc, save_proc,
GIMP_RUN_INTERACTIVE, GIMP_RUN_INTERACTIVE,
set_uri); set_uri_and_proc);
if (status != GIMP_PDB_SUCCESS && if (status != GIMP_PDB_SUCCESS &&
status != GIMP_PDB_CANCEL) status != GIMP_PDB_CANCEL)

View File

@ -62,12 +62,30 @@
/* public functions */ /* public functions */
GimpPDBStatusType GimpPDBStatusType
file_save (GimpImage *gimage, file_save (GimpImage *gimage,
const gchar *uri, GimpRunMode run_mode)
const gchar *raw_filename, {
PlugInProcDef *file_proc, const gchar *uri;
GimpRunMode run_mode, PlugInProcDef *file_proc;
gboolean set_uri)
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), GIMP_PDB_CALLING_ERROR);
uri = gimp_object_get_name (GIMP_OBJECT (gimage));
g_return_val_if_fail (uri != NULL, GIMP_PDB_CALLING_ERROR);
file_proc = gimp_image_get_save_proc (gimage);
return file_save_as (gimage, uri, uri, file_proc, run_mode, FALSE);
}
GimpPDBStatusType
file_save_as (GimpImage *gimage,
const gchar *uri,
const gchar *raw_filename,
PlugInProcDef *file_proc,
GimpRunMode run_mode,
gboolean set_uri_and_proc)
{ {
ProcRecord *proc; ProcRecord *proc;
Argument *args; Argument *args;
@ -77,33 +95,22 @@ file_save (GimpImage *gimage,
gchar *filename; gchar *filename;
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), GIMP_PDB_CALLING_ERROR); g_return_val_if_fail (GIMP_IS_IMAGE (gimage), GIMP_PDB_CALLING_ERROR);
g_return_val_if_fail (uri != NULL, GIMP_PDB_CALLING_ERROR);
g_return_val_if_fail (raw_filename != NULL, GIMP_PDB_CALLING_ERROR);
if (gimp_image_active_drawable (gimage) == NULL) if (gimp_image_active_drawable (gimage) == NULL)
return GIMP_PDB_EXECUTION_ERROR; return GIMP_PDB_EXECUTION_ERROR;
/* set the image's save_proc if we got passed one, otherwise if (! file_proc)
* try to find a matching file_proc file_proc = file_utils_find_proc (gimage->gimp->save_procs, raw_filename);
*/
if (file_proc) if (! file_proc)
{ {
gimp_image_set_save_proc (gimage, file_proc); g_message (_("Save failed.\n"
} "%s: Unknown file type."),
else uri);
{
file_proc = gimp_image_get_save_proc (gimage);
if (! file_proc) return GIMP_PDB_CANCEL; /* inhibits error messages by caller */
file_proc = file_utils_find_proc (gimage->gimp->save_procs,
raw_filename);
if (! file_proc)
{
g_message (_("Save failed.\n"
"%s: Unknown file type."),
uri);
return GIMP_PDB_CANCEL; /* inhibits error messages by caller */
}
} }
filename = g_filename_from_uri (uri, NULL, NULL); filename = g_filename_from_uri (uri, NULL, NULL);
@ -170,16 +177,16 @@ file_save (GimpImage *gimage,
documents = GIMP_DOCUMENT_LIST (gimage->gimp->documents); documents = GIMP_DOCUMENT_LIST (gimage->gimp->documents);
imagefile = gimp_document_list_add_uri (documents, uri); imagefile = gimp_document_list_add_uri (documents, uri);
if (set_uri) if (set_uri_and_proc)
{ {
/* set the image title */
gimp_image_set_uri (gimage, uri); gimp_image_set_uri (gimage, uri);
gimp_image_set_save_proc (gimage, file_proc);
} }
/* Write a thumbnail for the saved image, where appropriate */ /* Write a thumbnail for the saved image, where appropriate */
if (gimage->gimp->config->thumbnail_size != GIMP_THUMBNAIL_SIZE_NONE) if (gimage->gimp->config->thumbnail_size != GIMP_THUMBNAIL_SIZE_NONE)
{ {
if (set_uri) if (set_uri_and_proc)
{ {
gimp_imagefile_save_thumbnail (imagefile, gimage); gimp_imagefile_save_thumbnail (imagefile, gimage);
} }

View File

@ -20,12 +20,14 @@
#define __FILE_SAVE_H__ #define __FILE_SAVE_H__
GimpPDBStatusType file_save (GimpImage *gimage, GimpPDBStatusType file_save (GimpImage *gimage,
const gchar *uri, GimpRunMode run_mode);
const gchar *raw_filename, GimpPDBStatusType file_save_as (GimpImage *gimage,
PlugInProcDef *file_proc, const gchar *uri,
GimpRunMode run_mode, const gchar *raw_filename,
gboolean set_uri); PlugInProcDef *file_proc,
GimpRunMode run_mode,
gboolean set_uri_and_proc);
#endif /* __FILE_SAVE_H__ */ #endif /* __FILE_SAVE_H__ */

View File

@ -206,18 +206,19 @@ file_save_cmd_callback (GtkWidget *widget,
{ {
GimpPDBStatusType status; GimpPDBStatusType status;
status = file_save (gdisp->gimage, status = file_save (gdisp->gimage, GIMP_RUN_WITH_LAST_VALS);
uri,
uri,
NULL,
GIMP_RUN_WITH_LAST_VALS,
TRUE);
if (status != GIMP_PDB_SUCCESS && if (status != GIMP_PDB_SUCCESS &&
status != GIMP_PDB_CANCEL) status != GIMP_PDB_CANCEL)
{ {
gchar *filename;
filename = file_utils_uri_to_utf8_basename (uri);
/* Error message should be added. --bex */ /* Error message should be added. --bex */
g_message (_("Saving '%s' failed."), uri); g_message (_("Saving '%s' failed."), filename);
g_free (filename);
} }
} }
} }

View File

@ -70,14 +70,14 @@ static void file_save_dialog_save_image (GtkWidget *save_dialog,
const gchar *uri, const gchar *uri,
const gchar *raw_filename, const gchar *raw_filename,
PlugInProcDef *save_proc, PlugInProcDef *save_proc,
gboolean set_uri); gboolean set_uri_and_proc);
static GtkWidget *filesave = NULL; static GtkWidget *filesave = NULL;
static PlugInProcDef *save_file_proc = NULL; static PlugInProcDef *save_file_proc = NULL;
static GimpImage *the_gimage = NULL; static GimpImage *the_gimage = NULL;
static gboolean set_uri = TRUE; static gboolean set_uri_and_proc = TRUE;
/* public functions */ /* public functions */
@ -104,8 +104,8 @@ file_save_dialog_show (GimpImage *gimage,
if (! gimp_image_active_drawable (gimage)) if (! gimp_image_active_drawable (gimage))
return; return;
the_gimage = gimage; the_gimage = gimage;
set_uri = TRUE; set_uri_and_proc = TRUE;
if (! filesave) if (! filesave)
filesave = file_save_dialog_create (gimage->gimp, menu_factory); filesave = file_save_dialog_create (gimage->gimp, menu_factory);
@ -151,8 +151,8 @@ file_save_a_copy_dialog_show (GimpImage *gimage,
if (! gimp_image_active_drawable (gimage)) if (! gimp_image_active_drawable (gimage))
return; return;
the_gimage = gimage; the_gimage = gimage;
set_uri = FALSE; set_uri_and_proc = FALSE;
uri = gimp_object_get_name (GIMP_OBJECT (gimage)); uri = gimp_object_get_name (GIMP_OBJECT (gimage));
@ -292,7 +292,7 @@ file_save_ok_callback (GtkWidget *widget,
uri, uri,
raw_filename, raw_filename,
save_file_proc, save_file_proc,
set_uri); set_uri_and_proc);
gtk_widget_set_sensitive (GTK_WIDGET (fs), TRUE); gtk_widget_set_sensitive (GTK_WIDGET (fs), TRUE);
} }
@ -314,7 +314,8 @@ file_save_overwrite (GtkWidget *save_dialog,
{ {
OverwriteData *overwrite_data; OverwriteData *overwrite_data;
GtkWidget *query_box; GtkWidget *query_box;
gchar *overwrite_text; gchar *filename;
gchar *message;
overwrite_data = g_new0 (OverwriteData, 1); overwrite_data = g_new0 (OverwriteData, 1);
@ -322,20 +323,24 @@ file_save_overwrite (GtkWidget *save_dialog,
overwrite_data->uri = g_strdup (uri); overwrite_data->uri = g_strdup (uri);
overwrite_data->raw_filename = g_strdup (raw_filename); overwrite_data->raw_filename = g_strdup (raw_filename);
overwrite_text = g_strdup_printf (_("File '%s' exists.\n" filename = file_utils_uri_to_utf8_filename (uri);
"Overwrite it?"), uri);
message = g_strdup_printf (_("File '%s' exists.\n"
"Overwrite it?"), filename);
g_free (filename);
query_box = gimp_query_boolean_box (_("File Exists!"), query_box = gimp_query_boolean_box (_("File Exists!"),
gimp_standard_help_func, gimp_standard_help_func,
"save/file_exists.html", "save/file_exists.html",
GTK_STOCK_DIALOG_QUESTION, GTK_STOCK_DIALOG_QUESTION,
overwrite_text, message,
GTK_STOCK_YES, GTK_STOCK_NO, GTK_STOCK_YES, GTK_STOCK_NO,
NULL, NULL, NULL, NULL,
file_save_overwrite_callback, file_save_overwrite_callback,
overwrite_data); overwrite_data);
g_free (overwrite_text); g_free (message);
gtk_widget_show (query_box); gtk_widget_show (query_box);
@ -358,7 +363,7 @@ file_save_overwrite_callback (GtkWidget *widget,
overwrite_data->uri, overwrite_data->uri,
overwrite_data->raw_filename, overwrite_data->raw_filename,
save_file_proc, save_file_proc,
set_uri); set_uri_and_proc);
} }
gtk_widget_set_sensitive (overwrite_data->save_dialog, TRUE); gtk_widget_set_sensitive (overwrite_data->save_dialog, TRUE);
@ -374,16 +379,16 @@ file_save_dialog_save_image (GtkWidget *save_dialog,
const gchar *uri, const gchar *uri,
const gchar *raw_filename, const gchar *raw_filename,
PlugInProcDef *save_proc, PlugInProcDef *save_proc,
gboolean set_uri) gboolean set_uri_and_proc)
{ {
GimpPDBStatusType status; GimpPDBStatusType status;
status = file_save (gimage, status = file_save_as (gimage,
uri, uri,
raw_filename, raw_filename,
save_proc, save_proc,
GIMP_RUN_INTERACTIVE, GIMP_RUN_INTERACTIVE,
set_uri); set_uri_and_proc);
if (status != GIMP_PDB_SUCCESS && if (status != GIMP_PDB_SUCCESS &&
status != GIMP_PDB_CANCEL) status != GIMP_PDB_CANCEL)