From 9109818e704dd0945567b234af8f3d34ba4b2b67 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Fri, 7 Sep 2018 14:24:20 +0100 Subject: [PATCH] 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 --- src/jalview/io/JalviewFileChooser.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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(); -- 1.7.10.2