From 7ecde7ebddaf096bf66fb4b044fa61e7a0438a71 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 31 Jan 2012 16:48:22 +0100 Subject: [PATCH] don't reduce popup size when number of items is reduced (IDEA-61092 try #2) --- .../ide/util/gotoByName/ChooseByNameBase.java | 20 ++++++------- .../util/gotoByName/ChooseByNamePopup.java | 28 +++++++++++-------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java index 2b459981aa6c..8bb74f7f4a65 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java +++ b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java @@ -118,7 +118,7 @@ public abstract class ChooseByNameBase { private volatile boolean myListIsUpToDate = false; private boolean myDisposedFlag = false; - private ActionCallback myPosponedOkAction; + private ActionCallback myPostponedOkAction; private final String[][] myNames = new String[2][]; private CalcElementsThread myCalcElementsThread; @@ -141,8 +141,8 @@ public abstract class ChooseByNameBase { private String myFindUsagesTitle; public boolean checkDisposed() { - if (myDisposedFlag && myPosponedOkAction != null && !myPosponedOkAction.isProcessed()) { - myPosponedOkAction.setRejected(); + if (myDisposedFlag && myPostponedOkAction != null && !myPostponedOkAction.isProcessed()) { + myPostponedOkAction.setRejected(); } return myDisposedFlag; @@ -679,8 +679,8 @@ public abstract class ChooseByNameBase { final String text = myTextField.getText(); if (ok && !myListIsUpToDate && text != null && text.trim().length() > 0) { - myPosponedOkAction = new ActionCallback(); - IdeFocusManager.getInstance(myProject).typeAheadUntil(myPosponedOkAction); + myPostponedOkAction = new ActionCallback(); + IdeFocusManager.getInstance(myProject).typeAheadUntil(myPostponedOkAction); return true; } @@ -1067,7 +1067,7 @@ public abstract class ChooseByNameBase { } private void doPostponedOkIfNeeded() { - if (myPosponedOkAction != null) { + if (myPostponedOkAction != null) { if (getChosenElement() != null) { doClose(true); } @@ -1077,16 +1077,16 @@ public abstract class ChooseByNameBase { } private void clearPosponedOkAction(boolean success) { - if (myPosponedOkAction != null) { + if (myPostponedOkAction != null) { if (success) { - myPosponedOkAction.setDone(); + myPostponedOkAction.setDone(); } else { - myPosponedOkAction.setRejected(); + myPostponedOkAction.setRejected(); } } - myPosponedOkAction = null; + myPostponedOkAction = null; } protected abstract void showList(); diff --git a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNamePopup.java b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNamePopup.java index c7c1be5bd013..662cb6ce1063 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNamePopup.java +++ b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNamePopup.java @@ -48,7 +48,7 @@ public class ChooseByNamePopup extends ChooseByNameBase implements ChooseByNameP private boolean myMayRequestCurrentWindow; protected ChooseByNamePopup(final Project project, final ChooseByNameModel model, ChooseByNameItemProvider provider, final ChooseByNamePopup oldPopup, - @Nullable final String predefinedText, boolean mayRequestOpenInCurrentWundow, int initialIndex) { + @Nullable final String predefinedText, boolean mayRequestOpenInCurrentWindow, int initialIndex) { super(project, model, provider, oldPopup != null ? oldPopup.getEnteredText() : predefinedText, initialIndex); if (oldPopup == null && predefinedText != null) { setPreselectInitialText(true); @@ -56,7 +56,7 @@ public class ChooseByNamePopup extends ChooseByNameBase implements ChooseByNameP if (oldPopup != null) { //inherit old focus owner myOldFocusOwner = oldPopup.myPreviouslyFocusedComponent; } - myMayRequestCurrentWindow = mayRequestOpenInCurrentWundow; + myMayRequestCurrentWindow = mayRequestOpenInCurrentWindow; } public String getEnteredText() { @@ -113,13 +113,13 @@ public class ChooseByNamePopup extends ChooseByNameBase implements ChooseByNameP preferredScrollPaneSize.width = Math.max(myTextFieldPanel.getWidth(), preferredScrollPaneSize.width); - Rectangle prefferedBounds = new Rectangle(bounds.x, bounds.y, preferredScrollPaneSize.width, preferredScrollPaneSize.height); - Rectangle original = new Rectangle(prefferedBounds); + Rectangle preferredBounds = new Rectangle(bounds.x, bounds.y, preferredScrollPaneSize.width, preferredScrollPaneSize.height); + Rectangle original = new Rectangle(preferredBounds); - ScreenUtil.fitToScreen(prefferedBounds); - if (original.width > prefferedBounds.width) { + ScreenUtil.fitToScreen(preferredBounds); + if (original.width > preferredBounds.width) { int height = myListScrollPane.getHorizontalScrollBar().getPreferredSize().height; - prefferedBounds.height += height; + preferredBounds.height += height; } myListScrollPane.setVisible(true); @@ -136,12 +136,18 @@ public class ChooseByNamePopup extends ChooseByNameBase implements ChooseByNameP } }); myDropdownPopup = builder.createPopup(); - myDropdownPopup.setLocation(prefferedBounds.getLocation()); - myDropdownPopup.setSize(prefferedBounds.getSize()); + myDropdownPopup.setLocation(preferredBounds.getLocation()); + myDropdownPopup.setSize(preferredBounds.getSize()); myDropdownPopup.show(layeredPane); } else { - myDropdownPopup.setLocation(prefferedBounds.getLocation()); - myDropdownPopup.setSize(prefferedBounds.getSize()); + myDropdownPopup.setLocation(preferredBounds.getLocation()); + + // in 'focus follows mouse' mode, to avoid focus escaping to editor, don't reduce popup size when list size is reduced + final Dimension currentSize = myDropdownPopup.getSize(); + if (UISettings.getInstance().HIDE_NAVIGATION_ON_FOCUS_LOSS || + preferredBounds.width > currentSize.width || preferredBounds.height > currentSize.height) { + myDropdownPopup.setSize(preferredBounds.getSize()); + } } }