diff options
Diffstat (limited to 'platform/platform-impl/src/com/intellij/ui/popup')
3 files changed, 78 insertions, 32 deletions
diff --git a/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java b/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java index e1c326d33cd8..78802ccdf6bb 100644 --- a/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java +++ b/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java @@ -337,7 +337,7 @@ public class AbstractPopup implements JBPopup { } public void setShowHints(boolean show) { - final Window ancestor = SwingUtilities.getWindowAncestor(myComponent); + final Window ancestor = getContentWindow(myComponent); if (ancestor instanceof RootPaneContainer) { final JRootPane rootPane = ((RootPaneContainer)ancestor).getRootPane(); if (rootPane != null) { @@ -757,7 +757,33 @@ public class AbstractPopup implements JBPopup { PopupComponent.Factory factory = getFactory(myForcedHeavyweight || myResizable, forcedDialog); myNativePopup = factory.isNativePopup(); - myPopup = factory.getPopup(myOwner, myContent, targetBounds.x, targetBounds.y, this); + Component popupOwner = myOwner; + if (popupOwner instanceof RootPaneContainer) { + // JDK uses cached heavyweight popup for a window ancestor + RootPaneContainer root = (RootPaneContainer)popupOwner; + popupOwner = root.getRootPane(); + } + if (LOG.isDebugEnabled()) { + LOG.debug("expected preferred size: " + myContent.getPreferredSize()); + } + myPopup = factory.getPopup(popupOwner, myContent, targetBounds.x, targetBounds.y, this); + if (LOG.isDebugEnabled()) { + LOG.debug(" actual preferred size: " + myContent.getPreferredSize()); + } + if ((targetBounds.width != myContent.getWidth()) || (targetBounds.height != myContent.getHeight())) { + // JDK uses cached heavyweight popup that is not initialized properly + LOG.debug("the expected size is not equal to the actual size"); + Window popup = myPopup.getWindow(); + if (popup != null) { + popup.setSize(targetBounds.width, targetBounds.height); + if (myContent.getParent().getComponentCount() != 1) { + LOG.debug("unexpected count of components in heavy-weight popup"); + } + } + else { + LOG.debug("cannot fix size for non-heavy-weight popup"); + } + } if (myResizable) { final JRootPane root = myContent.getRootPane(); @@ -799,13 +825,10 @@ public class AbstractPopup implements JBPopup { listener.beforeShown(new LightweightWindowEvent(this)); } - // can be improved by moving in myPopup code - myPopup.getWindow().setSize(myContent.getSize()); - myPopup.setRequestFocus(myRequestFocus); myPopup.show(); - final Window window = SwingUtilities.getWindowAncestor(myContent); + final Window window = getContentWindow(myContent); myWindow = window; @@ -1185,14 +1208,17 @@ public class AbstractPopup implements JBPopup { size = computeWindowSize(size); - final Window window = SwingUtilities.getWindowAncestor(myContent); - window.setSize(size); + final Window window = getContentWindow(myContent); + if (window != null) { + window.setSize(size); + } } public void pack() { - final Window window = SwingUtilities.getWindowAncestor(myContent); - - window.pack(); + final Window window = getContentWindow(myContent); + if (window != null) { + window.pack(); + } } public JComponent getComponent() { @@ -1211,6 +1237,10 @@ public class AbstractPopup implements JBPopup { } myDisposed = true; + if (LOG.isDebugEnabled()) { + LOG.debug("start disposing " + myContent); + } + Disposer.dispose(this, false); ApplicationManager.getApplication().assertIsDispatchThread(); @@ -1257,6 +1287,10 @@ public class AbstractPopup implements JBPopup { IdeFocusManager.getInstance(myProject).typeAheadUntil(typeAheadDone); getFocusManager().doWhenFocusSettlesDown(runFinal); } + + if (LOG.isDebugEnabled()) { + LOG.debug("stop disposing content"); + } } private void resetWindow() { @@ -1385,15 +1419,27 @@ public class AbstractPopup implements JBPopup { } public static Window moveTo(JComponent content, Point screenPoint, final Dimension headerCorrectionSize) { - setDefaultCursor(content); - final Window wnd = SwingUtilities.getWindowAncestor(content); - if (headerCorrectionSize != null) { - screenPoint.y -= headerCorrectionSize.height; + final Window wnd = getContentWindow(content); + if (wnd != null) { + wnd.setCursor(Cursor.getDefaultCursor()); + if (headerCorrectionSize != null) { + screenPoint.y -= headerCorrectionSize.height; + } + wnd.setLocation(screenPoint); } - wnd.setLocation(screenPoint); return wnd; } + private static Window getContentWindow(Component content) { + Window window = SwingUtilities.getWindowAncestor(content); + if (window == null) { + if (LOG.isDebugEnabled()) { + LOG.debug("no window ancestor for " + content); + } + } + return window; + } + @Override public Point getLocationOnScreen() { Dimension headerCorrectionSize = myLocateByContent ? myHeaderPanel.getPreferredSize() : null; @@ -1467,7 +1513,7 @@ public class AbstractPopup implements JBPopup { } public static void setDefaultCursor(JComponent content) { - final Window wnd = SwingUtilities.getWindowAncestor(content); + final Window wnd = getContentWindow(content); if (wnd != null) { wnd.setCursor(Cursor.getDefaultCursor()); } diff --git a/platform/platform-impl/src/com/intellij/ui/popup/PopupFactoryImpl.java b/platform/platform-impl/src/com/intellij/ui/popup/PopupFactoryImpl.java index c7194ca5b4c4..2d7a8e3fb276 100644 --- a/platform/platform-impl/src/com/intellij/ui/popup/PopupFactoryImpl.java +++ b/platform/platform-impl/src/com/intellij/ui/popup/PopupFactoryImpl.java @@ -227,8 +227,11 @@ public class PopupFactoryImpl extends JBPopupFactory { Presentation presentation = new Presentation(); presentation.setDescription(action.getTemplatePresentation().getDescription()); final String actualActionPlace = actionPlace == null ? ActionPlaces.UNKNOWN : actionPlace; - action.update(new AnActionEvent(null, DataManager.getInstance().getDataContext(myComponent), actualActionPlace, presentation, - ActionManager.getInstance(), 0)); + final AnActionEvent actionEvent = + new AnActionEvent(null, DataManager.getInstance().getDataContext(myComponent), actualActionPlace, presentation, + ActionManager.getInstance(), 0); + actionEvent.setInjectedContext(action.isInInjectedContext()); + action.update(actionEvent); ActionMenu.showDescriptionInStatusBar(true, myComponent, presentation.getDescription()); } }); @@ -730,7 +733,10 @@ public class PopupFactoryImpl extends JBPopupFactory { myFinalRunnable = new Runnable() { @Override public void run() { - action.actionPerformed(new AnActionEvent(null, dataContext, ActionPlaces.UNKNOWN, action.getTemplatePresentation().clone(), ActionManager.getInstance(), eventModifiers)); + final AnActionEvent event = new AnActionEvent(null, dataContext, ActionPlaces.UNKNOWN, action.getTemplatePresentation().clone(), + ActionManager.getInstance(), eventModifiers); + event.setInjectedContext(action.isInInjectedContext()); + action.actionPerformed(event); } }; return FINAL_CHOICE; @@ -879,7 +885,10 @@ public class PopupFactoryImpl extends JBPopupFactory { @NotNull private AnActionEvent createActionEvent(@NotNull AnAction actionGroup) { - return new AnActionEvent(null, myDataContext, myActionPlace, getPresentation(actionGroup), ActionManager.getInstance(), 0); + final AnActionEvent actionEvent = + new AnActionEvent(null, myDataContext, myActionPlace, getPresentation(actionGroup), ActionManager.getInstance(), 0); + actionEvent.setInjectedContext(actionGroup.isInInjectedContext()); + return actionEvent; } private void appendActionsFromGroup(@NotNull ActionGroup actionGroup) { diff --git a/platform/platform-impl/src/com/intellij/ui/popup/list/GroupedItemsListRenderer.java b/platform/platform-impl/src/com/intellij/ui/popup/list/GroupedItemsListRenderer.java index 72f2e1dc3b37..9383f5c3f08e 100644 --- a/platform/platform-impl/src/com/intellij/ui/popup/list/GroupedItemsListRenderer.java +++ b/platform/platform-impl/src/com/intellij/ui/popup/list/GroupedItemsListRenderer.java @@ -18,9 +18,7 @@ package com.intellij.ui.popup.list; import com.intellij.openapi.ui.popup.ListItemDescriptor; import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.ui.EngravedLabel; import com.intellij.ui.ErrorLabel; -import com.intellij.ui.Gray; import com.intellij.ui.GroupedElementsRenderer; import com.intellij.ui.components.panels.OpaquePanel; @@ -58,15 +56,8 @@ public class GroupedItemsListRenderer extends GroupedElementsRenderer.List imple @Override protected JComponent createItemComponent() { - if (Registry.is("ide.new.project.settings")) { - myTextLabel = new EngravedLabel(); - myTextLabel.setFont(myTextLabel.getFont().deriveFont(Font.BOLD)); - myTextLabel.setForeground(Gray._240); - } else { - myTextLabel = new ErrorLabel(); - myTextLabel.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); - } - + myTextLabel = new ErrorLabel(); + myTextLabel.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); myTextLabel.setOpaque(true); return layoutComponent(myTextLabel); } |