System File Chooser: macOS: show file dialog in dark if current FlatLaf theme is dark

This commit is contained in:
Karl Tauber
2025-01-21 14:33:03 +01:00
parent 1e3e4d7c61
commit aecb496142
6 changed files with 25 additions and 7 deletions

View File

@@ -99,6 +99,8 @@ public class FlatNativeMacLibrary
* 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; or {@code null}
* @param dark appearance of the file dialog: {@code 1} = dark, {@code 0} = light, {@code -1} = default
* @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); or {@code null}
* @param prompt text displayed in default button; or {@code null}
@@ -120,7 +122,7 @@ public class FlatNativeMacLibrary
*
* @since 3.6
*/
public native static String[] showFileChooser( boolean open,
public native static String[] showFileChooser( Window owner, int dark, boolean open,
String title, String prompt, String message, String filterFieldLabel,
String nameFieldLabel, String nameFieldStringValue, String directoryURL,
int optionsSet, int optionsClear, FileChooserCallback callback,

View File

@@ -33,6 +33,7 @@ import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.filechooser.FileSystemView;
import com.formdev.flatlaf.FlatLaf;
import com.formdev.flatlaf.FlatSystemProperties;
import com.formdev.flatlaf.ui.FlatNativeLinuxLibrary;
import com.formdev.flatlaf.ui.FlatNativeMacLibrary;
@@ -837,6 +838,7 @@ public class SystemFileChooser
{
@Override
String[] showSystemDialog( Window owner, SystemFileChooser fc ) {
int dark = FlatLaf.isLafDark() ? 1 : 0;
boolean open = (fc.getDialogType() == OPEN_DIALOG);
String nameFieldStringValue = null;
String directoryURL = null;
@@ -901,7 +903,7 @@ public class SystemFileChooser
} : null;
// show system file dialog
return FlatNativeMacLibrary.showFileChooser( open,
return FlatNativeMacLibrary.showFileChooser( owner, dark, open,
fc.getDialogTitle(), fc.getApproveButtonText(),
fc.getPlatformProperty( MAC_MESSAGE ),
fc.getPlatformProperty( MAC_FILTER_FIELD_LABEL ),