diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeFrameImpl.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeFrameImpl.java index 2802a4a3efe1..3e40d12cf555 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeFrameImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeFrameImpl.java @@ -527,20 +527,6 @@ public class IdeFrameImpl extends JFrame implements IdeFrameEx, DataProvider { return b; } - @Nullable - public static Component findNearestModalComponent(@NotNull Component c) { - Component eachParent = c; - while (eachParent != null) { - if (eachParent instanceof IdeFrame) return eachParent; - if (eachParent instanceof JDialog) { - if (((JDialog)eachParent).isModal()) return eachParent; - } - eachParent = eachParent.getParent(); - } - - return null; - } - public final BalloonLayout getBalloonLayout() { return myBalloonLayout; } diff --git a/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java b/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java index fed66f5df62b..e31a364a80bf 100644 --- a/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java +++ b/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java @@ -37,7 +37,6 @@ import com.intellij.openapi.util.*; import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.wm.*; import com.intellij.openapi.wm.ex.WindowManagerEx; -import com.intellij.openapi.wm.impl.IdeFrameImpl; import com.intellij.openapi.wm.impl.IdeGlassPaneImpl; import com.intellij.ui.*; import com.intellij.ui.awt.RelativePoint; @@ -782,7 +781,7 @@ public class AbstractPopup implements JBPopup { myMouseOutCanceller.myEverEntered = targetBounds.equals(original); } - myOwner = IdeFrameImpl.findNearestModalComponent(owner); + myOwner = getFrameOrDialog(owner); // use correct popup owner for non-modal dialogs too if (myOwner == null) { myOwner = owner; } @@ -1862,4 +1861,22 @@ public class AbstractPopup implements JBPopup { private boolean isBusy() { return myResizeListener != null && myResizeListener.isBusy() || myMoveListener != null && myMoveListener.isBusy(); } + + /** + * Returns the first frame (or dialog) ancestor of the component. + * Note that this method returns the component itself if it is a frame (or dialog). + * + * @param component the component used to find corresponding frame (or dialog) + * @return the first frame (or dialog) ancestor of the component; or {@code null} + * if the component is not a frame (or dialog) and is not contained inside a frame (or dialog) + * + * @see UIUtil#getWindow + */ + private static Component getFrameOrDialog(Component component) { + while (component != null) { + if (component instanceof Frame || component instanceof Dialog) return component; + component = component.getParent(); + } + return null; + } }