Merge branch 'merge/JAL-1988_JAL-3772+JAL-3416+JAL-4054+JAL-4064' into bug/JAL-4125_f...
[jalview.git] / src / jalview / gui / Desktop.java
index 653cc73..7b4af59 100644 (file)
@@ -102,6 +102,7 @@ import org.stackoverflowusers.file.WindowsShortcut;
 
 import jalview.api.AlignViewportI;
 import jalview.api.AlignmentViewPanel;
+import jalview.api.structures.JalviewStructureDisplayI;
 import jalview.bin.Cache;
 import jalview.bin.Jalview;
 import jalview.gui.ImageExporter.ImageWriterI;
@@ -1379,7 +1380,17 @@ public class Desktop extends jalview.jbgui.GDesktop
       if (jvnews != null)
       {
         storeLastKnownDimensions("JALVIEW_RSS_WINDOW_", jvnews.getBounds());
+      }
+
+      // Frames should all close automatically. Keeping external
+      // viewers open should already be decided by user.
+      closeAll_actionPerformed(null);
 
+      // check for aborted quit
+      if (QuitHandler.quitCancelled())
+      {
+        jalview.bin.Console.debug("Desktop aborting quit");
+        return null;
       }
 
       if (dialogExecutor != null)
@@ -1387,8 +1398,6 @@ public class Desktop extends jalview.jbgui.GDesktop
         dialogExecutor.shutdownNow();
       }
 
-      closeAll_actionPerformed(null);
-
       if (groovyConsole != null)
       {
         // suppress a possible repeat prompt to save script
@@ -1573,6 +1582,22 @@ public class Desktop extends jalview.jbgui.GDesktop
     }
   }
 
+  public int structureViewersStillRunningCount()
+  {
+    int count = 0;
+    JInternalFrame[] frames = desktop.getAllFrames();
+    for (int i = 0; i < frames.length; i++)
+    {
+      if (frames[i] != null
+              && frames[i] instanceof JalviewStructureDisplayI)
+      {
+        if (((JalviewStructureDisplayI) frames[i]).stillRunning())
+          count++;
+      }
+    }
+    return count;
+  }
+
   @Override
   public void raiseRelated_actionPerformed(ActionEvent e)
   {
@@ -2974,7 +2999,7 @@ public class Desktop extends jalview.jbgui.GDesktop
   /**
    * single thread that handles display of dialogs to user.
    */
-  ExecutorService dialogExecutor = Executors.newSingleThreadExecutor();
+  ExecutorService dialogExecutor = Executors.newFixedThreadPool(3);
 
   /**
    * flag indicating if dialogExecutor should try to acquire a permit