From f99e75e5e3f9f76f6d8a68bcb771c8f20bbc763c Mon Sep 17 00:00:00 2001 From: Julia Beliaeva Date: Wed, 4 Nov 2015 18:22:32 +0300 Subject: [PATCH] [vcs-log] speedsearch for untracked remote branches in branch popup IDEA-140675 --- .../ui/filter/BranchFilterPopupComponent.java | 5 +- .../log/ui/filter/FlatSpeedSearchPopup.java | 104 ++++++++++++++++++ 2 files changed, 105 insertions(+), 4 deletions(-) create mode 100644 platform/vcs-log/impl/src/com/intellij/vcs/log/ui/filter/FlatSpeedSearchPopup.java diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/filter/BranchFilterPopupComponent.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/filter/BranchFilterPopupComponent.java index a81e36dc949d..f8e52576122a 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/filter/BranchFilterPopupComponent.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/filter/BranchFilterPopupComponent.java @@ -22,7 +22,6 @@ import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.DefaultActionGroup; import com.intellij.openapi.ui.popup.ListPopup; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.ui.popup.PopupFactoryImpl; import com.intellij.util.Function; import com.intellij.util.containers.ContainerUtil; import com.intellij.vcs.log.VcsLogBranchFilter; @@ -90,9 +89,7 @@ public class BranchFilterPopupComponent extends MultipleValueFilterPopupComponen @NotNull @Override protected ListPopup createPopupMenu() { - return new PopupFactoryImpl.ActionGroupPopup(null, createActionGroup(), DataManager.getInstance().getDataContext(this), - false, false, false, false, - null, -1, null, null); + return new FlatSpeedSearchPopup(createActionGroup(), DataManager.getInstance().getDataContext(this)); } @Override diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/filter/FlatSpeedSearchPopup.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/filter/FlatSpeedSearchPopup.java new file mode 100644 index 000000000000..3e7d4e6e1b1c --- /dev/null +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/filter/FlatSpeedSearchPopup.java @@ -0,0 +1,104 @@ +/* + * Copyright 2000-2015 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.vcs.log.ui.filter; + +import com.intellij.openapi.actionSystem.*; +import com.intellij.ui.popup.PopupFactoryImpl; +import org.jetbrains.annotations.NotNull; + +public class FlatSpeedSearchPopup extends PopupFactoryImpl.ActionGroupPopup { + public FlatSpeedSearchPopup(@NotNull ActionGroup actionGroup, + @NotNull ActionGroup speedSearchActionGroup, + @NotNull DataContext dataContext) { + super(null, new DefaultActionGroup(actionGroup, speedSearchActionGroup), dataContext, false, false, false, false, null, -1, null, null); + } + + public FlatSpeedSearchPopup(@NotNull ActionGroup actionGroup, @NotNull DataContext dataContext) { + this(actionGroup, createSpeedSearchActionGroup(actionGroup), dataContext); + } + + @NotNull + public static ActionGroup createSpeedSearchActionGroup(@NotNull ActionGroup actionGroup) { + DefaultActionGroup speedSearchActions = new DefaultActionGroup(); + createSpeedSearchActions(actionGroup, speedSearchActions, true); + return speedSearchActions; + } + + private static void createSpeedSearchActions(@NotNull ActionGroup actionGroup, + @NotNull DefaultActionGroup speedSearchActions, + boolean isFirstLevel) { + if (!isFirstLevel) speedSearchActions.addSeparator(actionGroup.getTemplatePresentation().getText()); + + for (AnAction child : actionGroup.getChildren(null)) { + if (!isFirstLevel && !(child instanceof ActionGroup || child instanceof Separator || child instanceof SpeedsearchAction)) { + speedSearchActions.add(createSpeedSearchWrapper(child)); + } + else if (child instanceof ActionGroup) { + createSpeedSearchActions((ActionGroup)child, speedSearchActions, isFirstLevel && !((ActionGroup)child).isPopup()); + } + } + } + + @NotNull + public static AnAction createSpeedSearchWrapper(@NotNull AnAction child) { + return new MySpeedSearchAction(child); + } + + @Override + public boolean shouldBeShowing(Object value) { + if (!super.shouldBeShowing(value)) return false; + if (!(value instanceof PopupFactoryImpl.ActionItem)) return true; + + AnAction action = ((PopupFactoryImpl.ActionItem)value).getAction(); + if (getSpeedSearch().isHoldingFilter()) { + return !(action instanceof ActionGroup); + } + else { + return !isSpeedsearchAction(action); + } + } + + private static boolean isSpeedsearchAction(@NotNull AnAction action) { + return action instanceof SpeedsearchAction; + } + + public interface SpeedsearchAction { + } + + private static class MySpeedSearchAction extends AnAction implements SpeedsearchAction { + @NotNull private final AnAction myAction; + + public MySpeedSearchAction(@NotNull AnAction action) { + myAction = action; + copyFrom(action); + } + + @Override + public boolean isDumbAware() { + return myAction.isDumbAware(); + } + + @Override + public void update(AnActionEvent e) { + myAction.update(e); + } + + @Override + public void actionPerformed(AnActionEvent e) { + myAction.actionPerformed(e); + } + } +}