fix popups: heavy/medium: restore state of factory after popup creation + delegate...
authorAlexey Pegov <alexey.pegov@jetbrains.com>
Tue, 10 Aug 2010 16:31:16 +0000 (20:31 +0400)
committerAlexey Pegov <alexey.pegov@jetbrains.com>
Tue, 10 Aug 2010 16:31:16 +0000 (20:31 +0400)
platform/platform-api/src/com/intellij/openapi/ui/popup/util/PopupUtil.java
platform/platform-impl/src/com/intellij/ide/ui/LafManagerImpl.java
platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java
platform/platform-impl/src/com/intellij/ui/popup/PopupComponent.java

index b8d9f8f87e14c86c6298c650f839f46893e8d675..02a92ed721f0bf21a61da1297e02c62410fac1c5 100644 (file)
  */
 package com.intellij.openapi.ui.popup.util;
 
+import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.ui.popup.JBPopup;
+import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
 import javax.swing.*;
 import java.awt.*;
+import java.lang.reflect.Method;
 
 public class PopupUtil {
+  private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.ui.popup.util.PopupUtil");
 
   private PopupUtil() {
   }
@@ -46,4 +50,29 @@ public class PopupUtil {
     }
   }
 
+  public static void setPopupType(@NotNull final PopupFactory factory, final int type) {
+    try {
+      final Method method = PopupFactory.class.getDeclaredMethod("setPopupType", int.class);
+      method.setAccessible(true);
+      method.invoke(factory, type);
+    }
+    catch (Throwable e) {
+      LOG.error(e);
+    }
+  }
+
+  public static int getPopupType(@NotNull final PopupFactory factory) {
+    try {
+      final Method method = PopupFactory.class.getDeclaredMethod("getPopupType");
+      method.setAccessible(true);
+      final Object result = method.invoke(factory);
+      return result instanceof Integer ? (Integer) result : -1;
+    }
+    catch (Throwable e) {
+      LOG.error(e);
+    }
+
+    return -1;
+  }
+
 }
\ No newline at end of file
index c3c279f8631b88f8696619eaff8e06f0ada10124..8c491af6dda856136ba3adbf70f790fed15bf3ff 100644 (file)
@@ -21,6 +21,7 @@ import com.intellij.idea.StartupUtil;
 import com.intellij.openapi.components.*;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.ui.Messages;
+import com.intellij.openapi.ui.popup.util.PopupUtil;
 import com.intellij.openapi.util.Comparing;
 import com.intellij.openapi.util.IconLoader;
 import com.intellij.openapi.util.SystemInfo;
@@ -308,10 +309,8 @@ public final class LafManagerImpl extends LafManager implements ApplicationCompo
     }
 
     popupWeight = popupWeight.trim();
-    final boolean heavyWeighPopup = HEAVY_WEIGHT_POPUP.equals(popupWeight);
 
     PopupFactory popupFactory;
-
     final PopupFactory oldFactory = PopupFactory.getSharedInstance();
     if (!(oldFactory instanceof OurPopupFactory)) {
       popupFactory = new OurPopupFactory() {
@@ -322,20 +321,17 @@ public final class LafManagerImpl extends LafManager implements ApplicationCompo
           int y
         ) throws IllegalArgumentException {
           final Point point = fixPopupLocation(contents, x, y);
-          try {
-            final Method method = PopupFactory.class.getDeclaredMethod("setPopupType", int.class);
-            method.setAccessible(true);
-            method.invoke(oldFactory, heavyWeighPopup ? 2 : 1);
 
-          }
-          catch (Throwable e) {
-            LOG.error(e);
+          final int popupType = PopupUtil.getPopupType(this);
+          if (popupType >= 0) {
+            PopupUtil.setPopupType(oldFactory, popupType);
           }
 
           return oldFactory.getPopup(owner, contents, point.x, point.y);
         }
       };
 
+      PopupUtil.setPopupType(popupFactory, HEAVY_WEIGHT_POPUP.equals(popupWeight) ? 2 : 1);
       PopupFactory.setSharedInstance(popupFactory);
     }
 
index 6f95abdfc7d04e8c17b7e65b7756f2c6c281cb07..db179130e98b17ff91d3767ecc8b0d77dc97025f 100644 (file)
@@ -710,7 +710,10 @@ public class AbstractPopup implements JBPopup {
     }
 
     if (myWindow != null) {
-      if (!myMayBeParent) {
+      // dialogwrapper-based popups do this internally through peer,
+      // for other popups like jdialog-based we should exclude them manually, but
+      // we still have to be able to use IdeFrame as parent
+      if (!myMayBeParent && !(myWindow instanceof Frame)) {
         WindowManager.getInstance().doNotSuggestAsParent(myWindow);
       }
     }
index c62669b4b13bc89614f3eca457241763ec0b6401..445c642a0e0a644ebd5a960256725c3f530f2974 100644 (file)
 package com.intellij.ui.popup;
 
 import com.intellij.openapi.diagnostic.Logger;
+import com.intellij.openapi.ui.popup.util.PopupUtil;
 import com.intellij.util.ReflectionUtil;
 
 import javax.swing.*;
 import java.awt.*;
-import java.lang.reflect.Method;
 
 public interface PopupComponent {
 
@@ -53,17 +53,12 @@ public interface PopupComponent {
       public PopupComponent getPopup(Component owner, Component content, int x, int y) {
         final PopupFactory factory = PopupFactory.getSharedInstance();
 
-        try {
-          final Method method = PopupFactory.class.getDeclaredMethod("setPopupType", int.class);
-          method.setAccessible(true);
-          method.invoke(factory, 2);
+        final int oldType = PopupUtil.getPopupType(factory);
+        PopupUtil.setPopupType(factory, 2);
+        final Popup popup = factory.getPopup(owner, content, x, y);
+        if (oldType >= 0) PopupUtil.setPopupType(factory, oldType);
 
-        }
-        catch (Throwable e) {
-          LOG.error(e);
-        }
-
-        return new AwtPopupWrapper(factory.getPopup(owner, content, x, y));
+        return new AwtPopupWrapper(popup);
       }
 
       public boolean isNativePopup() {