scope: display "Open Files" label in scope selector combobox instead of bare hashCode...
authorSergey Simonchik <sergey.simonchik@jetbrains.com>
Fri, 11 Mar 2016 08:05:22 +0000 (00:05 -0800)
committerSergey Simonchik <sergey.simonchik@jetbrains.com>
Fri, 11 Mar 2016 08:11:06 +0000 (00:11 -0800)
platform/core-api/src/com/intellij/psi/search/GlobalSearchScope.java
platform/lang-api/src/com/intellij/psi/search/GlobalSearchScopes.java
platform/lang-impl/src/com/intellij/ide/util/scopeChooser/ScopeChooserUtils.java

index 5ff729b586a06104842f56e1e3f2f000c83d7bd0..5b8a60ef81201d5235db40de1b89684a89ab355c 100644 (file)
@@ -300,7 +300,7 @@ public abstract class GlobalSearchScope extends SearchScope implements ProjectAw
   }
 
   @NotNull
-  public static GlobalSearchScope fileScope(@NotNull Project project, final VirtualFile virtualFile, @Nullable final String displayName) {
+  public static GlobalSearchScope fileScope(@NotNull Project project, @Nullable VirtualFile virtualFile, @Nullable final String displayName) {
     return new FileScope(project, virtualFile) {
       @NotNull
       @Override
@@ -708,7 +708,7 @@ public abstract class GlobalSearchScope extends SearchScope implements ProjectAw
     private final Module myModule;
     private final boolean mySearchOutsideContent;
 
-    private FileScope(@NotNull Project project, VirtualFile virtualFile) {
+    private FileScope(@NotNull Project project, @Nullable VirtualFile virtualFile) {
       super(project);
       myVirtualFile = virtualFile;
       final FileIndexFacade facade = FileIndexFacade.getInstance(project);
index 3acfe338d499655583c2043f71b2ad59c93da18b..85b7a63ea19f8a8f18c1767f8105fa0909606563 100644 (file)
@@ -18,6 +18,7 @@ package com.intellij.psi.search;
 import com.intellij.openapi.fileEditor.FileEditorManager;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.util.ArrayUtil;
 import org.jetbrains.annotations.NotNull;
 
 import java.util.Arrays;
@@ -26,12 +27,19 @@ import java.util.Arrays;
  * @author yole
  */
 public class GlobalSearchScopes extends GlobalSearchScopesCore {
+
+  public static final String OPEN_FILES_SCOPE_NAME = "Open Files";
+
   private GlobalSearchScopes() {
   }
 
   @NotNull
   public static GlobalSearchScope openFilesScope(@NotNull Project project) {
     final VirtualFile[] files = FileEditorManager.getInstance(project).getOpenFiles();
-    return GlobalSearchScope.filesScope(project, Arrays.asList(files), "Open Files");
+    if (ArrayUtil.isEmpty(files)) {
+      // prefer a scope with meaningful getDisplayName(), avoid GlobalSearchScope.EMPTY_SCOPE
+      return GlobalSearchScope.fileScope(project, null, OPEN_FILES_SCOPE_NAME);
+    }
+    return GlobalSearchScope.filesScope(project, Arrays.asList(files), OPEN_FILES_SCOPE_NAME);
   }
 }
index fb5a9bde7ab2a74ce11b2cbfcc8eaa72d44c5177..05bbf70cae0fb66dc449dd3a39eac083ced93a3c 100644 (file)
@@ -37,7 +37,6 @@ import java.util.List;
 
 public class ScopeChooserUtils {
 
-  private static final String OPEN_FILES_SCOPE_NAME = "Open Files";
   private static final String CURRENT_FILE_SCOPE_NAME = IdeBundle.message("scope.current.file");
 
   private ScopeChooserUtils() {
@@ -49,7 +48,7 @@ public class ScopeChooserUtils {
     if (namedScope == null) {
       namedScope = NamedScopesHolder.getScope(project, scopeName);
     }
-    if (namedScope == null && OPEN_FILES_SCOPE_NAME.equals(scopeName)) {
+    if (namedScope == null && GlobalSearchScopes.OPEN_FILES_SCOPE_NAME.equals(scopeName)) {
       return intersectWithContentScope(project, GlobalSearchScopes.openFilesScope(project));
     }
     if (namedScope == null && CURRENT_FILE_SCOPE_NAME.equals(scopeName)) {