System File Chooser: support "approve" callback and system message dialog on macOS (not yet used in SystemFileChooser
Some checks failed
CI / build (11, ) (push) Has been cancelled
CI / build (17, ) (push) Has been cancelled
CI / build (21, ) (push) Has been cancelled
CI / build (23, ) (push) Has been cancelled
CI / build (8, ) (push) Has been cancelled
Native Libraries / Natives (macos) (push) Has been cancelled
Native Libraries / Natives (ubuntu) (push) Has been cancelled
Native Libraries / Natives (windows) (push) Has been cancelled
CI / snapshot (push) Has been cancelled
CI / release (push) Has been cancelled

This commit is contained in:
Karl Tauber
2025-01-12 18:16:40 +01:00
parent d49282dfe8
commit 078e59a443
7 changed files with 252 additions and 32 deletions

View File

@@ -59,7 +59,7 @@ public class FlatSystemFileChooserMacTest
}
FlatTestFrame frame = FlatTestFrame.create( args, "FlatSystemFileChooserMacTest" );
addListeners( frame );
// addListeners( frame );
frame.showFrame( FlatSystemFileChooserMacTest::new );
} );
}
@@ -133,11 +133,24 @@ public class FlatSystemFileChooserMacTest
}
int fileTypeIndex = fileTypeIndexSlider.getValue();
FlatNativeMacLibrary.FileChooserCallback callback = (files, hwndFileDialog) -> {
System.out.println( " -- callback " + hwndFileDialog + " " + Arrays.toString( files ) );
if( showMessageDialogOnOKCheckBox.isSelected() ) {
int result = FlatNativeMacLibrary.showMessageDialog( hwndFileDialog,
JOptionPane.INFORMATION_MESSAGE,
"primary text", "secondary text", 0, "Yes", "No" );
System.out.println( " result " + result );
if( result != 0 )
return false;
}
return true;
};
if( direct ) {
String[] files = FlatNativeMacLibrary.showFileChooser( open,
title, prompt, message, filterFieldLabel,
nameFieldLabel, nameFieldStringValue, directoryURL,
optionsSet.get(), optionsClear.get(), fileTypeIndex, fileTypes );
optionsSet.get(), optionsClear.get(), callback, fileTypeIndex, fileTypes );
filesField.setText( (files != null) ? Arrays.toString( files ).replace( ',', '\n' ) : "null" );
} else {
@@ -148,7 +161,7 @@ public class FlatSystemFileChooserMacTest
String[] files = FlatNativeMacLibrary.showFileChooser( open,
title, prompt, message, filterFieldLabel,
nameFieldLabel, nameFieldStringValue, directoryURL,
optionsSet.get(), optionsClear.get(), fileTypeIndex, fileTypes2 );
optionsSet.get(), optionsClear.get(), callback, fileTypeIndex, fileTypes2 );
System.out.println( " secondaryLoop.exit() returned " + secondaryLoop.exit() );
@@ -173,6 +186,7 @@ public class FlatSystemFileChooserMacTest
optionsClear.set( optionsClear.get() | option );
}
@SuppressWarnings( "unused" )
private static void addListeners( Window w ) {
w.addWindowListener( new WindowListener() {
@Override
@@ -270,6 +284,7 @@ public class FlatSystemFileChooserMacTest
saveButton = new JButton();
openDirectButton = new JButton();
saveDirectButton = new JButton();
showMessageDialogOnOKCheckBox = new JCheckBox();
filesScrollPane = new JScrollPane();
filesField = new JTextArea();
@@ -468,6 +483,10 @@ public class FlatSystemFileChooserMacTest
saveDirectButton.addActionListener(e -> saveDirect());
add(saveDirectButton, "cell 0 10 3 1");
//---- showMessageDialogOnOKCheckBox ----
showMessageDialogOnOKCheckBox.setText("show message dialog on OK");
add(showMessageDialogOnOKCheckBox, "cell 0 10 3 1");
//======== filesScrollPane ========
{
@@ -519,6 +538,7 @@ public class FlatSystemFileChooserMacTest
private JButton saveButton;
private JButton openDirectButton;
private JButton saveDirectButton;
private JCheckBox showMessageDialogOnOKCheckBox;
private JScrollPane filesScrollPane;
private JTextArea filesField;
// JFormDesigner - End of variables declaration //GEN-END:variables

View File

@@ -257,6 +257,12 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 10 3 1"
} )
add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "showMessageDialogOnOKCheckBox"
"text": "show message dialog on OK"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 10 3 1"
} )
add( new FormContainer( "javax.swing.JScrollPane", new FormLayoutManager( class javax.swing.JScrollPane ) ) {
name: "filesScrollPane"
add( new FormComponent( "javax.swing.JTextArea" ) {