[vcs-log] declare action in xml file, improve ui

This commit is contained in:
Julia Beliaeva
2015-02-05 23:30:31 +03:00
parent 2ddb4c9f85
commit b2064aebbd
8 changed files with 127 additions and 74 deletions
@@ -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);
}
@@ -45,18 +45,26 @@ public interface PermanentGraph<CommitId> {
Set<CommitId> 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;
}
}
}
@@ -230,5 +230,4 @@ class LinearBekGraphBuilder {
return new LinearBekGraph(myGraph, myHiddenEdges, myDottedEdges);
}
}
}
@@ -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"/>
<action class="com.intellij.vcs.log.ui.VcsLogQuickSettingsActions" id="Vcs.Log.QuickSettings"
icon="AllIcons.General.Gear" text="Quick Settings" description="Quick Settings" />
<action class="com.intellij.vcs.log.ui.frame.IntelliSortChooserAction" id="Vcs.Log.IntelliSortChooser"
icon="VcsLogIcons.Branch" text="IntelliSort" description="Change IntelliSort Type"/>
<group id="Vcs.Log.Toolbar">
<reference id="Vcs.Log.GoToRef" />
<reference id="Vcs.Log.QuickSettings" />
@@ -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
@@ -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<Boolean> jumpToCommit(@NotNull Hash commitHash) {
SettableFuture<Boolean> future = SettableFuture.create();
@@ -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<PermanentGraph.SortType, AnAction>() {
@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);
}
}
}
}
@@ -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() {