private DefaultComboBoxModel createModel() {
    final DefaultComboBoxModel model = new DefaultComboBoxModel();

    createPredefinedScopeDescriptors(model);

    model.addElement(new ScopeSeparator("VCS Scopes"));
    final List<NamedScope> changeLists =
        ChangeListsScopesProvider.getInstance(myProject).getCustomScopes();
    for (NamedScope changeListScope : changeLists) {
      final GlobalSearchScope scope = GlobalSearchScopes.filterScope(myProject, changeListScope);
      model.addElement(new ScopeDescriptor(scope));
    }

    final List<ScopeDescriptor> customScopes = new ArrayList<ScopeDescriptor>();
    final NamedScopesHolder[] holders = NamedScopesHolder.getAllNamedScopeHolders(myProject);
    for (NamedScopesHolder holder : holders) {
      final NamedScope[] scopes = holder.getEditableScopes(); // predefined scopes already included
      for (NamedScope scope : scopes) {
        final GlobalSearchScope searchScope = GlobalSearchScopes.filterScope(myProject, scope);
        customScopes.add(new ScopeDescriptor(searchScope));
      }
    }
    if (!customScopes.isEmpty()) {
      model.addElement(new ScopeSeparator("Custom Scopes"));
      for (ScopeDescriptor scope : customScopes) {
        model.addElement(scope);
      }
    }

    return model;
  }
  @Override
  public SourceScope getSourceScope() {
    final String dirName = myConfiguration.getPersistentData().getDirName();
    final VirtualFile file =
        LocalFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(dirName));
    final GlobalSearchScope globalSearchScope =
        file == null
            ? GlobalSearchScope.EMPTY_SCOPE
            : GlobalSearchScopes.directoryScope(myProject, file, true);
    return new SourceScope() {
      @Override
      public GlobalSearchScope getGlobalSearchScope() {
        return globalSearchScope;
      }

      @Override
      public Project getProject() {
        return myProject;
      }

      @Override
      public GlobalSearchScope getLibrariesScope() {
        final Module module = myConfiguration.getConfigurationModule().getModule();
        LOG.assertTrue(module != null);
        return GlobalSearchScope.moduleWithLibrariesScope(module);
      }

      @Override
      public Module[] getModulesToCompile() {
        final Collection<Module> validModules = myConfiguration.getValidModules();
        return validModules.toArray(new Module[validModules.size()]);
      }
    };
  }
  public static Collection<JSQualifiedNamedElement> getCandidates(
      final Editor editor, final PsiFile file, final String name) {
    final Module module = ModuleUtil.findModuleForPsiElement(file);
    if (module != null) {
      GlobalSearchScope searchScope;
      VirtualFile virtualFile = file.getVirtualFile();
      if (virtualFile instanceof VirtualFileWindow)
        virtualFile = ((VirtualFileWindow) virtualFile).getDelegate();

      if (GlobalSearchScopes.projectProductionScope(file.getProject())
          .contains(virtualFile)) { // skip tests suggestions
        searchScope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module, false);
      } else {
        searchScope = JSResolveUtil.getResolveScope(file);
      }
      return JSResolveUtil.findElementsByName(name, editor.getProject(), searchScope);
    } else {
      return Collections.emptyList();
    }
  }
  public static List<SearchScope> getPredefinedScopes(
      @NotNull final Project project,
      @Nullable final DataContext dataContext,
      boolean suggestSearchInLibs,
      boolean prevSearchFiles,
      boolean currentSelection,
      boolean usageView) {
    ArrayList<SearchScope> result = new ArrayList<SearchScope>();
    result.add(GlobalSearchScope.projectScope(project));
    if (suggestSearchInLibs) {
      result.add(GlobalSearchScope.allScope(project));
    }

    if (!PlatformUtils.isCidr()
        && ModuleUtil.isSupportedRootType(
            project, JavaSourceRootType.TEST_SOURCE)) { // TODO: fix these scopes in AppCode
      result.add(GlobalSearchScopes.projectProductionScope(project));
      result.add(GlobalSearchScopes.projectTestScope(project));
    }

    result.add(GlobalSearchScopes.openFilesScope(project));

    if (dataContext != null) {
      PsiElement dataContextElement = CommonDataKeys.PSI_FILE.getData(dataContext);
      if (dataContextElement == null) {
        dataContextElement = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
      }
      if (dataContextElement != null) {
        if (!PlatformUtils.isCidr()) { // TODO: have an API to disable module scopes.
          Module module = ModuleUtilCore.findModuleForPsiElement(dataContextElement);
          if (module == null) {
            module = LangDataKeys.MODULE.getData(dataContext);
          }
          if (module != null) {
            result.add(module.getModuleScope());
          }
        }
        if (dataContextElement.getContainingFile() != null) {
          result.add(
              new LocalSearchScope(dataContextElement, IdeBundle.message("scope.current.file")));
        }
      }
    }

    if (currentSelection) {
      FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
      final Editor selectedTextEditor = fileEditorManager.getSelectedTextEditor();
      if (selectedTextEditor != null) {
        final PsiFile psiFile =
            PsiDocumentManager.getInstance(project).getPsiFile(selectedTextEditor.getDocument());
        if (psiFile != null) {
          if (selectedTextEditor.getSelectionModel().hasSelection()) {
            final PsiElement startElement =
                psiFile.findElementAt(selectedTextEditor.getSelectionModel().getSelectionStart());
            if (startElement != null) {
              final PsiElement endElement =
                  psiFile.findElementAt(selectedTextEditor.getSelectionModel().getSelectionEnd());
              if (endElement != null) {
                final PsiElement parent = PsiTreeUtil.findCommonParent(startElement, endElement);
                if (parent != null) {
                  final List<PsiElement> elements = new ArrayList<PsiElement>();
                  final PsiElement[] children = parent.getChildren();
                  for (PsiElement child : children) {
                    if (!(child instanceof PsiWhiteSpace) && child.getContainingFile() != null) {
                      elements.add(child);
                    }
                  }
                  if (!elements.isEmpty()) {
                    SearchScope local =
                        new LocalSearchScope(
                            PsiUtilCore.toPsiElementArray(elements),
                            IdeBundle.message("scope.selection"));
                    result.add(local);
                  }
                }
              }
            }
          }
        }
      }
    }

    if (usageView) {
      UsageView selectedUsageView = UsageViewManager.getInstance(project).getSelectedUsageView();
      if (selectedUsageView != null && !selectedUsageView.isSearchInProgress()) {
        final Set<Usage> usages = selectedUsageView.getUsages();
        final List<PsiElement> results = new ArrayList<PsiElement>(usages.size());

        if (prevSearchFiles) {
          final Set<VirtualFile> files = new HashSet<VirtualFile>();
          for (Usage usage : usages) {
            if (usage instanceof PsiElementUsage) {
              PsiElement psiElement = ((PsiElementUsage) usage).getElement();
              if (psiElement != null && psiElement.isValid()) {
                PsiFile psiFile = psiElement.getContainingFile();
                if (psiFile != null) {
                  VirtualFile file = psiFile.getVirtualFile();
                  if (file != null) files.add(file);
                }
              }
            }
          }
          if (!files.isEmpty()) {
            GlobalSearchScope prev =
                new GlobalSearchScope(project) {
                  @Override
                  public String getDisplayName() {
                    return IdeBundle.message("scope.files.in.previous.search.result");
                  }

                  @Override
                  public boolean contains(@NotNull VirtualFile file) {
                    return files.contains(file);
                  }

                  @Override
                  public int compare(@NotNull VirtualFile file1, @NotNull VirtualFile file2) {
                    return 0;
                  }

                  @Override
                  public boolean isSearchInModuleContent(@NotNull Module aModule) {
                    return true;
                  }

                  @Override
                  public boolean isSearchInLibraries() {
                    return true;
                  }
                };
            result.add(prev);
          }
        } else {
          for (Usage usage : usages) {
            if (usage instanceof PsiElementUsage) {
              final PsiElement element = ((PsiElementUsage) usage).getElement();
              if (element != null && element.isValid() && element.getContainingFile() != null) {
                results.add(element);
              }
            }
          }

          if (!results.isEmpty()) {
            result.add(
                new LocalSearchScope(
                    PsiUtilCore.toPsiElementArray(results),
                    IdeBundle.message("scope.previous.search.results")));
          }
        }
      }
    }

    final FavoritesManager favoritesManager = FavoritesManager.getInstance(project);
    if (favoritesManager != null) {
      for (final String favorite : favoritesManager.getAvailableFavoritesListNames()) {
        final Collection<TreeItem<Pair<AbstractUrl, String>>> rootUrls =
            favoritesManager.getFavoritesListRootUrls(favorite);
        if (rootUrls.isEmpty()) continue; // ignore unused root
        result.add(
            new GlobalSearchScope(project) {
              @Override
              public String getDisplayName() {
                return "Favorite \'" + favorite + "\'";
              }

              @Override
              public boolean contains(@NotNull final VirtualFile file) {
                return favoritesManager.contains(favorite, file);
              }

              @Override
              public int compare(
                  @NotNull final VirtualFile file1, @NotNull final VirtualFile file2) {
                return 0;
              }

              @Override
              public boolean isSearchInModuleContent(@NotNull final Module aModule) {
                return true;
              }

              @Override
              public boolean isSearchInLibraries() {
                return true;
              }
            });
      }
    }

    if (dataContext != null) {
      final VirtualFile[] files = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext);
      if (files != null) {
        final List<VirtualFile> openFiles = Arrays.asList(files);
        result.add(
            new DelegatingGlobalSearchScope(GlobalSearchScope.filesScope(project, openFiles)) {
              @Override
              public String getDisplayName() {
                return "Selected Files";
              }
            });
      }
    }

    return result;
  }
  private void buildOutputItemsList(
      final String outputDir,
      final Module module,
      VirtualFile from,
      final FileTypeManager typeManager,
      final VirtualFile sourceRoot,
      final String packagePrefix,
      final List<File> filesToRefresh,
      final Map<String, Collection<TranslatingCompiler.OutputItem>> results)
      throws CacheCorruptedException {
    final Ref<CacheCorruptedException> exRef = new Ref<CacheCorruptedException>(null);
    final ModuleFileIndex fileIndex = ModuleRootManager.getInstance(module).getFileIndex();
    final GlobalSearchScope srcRootScope =
        GlobalSearchScope.moduleScope(module)
            .intersectWith(GlobalSearchScopes.directoryScope(myProject, sourceRoot, true));

    final Collection<FileType> registeredInputTypes =
        CompilerManager.getInstance(myProject).getRegisteredInputTypes(myTranslatingCompiler);

    final ContentIterator contentIterator =
        new ContentIterator() {
          public boolean processFile(final VirtualFile child) {
            try {
              if (child.isValid()) {
                if (!child.isDirectory() && registeredInputTypes.contains(child.getFileType())) {
                  updateOutputItemsList(
                      outputDir,
                      child,
                      sourceRoot,
                      packagePrefix,
                      filesToRefresh,
                      results,
                      srcRootScope);
                }
              }
              return true;
            } catch (CacheCorruptedException e) {
              exRef.set(e);
              return false;
            }
          }
        };
    if (fileIndex.isInContent(from)) {
      // use file index for iteration to handle 'inner modules' and excludes properly
      fileIndex.iterateContentUnderDirectory(from, contentIterator);
    } else {
      // seems to be a root for generated sources
      VfsUtilCore.visitChildrenRecursively(
          from,
          new VirtualFileVisitor() {
            @Override
            public boolean visitFile(@NotNull VirtualFile file) {
              if (!file.isDirectory()) {
                contentIterator.processFile(file);
              }
              return true;
            }
          });
    }
    final CacheCorruptedException exc = exRef.get();
    if (exc != null) {
      throw exc;
    }
  }