System File Chooser: introduced class SystemFileChooser as replacement for JFileChooser

This commit is contained in:
Karl Tauber
2025-01-06 18:01:50 +01:00
parent 9453d55abd
commit 91e8d04a9f
16 changed files with 1721 additions and 12 deletions

View File

@@ -71,6 +71,17 @@ tasks {
else -> emptyList()
}
} )
doFirst {
// check required Java version
if( JavaVersion.current() < JavaVersion.VERSION_11 ) {
println()
println( "WARNING: Java 11 or later required to build Linux native library (running ${System.getProperty( "java.version" )})" )
println( " Native library built with older Java versions throw following exception when running in Java 17+:" )
println( " java.lang.UnsatisfiedLinkError: .../libjawt.so: version `SUNWprivate_1.1' not found" )
println()
}
}
}
withType<LinkSharedLibrary>().configureEach {

View File

@@ -177,11 +177,11 @@ JNIEXPORT jobjectArray JNICALL Java_com_formdev_flatlaf_ui_FlatNativeLinuxLibrar
bool multiSelect = isOptionSet( FC_select_multiple );
GtkWidget* dialog = gtk_file_chooser_dialog_new(
(ctitle != NULL) ? ctitle
: (open ? (selectFolder ? (multiSelect ? _("Select Folders") : _("Select Folder"))
: (multiSelect ? _("Open Files") : _("Open File"))) : _("Save File")),
: (selectFolder ? (multiSelect ? _("Select Folders") : _("Select Folder"))
: (open ? ((multiSelect ? _("Open Files") : _("Open File"))) : _("Save File"))),
NULL, // can not use AWT X11 window as parent because GtkWindow is required
open ? (selectFolder ? GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER : GTK_FILE_CHOOSER_ACTION_OPEN)
: GTK_FILE_CHOOSER_ACTION_SAVE,
selectFolder ? GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER
: (open ? GTK_FILE_CHOOSER_ACTION_OPEN : GTK_FILE_CHOOSER_ACTION_SAVE),
_("_Cancel"), GTK_RESPONSE_CANCEL,
(cokButtonLabel != NULL) ? cokButtonLabel : (open ? _("_Open") : _("_Save")), GTK_RESPONSE_ACCEPT,
NULL ); // marks end of buttons

View File

@@ -144,6 +144,7 @@ public:
//---- helper -----------------------------------------------------------------
#define isOptionSet( option ) ((optionsSet & com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_ ## option) != 0)
#define CHECK_HRESULT( code ) { if( (code) != S_OK ) return NULL; }
jobjectArray newJavaStringArray( JNIEnv* env, jsize count ) {
@@ -170,12 +171,12 @@ JNIEXPORT jobjectArray JNICALL Java_com_formdev_flatlaf_ui_FlatNativeWindowsLibr
return NULL;
// handle limitations (without this, some Win32 method fails and this method returns NULL)
if( (optionsSet & FOS_PICKFOLDERS) != 0 ) {
if( open )
fileTypes = NULL; // no filter allowed for picking folders
else
optionsSet &= ~FOS_PICKFOLDERS; // not allowed for save dialog
if( isOptionSet( FOS_PICKFOLDERS ) ) {
open = true; // always use IFileOpenDialog for picking folders
fileTypes = NULL; // no filter allowed for picking folders
}
if( !open && isOptionSet( FOS_ALLOWMULTISELECT ) )
optionsSet &= ~FOS_ALLOWMULTISELECT;
// convert Java strings to C strings
AutoReleaseString ctitle( env, title );
@@ -219,7 +220,7 @@ JNIEXPORT jobjectArray JNICALL Java_com_formdev_flatlaf_ui_FlatNativeWindowsLibr
CHECK_HRESULT( dialog->SetOptions ( (existingOptions & ~optionsClear) | optionsSet ) );
// initialize filter
if( specs.count > 0 && (optionsSet & FOS_PICKFOLDERS) == 0 ) {
if( specs.count > 0 ) {
CHECK_HRESULT( dialog->SetFileTypes( specs.count, specs.specs ) );
if( fileTypeIndex > 0 )
CHECK_HRESULT( dialog->SetFileTypeIndex( min( fileTypeIndex + 1, specs.count ) ) );