From 47db58ca49a87a367baf7cfbbd7fe3b6ac92e26c Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Mon, 24 Jun 2013 19:31:24 +0400 Subject: [PATCH] allow to configure default scopes for default project (IDEA-109472) --- .../ui/actions/AddScopeAction.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) 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 8c92e9ecab51..a5362daf8f91 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 @@ -27,6 +27,8 @@ import com.intellij.codeInspection.ex.ScopeToolState; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; +import com.intellij.openapi.project.ProjectManager; +import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.ui.Messages; import com.intellij.packageDependencies.DefaultScopesProvider; import com.intellij.profile.codeInspection.ui.InspectionConfigTreeNode; @@ -56,8 +58,7 @@ public abstract class AddScopeAction extends AnAction { final Presentation presentation = e.getPresentation(); presentation.setEnabled(false); if (getSelectedProfile() == null) return; - final Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext()); - if (project == null) return; + final Project project = getProject(e); final InspectionConfigTreeNode[] selectedNodes = myTree.getSelectedNodes(InspectionConfigTreeNode.class, null); if (selectedNodes == null) return; final List descriptors = new ArrayList(); @@ -68,6 +69,14 @@ public abstract class AddScopeAction extends AnAction { presentation.setEnabled(!getAvailableScopes(project, descriptors).isEmpty()); } + private static Project getProject(AnActionEvent e) { + Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext()); + if (project == null) { + project = ProjectManager.getInstance().getDefaultProject(); + } + return project; + } + @Override public void actionPerformed(AnActionEvent e) { final List descriptors = new ArrayList(); @@ -79,7 +88,7 @@ public abstract class AddScopeAction extends AnAction { collect(descriptors, nodes, node); } - final Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext()); + final Project project = getProject(e); final List availableScopes = getAvailableScopes(project, descriptors); final int idx = Messages.showChooseDialog(myTree, "Scope:", "Choose Scope", ArrayUtil.toStringArray(availableScopes), availableScopes.get(0), Messages.getQuestionIcon()); if (idx == -1) return; @@ -127,7 +136,7 @@ public abstract class AddScopeAction extends AnAction { for (NamedScopesHolder holder : NamedScopesHolder.getAllNamedScopeHolders(project)) { Collections.addAll(scopes, holder.getScopes()); } - scopes.remove(DefaultScopesProvider.getAllScope()); + scopes.remove(CustomScopesProviderEx.getAllScope()); CustomScopesProviderEx.filterNoSettingsScopes(project, scopes);