From: Jim Procter Date: Fri, 7 Sep 2018 13:24:20 +0000 (+0100) Subject: JAL-2988 if selected file is null (On Java 10/OSX - happens if user has entered text... X-Git-Tag: Release_2_10_5~4 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=9109818e704dd0945567b234af8f3d34ba4b2b67;p=jalview.git JAL-2988 if selected file is null (On Java 10/OSX - happens if user has entered text after selecting a file), try and get the filename from the UI. If no file can be gotten, cancel the save operation --- diff --git a/src/jalview/io/JalviewFileChooser.java b/src/jalview/io/JalviewFileChooser.java index 2ba7bbf..1294e89 100755 --- a/src/jalview/io/JalviewFileChooser.java +++ b/src/jalview/io/JalviewFileChooser.java @@ -302,6 +302,28 @@ public class JalviewFileChooser extends JFileChooser int ret = showDialog(parent, MessageManager.getString("action.save")); ourselectedFile = getSelectedFile(); + if (getSelectedFile() == null) + { + // Workaround for Java 9,10 on OSX - no selected file, but there is a + // filename typed in + try + { + String filename = ((BasicFileChooserUI) getUI()).getFileName(); + if (filename != null && filename.length() > 0) + { + ourselectedFile = new File(getCurrentDirectory(), filename); + } + } catch (Throwable x) + { + System.err.println( + "Unexpected exception when trying to get filename."); + x.printStackTrace(); + } + } + if (ourselectedFile == null) + { + return JalviewFileChooser.CANCEL_OPTION; + } if (getFileFilter() instanceof JalviewFileFilter) { JalviewFileFilter jvf = (JalviewFileFilter) getFileFilter();