inspection tool window: disable/enable button apply changes for all of scopes + "disabled" marker in tree considers all of scopes too IDEA-160955

This commit is contained in:
Dmitry Batkovich
2016-09-14 15:26:26 +03:00
parent 404e151530
commit e0f00070d4
5 changed files with 41 additions and 42 deletions
@@ -56,4 +56,9 @@ public class EntryPointsNode extends InspectionNode {
public void visitProblemSeverities(FactoryMap<HighlightDisplayLevel, Integer> counter) {
//do nothing here
}
@Override
public int getProblemCount(boolean allowSuppressed) {
return 0;
}
}
@@ -16,9 +16,10 @@
package com.intellij.codeInspection.ui;
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
import com.intellij.codeInspection.InspectionProfile;
import com.intellij.codeInspection.ex.InspectionProfileImpl;
import com.intellij.codeInspection.ex.InspectionToolWrapper;
import com.intellij.codeInspection.ex.ToolsImpl;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -26,13 +27,11 @@ import org.jetbrains.annotations.Nullable;
* @author max
*/
public class InspectionNode extends InspectionTreeNode {
private final HighlightDisplayKey myKey;
@NotNull private final InspectionProfile myProfile;
@NotNull private final InspectionProfileImpl myProfile;
public InspectionNode(@NotNull InspectionToolWrapper toolWrapper, @NotNull InspectionProfile profile) {
super(toolWrapper);
myKey = HighlightDisplayKey.find(toolWrapper.getShortName());
myProfile = profile;
myProfile = (InspectionProfileImpl)profile;
}
public String toString() {
@@ -47,11 +46,7 @@ public class InspectionNode extends InspectionTreeNode {
@Nullable
@Override
public String getCustomizedTailText() {
return myProfile.isToolEnabled(myKey) ? null : "Disabled";
}
@Override
public int getProblemCount(boolean allowSuppressed) {
return myKey == null ? 0 : super.getProblemCount(allowSuppressed);
final ToolsImpl tools = myProfile.getTools(getToolWrapper().getShortName(), null);
return tools.isEnabled() ? null : "Disabled";
}
}
@@ -15,16 +15,16 @@
*/
package com.intellij.codeInspection.ui;
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
import com.intellij.codeInspection.InspectionsBundle;
import com.intellij.codeInspection.actions.RunInspectionAction;
import com.intellij.codeInspection.ex.DisableInspectionToolAction;
import com.intellij.codeInspection.ex.InspectionProfileImpl;
import com.intellij.codeInspection.ex.InspectionToolWrapper;
import com.intellij.codeInspection.ex.ToolsImpl;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
import com.intellij.profile.codeInspection.ui.SingleInspectionProfilePanel;
import com.intellij.profile.codeInspection.ui.inspectionsTree.InspectionsConfigTreeTable;
import com.intellij.ui.*;
import com.intellij.ui.components.JBLabel;
import com.intellij.ui.components.JBLabelDecorator;
@@ -52,8 +52,8 @@ public class InspectionNodeInfo extends JPanel {
LOG.assertTrue(toolWrapper != null);
InspectionProfileImpl currentProfile =
(InspectionProfileImpl)InspectionProjectProfileManager.getInstance(project).getCurrentProfile();
HighlightDisplayKey key = HighlightDisplayKey.find(toolWrapper.getShortName());
boolean enabled = currentProfile.isToolEnabled(key);
final ToolsImpl tools = currentProfile.getTools(toolWrapper.getShortName(), project);
boolean enabled = tools.isEnabled();
JPanel titlePanel = new JPanel();
titlePanel.setLayout(new BoxLayout(titlePanel, BoxLayout.LINE_AXIS));
@@ -92,15 +92,8 @@ public class InspectionNodeInfo extends JPanel {
new ClickListener() {
@Override
public boolean onClick(@NotNull MouseEvent event, int clickCount) {
DisableInspectionToolAction.modifyAndCommitProjectProfile(model -> {
final String toolId = key.toString();
if (enabled) {
model.disableTool(toolId, project);
}
else {
((InspectionProfileImpl)model).enableTool(toolId, project);
}
}, project);
InspectionsConfigTreeTable.setToolEnabled(!enabled, currentProfile, toolWrapper.getShortName(), project);
tree.getContext().getView().profileChanged();
return true;
}
}.installOn(enableButton);
@@ -254,14 +254,18 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
@Override
public void profileChanged(Profile profile) {
if (profile == profileManager.getCurrentProfile()) {
myTree.revalidate();
myTree.repaint();
syncRightPanel();
InspectionResultsView.this.profileChanged();
}
}
}, this);
}
public void profileChanged() {
myTree.revalidate();
myTree.repaint();
syncRightPanel();
}
private void initTreeListeners() {
myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
@Override
@@ -205,6 +205,21 @@ public class InspectionsConfigTreeTable extends TreeTable {
public abstract void updateRightPanel();
}
public static void setToolEnabled(boolean newState,
@NotNull InspectionProfileImpl profile,
@NotNull String toolId,
@NotNull Project project) {
if (newState) {
profile.enableTool(toolId, project);
}
else {
profile.disableTool(toolId, project);
}
for (ScopeToolState scopeToolState : profile.getTools(toolId, project).getTools()) {
scopeToolState.setEnabled(newState);
}
}
private static class InspectionsConfigTreeTableModel extends DefaultTreeModel implements TreeTableModel {
private final InspectionsConfigTreeTableSettings mySettings;
@@ -303,7 +318,7 @@ public class InspectionsConfigTreeTable extends TreeTable {
final boolean doEnable = (Boolean) aValue;
final InspectionProfileImpl profile = mySettings.getInspectionProfile();
for (final InspectionConfigTreeNode aNode : InspectionsAggregationUtil.getInspectionsNodes((InspectionConfigTreeNode)node)) {
setToolEnabled(doEnable, profile, aNode.getKey());
setToolEnabled(doEnable, profile, aNode.getKey().toString(), mySettings.getProject());
aNode.dropCache();
mySettings.onChanged(aNode);
}
@@ -337,7 +352,7 @@ public class InspectionsConfigTreeTable extends TreeTable {
final InspectionProfileImpl profile = mySettings.getInspectionProfile();
for (HighlightDisplayKey tool : tools) {
setToolEnabled(newState, profile, tool);
setToolEnabled(newState, profile, tool.toString(), mySettings.getProject());
}
for (InspectionConfigTreeNode node : nodes) {
@@ -357,19 +372,6 @@ public class InspectionsConfigTreeTable extends TreeTable {
}
}
private void setToolEnabled(boolean newState, InspectionProfileImpl profile, HighlightDisplayKey tool) {
final String toolId = tool.toString();
if (newState) {
profile.enableTool(toolId, mySettings.getProject());
}
else {
profile.disableTool(toolId, mySettings.getProject());
}
for (ScopeToolState scopeToolState : profile.getTools(toolId, mySettings.getProject()).getTools()) {
scopeToolState.setEnabled(newState);
}
}
private static void collectInspectionFromNodes(final InspectionConfigTreeNode node,
final Set<HighlightDisplayKey> tools,
final List<InspectionConfigTreeNode> nodes) {