Commit f6cb341c authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann
Browse files

app/dialogs/file-save-dialog.c moved overwrite confirmation dialog to

2005-03-25  Sven Neumann  <sven@gimp.org>

	* app/dialogs/file-save-dialog.c
	* app/widgets/gimpfiledialog.[ch]: moved overwrite confirmation
	dialog to app/widgets.

	* app/widgets/gimpdnd-xds.c: set "Untitled.xcf" as default name
	for untitled images; ask for confirmation before overwriting a
	local file.
parent cd25a296
2005-03-25 Sven Neumann <sven@gimp.org>
* app/dialogs/file-save-dialog.c
* app/widgets/gimpfiledialog.[ch]: moved overwrite confirmation
dialog to app/widgets.
* app/widgets/gimpdnd-xds.c: set "Untitled.xcf" as default name
for untitled images; ask for confirmation before overwriting a
local file.
2005-03-25 Bill Skaggs <weskaggs@primate.ucdavis.edu>
* plug-ins/common/emboss.c: fix usage of RGBA data,
......
......@@ -58,8 +58,6 @@ static gboolean file_save_dialog_check_uri (GtkWidget *save_dialog,
PlugInProcDef **ret_save_proc);
static gboolean file_save_dialog_use_extension (GtkWidget *save_dialog,
const gchar *uri);
static gboolean file_save_dialog_overwrite (GtkWidget *save_dialog,
const gchar *uri);
static gboolean file_save_dialog_save_image (GtkWidget *save_dialog,
GimpImage *gimage,
const gchar *uri,
......@@ -375,7 +373,7 @@ file_save_dialog_check_uri (GtkWidget *save_dialog,
if (gtk_file_chooser_set_uri (GTK_FILE_CHOOSER (save_dialog), uri))
{
if (! file_save_dialog_overwrite (save_dialog, uri))
if (! gimp_file_overwrite_dialog (save_dialog, uri))
{
g_free (uri);
g_free (basename);
......@@ -435,55 +433,6 @@ file_save_dialog_use_extension (GtkWidget *save_dialog,
return use_name;
}
static gboolean
file_save_dialog_overwrite (GtkWidget *save_dialog,
const gchar *uri)
{
GtkWidget *dialog;
gchar *filename;
gboolean overwrite = FALSE;
dialog =
gimp_message_dialog_new (_("File exists"), GIMP_STOCK_WARNING,
save_dialog, GTK_DIALOG_DESTROY_WITH_PARENT,
gimp_standard_help_func, NULL,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
_("_Replace"), GTK_RESPONSE_OK,
NULL);
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
GTK_RESPONSE_OK,
GTK_RESPONSE_CANCEL,
-1);
filename = file_utils_uri_to_utf8_filename (uri);
gimp_message_box_set_primary_text (GIMP_MESSAGE_DIALOG (dialog)->box,
_("A file named '%s' already exists."),
filename);
g_free (filename);
gimp_message_box_set_text (GIMP_MESSAGE_DIALOG (dialog)->box,
_("Do you want to replace it with the image "
"you are saving?"));
gtk_dialog_set_response_sensitive (GTK_DIALOG (save_dialog),
GTK_RESPONSE_CANCEL, FALSE);
g_object_ref (dialog);
overwrite = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK);
gtk_widget_destroy (dialog);
g_object_unref (dialog);
gtk_dialog_set_response_sensitive (GTK_DIALOG (save_dialog),
GTK_RESPONSE_CANCEL, TRUE);
return overwrite;
}
static gboolean
file_save_dialog_save_image (GtkWidget *save_dialog,
GimpImage *gimage,
......
......@@ -40,6 +40,7 @@
#include "file/file-utils.h"
#include "gimpdnd-xds.h"
#include "gimpfiledialog.h"
#include "gimp-intl.h"
......@@ -59,7 +60,6 @@ gimp_dnd_xds_source_set (GdkDragContext *context,
GimpImage *image)
{
GdkAtom property;
gchar *filename;
g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
g_return_if_fail (image == NULL || GIMP_IS_IMAGE (image));
......@@ -68,14 +68,27 @@ gimp_dnd_xds_source_set (GdkDragContext *context,
property = gdk_atom_intern ("XdndDirectSave0", FALSE);
if (image && (filename = gimp_image_get_filename (image)))
if (image)
{
GdkAtom type = gdk_atom_intern ("text/plain", FALSE);
gchar *basename = g_path_get_basename (filename);
gchar *filename = gimp_image_get_filename (image);
gchar *basename;
if (filename)
{
basename = g_path_get_basename (filename);
}
else
{
gchar *tmp = g_strconcat (_("Untitled"), ".xcf", NULL);
basename = g_filename_from_utf8 (tmp, -1, NULL, NULL, NULL);
g_free (tmp);
}
gdk_property_change (context->source_window,
property, type, 8, GDK_PROP_MODE_REPLACE,
basename, strlen (basename));
basename, basename ? strlen (basename) : 0);
g_free (basename);
g_free (filename);
......@@ -116,33 +129,40 @@ gimp_dnd_xds_save_image (GdkDragContext *context,
proc = file_utils_find_proc (image->gimp->save_procs, uri);
if (! proc)
proc = file_utils_find_proc (image->gimp->save_procs,
gimp_object_get_name (GIMP_OBJECT (image)));
if (proc)
{
if (file_save (image, gimp_get_user_context (image->gimp), NULL,
uri, proc, GIMP_RUN_INTERACTIVE, FALSE,
&error) == GIMP_PDB_SUCCESS)
{
gtk_selection_data_set (selection, atom, 8, "S", 1);
}
else
{
gtk_selection_data_set (selection, atom, 8, "E", 1);
gchar *filename = file_utils_filename_from_uri (uri);
/* FIXME: shouldn't overwrite non-local files w/o confirmation */
if (error)
if (! filename ||
! g_file_test (filename, G_FILE_TEST_EXISTS) ||
gimp_file_overwrite_dialog (NULL, uri))
{
if (file_save (image, gimp_get_user_context (image->gimp), NULL,
uri, proc, GIMP_RUN_INTERACTIVE, FALSE,
&error) == GIMP_PDB_SUCCESS)
{
gchar *filename = file_utils_uri_to_utf8_filename (uri);
gtk_selection_data_set (selection, atom, 8, "S", 1);
}
else
{
gtk_selection_data_set (selection, atom, 8, "E", 1);
if (error)
{
gchar *filename = file_utils_uri_to_utf8_filename (uri);
g_message (_("Saving '%s' failed:\n\n%s"),
filename, error->message);
g_message (_("Saving '%s' failed:\n\n%s"),
filename, error->message);
g_free (filename);
g_error_free (error);
g_free (filename);
g_error_free (error);
}
}
}
g_free (filename);
}
else
{
......
......@@ -44,6 +44,8 @@
#include "gimpfiledialog.h"
#include "gimpfileprocview.h"
#include "gimphelp-ids.h"
#include "gimpmessagebox.h"
#include "gimpmessagedialog.h"
#include "gimpview.h"
#include "gimpviewrendererimagefile.h"
#include "gimpthumbbox.h"
......@@ -443,6 +445,58 @@ gimp_file_dialog_set_image (GimpFileDialog *dialog,
}
gboolean
gimp_file_overwrite_dialog (GtkWidget *parent,
const gchar *uri)
{
GtkWidget *dialog;
gchar *filename;
gboolean overwrite = FALSE;
dialog = gimp_message_dialog_new (_("File exists"), GIMP_STOCK_WARNING,
parent, GTK_DIALOG_DESTROY_WITH_PARENT,
gimp_standard_help_func, NULL,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
_("_Replace"), GTK_RESPONSE_OK,
NULL);
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
GTK_RESPONSE_OK,
GTK_RESPONSE_CANCEL,
-1);
filename = file_utils_uri_to_utf8_filename (uri);
gimp_message_box_set_primary_text (GIMP_MESSAGE_DIALOG (dialog)->box,
_("A file named '%s' already exists."),
filename);
g_free (filename);
gimp_message_box_set_text (GIMP_MESSAGE_DIALOG (dialog)->box,
_("Do you want to replace it with the image "
"you are saving?"));
if (GTK_IS_DIALOG (parent))
gtk_dialog_set_response_sensitive (GTK_DIALOG (parent),
GTK_RESPONSE_CANCEL, FALSE);
g_object_ref (dialog);
overwrite = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK);
gtk_widget_destroy (dialog);
g_object_unref (dialog);
if (GTK_IS_DIALOG (parent))
gtk_dialog_set_response_sensitive (GTK_DIALOG (parent),
GTK_RESPONSE_CANCEL, TRUE);
return overwrite;
}
/* private functions */
static void
......
......@@ -81,6 +81,8 @@ void gimp_file_dialog_set_image (GimpFileDialog *dialog,
GimpImage *gimage,
gboolean save_a_copy);
gboolean gimp_file_overwrite_dialog (GtkWidget *parent,
const gchar *uri);
G_END_DECLS
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment