System File Chooser: implemented native bindings for NSOpenPanel and NSSavePanel on macOS

This commit is contained in:
Karl Tauber
2024-12-30 12:46:28 +01:00
parent 80ba75fdeb
commit 516bd80702
8 changed files with 941 additions and 4 deletions

View File

@@ -44,7 +44,7 @@ import com.formdev.flatlaf.util.SystemInfo;
*/
public class FlatNativeMacLibrary
{
private static int API_VERSION_MACOS = 2001;
private static int API_VERSION_MACOS = 2002;
/**
* Checks whether native library is loaded/available.
@@ -68,4 +68,50 @@ public class FlatNativeMacLibrary
/** @since 3.4 */ public native static Rectangle getWindowButtonsBounds( Window window );
/** @since 3.4 */ public native static boolean isWindowFullScreen( Window window );
/** @since 3.4 */ public native static boolean toggleWindowFullScreen( Window window );
/** @since 3.6 */
public static final int
// NSOpenPanel
FC_canChooseFiles = 1 << 0, // default
FC_canChooseDirectories = 1 << 1,
FC_resolvesAliases_NO = 1 << 2, // default
FC_allowsMultipleSelection = 1 << 3,
// NSSavePanel
FC_showsTagField_YES = 1 << 8, // default for Save
FC_showsTagField_NO = 1 << 9, // default for Open
FC_canCreateDirectories_YES = 1 << 10, // default for Save
FC_canCreateDirectories_NO = 1 << 11, // default for Open
FC_canSelectHiddenExtension = 1 << 12,
FC_showsHiddenFiles = 1 << 14,
FC_extensionHidden = 1 << 16,
FC_allowsOtherFileTypes = 1 << 18,
FC_treatsFilePackagesAsDirectories = 1 << 20;
/**
* Shows the macOS system file dialogs
* <a href="https://developer.apple.com/documentation/appkit/nsopenpanel?language=objc">NSOpenPanel</a> or
* <a href="https://developer.apple.com/documentation/appkit/nssavepanel?language=objc">NSSavePanel</a>.
* <p>
* <b>Note:</b> This method blocks the current thread until the user closes
* the file dialog. It is highly recommended to invoke it from a new thread
* to avoid blocking the AWT event dispatching thread.
*
* @param open if {@code true}, shows the open dialog; if {@code false}, shows the save dialog
* @param title text displayed at top of save dialog (not used in open dialog)
* @param prompt text displayed in default button
* @param message text displayed at top of open/save dialogs
* @param nameFieldLabel text displayed in front of the filename text field in save dialog (not used in open dialog)
* @param nameFieldStringValue user-editable filename currently shown in the name field in save dialog (not used in open dialog)
* @param directoryURL current directory shown in the dialog
* @param options see {@code FC_*} constants
* @param allowedFileTypes allowed filename extensions (e.g. "txt")
* @return file path(s) that the user selected, or {@code null} if canceled
*
* @since 3.6
*/
public native static String[] showFileChooser( boolean open,
String title, String prompt, String message, String nameFieldLabel,
String nameFieldStringValue, String directoryURL, int options,
String... allowedFileTypes );
}