don't reduce popup size when number of items is reduced (IDEA-61092 try #2)
authorDmitry Jemerov <yole@jetbrains.com>
Tue, 31 Jan 2012 15:48:22 +0000 (16:48 +0100)
committerDmitry Jemerov <yole@jetbrains.com>
Tue, 31 Jan 2012 15:48:22 +0000 (16:48 +0100)
platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java
platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNamePopup.java

index 2b459981aa6c9157602a19f44f554693be803838..8bb74f7f4a650fbfc1b0e79de256197dad758eb4 100644 (file)
@@ -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();
index c7c1be5bd0137c26b9f9b30d696188cf9cc79c89..662cb6ce10633d0d4ff98d737f08c503e10cfe6e 100644 (file)
@@ -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());
+      }
     }
   }