revalidated show usages popup
authorKirill Kalishev <kirill.kalishev@jetbrains.com>
Wed, 7 Jul 2010 16:31:05 +0000 (20:31 +0400)
committerKirill Kalishev <kirill.kalishev@jetbrains.com>
Wed, 7 Jul 2010 16:31:05 +0000 (20:31 +0400)
platform/platform-api/src/com/intellij/openapi/ui/popup/JBPopup.java
platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionToolbarImpl.java
platform/platform-impl/src/com/intellij/openapi/wm/ex/WindowManagerEx.java
platform/platform-impl/src/com/intellij/openapi/wm/impl/TestWindowManager.java
platform/platform-impl/src/com/intellij/openapi/wm/impl/WindowManagerImpl.java
platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java

index b9dea20e77ee7fae6739e317b850e6a3effcedba..12b82a760899729bb25dc4aa13e276365471c92b 100644 (file)
@@ -151,6 +151,7 @@ public interface JBPopup extends Disposable, LightweightWindow {
   void setLocation(@NotNull Point screenPoint);
 
   void setSize(@NotNull Dimension size);
+  Dimension getSize();
 
   boolean isPersistent();
 
@@ -177,4 +178,6 @@ public interface JBPopup extends Disposable, LightweightWindow {
   void setMinimumSize(Dimension size);
 
   void setFinalRunnable(@Nullable Runnable runnable);
+
+  void moveToFitScreen();
 }
index 3047c9753bc2f5b5561b55aa489cd73beaf12a78..f05068661394eb30d2bd34acd05a124caccefb2d 100644 (file)
@@ -38,6 +38,8 @@ import com.intellij.openapi.util.Computable;
 import com.intellij.openapi.util.Disposer;
 import com.intellij.openapi.util.IconLoader;
 import com.intellij.openapi.wm.IdeFocusManager;
+import com.intellij.openapi.wm.WindowManager;
+import com.intellij.openapi.wm.ex.WindowManagerEx;
 import com.intellij.ui.awt.RelativePoint;
 import com.intellij.ui.awt.RelativeRectangle;
 import com.intellij.ui.switcher.SwitchTarget;
@@ -751,11 +753,15 @@ public class ActionToolbarImpl extends JPanel implements ActionToolbar {
           myVisibleActions = myNewVisibleActions;
           myNewVisibleActions = temp;
 
+          Dimension oldSize = getPreferredSize();
+
           removeAll();
           mySecondaryActions.removeAll();
           mySecondaryActionsButton = null;
           fillToolBar(myVisibleActions, getLayoutPolicy() == AUTO_LAYOUT_POLICY && myOrientation == SwingConstants.HORIZONTAL);
 
+          Dimension newSize = getPreferredSize();
+
           if (changeBarVisibility) {
             revalidate();
           }
@@ -766,6 +772,9 @@ public class ActionToolbarImpl extends JPanel implements ActionToolbar {
               parent.validate();
             }
           }
+
+          ((WindowManagerEx)WindowManager.getInstance()).adjustContainerWindow(ActionToolbarImpl.this, oldSize, newSize);
+
           repaint();
         }
       }
index a0cea2a06e2d1d102e04bd31861dfe032134248c..5e344ac4f8599f4354a4b86f989c92a932a59da7 100644 (file)
@@ -15,6 +15,7 @@
  */
 package com.intellij.openapi.wm.ex;
 
+import com.intellij.openapi.actionSystem.impl.ActionToolbarImpl;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.wm.WindowManager;
 import com.intellij.openapi.wm.IdeFrame;
@@ -141,4 +142,7 @@ public abstract class WindowManagerEx extends WindowManager {
    */
   public abstract void hideDialog(JDialog dialog, Project project);
 
+  public abstract void adjustContainerWindow(Component c, Dimension oldSize, Dimension newSize);
+
+
 }
index 3e7ee7f9269b73e0380bc0582477666b2ea67a29..7773f8596b5ab8f0f6ce4631ed0d04c17ad7b820 100644 (file)
@@ -239,6 +239,10 @@ public final class TestWindowManager extends WindowManagerEx implements Applicat
     dialog.dispose();
   }
 
+  @Override
+  public void adjustContainerWindow(Component c, Dimension oldSize, Dimension newSize) {
+  }
+
   public final String getComponentName() {
     return "TestWindowManager";
   }
index f8cbcd2e4918be03bded942294094d9503e6f8c1..350be8fb8329c30092f4da150b3731dbd6edc453 100644 (file)
@@ -28,6 +28,7 @@ import com.intellij.openapi.components.ApplicationComponent;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.project.ProjectManager;
+import com.intellij.openapi.ui.popup.JBPopup;
 import com.intellij.openapi.util.Disposer;
 import com.intellij.openapi.util.NamedJDOMExternalizable;
 import com.intellij.openapi.util.SystemInfo;
@@ -352,6 +353,25 @@ public final class WindowManagerImpl extends WindowManagerEx implements Applicat
     }
   }
 
+  @Override
+  public void adjustContainerWindow(Component c, Dimension oldSize, Dimension newSize) {
+    if (c == null) return;
+
+    Window wnd = SwingUtilities.getWindowAncestor(c);
+
+    if (wnd instanceof JWindow) {
+      JBPopup popup = (JBPopup)((JWindow)wnd).getRootPane().getClientProperty(JBPopup.KEY);
+      if (popup != null) {
+        if (oldSize.height < newSize.height) {
+          Dimension size = popup.getSize();
+          size.height += (newSize.height - oldSize.height);
+          popup.setSize(size);
+          popup.moveToFitScreen();
+        }
+      }
+    }
+  }
+
   public final void disposeComponent() {}
 
   public final void initComponent() {
index 67e15fca113a7504a1f4057ee8b1103746c744ef..6f95abdfc7d04e8c17b7e65b7756f2c6c281cb07 100644 (file)
@@ -1121,6 +1121,29 @@ public class AbstractPopup implements JBPopup {
     }
   }
 
+  @Override
+  public Dimension getSize() {
+    if (myPopup != null) {
+      final Window popupWindow = SwingUtilities.windowForComponent(myContent);
+      return popupWindow.getSize();
+    } else {
+      return myForcedSize;
+    }
+  }
+
+  @Override
+  public void moveToFitScreen() {
+    if (myPopup == null) return;
+    
+    final Window popupWindow = SwingUtilities.windowForComponent(myContent);
+    Rectangle bounds = popupWindow.getBounds();
+
+    ScreenUtil.moveRectangleToFitTheScreen(bounds);
+    setLocation(bounds.getLocation());
+    setSize(bounds.getSize());
+  }
+
+
   public static Window setSize(JComponent content, final Dimension size) {
     final Window popupWindow = SwingUtilities.windowForComponent(content);
     final Point location = popupWindow.getLocation();