mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-11 06:27:13 -06:00
System File Chooser: implemented native bindings for IFileOpenDialog and IFileSaveDialog on Windows
This commit is contained in:
@@ -30,7 +30,7 @@ import com.formdev.flatlaf.util.SystemInfo;
|
||||
*/
|
||||
public class FlatNativeWindowsLibrary
|
||||
{
|
||||
private static int API_VERSION_WINDOWS = 1001;
|
||||
private static int API_VERSION_WINDOWS = 1002;
|
||||
|
||||
private static long osBuildNumber = Long.MIN_VALUE;
|
||||
|
||||
@@ -158,4 +158,77 @@ public class FlatNativeWindowsLibrary
|
||||
// DwmSetWindowAttribute() expects COLORREF as attribute value, which is defined as DWORD
|
||||
return dwmSetWindowAttributeDWORD( hwnd, attribute, rgb );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* FILEOPENDIALOGOPTIONS
|
||||
* see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
|
||||
*
|
||||
* @since 3.6
|
||||
*/
|
||||
public static final int
|
||||
FOS_OVERWRITEPROMPT = 0x2, // default for Save
|
||||
FOS_STRICTFILETYPES = 0x4,
|
||||
FOS_NOCHANGEDIR = 0x8, // default
|
||||
FOS_PICKFOLDERS = 0x20,
|
||||
FOS_FORCEFILESYSTEM = 0x40,
|
||||
FOS_ALLNONSTORAGEITEMS = 0x80,
|
||||
FOS_NOVALIDATE = 0x100,
|
||||
FOS_ALLOWMULTISELECT = 0x200,
|
||||
FOS_PATHMUSTEXIST = 0x800, // default
|
||||
FOS_FILEMUSTEXIST = 0x1000, // default for Open
|
||||
FOS_CREATEPROMPT = 0x2000,
|
||||
FOS_SHAREAWARE = 0x4000,
|
||||
FOS_NOREADONLYRETURN = 0x8000, // default for Save
|
||||
FOS_NOTESTFILECREATE = 0x10000,
|
||||
FOS_HIDEMRUPLACES = 0x20000,
|
||||
FOS_HIDEPINNEDPLACES = 0x40000,
|
||||
FOS_NODEREFERENCELINKS = 0x100000,
|
||||
FOS_OKBUTTONNEEDSINTERACTION = 0x200000,
|
||||
FOS_DONTADDTORECENT = 0x2000000,
|
||||
FOS_FORCESHOWHIDDEN = 0x10000000,
|
||||
FOS_DEFAULTNOMINIMODE = 0x20000000,
|
||||
FOS_FORCEPREVIEWPANEON = 0x40000000,
|
||||
FOS_SUPPORTSTREAMABLEITEMS = 0x80000000;
|
||||
|
||||
/**
|
||||
* Shows the Windows system
|
||||
* <a href="https://learn.microsoft.com/en-us/windows/win32/shell/common-file-dialog">file dialogs</a>
|
||||
* <a href="https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nn-shobjidl_core-ifileopendialog">IFileOpenDialog</a> or
|
||||
* <a href="https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nn-shobjidl_core-ifilesavedialog">IFileSaveDialog</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 owner the owner of the file dialog
|
||||
* @param open if {@code true}, shows the open dialog; if {@code false}, shows the save dialog
|
||||
* @param title text displayed in dialog title; or {@code null}
|
||||
* @param okButtonLabel text displayed in default button; or {@code null}
|
||||
* @param fileNameLabel text displayed in front of the filename text field; or {@code null}
|
||||
* @param fileName user-editable filename currently shown in the filename field; or {@code null}
|
||||
* @param folder current directory shown in the dialog; or {@code null}
|
||||
* @param saveAsItem file to be used as the initial entry in a Save As dialog; or {@code null}.
|
||||
* File name is shown in filename text field, folder is selected in view.
|
||||
* To be used for saving files that already exist. For new files use {@code fileName}.
|
||||
* @param defaultFolder folder used as a default if there is not a recently used folder value available; or {@code null}.
|
||||
* Windows somewhere stores default folder on a per-app basis.
|
||||
* So this is probably used only once when the app opens a file dialog for first time.
|
||||
* @param defaultExtension default extension to be added to file name in save dialog; or {@code null}
|
||||
* @param optionsSet options to set; see {@code FOS_*} constants
|
||||
* @param optionsClear options to clear; see {@code FOS_*} constants
|
||||
* @param fileTypeIndex the file type that appears as selected (zero-based)
|
||||
* @param fileTypes file types that the dialog can open or save.
|
||||
* Pairs of strings are required.
|
||||
* First string is the display name of the filter shown in the combobox (e.g. "Text Files").
|
||||
* Second string is the filter pattern (e.g. "*.txt", "*.exe;*.dll" or "*.*").
|
||||
* @return file path(s) that the user selected; an empty array if canceled;
|
||||
* or {@code null} on failures (no dialog shown)
|
||||
*
|
||||
* @since 3.6
|
||||
*/
|
||||
public native static String[] showFileChooser( Window owner, boolean open,
|
||||
String title, String okButtonLabel, String fileNameLabel, String fileName,
|
||||
String folder, String saveAsItem, String defaultFolder, String defaultExtension,
|
||||
int optionsSet, int optionsClear, int fileTypeIndex, String... fileTypes );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user