Merge commit
[jalview.git] / src / jalview / gui / Desktop.java
index 06af0c1..70c8355 100644 (file)
@@ -1467,6 +1467,9 @@ public class Desktop extends jalview.jbgui.GDesktop implements
       final java.io.File choice = chooser.getSelectedFile();
       setProjectFile(choice);
 
+      // TODO or move inside the new Thread?
+      saveChimeraSessions(choice.getAbsolutePath());
+
       new Thread(new Runnable()
       {
         public void run()
@@ -1502,6 +1505,32 @@ public class Desktop extends jalview.jbgui.GDesktop implements
     }
   }
 
+  /**
+   * Request any open, linked Chimera sessions to save their state.
+   * 
+   * @param jalviewProjectFilename
+   *          the filename of the Jalview project; Chimera session files should
+   *          be given distinct, but obviously related, names.
+   */
+  public void saveChimeraSessions(String jalviewProjectFilename)
+  {
+    int i = 0;
+    for (JInternalFrame frame : getAllFrames())
+    {
+      if (frame instanceof ChimeraViewFrame)
+      {
+        /*
+         * Construct a filename for the Chimera session by append _chimera<n>.py
+         * to the Jalview project file name.
+         */
+        String chimeraPath = jalviewProjectFilename + "_chimera_" + i
+                + ".py";
+        ((ChimeraViewFrame) frame).saveSession(chimeraPath);
+        i++;
+      }
+    }
+  }
+
   private void setProjectFile(File choice)
   {
     this.projectFile = choice;