Skip to content

Commit 910dd63

Browse files
authored
Merge pull request #77 from khopland/feature/68-keybind
added feature to enable and disable all warings with a keybind
2 parents 86fbdd7 + a97ea83 commit 910dd63

15 files changed

Lines changed: 208 additions & 28 deletions

.idea/misc.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
<h3 align="center">InlineProblems</h3>
2424

2525
<!-- Plugin description -->
26-
Plugin to show problems like errors and warnings inside the text editor (inline) for IDEs based on the IntelliJ Platform, inspired by Error Lens and InlineError
26+
Plugin to show problems like errors and warnings inside the text editor (inline) for IDEs based on the IntelliJ Platform, inspired by Error Lens and InlineError.
27+
28+
You can turn this plugin on and off by the keyboard shortcut `alt+u`.
2729
<!-- Plugin description end -->
2830

2931
<p align="center">

src/main/java/org/overengineer/inlineproblems/DocumentMarkupModelScanner.java

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -84,24 +84,24 @@ public void scanForProblemsManually() {
8484

8585
if (projectManager != null) {
8686
List<InlineProblem> problems = new ArrayList<>();
87+
if (settingsState.isEnableInlineProblem())
88+
for (var project : projectManager.getOpenProjects()) {
89+
if (!project.isInitialized() || project.isDisposed())
90+
continue;
8791

88-
for (var project : projectManager.getOpenProjects()) {
89-
if (!project.isInitialized() || project.isDisposed())
90-
continue;
92+
FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
93+
for (var editor : fileEditorManager.getAllEditors()) {
9194

92-
FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
93-
for (var editor : fileEditorManager.getAllEditors()) {
95+
if (editor.getFile() == null || FileNameUtil.ignoreFile(editor.getFile().getName())) {
96+
continue;
97+
}
9498

95-
if (editor.getFile() == null || FileNameUtil.ignoreFile(editor.getFile().getName())) {
96-
continue;
97-
}
98-
99-
if (editor instanceof TextEditor) {
100-
var textEditor = (TextEditor) editor;
101-
problems.addAll(getProblemsInEditor(textEditor));
99+
if (editor instanceof TextEditor) {
100+
var textEditor = (TextEditor) editor;
101+
problems.addAll(getProblemsInEditor(textEditor));
102+
}
102103
}
103104
}
104-
}
105105

106106
problemManager.updateFromNewActiveProblems(problems);
107107
}
@@ -119,7 +119,7 @@ public void scanForProblemsManuallyInTextEditor(TextEditor textEditor) {
119119
mergingUpdateQueue.queue(new Update("scan") {
120120
@Override
121121
public void run() {
122-
List<InlineProblem> problems = getProblemsInEditor(textEditor);
122+
List<InlineProblem> problems = settingsState.isEnableInlineProblem() ? List.of() : getProblemsInEditor(textEditor);
123123

124124
problemManager.updateFromNewActiveProblemsForProjectAndFile(
125125
problems,
@@ -158,8 +158,7 @@ private List<InlineProblem> getProblemsInEditor(TextEditor textEditor) {
158158
!highlightInfo.getDescription().isEmpty() &&
159159
problemTextBeginningFilterList.stream()
160160
.noneMatch(f -> highlightInfo.getDescription().stripLeading().toLowerCase().startsWith(f.toLowerCase())) &&
161-
fileEndOffset >= highlightInfo.getStartOffset()
162-
;
161+
fileEndOffset >= highlightInfo.getStartOffset();
163162
}
164163

165164
return false;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.overengineer.inlineproblems.actions;
2+
3+
import com.intellij.notification.NotificationType;
4+
import com.intellij.openapi.actionSystem.AnAction;
5+
import com.intellij.openapi.actionSystem.AnActionEvent;
6+
import com.intellij.openapi.application.ApplicationManager;
7+
import org.jetbrains.annotations.NotNull;
8+
import org.overengineer.inlineproblems.DocumentMarkupModelScanner;
9+
import org.overengineer.inlineproblems.Notifier;
10+
import org.overengineer.inlineproblems.bundles.SettingsBundle;
11+
import org.overengineer.inlineproblems.settings.SettingsState;
12+
13+
public class EnableInlineProblemsAction extends AnAction {
14+
15+
@Override
16+
public void actionPerformed(@NotNull AnActionEvent anActionEvent) {
17+
SettingsState settingsState = SettingsState.getInstance();
18+
if (settingsState.isEnableInlineProblemsNotifications()) {
19+
Notifier.notify(SettingsBundle.message(
20+
settingsState.isEnableInlineProblem()
21+
? "settings.enableInlineProblem.disabled"
22+
: "settings.enableInlineProblem.enabled"),
23+
NotificationType.INFORMATION,
24+
anActionEvent.getProject()
25+
);
26+
}
27+
settingsState.setEnableInlineProblem(!settingsState.isEnableInlineProblem());
28+
ApplicationManager.getApplication().invokeAndWait(DocumentMarkupModelScanner.getInstance()::scanForProblemsManually);
29+
}
30+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.overengineer.inlineproblems.actions;
2+
3+
import com.intellij.openapi.actionSystem.AnAction;
4+
import com.intellij.openapi.actionSystem.AnActionEvent;
5+
import org.jetbrains.annotations.NotNull;
6+
import org.overengineer.inlineproblems.settings.SettingsState;
7+
8+
public class ShowErrorsAction extends AnAction {
9+
@Override
10+
public void actionPerformed(@NotNull AnActionEvent anActionEvent) {
11+
SettingsState settingsState = SettingsState.getInstance();
12+
settingsState.setShowErrors(!settingsState.isShowErrors());
13+
}
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.overengineer.inlineproblems.actions;
2+
3+
import com.intellij.openapi.actionSystem.AnAction;
4+
import com.intellij.openapi.actionSystem.AnActionEvent;
5+
import org.jetbrains.annotations.NotNull;
6+
import org.overengineer.inlineproblems.settings.SettingsState;
7+
8+
public class ShowInfosAction extends AnAction {
9+
@Override
10+
public void actionPerformed(@NotNull AnActionEvent anActionEvent) {
11+
SettingsState settingsState = SettingsState.getInstance();
12+
settingsState.setShowInfos(!settingsState.isShowInfos());
13+
}
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.overengineer.inlineproblems.actions;
2+
3+
import com.intellij.openapi.actionSystem.AnAction;
4+
import com.intellij.openapi.actionSystem.AnActionEvent;
5+
import org.jetbrains.annotations.NotNull;
6+
import org.overengineer.inlineproblems.settings.SettingsState;
7+
8+
public class ShowWarningsAction extends AnAction {
9+
@Override
10+
public void actionPerformed(@NotNull AnActionEvent anActionEvent) {
11+
SettingsState settingsState = SettingsState.getInstance();
12+
settingsState.setShowWarnings(!settingsState.isShowWarnings());
13+
}
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.overengineer.inlineproblems.actions;
2+
3+
import com.intellij.openapi.actionSystem.AnAction;
4+
import com.intellij.openapi.actionSystem.AnActionEvent;
5+
import org.jetbrains.annotations.NotNull;
6+
import org.overengineer.inlineproblems.settings.SettingsState;
7+
8+
public class ShowWeakWarningsAction extends AnAction {
9+
@Override
10+
public void actionPerformed(@NotNull AnActionEvent anActionEvent) {
11+
SettingsState settingsState = SettingsState.getInstance();
12+
settingsState.setShowWeakWarnings(!settingsState.isShowWeakWarnings());
13+
}
14+
}

src/main/java/org/overengineer/inlineproblems/listeners/MarkupModelProblemListener.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ public static void disposeAll() {
8888
}
8989

9090
private void handleEvent(EventType type, @NotNull RangeHighlighterEx highlighter) {
91+
if (!settingsState.isEnableInlineProblem())
92+
return;
9193

9294
if (settingsState.getEnabledListener() != Listener.MARKUP_MODEL_LISTENER)
9395
return;

src/main/java/org/overengineer/inlineproblems/settings/SettingsComponent.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ public class SettingsComponent {
5555
private final ColorPanel infoLabelBackgroundColor = new ColorPanel();
5656
private final ColorPanel infoHighlightColor = new ColorPanel();
5757

58+
private final JBCheckBox enableInlineProblem = new JBCheckBox(SettingsBundle.message("settings.enableInlineProblem"));
59+
private final JBCheckBox enableInlineProblemsNotifications = new JBCheckBox(SettingsBundle.message("settings.enableInlineProblemsNotifications"));
60+
5861
private final JBCheckBox forceErrorsInSameLine = new JBCheckBox(SettingsBundle.message("settings.forceProblemsInOneLine"));
5962
private final JBCheckBox drawBoxesAroundProblemLabels = new JBCheckBox(SettingsBundle.message("settings.drawBoxesAroundProblemLabels"));
6063
private final JBCheckBox roundedCornerBoxes = new JBCheckBox(SettingsBundle.message("settings.roundedCornerBoxes"));
@@ -115,6 +118,9 @@ public SettingsComponent() {
115118
infoLabelBackgroundColor.setSelectedColor(settingsState.getInfoBackgroundColor());
116119
infoHighlightColor.setSelectedColor(settingsState.getInfoHighlightColor());
117120

121+
enableInlineProblem.setSelected(settingsState.isEnableInlineProblem());
122+
enableInlineProblemsNotifications.setSelected(settingsState.isEnableInlineProblemsNotifications());
123+
118124
forceErrorsInSameLine.setSelected(settingsState.isForceProblemsInSameLine());
119125
drawBoxesAroundProblemLabels.setSelected(settingsState.isDrawBoxesAroundErrorLabels());
120126
roundedCornerBoxes.setSelected(settingsState.isRoundedCornerBoxes());
@@ -152,6 +158,8 @@ public SettingsComponent() {
152158

153159
settingsPanel = FormBuilder.createFormBuilder()
154160
.addComponent(new JBLabel(SettingsBundle.message("settings.submenu.label")))
161+
.addComponent(enableInlineProblem, 0)
162+
.addComponent(enableInlineProblemsNotifications, 0)
155163
.addComponent(drawBoxesAroundProblemLabels, 0)
156164
.addComponent(roundedCornerBoxes, 0)
157165
.addComponent(fillProblemLabels, 0)
@@ -231,6 +239,22 @@ public void setForceErrorsInSameLine(final boolean isSelected) {
231239
forceErrorsInSameLine.setSelected(isSelected);
232240
}
233241

242+
public boolean isEnableInlineProblem() {
243+
return enableInlineProblem.isSelected();
244+
}
245+
246+
public void setEnableInlineProblem(final boolean isSelected) {
247+
enableInlineProblem.setSelected(isSelected);
248+
}
249+
250+
public boolean isEnableInlineProblemsNotifications() {
251+
return enableInlineProblemsNotifications.isSelected();
252+
}
253+
254+
public void setEnableInlineProblemsNotifications(final boolean isSelected) {
255+
enableInlineProblemsNotifications.setSelected(isSelected);
256+
}
257+
234258
public boolean getDrawBoxesAroundProblemLabels() {
235259
return drawBoxesAroundProblemLabels.isSelected();
236260
}

0 commit comments

Comments
 (0)