JAL-2344 push Cache.getProperty("LAST_DIRECTORY") inside method
[jalview.git] / src / jalview / gui / Desktop.java
index cc897e3..0321662 100644 (file)
@@ -31,6 +31,7 @@ import jalview.io.DataSourceType;
 import jalview.io.FileFormat;
 import jalview.io.FileFormatException;
 import jalview.io.FileFormatI;
+import jalview.io.FileFormats;
 import jalview.io.FileLoader;
 import jalview.io.IdentifyFile;
 import jalview.io.JalviewFileChooser;
@@ -890,9 +891,10 @@ public class Desktop extends jalview.jbgui.GDesktop implements
       }
     });
 
+    desktop.add(frame);
+
     windowMenu.add(menuItem);
 
-    desktop.add(frame);
     frame.toFront();
     try
     {
@@ -1024,20 +1026,21 @@ public class Desktop extends jalview.jbgui.GDesktop implements
       Cache.setProperty("LAST_DIRECTORY", chooser
               .getSelectedFile().getParent());
 
-      FileFormatI format = null;
-      FileFormatI selectedFormat = chooser.getSelectedFormat();
-      if (FileFormat.Jalview.equals(selectedFormat))
-      {
-        format = FileFormat.Jalview;
-      }
-      else
+      FileFormatI format = chooser.getSelectedFormat();
+
+      /*
+       * Call IdentifyFile to verify the file contains what its extension implies.
+       * Skip this step for dynamically added file formats, because
+       * IdentifyFile does not know how to recognise them.
+       */
+      if (FileFormats.getInstance().isIdentifiable(format))
       {
         try
         {
           format = new IdentifyFile().identify(choice, DataSourceType.FILE);
         } catch (FileFormatException e)
         {
-          // format is null
+          // format = null; //??
         }
       }
 
@@ -1528,8 +1531,8 @@ public class Desktop extends jalview.jbgui.GDesktop implements
   @Override
   public void saveState_actionPerformed(ActionEvent e)
   {
-    JalviewFileChooser chooser = new JalviewFileChooser(
-            Cache.getProperty("LAST_DIRECTORY"), "jvp", "Jalview Project");
+    JalviewFileChooser chooser = new JalviewFileChooser("jvp",
+            "Jalview Project");
 
     chooser.setFileView(new JalviewFileView());
     chooser.setDialogTitle(MessageManager.getString("label.save_state"));
@@ -2182,8 +2185,8 @@ public class Desktop extends jalview.jbgui.GDesktop implements
   {
     if (v_client != null)
     {
-      JalviewFileChooser chooser = new JalviewFileChooser(
-              Cache.getProperty("LAST_DIRECTORY"), "vdj",// TODO: VAMSAS DOCUMENT EXTENSION is VDJ
+   // TODO: VAMSAS DOCUMENT EXTENSION is VDJ
+      JalviewFileChooser chooser = new JalviewFileChooser("vdj",
               "Vamsas Document");
 
       chooser.setFileView(new JalviewFileView());