From ed4232de35f8100a6ec2ba1acb3dec7a3641a190 Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Thu, 2 Mar 2017 17:09:24 +0300 Subject: [PATCH] ui: simplify ComboBoxAction * show popup in the center if invoked with shortcut (no need to search related combobox on toolbar and show it there) * do not set CUSTOM_COMPONENT_PROPERTY follow-up: 57feca3f95772ba29e37b3319653b8467d91df0e d76130c7cae028b6d90ff2ae1c787f5d91955e05 d619e4355f620d6a1df43418ef0c38984884494b --- .../RunConfigurationsComboBoxAction.java | 12 ----- .../actionSystem/ex/ComboBoxAction.java | 51 ++++++++----------- 2 files changed, 20 insertions(+), 43 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/execution/actions/RunConfigurationsComboBoxAction.java b/platform/lang-impl/src/com/intellij/execution/actions/RunConfigurationsComboBoxAction.java index 87d94ea9572e..9aa82d25e178 100644 --- a/platform/lang-impl/src/com/intellij/execution/actions/RunConfigurationsComboBoxAction.java +++ b/platform/lang-impl/src/com/intellij/execution/actions/RunConfigurationsComboBoxAction.java @@ -53,18 +53,6 @@ public class RunConfigurationsComboBoxAction extends ComboBoxAction implements D public static final Icon CHECKED_SELECTED_ICON = JBUI.scale(new SizedIcon(AllIcons.Actions.Checked_selected, 16, 16)); public static final Icon EMPTY_ICON = EmptyIcon.ICON_16; - @Override - public void actionPerformed(AnActionEvent e) { - if (e.getPresentation().getClientProperty(CUSTOM_COMPONENT_PROPERTY) == null) { - Project project = e.getProject(); - IdeFrameImpl frame = project != null ? WindowManagerEx.getInstanceEx().getFrame(project) : null; - if (frame != null) { - e.getPresentation().putClientProperty(CUSTOM_COMPONENT_PROPERTY, frame.getComponent()); - } - } - super.actionPerformed(e); - } - @Override public void update(AnActionEvent e) { Presentation presentation = e.getPresentation(); diff --git a/platform/platform-api/src/com/intellij/openapi/actionSystem/ex/ComboBoxAction.java b/platform/platform-api/src/com/intellij/openapi/actionSystem/ex/ComboBoxAction.java index ce81a52f87fd..794eaed2d96c 100644 --- a/platform/platform-api/src/com/intellij/openapi/actionSystem/ex/ComboBoxAction.java +++ b/platform/platform-api/src/com/intellij/openapi/actionSystem/ex/ComboBoxAction.java @@ -31,6 +31,8 @@ import com.intellij.openapi.util.IconLoader; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.wm.IdeFocusManager; +import com.intellij.openapi.wm.IdeFrame; +import com.intellij.openapi.wm.WindowManager; import com.intellij.ui.ColorUtil; import com.intellij.ui.Gray; import com.intellij.ui.JBColor; @@ -60,30 +62,23 @@ public abstract class ComboBoxAction extends AnAction implements CustomComponent @Override public void actionPerformed(AnActionEvent e) { - JComponent button = (JComponent)e.getPresentation().getClientProperty(CUSTOM_COMPONENT_PROPERTY); - if (button == null) { - Component contextComponent = e.getData(PlatformDataKeys.CONTEXT_COMPONENT); - JRootPane rootPane = UIUtil.getParentOfType(JRootPane.class, contextComponent); - if (rootPane != null) { - button = (ComboBoxButton) - UIUtil.uiTraverser(rootPane).bfsTraversal().filter( - component -> component instanceof ComboBoxButton && ((ComboBoxButton)component).getMyAction() == this).first(); - } - if (button == null) return; - } - if (!button.isShowing()) return; - if (button instanceof ComboBoxButton) { - ((ComboBoxButton)button).showPopup(); - } else { - DataContext context = e.getDataContext(); - Project project = e.getProject(); - if (project == null) return; - DefaultActionGroup group = createPopupActionGroup(button, context); - ListPopup popup = JBPopupFactory.getInstance().createActionGroupPopup( - myPopupTitle, group, context, false, shouldShowDisabledActions(), false, null, getMaxRows(), getPreselectCondition()); - popup.setMinimumSize(new Dimension(getMinWidth(), getMinHeight())); - popup.showCenteredInCurrentWindow(project); - } + Project project = e.getProject(); + if (project == null) return; + + JFrame frame = WindowManager.getInstance().getFrame(project); + if (!(frame instanceof IdeFrame)) return; + + ListPopup popup = createActionPopup(e.getDataContext(), ((IdeFrame)frame).getComponent(), null); + popup.showCenteredInCurrentWindow(project); + } + + @NotNull + private ListPopup createActionPopup(@NotNull DataContext context, @NotNull JComponent component, @Nullable Runnable disposeCallback) { + DefaultActionGroup group = createPopupActionGroup(component, context); + ListPopup popup = JBPopupFactory.getInstance().createActionGroupPopup( + myPopupTitle, group, context, false, shouldShowDisabledActions(), false, disposeCallback, getMaxRows(), getPreselectCondition()); + popup.setMinimumSize(new Dimension(getMinWidth(), getMinHeight())); + return popup; } @Override @@ -271,13 +266,7 @@ public abstract class ComboBoxAction extends AnAction implements CustomComponent } protected JBPopup createPopup(Runnable onDispose) { - - DataContext context = getDataContext(); - DefaultActionGroup group = createPopupActionGroup(this, context); - ListPopup popup = JBPopupFactory.getInstance().createActionGroupPopup( - myPopupTitle, group, context, false, shouldShowDisabledActions(), false, onDispose, getMaxRows(), getPreselectCondition()); - popup.setMinimumSize(new Dimension(getMinWidth(), getMinHeight())); - return popup; + return createActionPopup(getDataContext(), this, onDispose); } private ComboBoxAction getMyAction() {