summaryrefslogtreecommitdiff
path: root/gtk/gtkfilechooser.c
diff options
context:
space:
mode:
authorFederico Mena Quintero <federico@ximian.com>2005-07-15 04:55:56 +0000
committerFederico Mena Quintero <federico@src.gnome.org>2005-07-15 04:55:56 +0000
commitfb7d6ac4fdbbc2804f3e3dbd87244e5605d6b9d0 (patch)
tree768c291ffb7f5bbd98c1d597014597d9a94f9283 /gtk/gtkfilechooser.c
parent7158c558ae285d95d830c0430334484b73ceb97a (diff)
downloadgtk+-fb7d6ac4fdbbc2804f3e3dbd87244e5605d6b9d0.tar.gz
Add overwrite confirmation for SAVE mode. Fixes bug #152850:
2005-07-14 Federico Mena Quintero <federico@ximian.com> Add overwrite confirmation for SAVE mode. Fixes bug #152850: * gtk/gtkfilechooser.h: Add prototypes for gtk_file_chooser_set/get_do_overwrite_confirmation(). (GtkFileChooserConfirmation): New enum for the result of the "confirm-overwrite" signal. * gtk/gtkmarshalers.list: Add ENUM:VOID. * gtk/gtkfilechooser.c (gtk_file_chooser_class_init): Add a "do-overwrite-confirmation" boolean property. (gtk_file_chooser_set_do_overwrite_confirmation): Implement. (gtk_file_chooser_get_do_overwrite_confirmation): Implement. (confirm_overwrite_accumulator): New accumulator for the signal. * gtk/gtkfilechooserutils.h (GtkFileChooserProp): Add GTK_FILE_CHOOSER_PROP_DO_OVERWRITE_CONFIRMATION. * gtk/gtkfilechooserutils.c (_gtk_file_chooser_install_properties): Override the do-overwrite-confirmation property. * gtk/gtkfilechooserprivate.h (struct _GtkFileChooserIface): Add a confirm_overwrite signal to the vtable. * gtk/gtkfilechooserdefault.c (gtk_file_chooser_default_set_property): Handle the new property. (gtk_file_chooser_default_get_property): Likewise. (get_selected_file_info_from_file_list): New helper function; code taken from list_selection_changed(). (list_selection_changed): Use get_selected_file_info_from_file_list(). (should_respond_after_confirm_overwrite): New function. (gtk_file_chooser_default_should_respond): Confirm when necessary.
Diffstat (limited to 'gtk/gtkfilechooser.c')
-rw-r--r--gtk/gtkfilechooser.c88
1 files changed, 88 insertions, 0 deletions
diff --git a/gtk/gtkfilechooser.c b/gtk/gtkfilechooser.c
index 2241aef270..af870185a8 100644
--- a/gtk/gtkfilechooser.c
+++ b/gtk/gtkfilechooser.c
@@ -25,6 +25,7 @@
#include "gtkintl.h"
#include "gtktypebuiltins.h"
#include "gtkprivate.h"
+#include "gtkmarshalers.h"
#include "gtkalias.h"
static void gtk_file_chooser_class_init (gpointer g_iface);
@@ -56,6 +57,22 @@ gtk_file_chooser_get_type (void)
return file_chooser_type;
}
+static gboolean
+confirm_overwrite_accumulator (GSignalInvocationHint *ihint,
+ GValue *return_accu,
+ const GValue *handler_return,
+ gpointer dummy)
+{
+ gboolean continue_emission;
+ GtkFileChooserConfirmation conf;
+
+ conf = g_value_get_enum (handler_return);
+ g_value_set_enum (return_accu, conf);
+ continue_emission = (conf == GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM);
+
+ return continue_emission;
+}
+
static void
gtk_file_chooser_class_init (gpointer g_iface)
{
@@ -171,6 +188,20 @@ gtk_file_chooser_class_init (gpointer g_iface)
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
+
+ /**
+ * GtkFileChooser::confirm-overwrite
+ * @chooser: the object which received the signal.
+ *
+ * FIXME
+ */
+ g_signal_new ("confirm-overwrite",
+ iface_type,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GtkFileChooserIface, confirm_overwrite),
+ confirm_overwrite_accumulator, NULL,
+ _gtk_marshal_ENUM__VOID,
+ GTK_TYPE_FILE_CHOOSER_CONFIRMATION, 0);
g_object_interface_install_property (g_iface,
g_param_spec_enum ("action",
@@ -234,6 +265,15 @@ gtk_file_chooser_class_init (gpointer g_iface)
P_("Whether the hidden files and folders should be displayed"),
FALSE,
GTK_PARAM_READWRITE));
+
+ g_object_interface_install_property (g_iface,
+ g_param_spec_boolean ("do-overwrite-confirmation",
+ P_("Do overwrite confirmation"),
+ P_("Whether a file chooser in GTK_FILE_CHOOSER_ACTION_SAVE "
+ "will present an overwrite confirmation dialog if the user "
+ "selects a file name that already exists."),
+ FALSE,
+ GTK_PARAM_READWRITE));
}
/**
@@ -1832,6 +1872,54 @@ gtk_file_chooser_get_show_hidden (GtkFileChooser *chooser)
return show_hidden;
}
+/**
+ * gtk_file_chooser_set_do_overwrite_confirmation:
+ * @chooser: a #GtkFileChooser
+ * @do_overwrite_confirmation: whether to confirm overwriting in save mode
+ *
+ * Sets whether a file chooser in GTK_FILE_CHOOSER_ACTION_SAVE mode will present
+ * a confirmation dialog if the user types a file name that already exists. This
+ * is %FALSE by default.
+ *
+ * Regardless of this setting, the @chooser will emit the "confirm-overwrite"
+ * signal when appropriate.
+ *
+ * If all you need is the stock confirmation dialog, set this property to %TRUE.
+ * You can override the way confirmation is done by actually handling the
+ * "confirm-overwrite" signal; please refer to its documentation for the
+ * details.
+ **/
+void
+gtk_file_chooser_set_do_overwrite_confirmation (GtkFileChooser *chooser,
+ gboolean do_overwrite_confirmation)
+{
+ g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
+
+ g_object_set (chooser, "do-overwrite-confirmation", do_overwrite_confirmation, NULL);
+}
+
+/**
+ * gtk_file_chooser_get_do_overwrite_confirmation:
+ * @chooser: a #GtkFileChooser
+ *
+ * Queries whether a file chooser is set to confirm for overwriting when the user
+ * types a file name that already exists.
+ *
+ * Return value: %TRUE if the file chooser will present a confirmation dialog;
+ * %FALSE otherwise.
+ **/
+gboolean
+gtk_file_chooser_get_do_overwrite_confirmation (GtkFileChooser *chooser)
+{
+ gboolean do_overwrite_confirmation;
+
+ g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
+
+ g_object_get (chooser, "do-overwrite-confirmation", &do_overwrite_confirmation, NULL);
+
+ return do_overwrite_confirmation;
+}
+
#ifdef G_OS_WIN32
/* DLL ABI stability backward compatibility versions */