System File Chooser: macOS:

- use `optionsSet` and `optionsClear` (as on Windows)
- delete local reference after getting Java array item
- added "or null" to javadoc
This commit is contained in:
Karl Tauber
2024-12-31 18:36:29 +01:00
parent 49a0a83eca
commit 63272a03cf
5 changed files with 109 additions and 110 deletions

View File

@@ -17,28 +17,24 @@ extern "C" {
#define com_formdev_flatlaf_ui_FlatNativeMacLibrary_FC_canChooseFiles 1L
#undef com_formdev_flatlaf_ui_FlatNativeMacLibrary_FC_canChooseDirectories
#define com_formdev_flatlaf_ui_FlatNativeMacLibrary_FC_canChooseDirectories 2L
#undef com_formdev_flatlaf_ui_FlatNativeMacLibrary_FC_resolvesAliases_NO
#define com_formdev_flatlaf_ui_FlatNativeMacLibrary_FC_resolvesAliases_NO 4L
#undef com_formdev_flatlaf_ui_FlatNativeMacLibrary_FC_resolvesAliases
#define com_formdev_flatlaf_ui_FlatNativeMacLibrary_FC_resolvesAliases 4L
#undef com_formdev_flatlaf_ui_FlatNativeMacLibrary_FC_allowsMultipleSelection
#define com_formdev_flatlaf_ui_FlatNativeMacLibrary_FC_allowsMultipleSelection 8L
#undef com_formdev_flatlaf_ui_FlatNativeMacLibrary_FC_showsTagField_YES
#define com_formdev_flatlaf_ui_FlatNativeMacLibrary_FC_showsTagField_YES 256L
#undef com_formdev_flatlaf_ui_FlatNativeMacLibrary_FC_showsTagField_NO
#define com_formdev_flatlaf_ui_FlatNativeMacLibrary_FC_showsTagField_NO 512L
#undef com_formdev_flatlaf_ui_FlatNativeMacLibrary_FC_canCreateDirectories_YES
#define com_formdev_flatlaf_ui_FlatNativeMacLibrary_FC_canCreateDirectories_YES 1024L
#undef com_formdev_flatlaf_ui_FlatNativeMacLibrary_FC_canCreateDirectories_NO
#define com_formdev_flatlaf_ui_FlatNativeMacLibrary_FC_canCreateDirectories_NO 2048L
#undef com_formdev_flatlaf_ui_FlatNativeMacLibrary_FC_showsTagField
#define com_formdev_flatlaf_ui_FlatNativeMacLibrary_FC_showsTagField 256L
#undef com_formdev_flatlaf_ui_FlatNativeMacLibrary_FC_canCreateDirectories
#define com_formdev_flatlaf_ui_FlatNativeMacLibrary_FC_canCreateDirectories 512L
#undef com_formdev_flatlaf_ui_FlatNativeMacLibrary_FC_canSelectHiddenExtension
#define com_formdev_flatlaf_ui_FlatNativeMacLibrary_FC_canSelectHiddenExtension 4096L
#define com_formdev_flatlaf_ui_FlatNativeMacLibrary_FC_canSelectHiddenExtension 1024L
#undef com_formdev_flatlaf_ui_FlatNativeMacLibrary_FC_showsHiddenFiles
#define com_formdev_flatlaf_ui_FlatNativeMacLibrary_FC_showsHiddenFiles 16384L
#define com_formdev_flatlaf_ui_FlatNativeMacLibrary_FC_showsHiddenFiles 2048L
#undef com_formdev_flatlaf_ui_FlatNativeMacLibrary_FC_extensionHidden
#define com_formdev_flatlaf_ui_FlatNativeMacLibrary_FC_extensionHidden 65536L
#define com_formdev_flatlaf_ui_FlatNativeMacLibrary_FC_extensionHidden 4096L
#undef com_formdev_flatlaf_ui_FlatNativeMacLibrary_FC_allowsOtherFileTypes
#define com_formdev_flatlaf_ui_FlatNativeMacLibrary_FC_allowsOtherFileTypes 262144L
#define com_formdev_flatlaf_ui_FlatNativeMacLibrary_FC_allowsOtherFileTypes 8192L
#undef com_formdev_flatlaf_ui_FlatNativeMacLibrary_FC_treatsFilePackagesAsDirectories
#define com_formdev_flatlaf_ui_FlatNativeMacLibrary_FC_treatsFilePackagesAsDirectories 1048576L
#define com_formdev_flatlaf_ui_FlatNativeMacLibrary_FC_treatsFilePackagesAsDirectories 16384L
/*
* Class: com_formdev_flatlaf_ui_FlatNativeMacLibrary
* Method: setWindowRoundedBorder
@@ -82,10 +78,10 @@ JNIEXPORT jboolean JNICALL Java_com_formdev_flatlaf_ui_FlatNativeMacLibrary_togg
/*
* Class: com_formdev_flatlaf_ui_FlatNativeMacLibrary
* Method: showFileChooser
* Signature: (ZLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I[Ljava/lang/String;)[Ljava/lang/String;
* Signature: (ZLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;II[Ljava/lang/String;)[Ljava/lang/String;
*/
JNIEXPORT jobjectArray JNICALL Java_com_formdev_flatlaf_ui_FlatNativeMacLibrary_showFileChooser
(JNIEnv *, jclass, jboolean, jstring, jstring, jstring, jstring, jstring, jstring, jint, jobjectArray);
(JNIEnv *, jclass, jboolean, jstring, jstring, jstring, jstring, jstring, jstring, jint, jint, jobjectArray);
#ifdef __cplusplus
}

View File

@@ -25,8 +25,9 @@
* @author Karl Tauber
*/
#define isOptionSet( option ) ((options & com_formdev_flatlaf_ui_FlatNativeMacLibrary_ ## option) != 0)
#define isYesOrNoOptionSet( option ) isOptionSet( option ## _YES ) || isOptionSet( option ## _NO )
#define isOptionSet( option ) ((optionsSet & com_formdev_flatlaf_ui_FlatNativeMacLibrary_ ## option) != 0)
#define isOptionClear( option ) ((optionsClear & com_formdev_flatlaf_ui_FlatNativeMacLibrary_ ## option) != 0)
#define isOptionSetOrClear( option ) isOptionSet( option ) || isOptionClear( option )
// declare internal methods
NSWindow* getNSWindow( JNIEnv* env, jclass cls, jobject window );
@@ -38,7 +39,7 @@ JNIEXPORT jobjectArray JNICALL Java_com_formdev_flatlaf_ui_FlatNativeMacLibrary_
( JNIEnv* env, jclass cls, jboolean open,
jstring title, jstring prompt, jstring message, jstring nameFieldLabel,
jstring nameFieldStringValue, jstring directoryURL,
jint options, jobjectArray allowedFileTypes )
jint optionsSet, jint optionsClear, jobjectArray allowedFileTypes )
{
JNI_COCOA_ENTER()
@@ -56,8 +57,8 @@ JNIEXPORT jobjectArray JNICALL Java_com_formdev_flatlaf_ui_FlatNativeMacLibrary_
NSMutableArray* nsArray = [NSMutableArray arrayWithCapacity:len];
for( int i = 0; i < len; i++ ) {
jstring str = (jstring) env->GetObjectArrayElement( allowedFileTypes, i );
NSString* nsStr = JavaToNSString( env, str );
nsArray[i] = nsStr;
nsArray[i] = JavaToNSString( env, str );
env->DeleteLocalRef( str );
}
nsAllowedFileTypes = nsArray;
}
@@ -93,26 +94,27 @@ JNIEXPORT jobjectArray JNICALL Java_com_formdev_flatlaf_ui_FlatNativeMacLibrary_
canChooseFiles = true;
openDialog.canChooseFiles = canChooseFiles;
openDialog.canChooseDirectories = canChooseDirectories;
if( isOptionSet( FC_resolvesAliases_NO ) )
openDialog.resolvesAliases = NO;
if( isOptionSet( FC_allowsMultipleSelection ) )
openDialog.allowsMultipleSelection = YES;
if( isOptionSetOrClear( FC_resolvesAliases ) )
openDialog.resolvesAliases = isOptionSet( FC_resolvesAliases );
if( isOptionSetOrClear( FC_allowsMultipleSelection ) )
openDialog.allowsMultipleSelection = isOptionSet( FC_allowsMultipleSelection );
}
if( isYesOrNoOptionSet( FC_showsTagField ) )
dialog.showsTagField = isOptionSet( FC_showsTagField_YES );
if( isYesOrNoOptionSet( FC_canCreateDirectories ) )
dialog.canCreateDirectories = isOptionSet( FC_canCreateDirectories_YES );
if( isOptionSet( FC_canSelectHiddenExtension ) )
dialog.canSelectHiddenExtension = YES;
if( isOptionSet( FC_showsHiddenFiles) )
dialog.showsHiddenFiles = YES;
if( isOptionSet( FC_extensionHidden ) )
dialog.extensionHidden = YES;
if( isOptionSet( FC_allowsOtherFileTypes ) )
dialog.allowsOtherFileTypes = YES;
if( isOptionSet( FC_treatsFilePackagesAsDirectories ) )
dialog.treatsFilePackagesAsDirectories = YES;
if( isOptionSetOrClear( FC_showsTagField ) )
dialog.showsTagField = isOptionSet( FC_showsTagField );
if( isOptionSetOrClear( FC_canCreateDirectories ) )
dialog.canCreateDirectories = isOptionSet( FC_canCreateDirectories );
if( isOptionSetOrClear( FC_canSelectHiddenExtension ) )
dialog.canSelectHiddenExtension = isOptionSet( FC_canSelectHiddenExtension );
if( isOptionSetOrClear( FC_showsHiddenFiles) )
dialog.showsHiddenFiles = isOptionSet( FC_showsHiddenFiles);
if( isOptionSetOrClear( FC_extensionHidden ) )
dialog.extensionHidden = isOptionSet( FC_extensionHidden );
if( isOptionSetOrClear( FC_allowsOtherFileTypes ) )
dialog.allowsOtherFileTypes = isOptionSet( FC_allowsOtherFileTypes );
if( isOptionSetOrClear( FC_treatsFilePackagesAsDirectories ) )
dialog.treatsFilePackagesAsDirectories = isOptionSet( FC_treatsFilePackagesAsDirectories );
// use deprecated allowedFileTypes instead of newer allowedContentTypes (since macOS 11+)
// to support older macOS versions 10.14+ and because of some problems with allowedContentTypes: