Hide traffic light for commit message if found problems have <= TYPO severities

This commit is contained in:
Konstantin Kolosovsky
2017-04-25 16:19:57 +03:00
parent 087acaa195
commit 66dce364ad
3 changed files with 55 additions and 5 deletions
@@ -90,7 +90,7 @@ public class TrafficLightRenderer implements ErrorStripeRenderer, Disposable {
myDocument = document;
myFile = file;
mySeverityRegistrar = SeverityRegistrar.getSeverityRegistrar(myProject);
refresh();
refresh(null);
if (project != null) {
final MarkupModelEx model = (MarkupModelEx)DocumentMarkupModel.forDocument(document, project, true);
@@ -113,7 +113,12 @@ public class TrafficLightRenderer implements ErrorStripeRenderer, Disposable {
}
}
private void refresh() {
@NotNull
public SeverityRegistrar getSeverityRegistrar() {
return mySeverityRegistrar;
}
protected void refresh(@Nullable EditorMarkupModelImpl editorMarkupModel) {
int maxIndex = mySeverityRegistrar.getSeverityMaxIndex();
if (errorCount != null && maxIndex + 1 == errorCount.length) return;
errorCount = new int[maxIndex + 1];
@@ -130,8 +135,9 @@ public class TrafficLightRenderer implements ErrorStripeRenderer, Disposable {
ErrorStripeRenderer renderer = editorMarkupModel.getErrorStripeRenderer();
if (renderer instanceof TrafficLightRenderer) {
TrafficLightRenderer tlr = (TrafficLightRenderer)renderer;
tlr.refresh();
((EditorMarkupModelImpl)editorMarkupModel).repaintVerticalScrollBar();
EditorMarkupModelImpl markupModelImpl = (EditorMarkupModelImpl)editorMarkupModel;
tlr.refresh(markupModelImpl);
markupModelImpl.repaintVerticalScrollBar();
if (tlr.myFile == null || tlr.myFile.isValid()) return;
Disposer.dispose(tlr);
}
@@ -160,6 +160,14 @@ public class EditorMarkupModelImpl extends MarkupModelImpl implements EditorMark
dimensionsAreValid = scrollBarHeight != 0;
}
public void setTrafficLightIconVisible(boolean value) {
MyErrorPanel errorPanel = getErrorPanel();
if (errorPanel != null && errorPanel.myErrorStripeButton.isVisible() != value) {
errorPanel.myErrorStripeButton.setVisible(value);
repaint(-1, -1);
}
}
public void repaintTrafficLightIcon() {
MyErrorPanel errorPanel = getErrorPanel();
if (errorPanel != null) {
@@ -475,7 +483,11 @@ public class EditorMarkupModelImpl extends MarkupModelImpl implements EditorMark
@NotNull
@Override
public Dimension getPreferredSize() {
return new Dimension(getErrorIconWidth() + getThinGap(), getErrorIconHeight() + getThinGap());
return !isPreferredSizeSet()
? isVisible()
? new Dimension(getErrorIconWidth() + getThinGap(), getErrorIconHeight() + getThinGap())
: JBUI.emptySize()
: super.getPreferredSize();
}
}
@@ -15,8 +15,11 @@
*/
package com.intellij.openapi.vcs.ui;
import com.intellij.codeHighlighting.HighlightDisplayLevel;
import com.intellij.codeInsight.daemon.impl.TrafficLightRenderer;
import com.intellij.codeInsight.intention.IntentionManager;
import com.intellij.codeInspection.ex.InspectionProfileWrapper;
import com.intellij.lang.annotation.HighlightSeverity;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.application.WriteAction;
@@ -24,6 +27,7 @@ import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.ex.EditorEx;
import com.intellij.openapi.editor.impl.EditorMarkupModelImpl;
import com.intellij.openapi.fileTypes.FileTypes;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Key;
@@ -48,6 +52,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import static com.intellij.util.ObjectUtils.notNull;
import static com.intellij.vcs.commit.CommitMessageInspectionProfile.getBodyRightMargin;
public class CommitMessage extends JPanel implements Disposable, DataProvider, CommitMessageI {
@@ -223,6 +228,33 @@ public class CommitMessage extends JPanel implements Disposable, DataProvider, C
profile -> new InspectionProfileWrapper(CommitMessageInspectionProfile.getInstance(myProject)));
}
editor.putUserData(IntentionManager.SHOW_INTENTION_OPTIONS_KEY, false);
((EditorMarkupModelImpl)editor.getMarkupModel())
.setErrorStripeRenderer(new ConditionalTrafficLightRenderer(myProject, editor.getDocument(), file));
}
}
private static class ConditionalTrafficLightRenderer extends TrafficLightRenderer {
public ConditionalTrafficLightRenderer(@NotNull Project project, @NotNull Document document, @Nullable PsiFile file) {
super(project, document, file);
}
@Override
protected void refresh(@Nullable EditorMarkupModelImpl editorMarkupModel) {
super.refresh(editorMarkupModel);
if (editorMarkupModel != null) {
editorMarkupModel.setTrafficLightIconVisible(hasHighSeverities(errorCount));
}
}
private boolean hasHighSeverities(@NotNull int[] errorCount) {
HighlightSeverity minSeverity = notNull(HighlightDisplayLevel.find("TYPO"), HighlightDisplayLevel.DO_NOT_SHOW).getSeverity();
for (int i = 0; i < errorCount.length; i++) {
if (errorCount[i] > 0 && getSeverityRegistrar().compare(getSeverityRegistrar().getSeverityByIndex(i), minSeverity) > 0) {
return true;
}
}
return false;
}
}
}