diff --git a/platform/vcs-log/api/src/com/intellij/vcs/log/VcsLogUi.java b/platform/vcs-log/api/src/com/intellij/vcs/log/VcsLogUi.java index 4094b47c27a3..f4219bd20374 100644 --- a/platform/vcs-log/api/src/com/intellij/vcs/log/VcsLogUi.java +++ b/platform/vcs-log/api/src/com/intellij/vcs/log/VcsLogUi.java @@ -15,6 +15,7 @@ */ package com.intellij.vcs.log; +import com.intellij.vcs.log.graph.PermanentGraph; import org.jetbrains.annotations.NotNull; public interface VcsLogUi { @@ -33,7 +34,13 @@ public interface VcsLogUi { void setBranchesPanelVisible(boolean visible); + boolean areGraphActionsEnabled(); + boolean isMultipleRoots(); boolean isShowRootNames(); + + void setBekType(@NotNull PermanentGraph.SortType bekType); + @NotNull PermanentGraph.SortType getBekType(); + void setShowRootNames(boolean showRootNames); } diff --git a/platform/vcs-log/graph-api/src/com/intellij/vcs/log/graph/PermanentGraph.java b/platform/vcs-log/graph-api/src/com/intellij/vcs/log/graph/PermanentGraph.java index b275383652f0..5a8b164cc4b6 100644 --- a/platform/vcs-log/graph-api/src/com/intellij/vcs/log/graph/PermanentGraph.java +++ b/platform/vcs-log/graph-api/src/com/intellij/vcs/log/graph/PermanentGraph.java @@ -45,18 +45,26 @@ public interface PermanentGraph { Set getContainingBranches(@NotNull CommitId commit); enum SortType { - Normal("Off"), - Bek("Standard"), - LinearBek("Linear"); + Normal("Off", "Sort commits topologically and by date."), + Bek("Standard", "In case of merge show incoming commits first (directly below merge commit)."), + LinearBek("Linear", "In case of merge show incoming commits on top of main branch commits as if they were rebased."); - private final String myPresentation; + @NotNull private final String myPresentation; + @NotNull private final String myDescription; - SortType(String presentation) { + SortType(@NotNull String presentation, @NotNull String description) { myPresentation = presentation; + myDescription = description; } - public String getPresentation() { + @NotNull + public String getName() { return myPresentation; } + + @NotNull + public String getDescription() { + return myDescription; + } } } diff --git a/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/linearBek/LinearBekGraphBuilder.java b/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/linearBek/LinearBekGraphBuilder.java index e665ca4564a9..f1c1e7e8835e 100644 --- a/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/linearBek/LinearBekGraphBuilder.java +++ b/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/linearBek/LinearBekGraphBuilder.java @@ -230,5 +230,4 @@ class LinearBekGraphBuilder { return new LinearBekGraph(myGraph, myHiddenEdges, myDottedEdges); } } - } diff --git a/platform/vcs-log/impl/src/META-INF/vcs-log.xml b/platform/vcs-log/impl/src/META-INF/vcs-log.xml index 31522c0bcc54..0b621568428d 100644 --- a/platform/vcs-log/impl/src/META-INF/vcs-log.xml +++ b/platform/vcs-log/impl/src/META-INF/vcs-log.xml @@ -22,6 +22,8 @@ text="Go To Hash/Branch/Tag" description="Specify hash or name of a branch or a tag to navigate to the commit it points"/> + diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/VcsLogQuickSettingsActions.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/VcsLogQuickSettingsActions.java index 9c579f410b1e..ee7d537e3460 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/VcsLogQuickSettingsActions.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/VcsLogQuickSettingsActions.java @@ -20,6 +20,7 @@ import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.popup.JBPopupFactory; import com.intellij.openapi.wm.impl.content.ToolWindowContentUi; import com.intellij.vcs.log.VcsLogDataKeys; import com.intellij.vcs.log.VcsLogSettings; @@ -27,9 +28,6 @@ import com.intellij.vcs.log.VcsLogUi; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.awt.event.InputEvent; -import java.awt.event.MouseEvent; - public class VcsLogQuickSettingsActions extends DumbAwareAction { @Override @@ -38,16 +36,9 @@ public class VcsLogQuickSettingsActions extends DumbAwareAction { VcsLogUi logUi = e.getRequiredData(VcsLogDataKeys.VCS_LOG_UI); VcsLogSettings settings = ServiceManager.getService(project, VcsLogSettings.class); - ActionGroup settingsGroup = new MySettingsActionGroup(settings, logUi); - ActionPopupMenu popupMenu = ActionManager.getInstance().createActionPopupMenu(ToolWindowContentUi.POPUP_PLACE, settingsGroup); - int x = 0; - int y = 0; - InputEvent inputEvent = e.getInputEvent(); - if (inputEvent instanceof MouseEvent) { - x = ((MouseEvent)inputEvent).getX(); - y = ((MouseEvent)inputEvent).getY(); - } - popupMenu.getComponent().show(inputEvent.getComponent(), x, y); + JBPopupFactory.getInstance().createActionGroupPopup(null, new MySettingsActionGroup(settings, logUi), e.getDataContext(), + JBPopupFactory.ActionSelectionAid.MNEMONICS, true, ToolWindowContentUi.POPUP_PLACE) + .showUnderneathOf(e.getInputEvent().getComponent()); } @Override 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 3d6a29416a96..8a3260ca3ef4 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 @@ -41,6 +41,7 @@ public class VcsLogUiImpl implements VcsLogUi, Disposable { public static final String POPUP_ACTION_GROUP = "Vcs.Log.ContextMenu"; public static final String TOOLBAR_ACTION_GROUP = "Vcs.Log.Toolbar"; public static final String VCS_LOG_TABLE_PLACE = "Vcs.Log.ContextMenu"; + public static final String VCS_LOG_INTELLI_SORT_ACTION = "Vcs.Log.IntelliSortChooser"; private static final Logger LOG = Logger.getInstance(VcsLogUiImpl.class); @@ -175,11 +176,14 @@ public class VcsLogUiImpl implements VcsLogUi, Disposable { myUiProperties.setLongEdgesVisibility(visibility); } - public void setBek(PermanentGraph.SortType bekType) { + @Override + public void setBekType(@NotNull PermanentGraph.SortType bekType) { myUiProperties.setBek(bekType.ordinal()); myFilterer.onSortTypeChange(bekType); } + @Override + @NotNull public PermanentGraph.SortType getBekType() { return PermanentGraph.SortType.values()[myUiProperties.getBekSortType()]; } @@ -193,6 +197,11 @@ public class VcsLogUiImpl implements VcsLogUi, Disposable { return myUiProperties.isShowRootNames(); } + @Override + public boolean areGraphActionsEnabled() { + return myMainFrame.areGraphActionsEnabled(); + } + @NotNull public Future jumpToCommit(@NotNull Hash commitHash) { SettableFuture future = SettableFuture.create(); diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/IntelliSortChooserAction.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/IntelliSortChooserAction.java new file mode 100644 index 000000000000..d23094b8cac5 --- /dev/null +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/IntelliSortChooserAction.java @@ -0,0 +1,89 @@ +/* + * 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.frame; + +import com.intellij.openapi.actionSystem.*; +import com.intellij.openapi.project.DumbAware; +import com.intellij.openapi.project.DumbAwareAction; +import com.intellij.openapi.ui.popup.JBPopupFactory; +import com.intellij.openapi.wm.impl.content.ToolWindowContentUi; +import com.intellij.util.Function; +import com.intellij.util.containers.ContainerUtil; +import com.intellij.vcs.log.VcsLogDataKeys; +import com.intellij.vcs.log.VcsLogUi; +import com.intellij.vcs.log.graph.PermanentGraph; +import org.jetbrains.annotations.NotNull; + +class IntelliSortChooserAction extends DumbAwareAction { + @Override + public void actionPerformed(AnActionEvent e) { + final VcsLogUi logUI = e.getRequiredData(VcsLogDataKeys.VCS_LOG_UI); + + ActionGroup settingsGroup = + new DefaultActionGroup(ContainerUtil.map(PermanentGraph.SortType.values(), new Function() { + @Override + public AnAction fun(PermanentGraph.SortType sortType) { + return new SelectIntelliSortTypeAction(logUI, sortType); + } + })); + + JBPopupFactory.getInstance() + .createActionGroupPopup(null, settingsGroup, e.getDataContext(), JBPopupFactory.ActionSelectionAid.MNEMONICS, true, + ToolWindowContentUi.POPUP_PLACE).showUnderneathOf(e.getInputEvent().getComponent()); + + } + + @Override + public void update(AnActionEvent e) { + super.update(e); + VcsLogUi logUI = e.getData(VcsLogDataKeys.VCS_LOG_UI); + e.getPresentation().setEnabled(logUI != null); + if (logUI != null) { + String description = "IntelliSort: " + logUI.getBekType().getName(); + e.getPresentation().setDescription(description); + e.getPresentation().setText(description); + } + } + + private static class SelectIntelliSortTypeAction extends ToggleAction implements DumbAware { + private final PermanentGraph.SortType mySortType; + private final VcsLogUi myUI; + + public SelectIntelliSortTypeAction(VcsLogUi logUi, PermanentGraph.SortType sortType) { + super(sortType.getName(), sortType.getDescription(), null); + myUI = logUi; + mySortType = sortType; + } + + @Override + public void update(@NotNull AnActionEvent e) { + super.update(e); + e.getPresentation().setEnabled(myUI.areGraphActionsEnabled()); + } + + @Override + public boolean isSelected(AnActionEvent e) { + return myUI.getBekType().equals(mySortType); + } + + @Override + public void setSelected(AnActionEvent e, boolean state) { + if (state) { + myUI.setBekType(mySortType); + } + } + } +} 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 16bf882e1de8..d977483004e4 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 @@ -15,7 +15,6 @@ import com.intellij.openapi.vcs.changes.TextRevisionNumber; import com.intellij.openapi.vcs.changes.committed.RepositoryChangesBrowser; import com.intellij.openapi.vcs.changes.ui.ChangesBrowser; import com.intellij.openapi.vcs.history.VcsRevisionNumber; -import com.intellij.openapi.wm.impl.content.ToolWindowContentUi; import com.intellij.ui.ScrollPaneFactory; import com.intellij.ui.components.JBLoadingPanel; import com.intellij.util.ArrayUtil; @@ -26,7 +25,6 @@ import com.intellij.vcs.log.*; import com.intellij.vcs.log.data.VcsLogDataHolder; import com.intellij.vcs.log.data.VcsLogUiProperties; import com.intellij.vcs.log.data.VisiblePack; -import com.intellij.vcs.log.graph.PermanentGraph; import com.intellij.vcs.log.graph.impl.facade.bek.BekSorter; import com.intellij.vcs.log.ui.VcsLogUiImpl; import com.intellij.vcs.log.ui.filter.VcsLogClassicFilterUi; @@ -39,8 +37,6 @@ import javax.swing.*; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import java.awt.*; -import java.awt.event.InputEvent; -import java.awt.event.MouseEvent; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -242,7 +238,7 @@ public class MainFrame extends JPanel implements TypeSafeDataProvider { mainGroup.add(myFilterUi.createActionGroup()); mainGroup.addSeparator(); if (BekSorter.isBekEnabled()) { - mainGroup.add(createIntelliSortChooser()); + mainGroup.add(ActionManager.getInstance().getAction(VcsLogUiImpl.VCS_LOG_INTELLI_SORT_ACTION)); } mainGroup.add(toolbarGroup); ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.CHANGES_VIEW_TOOLBAR, mainGroup, true); @@ -250,27 +246,6 @@ public class MainFrame extends JPanel implements TypeSafeDataProvider { return toolbar.getComponent(); } - @NotNull - private AnAction createIntelliSortChooser() { - return new DumbAwareAction("IntelliSort", "IntelliSort", VcsLogIcons.Branch) { - @Override - public void actionPerformed(AnActionEvent e) { - ActionGroup settingsGroup = - new DefaultActionGroup(new BekAction(PermanentGraph.SortType.Normal), new BekAction(PermanentGraph.SortType.Bek), - new BekAction(PermanentGraph.SortType.LinearBek)); - ActionPopupMenu popupMenu = ActionManager.getInstance().createActionPopupMenu(ToolWindowContentUi.POPUP_PLACE, settingsGroup); - int x = 0; - int y = 0; - InputEvent inputEvent = e.getInputEvent(); - if (inputEvent instanceof MouseEvent) { - x = ((MouseEvent)inputEvent).getX(); - y = ((MouseEvent)inputEvent).getY(); - } - popupMenu.getComponent().show(inputEvent.getComponent(), x, y); - } - }; - } - public JComponent getMainComponent() { return this; } @@ -354,33 +329,6 @@ public class MainFrame extends JPanel implements TypeSafeDataProvider { } } - private class BekAction extends ToggleAction implements DumbAware { - private final PermanentGraph.SortType mySortType; - - public BekAction(PermanentGraph.SortType sortType) { - super(sortType.getPresentation(), "Set IntelliSort Type To " + sortType.getPresentation(), null); - mySortType = sortType; - } - - @Override - public void update(AnActionEvent e) { - super.update(e); - e.getPresentation().setEnabled(areGraphActionsEnabled()); - } - - @Override - public boolean isSelected(AnActionEvent e) { - return myUI.getBekType().equals(mySortType); - } - - @Override - public void setSelected(AnActionEvent e, boolean state) { - if (state) { - myUI.setBek(mySortType); - } - } - } - private class ShowDetailsAction extends ToggleAction implements DumbAware { public ShowDetailsAction() {