boolean (@NotNull ReplaceContext replaceContext, @NotNull Collection<? extends Usage> usages) { int[] replacedCount = {0}; boolean[] success = {true}; boolean result = ((ApplicationImpl)ApplicationManager.getApplication()).runWriteActionWithCancellableProgressInDispatchThread( FindBundle.message("find.replace.all.progress.title"), myProject, null, indicator -> { indicator.setIndeterminate(false); int processed = 0; VirtualFile lastFile = null; for (final Usage usage : usages) { ++processed; indicator.checkCanceled(); indicator.setFraction((float)processed / usages.size()); if (usage instanceof UsageInFile) { VirtualFile virtualFile = ((UsageInFile)usage).getFile(); if (virtualFile != null && !virtualFile.equals(lastFile)) { indicator.setText2(virtualFile.getPresentableUrl()); lastFile = virtualFile; } } ProgressManager.getInstance().executeNonCancelableSection(() -> { try { if (replaceUsage(usage, replaceContext.getFindModel(), replaceContext.getExcludedSetCached(), false)) { replacedCount[0]++; } } catch (FindManager.MalformedReplacementStringException ex) { markAsMalformedReplacement(replaceContext, usage); success[0] = false; } }); } FileDocumentManager.getInstance().saveAllDocuments(); } ); success[0] &= result; replaceContext.getUsageView().removeUsagesBulk(usages); reportNumberReplacedOccurrences(myProject, replacedCount[0]); return success[0]; }