From: Robert O'Callahan Subject: overwrite confirmation behaves strange (we need at least GTK2.8 for this) References: https://bugzilla.novell.com/show_bug.cgi?id=179531 https://bugzilla.mozilla.org/show_bug.cgi?id=341218 Index: widget/src/gtk2/nsFilePicker.cpp =================================================================== RCS file: /home/rocallahan/mozilla-cvs-mirror/mozilla/widget/src/gtk2/nsFilePicker.cpp,v retrieving revision 1.11 diff -u -t -p -1 -2 -r1.11 nsFilePicker.cpp --- widget/src/gtk2/nsFilePicker.cpp 17 Aug 2005 13:41:44 -0000 1.11 +++ widget/src/gtk2/nsFilePicker.cpp 12 Jun 2006 08:02:15 -0000 @@ -81,39 +81,41 @@ typedef enum GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER } GtkFileChooserAction; typedef gchar* (*_gtk_file_chooser_get_filename_fn)(GtkFileChooser *chooser); typedef GSList* (*_gtk_file_chooser_get_filenames_fn)(GtkFileChooser *chooser); typedef GtkWidget* (*_gtk_file_chooser_dialog_new_fn)(const gchar *title, GtkWindow *parent, GtkFileChooserAction action, const gchar *first_button_text, ...); typedef void (*_gtk_file_chooser_set_select_multiple_fn)(GtkFileChooser* chooser, gboolean truth); +typedef void (*_gtk_file_chooser_set_do_overwrite_confirmation_fn)(GtkFileChooser* chooser, gboolean do_confirm); typedef void (*_gtk_file_chooser_set_current_name_fn)(GtkFileChooser* chooser, const gchar* name); typedef void (*_gtk_file_chooser_set_current_folder_fn)(GtkFileChooser* chooser, const gchar* folder); typedef void (*_gtk_file_chooser_add_filter_fn)(GtkFileChooser* chooser, GtkFileFilter* filter); typedef void (*_gtk_file_chooser_set_filter_fn)(GtkFileChooser* chooser, GtkFileFilter* filter); typedef GtkFileFilter* (*_gtk_file_chooser_get_filter_fn)(GtkFileChooser* chooser); typedef GSList* (*_gtk_file_chooser_list_filters_fn)(GtkFileChooser* chooser); typedef GtkFileFilter* (*_gtk_file_filter_new_fn)(); typedef void (*_gtk_file_filter_add_pattern_fn)(GtkFileFilter* filter, const gchar* pattern); typedef void (*_gtk_file_filter_set_name_fn)(GtkFileFilter* filter, const gchar* name); DECL_FUNC_PTR(gtk_file_chooser_get_filename); DECL_FUNC_PTR(gtk_file_chooser_get_filenames); DECL_FUNC_PTR(gtk_file_chooser_dialog_new); DECL_FUNC_PTR(gtk_file_chooser_set_select_multiple); +DECL_FUNC_PTR(gtk_file_chooser_set_do_overwrite_confirmation); DECL_FUNC_PTR(gtk_file_chooser_set_current_name); DECL_FUNC_PTR(gtk_file_chooser_set_current_folder); DECL_FUNC_PTR(gtk_file_chooser_add_filter); DECL_FUNC_PTR(gtk_file_chooser_set_filter); DECL_FUNC_PTR(gtk_file_chooser_get_filter); DECL_FUNC_PTR(gtk_file_chooser_list_filters); DECL_FUNC_PTR(gtk_file_filter_new); DECL_FUNC_PTR(gtk_file_filter_add_pattern); DECL_FUNC_PTR(gtk_file_filter_set_name); static GtkWindow * get_gtk_window_for_nsiwidget(nsIWidget *widget) @@ -175,24 +177,25 @@ nsFilePicker::LoadSymbolsGTK24() } else { // XXX hmm, this seems to fail when gtk 2.4 is already loaded... mGTK24 = LoadVersionedLibrary("gtk-2", ".4"); if (!mGTK24) { return NS_ERROR_NOT_AVAILABLE; } GET_LIBGTK_FUNC(gtk_file_chooser_get_filename); } GET_LIBGTK_FUNC(gtk_file_chooser_get_filenames); GET_LIBGTK_FUNC(gtk_file_chooser_dialog_new); GET_LIBGTK_FUNC(gtk_file_chooser_set_select_multiple); + GET_LIBGTK_FUNC(gtk_file_chooser_set_do_overwrite_confirmation); GET_LIBGTK_FUNC(gtk_file_chooser_set_current_name); GET_LIBGTK_FUNC(gtk_file_chooser_set_current_folder); GET_LIBGTK_FUNC(gtk_file_chooser_add_filter); GET_LIBGTK_FUNC(gtk_file_chooser_set_filter); GET_LIBGTK_FUNC(gtk_file_chooser_get_filter); GET_LIBGTK_FUNC(gtk_file_chooser_list_filters); GET_LIBGTK_FUNC(gtk_file_filter_new); GET_LIBGTK_FUNC(gtk_file_filter_add_pattern); GET_LIBGTK_FUNC(gtk_file_filter_set_name); // Woot. return NS_OK; @@ -555,43 +558,51 @@ nsFilePicker::Show(PRInt16 *aReturn) const char *filter_pattern = mFilters[i]->get(); _gtk_file_filter_set_name (filter, filter_pattern); } _gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (file_chooser), filter); // Set the initially selected filter if (mSelectedType == i) { _gtk_file_chooser_set_filter (GTK_FILE_CHOOSER(file_chooser), filter); } } + PRBool manualConfirm = PR_TRUE; + if (_gtk_file_chooser_set_do_overwrite_confirmation) { + manualConfirm = PR_FALSE; + // Only available in GTK 2.8 + _gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(file_chooser), PR_TRUE); + } + gint response = gtk_dialog_run (GTK_DIALOG (file_chooser)); switch (response) { case GTK_RESPONSE_ACCEPT: ReadValuesFromFileChooser(file_chooser); *aReturn = nsIFilePicker::returnOK; if (mMode == nsIFilePicker::modeSave) { nsCOMPtr file; GetFile(getter_AddRefs(file)); if (file) { PRBool exists = PR_FALSE; file->Exists(&exists); if (exists) { - PRBool overwrite = confirm_overwrite_file (file_chooser, file); + PRBool overwrite = !manualConfirm || + confirm_overwrite_file (file_chooser, file); if (overwrite) { *aReturn = nsIFilePicker::returnReplace; } else { - *aReturn = nsIFilePicker::returnCancel; + *aReturn = nsIFilePicker::returnCancel; } } } } break; case GTK_RESPONSE_CANCEL: case GTK_RESPONSE_CLOSE: case GTK_RESPONSE_DELETE_EVENT: *aReturn = nsIFilePicker::returnCancel; break;