Search in sources :

Example 1 with TooManyUsagesStatus

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());
}
Also used : ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) Alarm(com.intellij.util.Alarm) Balloon(com.intellij.openapi.ui.popup.Balloon) TooManyUsagesStatus(com.intellij.openapi.progress.util.TooManyUsagesStatus)

Example 2 with TooManyUsagesStatus

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;
}
Also used : ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) Document(com.intellij.openapi.editor.Document) UsageInfo(com.intellij.usageView.UsageInfo) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) TooManyUsagesStatus(com.intellij.openapi.progress.util.TooManyUsagesStatus)

Aggregations

ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 TooManyUsagesStatus (com.intellij.openapi.progress.util.TooManyUsagesStatus)2 Document (com.intellij.openapi.editor.Document)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 Balloon (com.intellij.openapi.ui.popup.Balloon)1 UsageInfo (com.intellij.usageView.UsageInfo)1 Alarm (com.intellij.util.Alarm)1