ability to show "Current File" always (WEB-20644)

This commit is contained in:
Sergey Simonchik
2016-04-19 15:09:11 +03:00
parent e3c07073c5
commit 7553debfed
3 changed files with 32 additions and 8 deletions
@@ -33,5 +33,21 @@ public abstract class PredefinedSearchScopeProvider {
boolean suggestSearchInLibs,
boolean prevSearchFiles,
boolean currentSelection,
boolean usageView);
boolean usageView,
boolean showEmptyScopes);
public final List<SearchScope> getPredefinedScopes(@NotNull final Project project,
@Nullable final DataContext dataContext,
boolean suggestSearchInLibs,
boolean prevSearchFiles,
boolean currentSelection,
boolean usageView) {
return getPredefinedScopes(project,
dataContext,
suggestSearchInLibs,
prevSearchFiles,
currentSelection,
usageView,
false);
}
}
@@ -52,6 +52,7 @@ public class ScopeChooserCombo extends ComboboxWithBrowseButton implements Dispo
private boolean myCurrentSelection = true;
private boolean myUsageView = true;
private Condition<ScopeDescriptor> myScopeFilter;
private boolean myShowEmptyScopes = false;
public ScopeChooserCombo() {
super(new IgnoringComboBox(){
@@ -230,7 +231,7 @@ public class ScopeChooserCombo extends ComboboxWithBrowseButton implements Dispo
@SuppressWarnings("deprecation") final DataContext context = DataManager.getInstance().getDataContext();
for (SearchScope scope : PredefinedSearchScopeProvider.getInstance().getPredefinedScopes(myProject, context, mySuggestSearchInLibs,
myPrevSearchFiles, myCurrentSelection,
myUsageView)) {
myUsageView, myShowEmptyScopes)) {
addScopeDescriptor(model, new ScopeDescriptor(scope));
}
for (ScopeDescriptorProvider provider : Extensions.getExtensions(ScopeDescriptorProvider.EP_NAME)) {
@@ -248,6 +249,9 @@ public class ScopeChooserCombo extends ComboboxWithBrowseButton implements Dispo
}
}
public void setShowEmptyScopes(boolean showEmptyScopes) {
myShowEmptyScopes = showEmptyScopes;
}
@Nullable
public SearchScope getSelectedScope() {
@@ -66,7 +66,8 @@ public class PredefinedSearchScopeProviderImpl extends PredefinedSearchScopeProv
boolean suggestSearchInLibs,
boolean prevSearchFiles,
boolean currentSelection,
boolean usageView) {
boolean usageView,
boolean showEmptyScopes) {
Collection<SearchScope> result = ContainerUtil.newLinkedHashSet();
result.add(GlobalSearchScope.projectScope(project));
if (suggestSearchInLibs) {
@@ -85,9 +86,7 @@ public class PredefinedSearchScopeProviderImpl extends PredefinedSearchScopeProv
: null;
final PsiFile psiFile =
(selectedTextEditor != null) ? PsiDocumentManager.getInstance(project).getPsiFile(selectedTextEditor.getDocument()) : null;
if (psiFile != null) {
result.add(new LocalSearchScope(psiFile, IdeBundle.message("scope.current.file")));
}
PsiFile currentFile = psiFile;
if (dataContext != null) {
PsiElement dataContextElement = CommonDataKeys.PSI_FILE.getData(dataContext);
@@ -109,12 +108,17 @@ public class PredefinedSearchScopeProviderImpl extends PredefinedSearchScopeProv
result.add(module.getModuleScope());
}
}
if (psiFile == null && dataContextElement.getContainingFile() != null) {
result.add(new LocalSearchScope(dataContextElement, IdeBundle.message("scope.current.file")));
if (currentFile == null) {
currentFile = dataContextElement.getContainingFile();
}
}
}
if (currentFile != null || showEmptyScopes) {
PsiElement[] scope = currentFile != null ? new PsiElement[] {currentFile} : PsiElement.EMPTY_ARRAY;
result.add(new LocalSearchScope(scope, IdeBundle.message("scope.current.file")));
}
if (currentSelection && selectedTextEditor != null && psiFile != null) {
SelectionModel selectionModel = selectedTextEditor.getSelectionModel();
if (selectionModel.hasSelection()) {