JDK-8299969 : Cannot override prompt to confirm saving using FileChooser
  • Type: Enhancement
  • Component: javafx
  • Affected Version: openjfx19
  • Priority: P4
  • Status: New
  • Resolution: Unresolved
  • OS: linux
  • CPU: x86_64
  • Submitted: 2023-01-10
  • Updated: 2023-01-11
Description
A DESCRIPTION OF THE PROBLEM :
The TRUE at the following line assumes that application developers always want to force users to confirm overwriting an existing file:

        gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER (chooser), TRUE);

https://github.com/openjdk/jfx/blob/bca1bfc5e3b04293c13417fd923d99864cdd9147/modules/javafx.graphics/src/main/native-glass/gtk/GlassCommonDialogs.cpp#L125

This is not always the case. For example, sometimes a user may be repeating the same task numerous times and knows that the destination file is going to be overwritten. Further, the behaviour differs across different systems (Linux, the confirmation dialog can be dismissed by pressing Enter; Windows, dismissal requires two keyboard actions), which then adds complications to user manuals.

Here's a related SO question: https://stackoverflow.com/q/25045636/59087

Please update the file chooser to include a new parameter that controls whether the confirmation dialog is enabled. Specifically, something like:

JNIEXPORT jobject JNICALL Java_com_sun_glass_ui_gtk_GtkCommonDialogs__1showFileChooser
  (JNIEnv *env, jclass clazz, jlong parent, jstring folder, jstring name, jstring title,
   jint type, jboolean multiple, jobjectArray jFilters, jint default_filter_index, jboolean confirmOverwrite) { ...

Then, later:

        gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER (chooser), confirmOverwrite);

For Windows, there appears to be a similar option, at least for .NET:

https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.savefiledialog.overwriteprompt?view=netframework-4.8

macOS likely has similar functionality.