From 3922b236292a7d0d6b499eaf0f9e3f467cc2deea Mon Sep 17 00:00:00 2001 From: "Gregory.Shrago" Date: Fri, 6 Apr 2018 19:46:55 +0300 Subject: [PATCH] propagate place to NewElement popup --- .../impl/ui/actions/GroupToolbarAction.java | 50 --------------- .../ide/actions/NewElementAction.java | 49 +++++++-------- .../actions/NewElementSamePlaceAction.java | 9 ++- .../ide/actions/NewElementToolbarAction.java | 63 ------------------- .../openapi/ui/MasterDetailsComponent.java | 11 ++-- .../openapi/ui/popup/JBPopupFactory.java | 35 ++++++++--- .../ui/components/BasicOptionButtonUI.kt | 3 +- .../intellij/ui/popup/ActionPopupStep.java | 60 ++++++++++-------- .../intellij/ui/popup/PopupFactoryImpl.java | 36 +++-------- .../src/idea/LangActions.xml | 6 -- .../tasks/actions/SwitchTaskAction.java | 9 +-- 11 files changed, 111 insertions(+), 220 deletions(-) delete mode 100644 java/idea-ui/src/com/intellij/facet/impl/ui/actions/GroupToolbarAction.java delete mode 100644 platform/lang-impl/src/com/intellij/ide/actions/NewElementToolbarAction.java diff --git a/java/idea-ui/src/com/intellij/facet/impl/ui/actions/GroupToolbarAction.java b/java/idea-ui/src/com/intellij/facet/impl/ui/actions/GroupToolbarAction.java deleted file mode 100644 index 869cafef1ab5..000000000000 --- a/java/idea-ui/src/com/intellij/facet/impl/ui/actions/GroupToolbarAction.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.intellij.facet.impl.ui.actions; - -import com.intellij.openapi.actionSystem.*; -import com.intellij.openapi.ui.popup.JBPopupFactory; -import com.intellij.openapi.ui.popup.ListPopupStep; - -import javax.swing.*; - -/** - * @author nik - */ -public class GroupToolbarAction extends AnAction { - private final ActionGroup myGroup; - private final JComponent myToolbarComponent; - - public GroupToolbarAction(final ActionGroup group, JComponent toolbarComponent) { - super(group.getTemplatePresentation().getText(), group.getTemplatePresentation().getDescription(), - group.getTemplatePresentation().getIcon()); - myGroup = group; - myToolbarComponent = toolbarComponent; - } - - public void actionPerformed(AnActionEvent e) { - final JBPopupFactory popupFactory = JBPopupFactory.getInstance(); - final ListPopupStep popupStep = popupFactory.createActionsStep(myGroup, e.getDataContext(), false, false, - myGroup.getTemplatePresentation().getText(), myToolbarComponent, false, - 0, false); - popupFactory.createListPopup(popupStep).showUnderneathOf(myToolbarComponent); - } - - public void update(AnActionEvent e) { - myGroup.update(e); - } -} diff --git a/platform/lang-impl/src/com/intellij/ide/actions/NewElementAction.java b/platform/lang-impl/src/com/intellij/ide/actions/NewElementAction.java index 058c4d737b0d..e038bcf74764 100644 --- a/platform/lang-impl/src/com/intellij/ide/actions/NewElementAction.java +++ b/platform/lang-impl/src/com/intellij/ide/actions/NewElementAction.java @@ -23,33 +23,40 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.popup.JBPopupFactory; import com.intellij.openapi.ui.popup.ListPopup; import com.intellij.openapi.util.Condition; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** * @author Konstantin Bulenkov */ @SuppressWarnings({"MethodMayBeStatic"}) -public class NewElementAction extends AnAction implements DumbAware, PopupAction { +public class NewElementAction extends AnAction implements DumbAware, PopupAction { @Override - public void actionPerformed(final AnActionEvent event) { - showPopup(event.getDataContext()); + public void actionPerformed(AnActionEvent e) { + showPopup(e); } - protected void showPopup(DataContext context) { - createPopup(context).showInBestPositionFor(context); + protected void showPopup(AnActionEvent e) { + createPopup(e).showInBestPositionFor(e.getDataContext()); } - protected ListPopup createPopup(DataContext dataContext) { - return JBPopupFactory.getInstance() - .createActionGroupPopup(getPopupTitle(), - getGroup(dataContext), - dataContext, - isShowNumbers(), - isShowDisabledActions(), - isHonorActionMnemonics(), - getDisposeCallback(), - getMaxRowCount(), - getPreselectActionCondition(dataContext)); + @NotNull + protected ListPopup createPopup(@NotNull AnActionEvent e) { + return JBPopupFactory.getInstance().createActionGroupPopup( + getPopupTitle(), + getGroup(e.getDataContext()), + e.getDataContext(), + getActionSelectionAid(), + isShowDisabledActions(), + getDisposeCallback(), + getMaxRowCount(), + getPreselectActionCondition(e.getDataContext()), + e.getPlace()); + } + + @Nullable + protected JBPopupFactory.ActionSelectionAid getActionSelectionAid() { + return null; } protected int getMaxRowCount() { @@ -66,24 +73,16 @@ public class NewElementAction extends AnAction implements DumbAware, PopupActio return null; } - protected boolean isHonorActionMnemonics() { - return false; - } - protected boolean isShowDisabledActions() { return false; } - protected boolean isShowNumbers() { - return false; - } - protected String getPopupTitle() { return IdeBundle.message("title.popup.new.element"); } @Override - public void update(AnActionEvent e){ + public void update(AnActionEvent e) { Presentation presentation = e.getPresentation(); Project project = e.getProject(); if (project == null) { diff --git a/platform/lang-impl/src/com/intellij/ide/actions/NewElementSamePlaceAction.java b/platform/lang-impl/src/com/intellij/ide/actions/NewElementSamePlaceAction.java index 085bee7c60d5..767326b88f1f 100644 --- a/platform/lang-impl/src/com/intellij/ide/actions/NewElementSamePlaceAction.java +++ b/platform/lang-impl/src/com/intellij/ide/actions/NewElementSamePlaceAction.java @@ -19,7 +19,6 @@ package com.intellij.ide.actions; import com.intellij.ide.IdeBundle; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.CommonDataKeys; -import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.actionSystem.LangDataKeys; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.popup.ListPopup; @@ -35,14 +34,14 @@ public class NewElementSamePlaceAction extends NewElementAction { return LangDataKeys.IDE_VIEW.getData(e.getDataContext()) != null; } - protected void showPopup(DataContext context) { - ListPopup popup = createPopup(context); - Project project = CommonDataKeys.PROJECT.getData(context); + protected void showPopup(AnActionEvent e) { + ListPopup popup = createPopup(e); + Project project = e.getData(CommonDataKeys.PROJECT); if (project != null) { popup.showCenteredInCurrentWindow(project); } else { - popup.showInBestPositionFor(context); + popup.showInBestPositionFor(e.getDataContext()); } } } \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/ide/actions/NewElementToolbarAction.java b/platform/lang-impl/src/com/intellij/ide/actions/NewElementToolbarAction.java deleted file mode 100644 index b900c70fe2ac..000000000000 --- a/platform/lang-impl/src/com/intellij/ide/actions/NewElementToolbarAction.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.intellij.ide.actions; - -import com.intellij.ide.DataManager; -import com.intellij.ide.projectView.impl.ProjectViewImpl; -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.actionSystem.CommonDataKeys; -import com.intellij.openapi.actionSystem.LangDataKeys; -import com.intellij.openapi.actionSystem.PlatformDataKeys; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.wm.ToolWindow; -import com.intellij.openapi.wm.ToolWindowId; -import com.intellij.openapi.wm.ToolWindowManager; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiFileSystemItem; - -/** - * @author yole - */ -public class NewElementToolbarAction extends NewElementAction { - @Override - public void actionPerformed(AnActionEvent e) { - if (e.getData(LangDataKeys.IDE_VIEW) == null) { - final Project project = e.getData(CommonDataKeys.PROJECT); - final PsiFileSystemItem psiFile = e.getData(CommonDataKeys.PSI_FILE).getParent(); - ProjectViewImpl.getInstance(project).selectCB(psiFile, psiFile.getVirtualFile(), true).doWhenDone( - () -> showPopup(DataManager.getInstance().getDataContext())); - } - else { - super.actionPerformed(e); - } - } - - @Override - public void update(AnActionEvent event) { - super.update(event); - if (event.getData(LangDataKeys.IDE_VIEW) == null) { - Project project = event.getData(CommonDataKeys.PROJECT); - PsiFile psiFile = event.getData(CommonDataKeys.PSI_FILE); - if (project != null && psiFile != null) { - final ToolWindow projectViewWindow = ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.PROJECT_VIEW); - if (projectViewWindow.isVisible()) { - event.getPresentation().setEnabled(true); - } - } - } - } -} diff --git a/platform/platform-api/src/com/intellij/openapi/ui/MasterDetailsComponent.java b/platform/platform-api/src/com/intellij/openapi/ui/MasterDetailsComponent.java index d707fbe3e1f5..1aa17ebc6749 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/MasterDetailsComponent.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/MasterDetailsComponent.java @@ -926,11 +926,12 @@ public abstract class MasterDetailsComponent implements Configurable, DetailsCom @Override public void actionPerformed(AnActionEvent e) { - final JBPopupFactory popupFactory = JBPopupFactory.getInstance(); - final DataContext dataContext = e.getDataContext(); - final ListPopupStep step = popupFactory.createActionsStep(myActionGroup, dataContext, false, false, - myActionGroup.getTemplatePresentation().getText(), myTree, true, - myPreselection != null ? myPreselection.getDefaultIndex() : 0, true); + JBPopupFactory popupFactory = JBPopupFactory.getInstance(); + DataContext dataContext = e.getDataContext(); + ListPopupStep step = popupFactory.createActionsStep( + myActionGroup, dataContext, ActionPlaces.UNKNOWN, false, + false, myActionGroup.getTemplatePresentation().getText(), myTree, + true, myPreselection != null ? myPreselection.getDefaultIndex() : 0, true); final ListPopup listPopup = popupFactory.createListPopup(step); listPopup.setHandleAutoSelectionBeforeShow(true); if (e instanceof AnActionButton.AnActionEventWrapper) { diff --git a/platform/platform-api/src/com/intellij/openapi/ui/popup/JBPopupFactory.java b/platform/platform-api/src/com/intellij/openapi/ui/popup/JBPopupFactory.java index 3557f7f2c9ac..ba20cb5e60c0 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/popup/JBPopupFactory.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/popup/JBPopupFactory.java @@ -95,24 +95,43 @@ public abstract class JBPopupFactory { Runnable onNo, int defaultOptionIndex); + @Deprecated @NotNull - public abstract ListPopupStep createActionsStep(@NotNull ActionGroup actionGroup, - @NotNull DataContext dataContext, - boolean showNumbers, - boolean showDisabledActions, - String title, - Component component, - boolean honorActionMnemonics); + public ListPopupStep createActionsStep(@NotNull ActionGroup actionGroup, + @NotNull DataContext dataContext, + boolean showNumbers, + boolean showDisabledActions, + String title, + Component component, + boolean honorActionMnemonics) { + return createActionsStep(actionGroup, dataContext, null, showNumbers, showDisabledActions, title, component, honorActionMnemonics, 0, false); + } + + @Deprecated + @NotNull + public ListPopupStep createActionsStep(@NotNull ActionGroup actionGroup, + @NotNull DataContext dataContext, + boolean showNumbers, + boolean showDisabledActions, + String title, + Component component, + boolean honorActionMnemonics, + int defaultOptionIndex, + boolean autoSelectionEnabled) { + return createActionsStep(actionGroup, dataContext, null, showNumbers, showDisabledActions, title, component, honorActionMnemonics, defaultOptionIndex, autoSelectionEnabled); + } @NotNull public abstract ListPopupStep createActionsStep(@NotNull ActionGroup actionGroup, @NotNull DataContext dataContext, + @Nullable String actionPlace, boolean showNumbers, boolean showDisabledActions, String title, Component component, boolean honorActionMnemonics, - int defaultOptionIndex, final boolean autoSelectionEnabled); + int defaultOptionIndex, + boolean autoSelectionEnabled); @NotNull public abstract RelativePoint guessBestPopupLocation(@NotNull JComponent component); diff --git a/platform/platform-impl/src/com/intellij/ui/components/BasicOptionButtonUI.kt b/platform/platform-impl/src/com/intellij/ui/components/BasicOptionButtonUI.kt index 82b9aab5d962..dc5f65e79866 100644 --- a/platform/platform-impl/src/com/intellij/ui/components/BasicOptionButtonUI.kt +++ b/platform/platform-impl/src/com/intellij/ui/components/BasicOptionButtonUI.kt @@ -358,7 +358,8 @@ open class BasicOptionButtonUI : OptionButtonUI() { open inner class OptionButtonPopupStep(actions: List, private val defaultSelection: Condition?) : ActionPopupStep(actions, null, - Supplier { DataManager.getInstance().getDataContext(optionButton) }, true, defaultSelection, false, true) { + Supplier { DataManager.getInstance().getDataContext(optionButton) }, + null, true, defaultSelection, false, true) { // if there is no default selection condition - -1 should be returned, this way first enabled action should be selected by // OptionButtonPopup.afterShow() (if corresponding ensureSelection parameter is true) override fun getDefaultOptionIndex() = defaultSelection?.let { super.getDefaultOptionIndex() } ?: -1 diff --git a/platform/platform-impl/src/com/intellij/ui/popup/ActionPopupStep.java b/platform/platform-impl/src/com/intellij/ui/popup/ActionPopupStep.java index 38b0de88453b..f46617aa428c 100644 --- a/platform/platform-impl/src/com/intellij/ui/popup/ActionPopupStep.java +++ b/platform/platform-impl/src/com/intellij/ui/popup/ActionPopupStep.java @@ -5,6 +5,7 @@ import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.actionSystem.ex.ActionUtil; import com.intellij.openapi.ui.popup.*; import com.intellij.openapi.util.Condition; +import com.intellij.util.ObjectUtils; import com.intellij.util.ui.StatusText; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; @@ -20,23 +21,26 @@ public class ActionPopupStep implements ListPopupStepEx myItems; private final String myTitle; private final Supplier myContext; + private final String myActionPlace; private final boolean myEnableMnemonics; private final int myDefaultOptionIndex; private final boolean myAutoSelectionEnabled; private final boolean myShowDisabledActions; private Runnable myFinalRunnable; - @Nullable private final Condition myPreselectActionCondition; + private final Condition myPreselectActionCondition; - public ActionPopupStep(@NotNull final List items, - final String title, + public ActionPopupStep(@NotNull List items, + String title, @NotNull Supplier context, + @Nullable String actionPlace, boolean enableMnemonics, @Nullable Condition preselectActionCondition, - final boolean autoSelection, + boolean autoSelection, boolean showDisabledActions) { myItems = items; myTitle = title; myContext = context; + myActionPlace = ObjectUtils.notNull(actionPlace, ActionPlaces.UNKNOWN); myEnableMnemonics = enableMnemonics; myDefaultOptionIndex = getDefaultOptionIndexFromSelectCondition(preselectActionCondition, items); myPreselectActionCondition = preselectActionCondition; @@ -65,8 +69,10 @@ public class ActionPopupStep implements ListPopupStepEx contextSupplier, + @Nullable String actionPlace, Condition preselectCondition, int defaultOptionIndex) { final ActionStepBuilder builder = @@ -77,15 +83,13 @@ public class ActionPopupStep implements ListPopupStepEx actionItem.getAction().getTemplatePresentation().getMnemonic() != 0); - return new ActionPopupStep(items, - title, - contextSupplier, - enableMnemonics, - preselectCondition != null ? preselectCondition : action -> defaultOptionIndex >= 0 && - defaultOptionIndex < items.size() && - items.get(defaultOptionIndex).getAction().equals(action), - autoSelectionEnabled, - showDisabledActions); + return new ActionPopupStep( + items, title, contextSupplier, actionPlace, enableMnemonics, + preselectCondition != null ? preselectCondition : + action -> defaultOptionIndex >= 0 && + defaultOptionIndex < items.size() && items.get(defaultOptionIndex).getAction().equals(action), + autoSelectionEnabled, + showDisabledActions); } @Override @@ -164,16 +168,17 @@ public class ActionPopupStep implements ListPopupStepEx performAction(action, eventModifiers); @@ -186,9 +191,10 @@ public class ActionPopupStep implements ListPopupStepEx preselectActionCondition, - @Nullable String actionPlace, boolean autoSelection) { + @Nullable String actionPlace, + boolean autoSelection) { final Component component = PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext); LOG.assertTrue(component != null, "dataContext has no component for new ListPopupStep"); List items = getActionItems(actionGroup, dataContext, showNumbers, useAlphaAsNumbers, showDisabledActions, honorActionMnemonics, actionPlace); - return new ActionPopupStep(items, title, getComponentContextSupplier(component), showNumbers || honorActionMnemonics && itemsHaveMnemonics(items), + return new ActionPopupStep(items, title, getComponentContextSupplier(component), actionPlace, showNumbers || honorActionMnemonics && itemsHaveMnemonics(items), preselectActionCondition, autoSelection, showDisabledActions); } @@ -380,40 +381,23 @@ public class PopupFactoryImpl extends JBPopupFactory { disposeCallback, maxRowCount, preselectActionCondition, null); } - @NotNull - @Override - public ListPopupStep createActionsStep(@NotNull final ActionGroup actionGroup, - @NotNull DataContext dataContext, - final boolean showNumbers, - final boolean showDisabledActions, - final String title, - final Component component, - final boolean honorActionMnemonics) { - return createActionsStep(actionGroup, dataContext, showNumbers, showDisabledActions, title, component, honorActionMnemonics, 0, false); - } - @NotNull @Override public ListPopupStep createActionsStep(@NotNull ActionGroup actionGroup, @NotNull DataContext dataContext, + @Nullable String actionPlace, boolean showNumbers, boolean showDisabledActions, String title, Component component, boolean honorActionMnemonics, int defaultOptionIndex, - final boolean autoSelectionEnabled) { - return ActionPopupStep.createActionsStep(actionGroup, - dataContext, - showNumbers, - true, - showDisabledActions, - title, - honorActionMnemonics, - autoSelectionEnabled, - getComponentContextSupplier(component), - null, - defaultOptionIndex); + boolean autoSelectionEnabled) { + return ActionPopupStep.createActionsStep( + actionGroup, dataContext, showNumbers, true, showDisabledActions, + title, honorActionMnemonics, autoSelectionEnabled, + getComponentContextSupplier(component), + actionPlace, null, defaultOptionIndex); } private static boolean itemsHaveMnemonics(final List items) { diff --git a/platform/platform-resources/src/idea/LangActions.xml b/platform/platform-resources/src/idea/LangActions.xml index 7ca132c9f087..33537b677256 100644 --- a/platform/platform-resources/src/idea/LangActions.xml +++ b/platform/platform-resources/src/idea/LangActions.xml @@ -398,12 +398,6 @@ - diff --git a/plugins/tasks/tasks-core/src/com/intellij/tasks/actions/SwitchTaskAction.java b/plugins/tasks/tasks-core/src/com/intellij/tasks/actions/SwitchTaskAction.java index 3ac0c07f66f2..0f8263d7a3e8 100644 --- a/plugins/tasks/tasks-core/src/com/intellij/tasks/actions/SwitchTaskAction.java +++ b/plugins/tasks/tasks-core/src/com/intellij/tasks/actions/SwitchTaskAction.java @@ -121,8 +121,8 @@ public class SwitchTaskAction extends ComboBoxAction implements DumbAware { popup.showCenteredInCurrentWindow(project); } - private static ListPopupImpl createPopup(final DataContext dataContext, - @Nullable final Runnable onDispose, + private static ListPopupImpl createPopup(@NotNull DataContext dataContext, + @Nullable Runnable onDispose, boolean withTitle) { final Project project = CommonDataKeys.PROJECT.getData(dataContext); final Ref shiftPressed = Ref.create(false); @@ -138,8 +138,9 @@ public class SwitchTaskAction extends ComboBoxAction implements DumbAware { return FINAL_CHOICE; } ActionGroup group = createActionsStep(selectedValues, project, shiftPressed); - return JBPopupFactory.getInstance() - .createActionsStep(group, DataManager.getInstance().getDataContext(componentRef.get()), false, false, null, null, true); + DataContext dataContext = DataManager.getInstance().getDataContext(componentRef.get()); + return JBPopupFactory.getInstance().createActionsStep( + group, dataContext, null, false, false, null, null, true, 0, false); } @Override