Skip to content

Commit

Permalink
fix #21497 - see #21344 - don't use FILES_AND_DIRECTORIES selection m…
Browse files Browse the repository at this point in the history
…ode if user chose native file dialogs (patch by taylor.smock)

git-svn-id: https://josm.openstreetmap.de/svn/trunk@18314 0c6e7542-c601-0410-84e7-c038aed88b3b
  • Loading branch information
don-vip committed Nov 7, 2021
1 parent 204e369 commit 71589d9
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/org/openstreetmap/josm/actions/OpenFileAction.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// License: GPL. For details, see LICENSE file.
package org.openstreetmap.josm.actions;

import static javax.swing.JFileChooser.FILES_AND_DIRECTORIES;
import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
import static org.openstreetmap.josm.tools.I18n.tr;
import static org.openstreetmap.josm.tools.I18n.trn;
Expand Down Expand Up @@ -28,7 +29,6 @@
import java.util.regex.Pattern;
import java.util.stream.Stream;

import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.filechooser.FileFilter;
Expand All @@ -44,6 +44,8 @@
import org.openstreetmap.josm.gui.io.importexport.Options;
import org.openstreetmap.josm.gui.util.GuiHelper;
import org.openstreetmap.josm.gui.widgets.AbstractFileChooser;
import org.openstreetmap.josm.gui.widgets.FileChooserManager;
import org.openstreetmap.josm.gui.widgets.NativeFileChooser;
import org.openstreetmap.josm.io.OsmTransferException;
import org.openstreetmap.josm.spi.preferences.Config;
import org.openstreetmap.josm.tools.Logging;
Expand Down Expand Up @@ -78,8 +80,16 @@ public OpenFileAction() {

@Override
public void actionPerformed(ActionEvent e) {
AbstractFileChooser fc = createAndOpenFileChooser(true, true, null, null, JFileChooser.FILES_AND_DIRECTORIES,
true, null);
final AbstractFileChooser fc;
// If the user explicitly wants native file dialogs, let them use it.
// Rather unfortunately, this means that they will not be able to select files and directories.
if (FileChooserManager.PROP_USE_NATIVE_FILE_DIALOG.get()
// This is almost redundant, as the JDK currently doesn't support this with (all?) native file choosers.
&& !NativeFileChooser.supportsSelectionMode(FILES_AND_DIRECTORIES)) {
fc = createAndOpenFileChooser(true, true, null);
} else {
fc = createAndOpenFileChooser(true, true, null, null, FILES_AND_DIRECTORIES, true, null);
}
if (fc == null)
return;
File[] files = fc.getSelectedFiles();
Expand Down

0 comments on commit 71589d9

Please sign in to comment.