*/
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() {
}
}
}
+ 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
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;
}
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() {
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);
}
}
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);
}
}
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 {
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() {