IDEA-224049 lst: allow to disable error stripe markers

Hide stripe markers if gutter markers are not visible.

GitOrigin-RevId: e12d15cee65a1a5ad12a233fa91839c1fe16f89f
This commit is contained in:
Aleksey Pivovarov
2020-05-04 18:46:22 +00:00
committed by intellij-monorepo-bot
parent a6fc2c2e15
commit e6ab8856ae
9 changed files with 59 additions and 36 deletions
@@ -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<? extends Range> 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<? extends Range> 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<? extends Range> 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);
}
@@ -224,7 +224,7 @@ abstract class LineStatusTrackerBase<R : Range> : LineStatusTrackerI<R> {
}
@CalledInAwt
protected fun updateInnerRanges() {
protected fun resetInnerRanges() {
LOCK.write {
if (isDetectWhitespaceChangedLines()) {
for (block in blocks) {
@@ -236,8 +236,6 @@ abstract class LineStatusTrackerBase<R : Range> : LineStatusTrackerI<R> {
block.ourData.innerRanges = null
}
}
updateHighlighters()
}
}
@@ -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
@@ -20,6 +20,7 @@ public class VcsApplicationSettings implements PersistentStateComponent<VcsAppli
public String PATCH_STORAGE_LOCATION = null;
public boolean SHOW_WHITESPACES_IN_LST = true;
public boolean SHOW_LST_GUTTER_MARKERS = true;
public boolean SHOW_LST_ERROR_STRIPE_MARKERS = true;
public boolean DETECT_PATCH_ON_THE_FLY = false;
public boolean ENABLE_PARTIAL_CHANGELISTS = true;
public boolean MANAGE_IGNORE_FILES = false;
@@ -19,9 +19,7 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import org.jetbrains.annotations.CalledInAny
import org.jetbrains.annotations.CalledInAwt
import java.awt.Graphics
import java.awt.Point
import java.awt.event.MouseEvent
import java.util.*
interface LineStatusTracker<out R : Range> : LineStatusTrackerI<R> {
@@ -41,9 +39,9 @@ abstract class LocalLineStatusTracker<R : Range> constructor(override val projec
override val virtualFile: VirtualFile,
mode: Mode
) : LineStatusTrackerBase<R>(project, document), LineStatusTracker<R> {
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<R : Range> 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<R : Range> constructor(override val projec
: LineStatusMarkerPopupRenderer(tracker) {
override fun getEditorFilter(): MarkupEditorFilter? = MarkupEditorFilterFactory.createIsNotDiffFilter()
override fun canDoAction(editor: Editor, ranges: List<Range>, 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<AnAction> {
@@ -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
@@ -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)
@@ -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
}
@@ -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)
}