Fix incorrect foremost window detection (IDEA-121261).
authorDmitry Trofimov <dmitry.trofimov@jetbrains.com>
Tue, 25 Feb 2014 22:20:47 +0000 (23:20 +0100)
committerDmitry Trofimov <dmitry.trofimov@jetbrains.com>
Tue, 25 Feb 2014 22:20:47 +0000 (23:20 +0100)
platform/platform-impl/src/com/intellij/ui/mac/MacMessagesImpl.java
platform/util/src/com/intellij/util/ui/UIUtil.java

index 1ffa4e261858229993bcdc1b3a00069b7d2d9239..5b58847427e9aa0eb2941308d449f0182ebdfb53 100644 (file)
@@ -743,6 +743,11 @@ public class MacMessagesImpl extends MacMessages {
       _window = _window.getOwner();
     }
 
+    if (_window != null && UIUtil.isAncestor(_window, window)) {
+      //if _window is an ancestor of other window it isn't foremost for sure
+      return null;
+    }
+
     return _window;
   }
 
index b63ff6ec773a9bb7779ca1d149e6d31702c57fbb..546083fb7585006ef424c114ab4a4e5b4937becf 100644 (file)
@@ -2766,4 +2766,14 @@ public class UIUtil {
       }
     }
   }
+
+  public static boolean isAncestor(@NotNull Component ancestor, @Nullable Component descendant) {
+    while (descendant != null) {
+      if (descendant == ancestor) {
+        return true;
+      }
+      descendant = descendant.getParent();
+    }
+    return false;
+  }
 }