Gtk.FileChooser::confirm-overwrite
function callback(file_chooser, ):Gtk.FileChooserConfirmation;
This signal gets emitted whenever it is appropriate to present a confirmation dialog when the user has selected a file name that already exists. The signal only gets emitted when the file chooser is in Gtk.FileChooserAction.save mode.
Most applications just need to turn on the Gtk.do-overwrite-confirmation property (or call the Gtk.FileChooser.prototype.set_do_overwrite_confirmation function), and they will automatically get a stock confirmation dialog. Applications which need to customize this behavior should do that, and also connect to the Gtk.FileChooser::confirm-overwrite signal.
A signal handler for this signal must return a Gtk.FileChooserConfirmation value, which indicates the action to take. If the handler determines that the user wants to select a different filename, it should return Gtk.FileChooserConfirmation.select_again. If it determines that the user is satisfied with his choice of file name, it should return Gtk.FileChooserConfirmation.accept_filename. On the other hand, if it determines that the stock confirmation dialog should be used, it should return Gtk.FileChooserConfirmation.confirm. The following example illustrates this. <example id="gtkfilechooser-confirmation"> <title>Custom confirmation</title> <programlisting> static GtkFileChooserConfirmation confirm_overwrite_callback (GtkFileChooser *chooser, gpointer data) { char *uri;
uri = gtk_file_chooser_get_uri (chooser);
if (is_uri_read_only (uri)) { if (user_wants_to_replace_read_only_file (uri)) return GTK_FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME; else return GTK_FILE_CHOOSER_CONFIRMATION_SELECT_AGAIN; } else return GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM; // fall back to the default dialog }
...
chooser = gtk_file_chooser_dialog_new (...);
gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE); g_signal_connect (chooser, "confirm-overwrite", G_CALLBACK (confirm_overwrite_callback), NULL);
if (gtk_dialog_run (chooser) == GTK_RESPONSE_ACCEPT) save_to_file (gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser));
gtk_widget_destroy (chooser); </programlisting> </example>
Since 2.8
- file_chooser
instance of Gtk.FileChooser that is emitting the signal