From 214727999680506532f83cfd0f40c854dce7c99f Mon Sep 17 00:00:00 2001 From: Erokhin Stanislav Date: Mon, 19 May 2014 21:19:02 +0400 Subject: [PATCH] [log] Add bek button. --- .../vcs/log/graph/BekGraphAction.java | 33 ++++++++++++++++ .../intellij/vcs/log/graph/GraphFacade.java | 2 - .../intellij/vcs/log/DelegateGraphFacade.java | 39 ++++++++++--------- .../vcs/log/data/EmptyGraphFacade.java | 4 -- .../vcs/log/data/VcsLogUiProperties.java | 9 +++++ .../com/intellij/vcs/log/ui/VcsLogUiImpl.java | 24 +++++++++++- .../intellij/vcs/log/ui/frame/MainFrame.java | 26 ++++++++++++- 7 files changed, 110 insertions(+), 27 deletions(-) create mode 100644 platform/vcs-log/api/src/com/intellij/vcs/log/graph/BekGraphAction.java diff --git a/platform/vcs-log/api/src/com/intellij/vcs/log/graph/BekGraphAction.java b/platform/vcs-log/api/src/com/intellij/vcs/log/graph/BekGraphAction.java new file mode 100644 index 000000000000..1deb51f6632b --- /dev/null +++ b/platform/vcs-log/api/src/com/intellij/vcs/log/graph/BekGraphAction.java @@ -0,0 +1,33 @@ +/* + * Copyright 2000-2014 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.graph; + +import org.jetbrains.annotations.NotNull; + +public class BekGraphAction implements GraphAction { + + @NotNull + private final PermanentGraph.SortType mySortType; + + public BekGraphAction(@NotNull PermanentGraph.SortType sortType) { + mySortType = sortType; + } + + @NotNull + public PermanentGraph.SortType getSortType() { + return mySortType; + } +} diff --git a/platform/vcs-log/api/src/com/intellij/vcs/log/graph/GraphFacade.java b/platform/vcs-log/api/src/com/intellij/vcs/log/graph/GraphFacade.java index 073decb52303..b48e70266f50 100644 --- a/platform/vcs-log/api/src/com/intellij/vcs/log/graph/GraphFacade.java +++ b/platform/vcs-log/api/src/com/intellij/vcs/log/graph/GraphFacade.java @@ -78,8 +78,6 @@ public interface GraphFacade { */ void setFilter(@Nullable Condition visibilityPredicate); - void setSortType(@NotNull PermanentGraph.SortType sortType); - /** * Returns the provider of some information about the graph. */ diff --git a/platform/vcs-log/graph/src/com/intellij/vcs/log/DelegateGraphFacade.java b/platform/vcs-log/graph/src/com/intellij/vcs/log/DelegateGraphFacade.java index 49d63f9b2f8c..7e723580afaf 100644 --- a/platform/vcs-log/graph/src/com/intellij/vcs/log/DelegateGraphFacade.java +++ b/platform/vcs-log/graph/src/com/intellij/vcs/log/DelegateGraphFacade.java @@ -36,6 +36,21 @@ import java.util.List; import java.util.Set; public class DelegateGraphFacade implements GraphFacade { + @NotNull + public static final GraphAnswer JUMP_TO_0_GRAPH_ANSWER = new GraphAnswer() { + @Nullable + @Override + public GraphChange getGraphChange() { + return new GraphChange() { + }; + } + + @Nullable + @Override + public GraphActionRequest getActionRequest() { + return new JumpToRowActionRequest(0); + } + }; @NotNull private final PermanentGraph myPermanentGraph; @@ -124,19 +139,13 @@ public class DelegateGraphFacade implements GraphFacade { if (action instanceof LinearBranchesExpansionAction) { boolean shouldExpand = ((LinearBranchesExpansionAction)action).shouldExpand(); actionController.setLinearBranchesExpansion(!shouldExpand); - return new GraphAnswer() { - @Nullable - @Override - public GraphChange getGraphChange() { - return new GraphChange() {}; - } + return JUMP_TO_0_GRAPH_ANSWER; + } - @Nullable - @Override - public GraphActionRequest getActionRequest() { - return new JumpToRowActionRequest(0); - } - }; + if (action instanceof BekGraphAction) { + mySortType = ((BekGraphAction)action).getSortType(); + updateVisibleGraph(); + return JUMP_TO_0_GRAPH_ANSWER; } return null; @@ -211,12 +220,6 @@ public class DelegateGraphFacade implements GraphFacade { updateVisibleGraph(); } - @Override - public void setSortType(@NotNull PermanentGraph.SortType sortType) { - mySortType = sortType; - updateVisibleGraph(); - } - @NotNull @Override public GraphInfoProvider getInfoProvider() { diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/EmptyGraphFacade.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/EmptyGraphFacade.java index ef5cc5d75c31..cf52495938bf 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/EmptyGraphFacade.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/EmptyGraphFacade.java @@ -79,10 +79,6 @@ class EmptyGraphFacade implements GraphFacade { public void setFilter(@Nullable Condition visibilityPredicate) { } - @Override - public void setSortType(@NotNull PermanentGraph.SortType sortType) { - } - @NotNull @Override public GraphInfoProvider getInfoProvider() { diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/VcsLogUiProperties.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/VcsLogUiProperties.java index 05c8bda79a1f..1db1181dfb3b 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/VcsLogUiProperties.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/VcsLogUiProperties.java @@ -42,6 +42,7 @@ public class VcsLogUiProperties implements PersistentStateComponent RECENTLY_FILTERED_USER_GROUPS = new ArrayDeque(); public Deque RECENTLY_FILTERED_BRANCH_GROUPS = new ArrayDeque(); } @@ -117,6 +118,14 @@ public class VcsLogUiProperties implements PersistentStateComponent users = new ArrayList(); diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/VcsLogUiImpl.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/VcsLogUiImpl.java index 415fdc26bd83..b67e267c20e1 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/VcsLogUiImpl.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/VcsLogUiImpl.java @@ -134,7 +134,6 @@ public class VcsLogUiImpl implements VcsLogUi, Disposable { @Override public void run() { handleAnswer(answer); - jumpToRow(0); } }); } @@ -150,7 +149,6 @@ public class VcsLogUiImpl implements VcsLogUi, Disposable { @Override public void run() { handleAnswer(answer); - jumpToRow(0); } }); } @@ -166,6 +164,27 @@ public class VcsLogUiImpl implements VcsLogUi, Disposable { return myDataPack.getGraphFacade().getInfoProvider().areLongEdgesHidden(); } + public void setBek(boolean bek) { + myUiProperties.setBek(bek); + final BekGraphAction bekGraphAction = new BekGraphAction(bek ? PermanentGraph.SortType.Bek : PermanentGraph.SortType.Normal); + runUnderModalProgress("Apply sort type...", new Runnable() { + @Override + public void run() { + final GraphAnswer answer = myDataPack.getGraphFacade().performAction(bekGraphAction); + UIUtil.invokeLaterIfNeeded(new Runnable() { + @Override + public void run() { + handleAnswer(answer); + } + }); + } + }); + } + + public boolean isBek() { + return myUiProperties.isBek(); + } + public void click(int rowIndex) { handleAnswer(myDataPack.getGraphFacade().performAction(new ClickGraphAction(rowIndex, null))); } @@ -300,6 +319,7 @@ public class VcsLogUiImpl implements VcsLogUi, Disposable { setModel(newModel, myDataPack, previouslySelected); myMainFrame.updateDataPack(myDataPack); setLongEdgeVisibility(myUiProperties.areLongEdgesVisible()); + setBek(myUiProperties.isBek()); fireFilterChangeEvent(); repaintUI(); diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/MainFrame.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/MainFrame.java index 26457599ab9d..163be9ecc918 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/MainFrame.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/MainFrame.java @@ -163,6 +163,8 @@ public class MainFrame extends JPanel implements TypeSafeDataProvider { } private JComponent createActionsToolbar() { + AnAction bekAction = new BekAction(); + AnAction hideBranchesAction = new GraphAction("Collapse linear branches", "Collapse linear branches", VcsLogIcons.CollapseBranches) { @Override public void actionPerformed(AnActionEvent e) { @@ -194,7 +196,7 @@ public class MainFrame extends JPanel implements TypeSafeDataProvider { refreshAction.registerShortcutOn(this); - DefaultActionGroup toolbarGroup = new DefaultActionGroup(hideBranchesAction, showBranchesAction, showFullPatchAction, refreshAction, + DefaultActionGroup toolbarGroup = new DefaultActionGroup(bekAction, hideBranchesAction, showBranchesAction, showFullPatchAction, refreshAction, showDetailsAction); toolbarGroup.add(ActionManager.getInstance().getAction(VcsLogUiImpl.TOOLBAR_ACTION_GROUP)); @@ -276,6 +278,28 @@ public class MainFrame extends JPanel implements TypeSafeDataProvider { } } + private class BekAction extends ToggleAction implements DumbAware { + public BekAction() { + super("BEK", "BEK", AllIcons.Actions.Lightning); + } + + @Override + public boolean isSelected(AnActionEvent e) { + return myUI.isBek(); + } + + @Override + public void setSelected(AnActionEvent e, boolean state) { + myUI.setBek(state); + } + + @Override + public void update(AnActionEvent e) { + super.update(e); + e.getPresentation().setEnabled(areGraphActionsEnabled()); + } + } + private class ShowDetailsAction extends ToggleAction implements DumbAware { public ShowDetailsAction() {