ability to show "Current File" always (WEB-20644)
authorSergey Simonchik <sergey.simonchik@jetbrains.com>
Tue, 19 Apr 2016 12:09:11 +0000 (15:09 +0300)
committerSergey Simonchik <sergey.simonchik@jetbrains.com>
Tue, 19 Apr 2016 12:09:11 +0000 (15:09 +0300)
platform/analysis-impl/src/com/intellij/psi/search/PredefinedSearchScopeProvider.java
platform/lang-impl/src/com/intellij/ide/util/scopeChooser/ScopeChooserCombo.java
platform/lang-impl/src/com/intellij/psi/search/PredefinedSearchScopeProviderImpl.java

index 76881d876956feae0400c87ed6de3f37ae099983..b6f45874e084d43c5498e0e3175096027413601b 100644 (file)
@@ -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);
+  }
 }
index bbe00fdd09a22e1ae836505b5512cfbf240788b5..40a0586ad80370ed221f20e78d6b916176f9cc5f 100644 (file)
@@ -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() {
index 35d1b9fee5e14e08049c3e8c2cfd40f5ad5efa9c..fc3f6deeed22bff3621a04a26246297121aab1ea 100644 (file)
@@ -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()) {