use of com.intellij.usages.FindUsagesProcessPresentation in project intellij-community by JetBrains.
the class IconsReferencesContributor method execute.
@Override
public boolean execute(@NotNull ReferencesSearch.SearchParameters queryParameters, @NotNull final Processor<PsiReference> consumer) {
final PsiElement file = queryParameters.getElementToSearch();
if (file instanceof PsiBinaryFile) {
final Module module = ApplicationManager.getApplication().runReadAction(new Computable<Module>() {
@Override
public Module compute() {
return ModuleUtilCore.findModuleForPsiElement(file);
}
});
final VirtualFile image = ((PsiBinaryFile) file).getVirtualFile();
if (isImage(image) && isIconsModule(module)) {
final Project project = file.getProject();
final FindModel model = new FindModel();
final String path = getPathToImage(image, module);
if (path == null)
return true;
model.setStringToFind(path);
model.setCaseSensitive(true);
model.setFindAll(true);
model.setWholeWordsOnly(true);
FindInProjectUtil.findUsages(model, project, usage -> {
ApplicationManager.getApplication().runReadAction(() -> {
final PsiElement element = usage.getElement();
final ProperTextRange textRange = usage.getRangeInElement();
if (element != null && textRange != null) {
final PsiElement start = element.findElementAt(textRange.getStartOffset());
final PsiElement end = element.findElementAt(textRange.getEndOffset());
if (start != null && end != null) {
PsiElement value = PsiTreeUtil.findCommonParent(start, end);
if (value instanceof PsiJavaToken) {
value = value.getParent();
}
if (value != null) {
final PsiFileReference reference = FileReferenceUtil.findFileReference(value);
if (reference != null) {
consumer.process(reference);
}
}
}
}
});
return true;
}, new FindUsagesProcessPresentation(new UsageViewPresentation()));
}
}
return true;
}
use of com.intellij.usages.FindUsagesProcessPresentation in project intellij-community by JetBrains.
the class FindInProjectTask method searchInFiles.
private void searchInFiles(@NotNull Collection<VirtualFile> virtualFiles, @NotNull FindUsagesProcessPresentation processPresentation, @NotNull final Processor<UsageInfo> consumer) {
AtomicInteger occurrenceCount = new AtomicInteger();
AtomicInteger processedFileCount = new AtomicInteger();
Processor<VirtualFile> processor = virtualFile -> {
if (!virtualFile.isValid())
return true;
long fileLength = UsageViewManagerImpl.getFileLength(virtualFile);
if (fileLength == -1)
return true;
final boolean skipProjectFile = ProjectUtil.isProjectOrWorkspaceFile(virtualFile) && !myFindModel.isSearchInProjectFiles();
if (skipProjectFile && !Registry.is("find.search.in.project.files"))
return true;
if (fileLength > SINGLE_FILE_SIZE_LIMIT) {
myLargeFiles.add(virtualFile);
return true;
}
myProgress.checkCanceled();
if (myProgress.isRunning()) {
double fraction = (double) processedFileCount.incrementAndGet() / virtualFiles.size();
myProgress.setFraction(fraction);
}
String text = FindBundle.message("find.searching.for.string.in.file.progress", myFindModel.getStringToFind(), virtualFile.getPresentableUrl());
myProgress.setText(text);
myProgress.setText2(FindBundle.message("find.searching.for.string.in.file.occurrences.progress", occurrenceCount));
Pair.NonNull<PsiFile, VirtualFile> pair = ReadAction.compute(() -> findFile(virtualFile));
if (pair == null)
return true;
PsiFile psiFile = pair.first;
VirtualFile sourceVirtualFile = pair.second;
int countInFile = FindInProjectUtil.processUsagesInFile(psiFile, sourceVirtualFile, myFindModel, info -> skipProjectFile || consumer.process(info));
if (countInFile > 0 && skipProjectFile) {
processPresentation.projectFileUsagesFound(() -> {
FindModel model = myFindModel.clone();
model.setSearchInProjectFiles(true);
FindInProjectManager.getInstance(myProject).startFindInProject(model);
});
return true;
}
occurrenceCount.addAndGet(countInFile);
if (countInFile > 0) {
if (myTotalFilesSize.addAndGet(fileLength) > FILES_SIZE_LIMIT && myWarningShown.compareAndSet(false, true)) {
String message = FindBundle.message("find.excessive.total.size.prompt", UsageViewManagerImpl.presentableSize(myTotalFilesSize.longValue()), ApplicationNamesInfo.getInstance().getProductName());
UsageLimitUtil.showAndCancelIfAborted(myProject, message, processPresentation.getUsageViewPresentation());
}
}
return true;
};
PsiSearchHelperImpl.processFilesConcurrentlyDespiteWriteActions(myProject, new ArrayList<>(virtualFiles), myProgress, processor);
}
use of com.intellij.usages.FindUsagesProcessPresentation in project intellij-community by JetBrains.
the class FindInProjectUtil method setupProcessPresentation.
@NotNull
public static FindUsagesProcessPresentation setupProcessPresentation(@NotNull final Project project, final boolean showPanelIfOnlyOneUsage, @NotNull final UsageViewPresentation presentation) {
FindUsagesProcessPresentation processPresentation = new FindUsagesProcessPresentation(presentation);
processPresentation.setShowNotFoundMessage(true);
processPresentation.setShowPanelIfOnlyOneUsage(showPanelIfOnlyOneUsage);
processPresentation.setProgressIndicatorFactory(() -> new FindProgressIndicator(project, presentation.getScopeText()));
return processPresentation;
}
Aggregations