diff --git a/platform/lang-impl/src/com/intellij/ide/scratch/ScratchFileServiceImpl.java b/platform/lang-impl/src/com/intellij/ide/scratch/ScratchFileServiceImpl.java index 2b98cab65b67..67062e94e968 100644 --- a/platform/lang-impl/src/com/intellij/ide/scratch/ScratchFileServiceImpl.java +++ b/platform/lang-impl/src/com/intellij/ide/scratch/ScratchFileServiceImpl.java @@ -315,7 +315,7 @@ public class ScratchFileServiceImpl extends ScratchFileService implements Persis @NotNull @Override public String getDisplayName() { - return "Scratches and Consoles"; + return ScratchesAndConsolesNamedScope.NAME; } @Override diff --git a/platform/lang-impl/src/com/intellij/ide/scratch/ScratchesAndConsolesNamedScope.java b/platform/lang-impl/src/com/intellij/ide/scratch/ScratchesAndConsolesNamedScope.java new file mode 100644 index 000000000000..08c636d47a1a --- /dev/null +++ b/platform/lang-impl/src/com/intellij/ide/scratch/ScratchesAndConsolesNamedScope.java @@ -0,0 +1,29 @@ +// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.intellij.ide.scratch; + +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.search.scope.packageSet.AbstractPackageSet; +import com.intellij.psi.search.scope.packageSet.NamedScope; +import com.intellij.psi.search.scope.packageSet.NamedScopesHolder; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class ScratchesAndConsolesNamedScope extends NamedScope { + public static final String NAME = "Scratches and Consoles"; + + public ScratchesAndConsolesNamedScope() { + super(NAME, new AbstractPackageSet(NAME) { + @Override + public boolean contains(VirtualFile file, NamedScopesHolder holder) { + return contains(file, holder.getProject(), holder); + } + + @Override + public boolean contains(VirtualFile file, @NotNull Project project, @Nullable NamedScopesHolder holder) { + RootType rootType = ScratchUtil.isScratch(file) ? ScratchFileService.getInstance().getRootType(file) : null; + return rootType != null && !rootType.isHidden(); + } + }); + } +} diff --git a/platform/lang-impl/src/com/intellij/ide/util/scopeChooser/ScopeChooserUtils.java b/platform/lang-impl/src/com/intellij/ide/util/scopeChooser/ScopeChooserUtils.java index f012eef2b4c5..dec4a8b4af92 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/scopeChooser/ScopeChooserUtils.java +++ b/platform/lang-impl/src/com/intellij/ide/util/scopeChooser/ScopeChooserUtils.java @@ -16,6 +16,7 @@ package com.intellij.ide.util.scopeChooser; import com.intellij.ide.IdeBundle; +import com.intellij.ide.scratch.ScratchesAndConsolesNamedScope; import com.intellij.openapi.fileEditor.FileEditorManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; @@ -62,7 +63,9 @@ public class ScopeChooserUtils { namedScope = new ProjectFilesScope(); } GlobalSearchScope scope = GlobalSearchScopesCore.filterScope(project, namedScope); - if (namedScope instanceof ProjectFilesScope || namedScope instanceof ProjectProductionScope) { + if (namedScope instanceof ProjectFilesScope || + namedScope instanceof ProjectProductionScope || + namedScope instanceof ScratchesAndConsolesNamedScope) { return scope; } return intersectWithContentScope(project, scope); diff --git a/platform/lang-impl/src/com/intellij/packageDependencies/DefaultScopesProvider.java b/platform/lang-impl/src/com/intellij/packageDependencies/DefaultScopesProvider.java index 92443d9af0ee..9b8c734fd424 100644 --- a/platform/lang-impl/src/com/intellij/packageDependencies/DefaultScopesProvider.java +++ b/platform/lang-impl/src/com/intellij/packageDependencies/DefaultScopesProvider.java @@ -15,6 +15,7 @@ */ package com.intellij.packageDependencies; +import com.intellij.ide.scratch.ScratchesAndConsolesNamedScope; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.project.Project; import com.intellij.psi.search.scope.NonProjectFilesScope; @@ -47,7 +48,7 @@ public class DefaultScopesProvider extends CustomScopesProviderEx { NamedScope projectScope = new ProjectFilesScope(); NamedScope nonProjectScope = new NonProjectFilesScope(); myProblemsScope = new ProblemScope(project); - myScopes = Arrays.asList(projectScope, getProblemsScope(), getAllScope(), nonProjectScope); + myScopes = Arrays.asList(projectScope, getProblemsScope(), getAllScope(), nonProjectScope, new ScratchesAndConsolesNamedScope()); } @Override