From e6ab8856ae80dd23dd5139db0925b295fd556e73 Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Mon, 4 May 2020 20:11:34 +0300 Subject: [PATCH] IDEA-224049 lst: allow to disable error stripe markers Hide stripe markers if gutter markers are not visible. GitOrigin-RevId: e12d15cee65a1a5ad12a233fa91839c1fe16f89f --- .../vcs/ex/LineStatusMarkerRenderer.java | 38 +++++++++++++------ .../openapi/vcs/ex/LineStatusTrackerBase.kt | 4 +- .../messages/ApplicationBundle.properties | 1 + .../openapi/vcs/VcsApplicationSettings.java | 1 + .../openapi/vcs/ex/LineStatusTracker.kt | 25 ++++++------ .../vcs/impl/LineStatusTrackerManager.kt | 8 ++-- .../VcsGeneralEditorOptionsExtension.kt | 14 ++++++- .../vcs/BaseLineStatusTrackerTestCase.kt | 2 +- .../light/LightGitEditorHighlighterManager.kt | 2 +- 9 files changed, 59 insertions(+), 36 deletions(-) diff --git a/platform/diff-impl/src/com/intellij/openapi/vcs/ex/LineStatusMarkerRenderer.java b/platform/diff-impl/src/com/intellij/openapi/vcs/ex/LineStatusMarkerRenderer.java index 7f5907e94d6e..cf65d05087c1 100644 --- a/platform/diff-impl/src/com/intellij/openapi/vcs/ex/LineStatusMarkerRenderer.java +++ b/platform/diff-impl/src/com/intellij/openapi/vcs/ex/LineStatusMarkerRenderer.java @@ -90,18 +90,20 @@ public abstract class LineStatusMarkerRenderer { private void updateHighlighters() { if (myDisposed) return; - for (RangeHighlighter highlighter: myTooltipHighlighters) { + for (RangeHighlighter highlighter : myTooltipHighlighters) { disposeHighlighter(highlighter); } myTooltipHighlighters.clear(); - List ranges = myTracker.getRanges(); - if (ranges != null) { - MarkupModel markupModel = DocumentMarkupModel.forDocument(myTracker.getDocument(), myTracker.getProject(), true); - for (Range range: ranges) { - RangeHighlighter highlighter = createTooltipRangeHighlighter(range, markupModel); - if (myEditorFilter != null) highlighter.setEditorFilter(myEditorFilter); - myTooltipHighlighters.add(highlighter); + if (shouldPaintErrorStripeMarkers()) { + List ranges = myTracker.getRanges(); + if (ranges != null) { + MarkupModel markupModel = DocumentMarkupModel.forDocument(myTracker.getDocument(), myTracker.getProject(), true); + for (Range range : ranges) { + RangeHighlighter highlighter = createTooltipRangeHighlighter(range, markupModel); + if (myEditorFilter != null) highlighter.setEditorFilter(myEditorFilter); + myTooltipHighlighters.add(highlighter); + } } } } @@ -274,6 +276,14 @@ public abstract class LineStatusMarkerRenderer { return new Rectangle(area.val1, y, area.val2 - area.val1, endY - y); } + protected boolean shouldPaintGutter() { + return true; + } + + protected boolean shouldPaintErrorStripeMarkers() { + return shouldPaintGutter(); + } + protected void paint(@NotNull Editor editor, @NotNull Graphics g) { List ranges = myTracker.getRanges(); if (ranges == null) return; @@ -706,22 +716,28 @@ public abstract class LineStatusMarkerRenderer { private class MyActiveGutterRenderer implements ActiveGutterRenderer { @Override public void paint(@NotNull Editor editor, @NotNull Graphics g, @NotNull Rectangle r) { - LineStatusMarkerRenderer.this.paint(editor, g); + if (shouldPaintGutter()) { + LineStatusMarkerRenderer.this.paint(editor, g); + } } @Override public boolean canDoAction(@NotNull Editor editor, @NotNull MouseEvent e) { - return LineStatusMarkerRenderer.this.canDoAction(editor, e); + return shouldPaintGutter() && + LineStatusMarkerRenderer.this.canDoAction(editor, e); } @Override public void doAction(@NotNull Editor editor, @NotNull MouseEvent e) { - LineStatusMarkerRenderer.this.doAction(editor, e); + if (shouldPaintGutter()) { + LineStatusMarkerRenderer.this.doAction(editor, e); + } } @Nullable @Override public Rectangle calcBounds(@NotNull Editor editor, int lineNum, @NotNull Rectangle preferredBounds) { + if (!shouldPaintGutter()) return new Rectangle(-1, -1, 0, 0); return LineStatusMarkerRenderer.this.calcBounds(editor, lineNum, preferredBounds); } diff --git a/platform/diff-impl/src/com/intellij/openapi/vcs/ex/LineStatusTrackerBase.kt b/platform/diff-impl/src/com/intellij/openapi/vcs/ex/LineStatusTrackerBase.kt index c1d952389c95..7eba872bd3c1 100644 --- a/platform/diff-impl/src/com/intellij/openapi/vcs/ex/LineStatusTrackerBase.kt +++ b/platform/diff-impl/src/com/intellij/openapi/vcs/ex/LineStatusTrackerBase.kt @@ -224,7 +224,7 @@ abstract class LineStatusTrackerBase : LineStatusTrackerI { } @CalledInAwt - protected fun updateInnerRanges() { + protected fun resetInnerRanges() { LOCK.write { if (isDetectWhitespaceChangedLines()) { for (block in blocks) { @@ -236,8 +236,6 @@ abstract class LineStatusTrackerBase : LineStatusTrackerI { block.ourData.innerRanges = null } } - - updateHighlighters() } } diff --git a/platform/platform-api/resources/messages/ApplicationBundle.properties b/platform/platform-api/resources/messages/ApplicationBundle.properties index 402fa80e5faf..048deebdb9fd 100644 --- a/platform/platform-api/resources/messages/ApplicationBundle.properties +++ b/platform/platform-api/resources/messages/ApplicationBundle.properties @@ -851,6 +851,7 @@ editor.options.gutter.group=Gutter editor.options.line.feed=Ensure an empty line at the end of a file on Save editor.options.quick.doc.on.mouse.hover=Show quick documentation on mouse move editor.options.highlight.modified.line=Highlight modified lines in the gutter +editor.options.highlight.modified.line.error.stripe=Highlight modified lines in error stripe on the scrollbar editor.options.whitespace.line.color=Highlight lines with whitespace-only modifications with a different color editor.options.tooltip.delay=Tooltip delay: editor.options.ms=milliseconds diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/VcsApplicationSettings.java b/platform/vcs-api/src/com/intellij/openapi/vcs/VcsApplicationSettings.java index 15df1cb33b43..73b9cf5ef2f8 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/VcsApplicationSettings.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/VcsApplicationSettings.java @@ -20,6 +20,7 @@ public class VcsApplicationSettings implements PersistentStateComponent : LineStatusTrackerI { @@ -41,9 +39,9 @@ abstract class LocalLineStatusTracker constructor(override val projec override val virtualFile: VirtualFile, mode: Mode ) : LineStatusTrackerBase(project, document), LineStatusTracker { - enum class Mode { - DEFAULT, SMART, SILENT - } + class Mode(val isVisible: Boolean, + val showErrorStripeMarkers: Boolean, + val detectWhitespaceChangedLines: Boolean) abstract override val renderer: LocalLineStatusMarkerRenderer @@ -51,17 +49,18 @@ abstract class LocalLineStatusTracker constructor(override val projec set(value) { if (value == mode) return field = value - updateInnerRanges() + resetInnerRanges() + updateHighlighters() } @CalledInAwt override fun isAvailableAt(editor: Editor): Boolean { - return mode != Mode.SILENT && editor.settings.isLineMarkerAreaShown && !DiffUtil.isDiffEditor(editor) + return mode.isVisible && editor.settings.isLineMarkerAreaShown && !DiffUtil.isDiffEditor(editor) } @CalledInAwt - override fun isDetectWhitespaceChangedLines(): Boolean = mode == Mode.SMART + override fun isDetectWhitespaceChangedLines(): Boolean = mode.isVisible && mode.detectWhitespaceChangedLines @CalledInAwt override fun fireFileUnchanged() { @@ -92,14 +91,12 @@ abstract class LocalLineStatusTracker constructor(override val projec : LineStatusMarkerPopupRenderer(tracker) { override fun getEditorFilter(): MarkupEditorFilter? = MarkupEditorFilterFactory.createIsNotDiffFilter() - override fun canDoAction(editor: Editor, ranges: List, e: MouseEvent): Boolean { - if (tracker.mode == Mode.SILENT) return false - return super.canDoAction(editor, ranges, e) + override fun shouldPaintGutter(): Boolean { + return tracker.mode.isVisible } - override fun paint(editor: Editor, g: Graphics) { - if (tracker.mode == Mode.SILENT) return - super.paint(editor, g) + override fun shouldPaintErrorStripeMarkers(): Boolean { + return tracker.mode.isVisible && tracker.mode.showErrorStripeMarkers } override fun createToolbarActions(editor: Editor, range: Range, mousePosition: Point?): List { diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/LineStatusTrackerManager.kt b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/LineStatusTrackerManager.kt index 63a25b8e4453..1bda17022b37 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/LineStatusTrackerManager.kt +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/LineStatusTrackerManager.kt @@ -383,7 +383,7 @@ class LineStatusTrackerManager(private val project: Project) : LineStatusTracker override fun arePartialChangelistsEnabled(virtualFile: VirtualFile): Boolean { if (!partialChangeListsEnabled) return false - if (getTrackingMode() == LocalLineStatusTracker.Mode.SILENT) return false + if (!getTrackingMode().isVisible) return false val vcs = VcsUtil.getVcsFor(project, virtualFile) return vcs != null && vcs.arePartialChangelistsSupported() @@ -467,9 +467,9 @@ class LineStatusTrackerManager(private val project: Project) : LineStatusTracker private fun getTrackingMode(): LocalLineStatusTracker.Mode { val settings = VcsApplicationSettings.getInstance() - if (!settings.SHOW_LST_GUTTER_MARKERS) return LocalLineStatusTracker.Mode.SILENT - if (settings.SHOW_WHITESPACES_IN_LST) return LocalLineStatusTracker.Mode.SMART - return LocalLineStatusTracker.Mode.DEFAULT + return LocalLineStatusTracker.Mode(settings.SHOW_LST_GUTTER_MARKERS, + settings.SHOW_LST_ERROR_STRIPE_MARKERS, + settings.SHOW_WHITESPACES_IN_LST) } @CalledInAwt diff --git a/platform/vcs-impl/src/com/intellij/options/VcsGeneralEditorOptionsExtension.kt b/platform/vcs-impl/src/com/intellij/options/VcsGeneralEditorOptionsExtension.kt index efe33b53ae89..edcadd612dfe 100644 --- a/platform/vcs-impl/src/com/intellij/options/VcsGeneralEditorOptionsExtension.kt +++ b/platform/vcs-impl/src/com/intellij/options/VcsGeneralEditorOptionsExtension.kt @@ -13,9 +13,14 @@ import com.intellij.ui.layout.* private val vcsSettings get() = VcsApplicationSettings.getInstance() private val cdShowLSTInGutterCheckBox - get() = CheckboxDescriptor(ApplicationBundle.message("editor.options.highlight.modified.line"), vcsSettings::SHOW_LST_GUTTER_MARKERS) + get() = CheckboxDescriptor(ApplicationBundle.message("editor.options.highlight.modified.line"), + vcsSettings::SHOW_LST_GUTTER_MARKERS) +private val cdShowLSTInErrorStripesCheckBox + get() = CheckboxDescriptor(ApplicationBundle.message("editor.options.highlight.modified.line.error.stripe"), + vcsSettings::SHOW_LST_ERROR_STRIPE_MARKERS) private val cdShowWhitespacesInLSTGutterCheckBox - get() = CheckboxDescriptor(ApplicationBundle.message("editor.options.whitespace.line.color"), vcsSettings::SHOW_WHITESPACES_IN_LST) + get() = CheckboxDescriptor(ApplicationBundle.message("editor.options.whitespace.line.color"), + vcsSettings::SHOW_WHITESPACES_IN_LST) class VcsGeneralEditorOptionsExtension : UiDslConfigurable.Simple() { override fun RowBuilder.createComponentRow() { @@ -26,6 +31,11 @@ class VcsGeneralEditorOptionsExtension : UiDslConfigurable.Simple() { row { val showLstGutter = checkBox(cdShowLSTInGutterCheckBox) .onApply(::fireLSTSettingsChanged) + row { + checkBox(cdShowLSTInErrorStripesCheckBox) + .enableIf(showLstGutter.selected) + .onApply(::fireLSTSettingsChanged) + } row { checkBox(cdShowWhitespacesInLSTGutterCheckBox) .enableIf(showLstGutter.selected) diff --git a/platform/vcs-tests/testSrc/com/intellij/openapi/vcs/BaseLineStatusTrackerTestCase.kt b/platform/vcs-tests/testSrc/com/intellij/openapi/vcs/BaseLineStatusTrackerTestCase.kt index 799e2d92bd76..c13767e61818 100644 --- a/platform/vcs-tests/testSrc/com/intellij/openapi/vcs/BaseLineStatusTrackerTestCase.kt +++ b/platform/vcs-tests/testSrc/com/intellij/openapi/vcs/BaseLineStatusTrackerTestCase.kt @@ -65,7 +65,7 @@ abstract class BaseLineStatusTrackerTestCase : BaseLineStatusTrackerManagerTest( val file = LightVirtualFile("LSTTestFile", PlainTextFileType.INSTANCE, parseInput(text)) val document = FileDocumentManager.getInstance().getDocument(file)!! val tracker = runWriteAction { - val tracker = SimpleLocalLineStatusTracker.createTracker(getProject(), document, file, if (smart) Mode.SMART else Mode.DEFAULT) + val tracker = SimpleLocalLineStatusTracker.createTracker(getProject(), document, file, Mode(true, true, smart)) tracker.setBaseRevision(parseInput(vcsText)) tracker } diff --git a/plugins/git4idea/src/git4idea/light/LightGitEditorHighlighterManager.kt b/plugins/git4idea/src/git4idea/light/LightGitEditorHighlighterManager.kt index b05393b91286..63b102350292 100644 --- a/plugins/git4idea/src/git4idea/light/LightGitEditorHighlighterManager.kt +++ b/plugins/git4idea/src/git4idea/light/LightGitEditorHighlighterManager.kt @@ -87,7 +87,7 @@ class LightGitEditorHighlighterManager(val tracker: LightGitTracker) : Disposabl if (lst == null) { lst = SimpleLocalLineStatusTracker.createTracker(lightEditService.project, editor.document, file, - LocalLineStatusTracker.Mode.DEFAULT) + LocalLineStatusTracker.Mode(true, true, false)) } readBaseVersion(file, status.repositoryPath) }