From 987e0ec5e59a64c4d0c0fb2c53d0d36c99de62c4 Mon Sep 17 00:00:00 2001 From: Viktor Shatrov Date: Wed, 14 Jul 2021 18:54:10 +0300 Subject: [PATCH] xdebugger: update evaluation popup size on tree expansion IDEA-269295 GitOrigin-RevId: 1728fea6bb790ed35699fe5101c81f40d50183c7 --- .../common/DebuggerTreeWithHistoryPopup.java | 17 +------ .../impl/inline/XDebuggerTreeInlayPopup.java | 49 +++++++++++-------- 2 files changed, 30 insertions(+), 36 deletions(-) diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/evaluate/quick/common/DebuggerTreeWithHistoryPopup.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/evaluate/quick/common/DebuggerTreeWithHistoryPopup.java index e2a7b5f55396..8e305730f358 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/evaluate/quick/common/DebuggerTreeWithHistoryPopup.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/evaluate/quick/common/DebuggerTreeWithHistoryPopup.java @@ -30,7 +30,7 @@ import javax.swing.tree.TreePath; import java.awt.*; import java.util.List; -import static com.intellij.xdebugger.impl.inline.XDebuggerTreeInlayPopup.updateDebugPopupBounds; +import static com.intellij.xdebugger.impl.inline.XDebuggerTreeInlayPopup.setAutoResize; final class DebuggerTreeWithHistoryPopup extends DebuggerTreeWithHistoryContainer { @NonNls private final static String DIMENSION_SERVICE_KEY = "DebuggerActiveHint"; @@ -123,20 +123,7 @@ final class DebuggerTreeWithHistoryPopup extends DebuggerTreeWithHistoryConta return; } myPopup.show(new RelativePoint(myEditor.getContentComponent(), myPoint)); - - ((XDebuggerTree)tree).addTreeListener(new XDebuggerTreeListener() { - @Override - public void childrenLoaded(@NotNull XDebuggerTreeNode node, - @NotNull List> children, - boolean last) { - if (last) { - updateDebugPopupBounds(tree, myToolbar, myPopup); - ((XDebuggerTree)tree).removeTreeListener(this); - } - } - }); - - updateDebugPopupBounds(tree, myToolbar, myPopup); + setAutoResize(tree, myToolbar, myPopup); } private void resize(final TreePath path, JTree tree) { diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/inline/XDebuggerTreeInlayPopup.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/inline/XDebuggerTreeInlayPopup.java index b479a24aca42..beb75eced932 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/inline/XDebuggerTreeInlayPopup.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/inline/XDebuggerTreeInlayPopup.java @@ -286,20 +286,7 @@ public class XDebuggerTreeInlayPopup { } myPopup.setSize(new Dimension(0, 0)); myPopup.show(new RelativePoint(myEditor.getContentComponent(), myPoint)); - - ((XDebuggerTree)tree).addTreeListener(new XDebuggerTreeListener() { - @Override - public void childrenLoaded(@NotNull XDebuggerTreeNode node, - @NotNull List> children, - boolean last) { - if (last) { - updateDebugPopupBounds(tree, myToolbar, myPopup); - ((XDebuggerTree)tree).removeTreeListener(this); - } - } - }); - - updateDebugPopupBounds(tree, myToolbar, myPopup); + setAutoResize(tree, myToolbar, myPopup); } private void resize(final TreePath path, JTree tree) { @@ -322,22 +309,42 @@ public class XDebuggerTreeInlayPopup { popupWindow.repaint(); } - public static void updateDebugPopupBounds(final Tree tree, JComponent toolbar, JBPopup popup) { + public static void setAutoResize(Tree tree, JComponent myToolbar, JBPopup myPopup) { + final boolean[] canShrink = {true}; + ((XDebuggerTree)tree).addTreeListener(new XDebuggerTreeListener() { + @Override + public void childrenLoaded(@NotNull XDebuggerTreeNode node, + @NotNull List> children, + boolean last) { + if (last) { + updateDebugPopupBounds(tree, myToolbar, myPopup, canShrink[0]); + canShrink[0] = false; + } + } + }); + updateDebugPopupBounds(tree, myToolbar, myPopup, canShrink[0]); + } + + public static void updateDebugPopupBounds(final Tree tree, JComponent toolbar, JBPopup popup, boolean canShrink) { final Window popupWindow = SwingUtilities.windowForComponent(popup.getContent()); final Dimension size = tree.getPreferredSize(); final Point location = popupWindow.getLocation(); - int hMargin = JBUI.scale(150); - int width = Math.max(size.width, toolbar.getPreferredSize().width) + hMargin; - int maxWidth = JBUI.scale(600); - int row = Math.min(12, tree.getRowCount() - 1); - Rectangle bounds = tree.getRowBounds(row); + int hMargin = JBUI.scale(30); int vMargin = JBUI.scale(30); + int width = Math.max(size.width, toolbar.getPreferredSize().width) + hMargin; + Rectangle bounds = tree.getRowBounds(tree.getRowCount() - 1); int height = toolbar.getHeight() + vMargin + (bounds == null ? 0 : bounds.y + bounds.height); + int maxWidth = ScreenUtil.getScreenRectangle(toolbar).width / 2; + int maxHeight = ScreenUtil.getScreenRectangle(toolbar).height / 2; final Rectangle targetBounds = new Rectangle(location.x, location.y, Math.min(width, maxWidth), - height); + Math.min(height, maxHeight)); + if (!canShrink) { + targetBounds.width = Math.max(targetBounds.width, popupWindow.getWidth()); + targetBounds.height = Math.max(targetBounds.height, popupWindow.getHeight()); + } ScreenUtil.cropRectangleToFitTheScreen(targetBounds); popupWindow.setBounds(targetBounds); popupWindow.validate();