diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java b/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java index 6da46cf1adec..6cbbba6a4c2b 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java @@ -426,11 +426,15 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel, } public void disableToolByDefault(String toolId) { - getTools(toolId).getDefaultState().setEnabled(false); + getToolDefaultState(toolId).setEnabled(false); + } + + public ScopeToolState getToolDefaultState(String toolId) { + return getTools(toolId).getDefaultState(); } public void enableToolByDefault(String toolId) { - getTools(toolId).getDefaultState().setEnabled(true); + getToolDefaultState(toolId).setEnabled(true); } public boolean wasInitialized() { diff --git a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/SingleInspectionProfilePanel.java b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/SingleInspectionProfilePanel.java index ba2c682d3ecf..3fd374b320bf 100644 --- a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/SingleInspectionProfilePanel.java +++ b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/SingleInspectionProfilePanel.java @@ -1048,29 +1048,13 @@ public class SingleInspectionProfilePanel extends JPanel { for (int i = 0; rows != null && i < rows.length; i++) { final InspectionConfigTreeNode node = (InspectionConfigTreeNode)myTree.getPathForRow(rows[i]).getLastPathComponent(); final InspectionConfigTreeNode parent = (InspectionConfigTreeNode)node.getParent(); - if (node.getUserObject() instanceof Descriptor) { + final Object userObject = node.getUserObject(); + if (userObject instanceof Descriptor && (node.getScopeName() != null || node.isLeaf())) { updateErrorLevel(node, showOptionsAndDescriptorPanels, level); updateUpHierarchy(node, parent); } else { - node.isProperSetting = false; - for (int j = 0; j < node.getChildCount(); j++) { - final InspectionConfigTreeNode child = (InspectionConfigTreeNode)node.getChildAt(j); - if (child.getUserObject() instanceof Descriptor) { //group node - updateErrorLevel(child, showOptionsAndDescriptorPanels, level); - } - else { //root node - child.isProperSetting = false; - for (int k = 0; k < child.getChildCount(); k++) { - final InspectionConfigTreeNode descriptorNode = (InspectionConfigTreeNode)child.getChildAt(k); - if (descriptorNode.getUserObject() instanceof Descriptor) { - updateErrorLevel(descriptorNode, showOptionsAndDescriptorPanels, level); - } - child.isProperSetting |= descriptorNode.isProperSetting; - } - } - node.isProperSetting |= child.isProperSetting; - } + updateErrorLevelUpInHierarchy(level, showOptionsAndDescriptorPanels, node); updateUpHierarchy(node, parent); } } @@ -1083,6 +1067,23 @@ public class SingleInspectionProfilePanel extends JPanel { repaintTableData(); } + private void updateErrorLevelUpInHierarchy(HighlightDisplayLevel level, + boolean showOptionsAndDescriptorPanels, + InspectionConfigTreeNode node) { + node.isProperSetting = false; + for (int j = 0; j < node.getChildCount(); j++) { + final InspectionConfigTreeNode child = (InspectionConfigTreeNode)node.getChildAt(j); + final Object userObject = child.getUserObject(); + if (userObject instanceof Descriptor && (child.getScopeName() != null || child.isLeaf())) { + updateErrorLevel(child, showOptionsAndDescriptorPanels, level); + } + else { + updateErrorLevelUpInHierarchy(level, showOptionsAndDescriptorPanels, child); + } + node.isProperSetting |= child.isProperSetting; + } + } + private void updateErrorLevel(final InspectionConfigTreeNode child, final boolean showOptionsAndDescriptorPanels, final HighlightDisplayLevel level) { final HighlightDisplayKey key = child.getDesriptor().getKey(); diff --git a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/actions/AddScopeAction.java b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/actions/AddScopeAction.java index ccc3f0817d40..67c9e658c90b 100644 --- a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/actions/AddScopeAction.java +++ b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/actions/AddScopeAction.java @@ -59,13 +59,11 @@ public abstract class AddScopeAction extends AnAction { if (getSelectedProfile() == null) return; final Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext()); if (project == null) return; - final InspectionConfigTreeNode[] nodes = myTree.getSelectedNodes(InspectionConfigTreeNode.class, null); + final InspectionConfigTreeNode[] selectedNodes = myTree.getSelectedNodes(InspectionConfigTreeNode.class, null); + if (selectedNodes == null) return; final List descriptors = new ArrayList(); - for (InspectionConfigTreeNode node : nodes) { - final Descriptor descriptor = node.getDesriptor(); - if (descriptor != null && node.getScopeName() == null) { - descriptors.add(descriptor); - } + for (InspectionConfigTreeNode node : selectedNodes) { + collect(descriptors, new ArrayList(), node); } presentation.setEnabled(!getAvailableScopes(project, descriptors).isEmpty()); @@ -73,13 +71,13 @@ public abstract class AddScopeAction extends AnAction { @Override public void actionPerformed(AnActionEvent e) { - final InspectionConfigTreeNode[] nodes = myTree.getSelectedNodes(InspectionConfigTreeNode.class, null); - List descriptors = new ArrayList(); - for (InspectionConfigTreeNode node : nodes) { - final Descriptor descriptor = node.getDesriptor(); - if (node.getScopeName() == null && descriptor != null) { - descriptors.add(descriptor); - } + final List descriptors = new ArrayList(); + final InspectionConfigTreeNode[] selectedNodes = myTree.getSelectedNodes(InspectionConfigTreeNode.class, null); + LOG.assertTrue(selectedNodes != null); + + final List nodes = new ArrayList(Arrays.asList(selectedNodes)); + for (InspectionConfigTreeNode node : selectedNodes) { + collect(descriptors, nodes, node); } final Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext()); @@ -97,7 +95,7 @@ public abstract class AddScopeAction extends AnAction { getSelectedProfile().isToolEnabled(descriptor.getKey())); final Descriptor addedDescriptor = new Descriptor(scopeToolState, getSelectedProfile()); if (node.getChildCount() == 0) { - node.add(new InspectionConfigTreeNode(descriptor, scopeToolState, true, true, false)); + node.add(new InspectionConfigTreeNode(descriptor, getSelectedProfile().getToolDefaultState(descriptor.getKey().getID()), true, true, false)); } node.insert(new InspectionConfigTreeNode(addedDescriptor, scopeToolState, false, true, false), 0); node.setInspectionNode(false); @@ -108,6 +106,23 @@ public abstract class AddScopeAction extends AnAction { myTree.revalidate(); } + private static void collect(List descriptors, + List nodes, + InspectionConfigTreeNode node) { + final Descriptor descriptor = node.getDesriptor(); + if (descriptor != null) { + if (node.getScopeName() == null) { + descriptors.add(descriptor); + } + } else if (node.getUserObject() instanceof String) { + for(int i = 0; i < node.getChildCount(); i++) { + final InspectionConfigTreeNode childNode = (InspectionConfigTreeNode)node.getChildAt(i); + nodes.add(childNode); + collect(descriptors, nodes, childNode); + } + } + } + private List getAvailableScopes(Project project, List descriptors) { final ArrayList scopes = new ArrayList(); for (NamedScopesHolder holder : NamedScopesHolder.getAllNamedScopeHolders(project)) {