JAL-2988 if selected file is null (On Java 10/OSX - happens if user has entered text...
authorJim Procter <jprocter@issues.jalview.org>
Fri, 7 Sep 2018 13:24:20 +0000 (14:24 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Fri, 7 Sep 2018 13:24:20 +0000 (14:24 +0100)
src/jalview/io/JalviewFileChooser.java

index 2ba7bbf..1294e89 100755 (executable)
@@ -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();