@NotNull @Override public GlobalSearchScope intersectWith(@NotNull GlobalSearchScope scope) { if (scope == this) return this; if (!scope.isSearchInLibraries()) return scope; return super.intersectWith(scope); }
@NotNull @Override public GlobalSearchScope uniteWith(@NotNull GlobalSearchScope scope) { if (scope == this || !scope.isSearchInLibraries() || !scope.isSearchOutsideRootModel()) return this; return super.uniteWith(scope); }
@NotNull @Override protected List<PyClass> getClassesByName( String name, boolean checkBoxState, String pattern, GlobalSearchScope searchScope) { final Collection<PyClass> classes = PyClassNameIndex.find(name, getProject(), searchScope.isSearchInLibraries()); final List<PyClass> result = Lists.newArrayList(); for (PyClass c : classes) { if (getFilter().isAccepted(c)) { result.add(c); } } return result; }
@Override protected JComponent createCenterPanel() { final DefaultTreeModel model = new DefaultTreeModel(new DefaultMutableTreeNode()); myTree = new Tree(model); ProjectAbstractTreeStructureBase treeStructure = new AbstractProjectTreeStructure(myProject) { @Override public boolean isFlattenPackages() { return false; } @Override public boolean isShowMembers() { return myIsShowMembers; } @Override public boolean isHideEmptyMiddlePackages() { return true; } @Override public boolean isAbbreviatePackageNames() { return false; } @Override public boolean isShowLibraryContents() { return myIsShowLibraryContents; } @Override public boolean isShowModules() { return false; } }; myBuilder = new ProjectTreeBuilder(myProject, myTree, model, AlphaComparator.INSTANCE, treeStructure); myTree.setRootVisible(false); myTree.setShowsRootHandles(true); myTree.expandRow(0); myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); myTree.setCellRenderer(new NodeRenderer()); UIUtil.setLineStyleAngled(myTree); JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTree); scrollPane.setPreferredSize(new Dimension(500, 300)); myTree.addKeyListener( new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (KeyEvent.VK_ENTER == e.getKeyCode()) { doOKAction(); } } }); new DoubleClickListener() { @Override protected boolean onDoubleClick(MouseEvent event) { TreePath path = myTree.getPathForLocation(event.getX(), event.getY()); if (path != null && myTree.isPathSelected(path)) { doOKAction(); return true; } return false; } }.installOn(myTree); myTree.addTreeSelectionListener( new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { handleSelectionChanged(); } }); new TreeSpeedSearch(myTree); myTabbedPane = new TabbedPaneWrapper(getDisposable()); final JPanel dummyPanel = new JPanel(new BorderLayout()); String name = null; /* if (myInitialClass != null) { name = myInitialClass.getName(); } */ myGotoByNamePanel = new ChooseByNamePanel( myProject, createChooseByNameModel(), name, myScope.isSearchInLibraries(), getContext()) { @Override protected void showTextFieldPanel() {} @Override protected void close(boolean isOk) { super.close(isOk); if (isOk) { doOKAction(); } else { doCancelAction(); } } @NotNull @Override protected Set<Object> filter(@NotNull Set<Object> elements) { return doFilter(elements); } @Override protected void initUI( ChooseByNamePopupComponent.Callback callback, ModalityState modalityState, boolean allowMultipleSelection) { super.initUI(callback, modalityState, allowMultipleSelection); dummyPanel.add(myGotoByNamePanel.getPanel(), BorderLayout.CENTER); IdeFocusTraversalPolicy.getPreferredFocusedComponent(myGotoByNamePanel.getPanel()) .requestFocus(); } @Override protected void showList() { super.showList(); if (myInitialClass != null && myList.getModel().getSize() > 0) { myList.setSelectedValue(myInitialClass, true); myInitialClass = null; } } @Override protected void chosenElementMightChange() { handleSelectionChanged(); } }; Disposer.register(myDisposable, myGotoByNamePanel); myTabbedPane.addTab(IdeBundle.message("tab.chooser.search.by.name"), dummyPanel); myTabbedPane.addTab(IdeBundle.message("tab.chooser.project"), scrollPane); myGotoByNamePanel.invoke(new MyCallback(), getModalityState(), false); myTabbedPane.addChangeListener( new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { handleSelectionChanged(); } }); return myTabbedPane.getComponent(); }
@NotNull private Collection<PsiFile> collectFilesInScope( @NotNull final Set<PsiFile> alreadySearched, final boolean skipIndexed) { SearchScope customScope = myFindModel.getCustomScope(); final GlobalSearchScope globalCustomScope = toGlobal(customScope); final ProjectFileIndex fileIndex = ProjectFileIndex.SERVICE.getInstance(myProject); final boolean hasTrigrams = hasTrigrams(myFindModel.getStringToFind()); class EnumContentIterator implements ContentIterator { final Set<PsiFile> myFiles = new LinkedHashSet<PsiFile>(); @Override public boolean processFile(@NotNull final VirtualFile virtualFile) { ApplicationManager.getApplication() .runReadAction( new Runnable() { @Override public void run() { ProgressManager.checkCanceled(); if (virtualFile.isDirectory() || !virtualFile.isValid() || !myFileMask.value(virtualFile) || globalCustomScope != null && !globalCustomScope.contains(virtualFile)) { return; } if (skipIndexed && isCoveredByIndex(virtualFile) && (fileIndex.isInContent(virtualFile) || fileIndex.isInLibraryClasses(virtualFile) || fileIndex.isInLibrarySource(virtualFile))) { return; } PsiFile psiFile = myPsiManager.findFile(virtualFile); if (psiFile != null && !(psiFile instanceof PsiBinaryFile) && !alreadySearched.contains(psiFile)) { PsiFile sourceFile = (PsiFile) psiFile.getNavigationElement(); if (sourceFile != null) psiFile = sourceFile; if (!psiFile.getFileType().isBinary()) { myFiles.add(psiFile); } } } final FileBasedIndexImpl fileBasedIndex = (FileBasedIndexImpl) FileBasedIndex.getInstance(); private boolean isCoveredByIndex(VirtualFile file) { FileType fileType = file.getFileType(); if (hasTrigrams) { return TrigramIndex.isIndexable(fileType) && fileBasedIndex.isIndexingCandidate(file, TrigramIndex.INDEX_ID); } return IdIndex.isIndexable(fileType) && fileBasedIndex.isIndexingCandidate(file, IdIndex.NAME); } }); return true; } @NotNull private Collection<PsiFile> getFiles() { return myFiles; } } final EnumContentIterator iterator = new EnumContentIterator(); if (customScope instanceof LocalSearchScope) { for (VirtualFile file : getLocalScopeFiles((LocalSearchScope) customScope)) { iterator.processFile(file); } } else if (customScope instanceof Iterable) { // GlobalSearchScope can span files out of project roots e.g. FileScope / // FilesScope //noinspection unchecked for (VirtualFile file : (Iterable<VirtualFile>) customScope) { iterator.processFile(file); } } else if (myPsiDirectory != null) { ApplicationManager.getApplication() .runReadAction( new Runnable() { @Override public void run() { if (myPsiDirectory.isValid()) { addFilesUnderDirectory(myPsiDirectory, iterator); } } }); myFileIndex.iterateContentUnderDirectory(myPsiDirectory.getVirtualFile(), iterator); } else { boolean success = myFileIndex.iterateContent(iterator); if (success && globalCustomScope != null && globalCustomScope.isSearchInLibraries()) { final VirtualFile[] librarySources = ApplicationManager.getApplication() .runReadAction( new Computable<VirtualFile[]>() { @Override public VirtualFile[] compute() { OrderEnumerator enumerator = myModule == null ? OrderEnumerator.orderEntries(myProject) : OrderEnumerator.orderEntries(myModule); return enumerator .withoutModuleSourceEntries() .withoutDepModules() .getSourceRoots(); } }); iterateAll(librarySources, globalCustomScope, iterator); } } return iterator.getFiles(); }
public boolean isSearchInLibraries() { return myDelegate == null || myDelegate.isSearchInLibraries(); }
@Override public boolean isSearchInLibraries() { return myScope1.isSearchInLibraries() && myScope2.isSearchInLibraries(); }