From 7e8d2c7f97e9c55e2c2e86689231386728213443 Mon Sep 17 00:00:00 2001 From: "Denis.Zhdanov" Date: Wed, 1 Aug 2012 12:14:42 +0400 Subject: [PATCH] IDEA-89555 Autopositioning quick documentation popup if there are not anough free space at bottom of IDE --- .../com/intellij/ui/popup/AbstractPopup.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) 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 48849f6503d0..0653a27c8c44 100644 --- a/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java +++ b/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java @@ -485,10 +485,30 @@ public class AbstractPopup implements JBPopup { show(relativePointWithDominantRectangle(layeredPane, dominantArea)); } else { - show(JBPopupFactory.getInstance().guessBestPopupLocation(editor)); + show(guessBestPopupLocation(editor)); } } + @NotNull + private RelativePoint guessBestPopupLocation(@NotNull Editor editor) { + RelativePoint preferredLocation = JBPopupFactory.getInstance().guessBestPopupLocation(editor); + if (myDimensionServiceKey == null) { + return preferredLocation; + } + Dimension preferredSize = DimensionService.getInstance().getSize(myDimensionServiceKey, myProject); + if (preferredSize == null) { + return preferredLocation; + } + Rectangle preferredBounds = new Rectangle(preferredLocation.getScreenPoint(), preferredSize); + Rectangle adjustedBounds = new Rectangle(preferredBounds); + ScreenUtil.moveRectangleToFitTheScreen(adjustedBounds); + if (preferredBounds.y - adjustedBounds.y <= 0) { + return preferredLocation; + } + int adjustedY = preferredBounds.y - (editor.getLineHeight() * 3 / 2) - preferredSize.height; + return adjustedY >= 0 ? RelativePoint.fromScreen(new Point(preferredBounds.x, adjustedY)) : preferredLocation; + } + public void addPopupListener(JBPopupListener listener) { myListeners.add(listener); }