use of com.intellij.openapi.progress.util.TooManyUsagesStatus in project intellij-community by JetBrains.
the class SearchForUsagesRunnable method searchUsages.
private void searchUsages(@NotNull final AtomicBoolean findStartedBalloonShown) {
ProgressIndicator indicator = ProgressWrapper.unwrap(ProgressManager.getInstance().getProgressIndicator());
assert indicator != null : "must run find usages under progress";
TooManyUsagesStatus.createFor(indicator);
Alarm findUsagesStartedBalloon = new Alarm();
findUsagesStartedBalloon.addRequest(() -> {
notifyByFindBalloon(null, MessageType.WARNING, myProcessPresentation, myProject, Collections.singletonList(StringUtil.escapeXml(UsageViewManagerImpl.getProgressTitle(myPresentation))));
findStartedBalloonShown.set(true);
}, 300, ModalityState.NON_MODAL);
UsageSearcher usageSearcher = mySearcherFactory.create();
usageSearcher.generate(usage -> {
ProgressIndicator indicator1 = ProgressWrapper.unwrap(ProgressManager.getInstance().getProgressIndicator());
assert indicator1 != null : "must run find usages under progress";
if (indicator1.isCanceled())
return false;
if (!UsageViewManagerImpl.isInScope(usage, mySearchScopeToWarnOfFallingOutOf)) {
myOutOfScopeUsages.incrementAndGet();
return true;
}
boolean incrementCounter = !UsageViewManager.isSelfUsage(usage, mySearchFor);
if (incrementCounter) {
final int usageCount = myUsageCountWithoutDefinition.incrementAndGet();
if (usageCount == 1 && !myProcessPresentation.isShowPanelIfOnlyOneUsage()) {
myFirstUsage.compareAndSet(null, usage);
}
final UsageViewImpl usageView = getUsageView(indicator1);
TooManyUsagesStatus tooManyUsagesStatus = TooManyUsagesStatus.getFrom(indicator1);
if (usageCount > UsageLimitUtil.USAGES_LIMIT && tooManyUsagesStatus.switchTooManyUsagesStatus()) {
UsageViewManagerImpl.showTooManyUsagesWarning(myProject, tooManyUsagesStatus, indicator1, myPresentation, usageCount, usageView);
}
tooManyUsagesStatus.pauseProcessingIfTooManyUsages();
if (usageView != null) {
ApplicationManager.getApplication().runReadAction(() -> usageView.appendUsage(usage));
}
}
return !indicator1.isCanceled();
});
if (getUsageView(indicator) != null) {
ApplicationManager.getApplication().invokeLater(() -> myUsageViewManager.showToolWindow(true), myProject.getDisposed());
}
Disposer.dispose(findUsagesStartedBalloon);
ApplicationManager.getApplication().invokeLater(() -> {
if (findStartedBalloonShown.get()) {
Balloon balloon = ToolWindowManager.getInstance(myProject).getToolWindowBalloon(ToolWindowId.FIND);
if (balloon != null) {
balloon.hide();
}
}
}, myProject.getDisposed());
}
use of com.intellij.openapi.progress.util.TooManyUsagesStatus in project intellij-community by JetBrains.
the class FindInProjectUtil method processUsagesInFile.
// returns number of hits
static int processUsagesInFile(@NotNull final PsiFile psiFile, @NotNull final VirtualFile virtualFile, @NotNull final FindModel findModel, @NotNull final Processor<UsageInfo> consumer) {
if (findModel.getStringToFind().isEmpty()) {
if (!ReadAction.compute(() -> consumer.process(new UsageInfo(psiFile)))) {
throw new ProcessCanceledException();
}
return 1;
}
// do not decompile .class files
if (virtualFile.getFileType().isBinary())
return 0;
final Document document = ReadAction.compute(() -> virtualFile.isValid() ? FileDocumentManager.getInstance().getDocument(virtualFile) : null);
if (document == null)
return 0;
final int[] offset = { 0 };
int count = 0;
int found;
ProgressIndicator indicator = ProgressWrapper.unwrap(ProgressManager.getInstance().getProgressIndicator());
TooManyUsagesStatus tooManyUsagesStatus = TooManyUsagesStatus.getFrom(indicator);
do {
// wait for user out of read action
tooManyUsagesStatus.pauseProcessingIfTooManyUsages();
found = ReadAction.compute(() -> {
if (!psiFile.isValid())
return 0;
return addToUsages(document, consumer, findModel, psiFile, offset, USAGES_PER_READ_ACTION);
});
count += found;
} while (found != 0);
return count;
}
Aggregations