JAL-4214 Linux only: Disable menus when internal modal is open but allow menu acceler...
[jalview.git] / src / jalview / gui / Desktop.java
index b901ae4..5e6f40e 100644 (file)
@@ -51,6 +51,7 @@ import java.awt.event.WindowEvent;
 import java.awt.geom.AffineTransform;
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
+import java.beans.PropertyVetoException;
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
@@ -63,6 +64,7 @@ import java.util.Hashtable;
 import java.util.List;
 import java.util.ListIterator;
 import java.util.Locale;
+import java.util.Map;
 import java.util.Vector;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
@@ -3629,17 +3631,19 @@ public class Desktop extends jalview.jbgui.GDesktop
   }
 
   /**
-   * checks if any progress bars are being displayed in any of the windows managed by the desktop
+   * checks if any progress bars are being displayed in any of the windows
+   * managed by the desktop
+   * 
    * @return
    */
   public boolean operationsAreInProgress()
   {
     JInternalFrame[] frames = getAllFrames();
-    for (JInternalFrame frame:frames)
+    for (JInternalFrame frame : frames)
     {
       if (frame instanceof IProgressIndicator)
       {
-        if (((IProgressIndicator)frame).operationInProgress())
+        if (((IProgressIndicator) frame).operationInProgress())
         {
           return true;
         }
@@ -3647,4 +3651,37 @@ public class Desktop extends jalview.jbgui.GDesktop
     }
     return operationInProgress();
   }
+
+  /**
+   * keep track of modal JvOptionPanes open as modal dialogs for AlignFrames.
+   * The way the modal JInternalFrame is made means it cannot be a child of an
+   * AlignFrame, so closing the AlignFrame might leave the modal open :(
+   */
+  private static Map<AlignFrame, JInternalFrame> alignFrameModalMap = new HashMap<>();
+
+  protected static void addModal(AlignFrame af, JInternalFrame jif)
+  {
+    alignFrameModalMap.put(af, jif);
+  }
+
+  protected static void closeModal(AlignFrame af)
+  {
+    if (!alignFrameModalMap.containsKey(af))
+    {
+      return;
+    }
+    JInternalFrame jif = alignFrameModalMap.get(af);
+    if (jif != null)
+    {
+      try
+      {
+        jif.setClosed(true);
+      } catch (PropertyVetoException e)
+      {
+        e.printStackTrace();
+      }
+    }
+    alignFrameModalMap.remove(af);
+  }
+
 }