diff --git a/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/impl/facade/VisibleGraphImpl.java b/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/impl/facade/VisibleGraphImpl.java index 43b68cccb70f..738384fdc85b 100644 --- a/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/impl/facade/VisibleGraphImpl.java +++ b/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/impl/facade/VisibleGraphImpl.java @@ -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 implements VisibleGraph { @NotNull private final LinearGraphController myGraphController; @@ -113,10 +119,56 @@ public class VisibleGraphImpl implements VisibleGraph { private class ActionControllerImpl implements ActionController { + @Nullable + private Integer convertToNodeId(@Nullable Integer nodeIndex) { + if (nodeIndex == null) return null; + return myGraphController.getCompiledGraph().getNodeId(nodeIndex); + } + + @Nullable + private GraphAnswer 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(getCursor(true), null); + } + + if (action.getType() == GraphAction.Type.MOUSE_CLICK) { + return new GraphAnswerImpl(getCursor(false), myPermanentGraph.getPermanentCommitsInfo().getCommitId(targetId)); + } + + return null; + } + @NotNull @Override public GraphAnswer performAction(@NotNull GraphAction graphAction) { - LinearGraphController.LinearGraphAnswer answer = myGraphController.performLinearGraphAction(convert(graphAction)); + myPrintElementManager.setSelectedElements(Collections.emptySet()); + + LinearGraphAction action = convert(graphAction); + GraphAnswer 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 implements VisibleGraph { 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 implements VisibleGraph { } } - 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;