fix "Open Files" scope when no files are open (IDEA-149129)

This commit is contained in:
Bas Leijdekkers
2016-04-20 12:17:14 +02:00
parent 5f28430779
commit fe3da07870
4 changed files with 21 additions and 13 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,6 +28,13 @@ public abstract class PredefinedSearchScopeProvider {
return ServiceManager.getService(PredefinedSearchScopeProvider.class);
}
/**
* @param suggestSearchInLibs add <i>Project and Libraries</i> scope
* @param prevSearchFiles add <i>Files in Previous Search Result</i> instead of <i>Previous Search Result</i> (only if {@code usageView == true})
* @param currentSelection add <i>Selection</i> scope if text is selected in the editor
* @param usageView add <i>Previous Search Result</i> and <i>Hierarchy 'X' (visible nodes only)</i> scopes if there are search results or hierarchies open
* @param showEmptyScopes add <i>Current File</i> and <i>Open Files</i> scopes even if there are no files open
*/
public abstract List<SearchScope> getPredefinedScopes(@NotNull final Project project,
@Nullable final DataContext dataContext,
boolean suggestSearchInLibs,
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,10 +15,10 @@
*/
package com.intellij.psi.search;
import com.intellij.ide.IdeBundle;
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;
@@ -28,18 +28,11 @@ import java.util.Arrays;
*/
public class GlobalSearchScopes extends GlobalSearchScopesCore {
public static final String OPEN_FILES_SCOPE_NAME = "Open Files";
private GlobalSearchScopes() {
}
private GlobalSearchScopes() {}
@NotNull
public static GlobalSearchScope openFilesScope(@NotNull Project project) {
final VirtualFile[] files = FileEditorManager.getInstance(project).getOpenFiles();
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);
return GlobalSearchScope.filesScope(project, Arrays.asList(files), IdeBundle.message("scope.open.files"));
}
}
@@ -59,6 +59,7 @@ import javax.swing.*;
import java.util.*;
public class PredefinedSearchScopeProviderImpl extends PredefinedSearchScopeProvider {
@NotNull
@Override
public List<SearchScope> getPredefinedScopes(@NotNull final Project project,
@@ -79,7 +80,13 @@ public class PredefinedSearchScopeProviderImpl extends PredefinedSearchScopeProv
result.add(GlobalSearchScopesCore.projectTestScope(project));
}
result.add(GlobalSearchScopes.openFilesScope(project));
final GlobalSearchScope openFilesScope = GlobalSearchScopes.openFilesScope(project);
if (openFilesScope != GlobalSearchScope.EMPTY_SCOPE) {
result.add(openFilesScope);
}
else if (showEmptyScopes) {
result.add(new LocalSearchScope(PsiElement.EMPTY_ARRAY, IdeBundle.message("scope.open.files")));
}
final Editor selectedTextEditor = ApplicationManager.getApplication().isDispatchThread()
? FileEditorManager.getInstance(project).getSelectedTextEditor()
@@ -805,6 +805,7 @@ action.group.by.scope.type=Group by Scope Type
action.description.group.by.scope=Group by Scope Type (production, test, libraries)
action.show.included.only=Show Included Only
action.description.show.included.only=Show only files included to the current scope selected
scope.open.files=Open Files
scope.current.file=Current File
scope.selection=Selection
scope.files.in.previous.search.result=Files in Previous Search Result