From e0f00070d4faf44ee08d1e001bdd13b30b08e2b3 Mon Sep 17 00:00:00 2001 From: Dmitry Batkovich Date: Wed, 14 Sep 2016 15:25:45 +0300 Subject: [PATCH] inspection tool window: disable/enable button apply changes for all of scopes + "disabled" marker in tree considers all of scopes too IDEA-160955 --- .../codeInspection/ui/EntryPointsNode.java | 5 +++ .../codeInspection/ui/InspectionNode.java | 17 ++++------ .../codeInspection/ui/InspectionNodeInfo.java | 19 ++++------- .../ui/InspectionResultsView.java | 10 ++++-- .../InspectionsConfigTreeTable.java | 32 ++++++++++--------- 5 files changed, 41 insertions(+), 42 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInspection/ui/EntryPointsNode.java b/java/java-impl/src/com/intellij/codeInspection/ui/EntryPointsNode.java index cefbbc77a9b3..7558f4f96808 100644 --- a/java/java-impl/src/com/intellij/codeInspection/ui/EntryPointsNode.java +++ b/java/java-impl/src/com/intellij/codeInspection/ui/EntryPointsNode.java @@ -56,4 +56,9 @@ public class EntryPointsNode extends InspectionNode { public void visitProblemSeverities(FactoryMap counter) { //do nothing here } + + @Override + public int getProblemCount(boolean allowSuppressed) { + return 0; + } } diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionNode.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionNode.java index 4ee35da099b3..f09a2b6a88fd 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionNode.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionNode.java @@ -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"; } } diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionNodeInfo.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionNodeInfo.java index f5242b0e0143..95a45dcf046a 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionNodeInfo.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionNodeInfo.java @@ -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); diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java index 5afbe839f96c..5135de979590 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java @@ -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 diff --git a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/inspectionsTree/InspectionsConfigTreeTable.java b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/inspectionsTree/InspectionsConfigTreeTable.java index 9237fcbbb2de..15a6d7009a9a 100644 --- a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/inspectionsTree/InspectionsConfigTreeTable.java +++ b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/inspectionsTree/InspectionsConfigTreeTable.java @@ -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 tools, final List nodes) {