[log] Added arrow navigation support.

This commit is contained in:
Stanislav.Erokhin
2015-02-02 16:45:46 +03:00
committed by Julia Beliaeva
parent 2df738376a
commit d8cfde5164
@@ -15,16 +15,17 @@
*/
package com.intellij.vcs.log.graph.impl.facade;
import com.intellij.vcs.log.graph.PrintElement;
import com.intellij.vcs.log.graph.RowInfo;
import com.intellij.vcs.log.graph.RowType;
import com.intellij.vcs.log.graph.VisibleGraph;
import com.intellij.vcs.log.graph.*;
import com.intellij.vcs.log.graph.actions.ActionController;
import com.intellij.vcs.log.graph.actions.GraphAction;
import com.intellij.vcs.log.graph.actions.GraphAnswer;
import com.intellij.vcs.log.graph.api.elements.GraphEdge;
import com.intellij.vcs.log.graph.api.elements.GraphEdgeType;
import com.intellij.vcs.log.graph.api.elements.GraphNodeType;
import com.intellij.vcs.log.graph.api.elements.GraphElement;
import com.intellij.vcs.log.graph.api.permanent.PermanentGraphInfo;
import com.intellij.vcs.log.graph.api.printer.PrintElementGenerator;
import com.intellij.vcs.log.graph.impl.facade.LinearGraphController.LinearGraphAction;
import com.intellij.vcs.log.graph.impl.print.PrintElementGeneratorImpl;
import com.intellij.vcs.log.graph.impl.print.elements.PrintElementWithGraphElement;
import org.jetbrains.annotations.NotNull;
@@ -32,6 +33,11 @@ import org.jetbrains.annotations.Nullable;
import java.awt.*;
import java.util.Collection;
import java.util.Collections;
import static com.intellij.vcs.log.graph.SimplePrintElement.Type.DOWN_ARROW;
import static com.intellij.vcs.log.graph.SimplePrintElement.Type.UP_ARROW;
import static com.intellij.vcs.log.graph.utils.LinearGraphUtils.getCursor;
public class VisibleGraphImpl<CommitId> implements VisibleGraph<CommitId> {
@NotNull private final LinearGraphController myGraphController;
@@ -113,10 +119,56 @@ public class VisibleGraphImpl<CommitId> implements VisibleGraph<CommitId> {
private class ActionControllerImpl implements ActionController<CommitId> {
@Nullable
private Integer convertToNodeId(@Nullable Integer nodeIndex) {
if (nodeIndex == null) return null;
return myGraphController.getCompiledGraph().getNodeId(nodeIndex);
}
@Nullable
private GraphAnswer<CommitId> performArrowAction(@NotNull LinearGraphAction action) {
PrintElementWithGraphElement affectedElement = action.getAffectedElement();
if (!(affectedElement instanceof SimplePrintElement)) return null;
SimplePrintElement.Type printElementType = ((SimplePrintElement)affectedElement).getType();
if (printElementType != DOWN_ARROW && printElementType != UP_ARROW) return null;
GraphElement graphElement = affectedElement.getGraphElement();
if (!(graphElement instanceof GraphEdge)) return null;
GraphEdge edge = (GraphEdge)graphElement;
Integer targetId = null;
if (edge.getType() == GraphEdgeType.NOT_LOAD_COMMIT) {
assert printElementType == DOWN_ARROW;
targetId = edge.getTargetId();
}
if (edge.getType().isNormalEdge()) {
if (printElementType == DOWN_ARROW) targetId = convertToNodeId(edge.getDownNodeIndex());
else targetId = convertToNodeId(edge.getUpNodeIndex());
}
if (targetId == null) return null;
if (action.getType() == GraphAction.Type.MOUSE_OVER) {
myPrintElementManager.setSelectedElement(affectedElement);
return new GraphAnswerImpl<CommitId>(getCursor(true), null);
}
if (action.getType() == GraphAction.Type.MOUSE_CLICK) {
return new GraphAnswerImpl<CommitId>(getCursor(false), myPermanentGraph.getPermanentCommitsInfo().getCommitId(targetId));
}
return null;
}
@NotNull
@Override
public GraphAnswer<CommitId> performAction(@NotNull GraphAction graphAction) {
LinearGraphController.LinearGraphAnswer answer = myGraphController.performLinearGraphAction(convert(graphAction));
myPrintElementManager.setSelectedElements(Collections.<Integer>emptySet());
LinearGraphAction action = convert(graphAction);
GraphAnswer<CommitId> graphAnswer = performArrowAction(action);
if (graphAnswer != null) return graphAnswer;
LinearGraphController.LinearGraphAnswer answer = myGraphController.performLinearGraphAction(action);
if (answer.getSelectedNodeIds() != null) myPrintElementManager.setSelectedElements(answer.getSelectedNodeIds());
if (answer.getGraphChanges() != null) updatePrintElementGenerator();
@@ -146,7 +198,7 @@ public class VisibleGraphImpl<CommitId> implements VisibleGraph<CommitId> {
if (answer.getGraphChanges() != null) updatePrintElementGenerator();
}
private LinearGraphController.LinearGraphAction convert(@NotNull GraphAction graphAction) {
private LinearGraphAction convert(@NotNull GraphAction graphAction) {
PrintElementWithGraphElement printElement = null;
if (graphAction.getAffectedElement() != null) {
printElement = myPrintElementGenerator.toPrintElementWithGraphElement(graphAction.getAffectedElement());
@@ -184,9 +236,9 @@ public class VisibleGraphImpl<CommitId> implements VisibleGraph<CommitId> {
}
}
private static class LinearGraphActionImpl implements LinearGraphController.LinearGraphAction {
private final static LinearGraphController.LinearGraphAction COLLAPSE = new LinearGraphActionImpl(null, Type.BUTTON_COLLAPSE);
private final static LinearGraphController.LinearGraphAction EXPAND = new LinearGraphActionImpl(null, Type.BUTTON_EXPAND);
private static class LinearGraphActionImpl implements LinearGraphAction {
private final static LinearGraphAction COLLAPSE = new LinearGraphActionImpl(null, Type.BUTTON_COLLAPSE);
private final static LinearGraphAction EXPAND = new LinearGraphActionImpl(null, Type.BUTTON_EXPAND);
@Nullable private final PrintElementWithGraphElement myAffectedElement;
@NotNull private final Type myType;