From 1dc22d2d91f6b065c616da7d0a717be2ce6bb9b5 Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Tue, 10 Nov 2015 15:10:11 +0300 Subject: [PATCH] diff: disable "annotate previous revision" for slave-side lines in Unified Viewer --- .../localVcs/UpToDateLineNumberProvider.java | 1 + .../vcs/actions/AnnotateDiffViewerAction.java | 4 ++-- .../AnnotatePreviousRevisionAction.java | 3 ++- .../AnnotationGutterLineConvertorProxy.java | 18 +++++++++++------- .../impl/UpToDateLineNumberProviderImpl.java | 4 ++-- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/platform/vcs-api/src/com/intellij/openapi/localVcs/UpToDateLineNumberProvider.java b/platform/vcs-api/src/com/intellij/openapi/localVcs/UpToDateLineNumberProvider.java index bacb8ba9e42e..a10f34645ab6 100644 --- a/platform/vcs-api/src/com/intellij/openapi/localVcs/UpToDateLineNumberProvider.java +++ b/platform/vcs-api/src/com/intellij/openapi/localVcs/UpToDateLineNumberProvider.java @@ -17,6 +17,7 @@ package com.intellij.openapi.localVcs; public interface UpToDateLineNumberProvider { int ABSENT_LINE_NUMBER = -1; + int FAKE_LINE_NUMBER = -2; int getLineNumber(int currentNumber); boolean isLineChanged(int currentNumber); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AnnotateDiffViewerAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AnnotateDiffViewerAction.java index fb977eff25bd..7faa7b585e98 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AnnotateDiffViewerAction.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AnnotateDiffViewerAction.java @@ -503,12 +503,12 @@ public class AnnotateDiffViewerAction extends ToggleAction implements DumbAware @Override public int getLineNumber(int currentNumber) { int number = myViewer.transferLineFromOnesideStrict(mySide, currentNumber); - return number != -1 ? myLocalChangesProvider.getLineNumber(number) : -1; + return number != -1 ? myLocalChangesProvider.getLineNumber(number) : FAKE_LINE_NUMBER; } @Override public boolean isLineChanged(int currentNumber) { - return getLineNumber(currentNumber) == -1; + return getLineNumber(currentNumber) == ABSENT_LINE_NUMBER; } @Override diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AnnotatePreviousRevisionAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AnnotatePreviousRevisionAction.java index 3318a1544ed5..16e6cebd6cc3 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AnnotatePreviousRevisionAction.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AnnotatePreviousRevisionAction.java @@ -2,6 +2,7 @@ package com.intellij.openapi.vcs.actions; import com.intellij.icons.AllIcons; import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.localVcs.UpToDateLineNumberProvider; import com.intellij.openapi.vcs.AbstractVcs; import com.intellij.openapi.vcs.annotate.FileAnnotation; import com.intellij.openapi.vcs.history.VcsFileRevision; @@ -53,7 +54,7 @@ class AnnotatePreviousRevisionAction extends AnnotateRevisionAction { @Nullable @Override protected VcsFileRevision getFileRevision(@NotNull AnActionEvent e) { - if (getCurrentLine() == -1) { + if (getCurrentLine() == UpToDateLineNumberProvider.ABSENT_LINE_NUMBER) { return myLastRevision; } return super.getFileRevision(e); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AnnotationGutterLineConvertorProxy.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AnnotationGutterLineConvertorProxy.java index 52ce811f0cd7..ccc1e57846da 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AnnotationGutterLineConvertorProxy.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AnnotationGutterLineConvertorProxy.java @@ -40,31 +40,31 @@ public class AnnotationGutterLineConvertorProxy implements ActiveAnnotationGutte public String getLineText(int line, Editor editor) { int currentLine = myGetUpToDateLineNumber.getLineNumber(line); - if (currentLine == UpToDateLineNumberProvider.ABSENT_LINE_NUMBER) return ""; + if (!canBeAnnotated(currentLine)) return ""; return myDelegate.getLineText(currentLine, editor); } public String getToolTip(int line, Editor editor) { int currentLine = myGetUpToDateLineNumber.getLineNumber(line); - if (currentLine == UpToDateLineNumberProvider.ABSENT_LINE_NUMBER) return ""; + if (!canBeAnnotated(currentLine)) return ""; return myDelegate.getToolTip(currentLine, editor); } public EditorFontType getStyle(int line, Editor editor) { int currentLine = myGetUpToDateLineNumber.getLineNumber(line); - if (currentLine == UpToDateLineNumberProvider.ABSENT_LINE_NUMBER) return EditorFontType.PLAIN; + if (!canBeAnnotated(currentLine)) return EditorFontType.PLAIN; return myDelegate.getStyle(currentLine, editor); } public ColorKey getColor(int line, Editor editor) { int currentLine = myGetUpToDateLineNumber.getLineNumber(line); - if (currentLine == UpToDateLineNumberProvider.ABSENT_LINE_NUMBER) return AnnotationSource.LOCAL.getColor(); + if (!canBeAnnotated(currentLine)) return AnnotationSource.LOCAL.getColor(); return myDelegate.getColor(currentLine, editor); } public Color getBgColor(int line, Editor editor) { int currentLine = myGetUpToDateLineNumber.getLineNumber(line); - if (currentLine == UpToDateLineNumberProvider.ABSENT_LINE_NUMBER) return null; + if (!canBeAnnotated(currentLine)) return null; return myDelegate.getBgColor(currentLine, editor); } @@ -78,13 +78,17 @@ public class AnnotationGutterLineConvertorProxy implements ActiveAnnotationGutte public void doAction(int lineNum) { int currentLine = myGetUpToDateLineNumber.getLineNumber(lineNum); - if (currentLine == UpToDateLineNumberProvider.ABSENT_LINE_NUMBER) return; + if (!canBeAnnotated(currentLine)) return; myDelegate.doAction(currentLine); } public Cursor getCursor(int lineNum) { int currentLine = myGetUpToDateLineNumber.getLineNumber(lineNum); - if (currentLine == UpToDateLineNumberProvider.ABSENT_LINE_NUMBER) return Cursor.getDefaultCursor(); + if (!canBeAnnotated(currentLine)) return Cursor.getDefaultCursor(); return myDelegate.getCursor(currentLine); } + + private static boolean canBeAnnotated(int currentLine) { + return currentLine >= 0; + } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/UpToDateLineNumberProviderImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/UpToDateLineNumberProviderImpl.java index 19f28961b96a..a1762dbc1ab0 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/UpToDateLineNumberProviderImpl.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/UpToDateLineNumberProviderImpl.java @@ -20,6 +20,7 @@ import com.intellij.openapi.localVcs.UpToDateLineNumberProvider; import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.ex.LineStatusTracker; import com.intellij.openapi.vcs.ex.Range; +import org.jetbrains.annotations.NotNull; import java.util.List; @@ -104,8 +105,7 @@ public class UpToDateLineNumberProviderImpl implements UpToDateLineNumberProvide return content; } - private static int calcLineNumber(LineStatusTracker tracker, int currentNumber){ - if (tracker == null) return -1; + private static int calcLineNumber(@NotNull LineStatusTracker tracker, int currentNumber) { List ranges = tracker.getRanges(); int result = currentNumber;