fail faster if searching was cancelled by typing (IDEA-169907)

This commit is contained in:
Maxim.Mossienko
2017-03-20 17:01:04 +01:00
parent d6fb4038db
commit f2f4eac9ca
2 changed files with 20 additions and 2 deletions
@@ -496,6 +496,9 @@ public class FindDialog extends DialogWrapper implements FindUI {
Ref<VirtualFile> lastUsageFileRef = new Ref<>();
FindInProjectUtil.findUsages(findModel, myProject, info -> {
if(isCancelled()) {
return false;
}
final Usage usage = UsageInfo2UsageAdapter.CONVERTER.fun(info);
usage.getPresentation().getIcon(); // cache icon
@@ -507,6 +510,7 @@ public class FindDialog extends DialogWrapper implements FindUI {
}
ApplicationManager.getApplication().invokeLater(() -> {
if (isCancelled()) return;
model.addRow(new Object[]{usage});
}, state);
return resultsCount.incrementAndGet() < ShowUsagesAction.USAGES_PAGE_SIZE;
@@ -515,7 +519,7 @@ public class FindDialog extends DialogWrapper implements FindUI {
boolean succeeded = !progressIndicatorWhenSearchStarted.isCanceled();
if (succeeded) {
return new Continuation(() -> {
if (progressIndicatorWhenSearchStarted == myResultsPreviewSearchProgress && !myResultsPreviewSearchProgress.isCanceled()) {
if (!isCancelled()) {
int occurrences = resultsCount.get();
int filesWithOccurrences = resultsFilesCount.get();
if (occurrences == 0) myResultsPreviewTable.getEmptyText().setText(UIBundle.message("message.nothingToShow"));
@@ -534,6 +538,10 @@ public class FindDialog extends DialogWrapper implements FindUI {
return null;
}
boolean isCancelled() {
return progressIndicatorWhenSearchStarted != myResultsPreviewSearchProgress || myResultsPreviewSearchProgress.isCanceled();
}
@Override
public void onCanceled(@NotNull ProgressIndicator indicator) {
if (isShowing() && progressIndicatorWhenSearchStarted == myResultsPreviewSearchProgress) {
@@ -809,6 +809,9 @@ public class FindPopupPanel extends JBPanel implements FindUI, DataProvider {
Ref<VirtualFile> lastUsageFileRef = new Ref<>();
FindInProjectUtil.findUsages(myHelper.getModel().clone(), myProject, info -> {
if(isCancelled()) {
return false;
}
final Usage usage = UsageInfo2UsageAdapter.CONVERTER.fun(info);
usage.getPresentation().getIcon(); // cache icon
@@ -820,6 +823,9 @@ public class FindPopupPanel extends JBPanel implements FindUI, DataProvider {
}
ApplicationManager.getApplication().invokeLater(() -> {
if(isCancelled()) {
return;
}
model.addRow(new Object[]{usage});
myCodePreviewComponent.setVisible(true);
if (model.getRowCount() == 1 && myResultsPreviewTable.getModel() == model) {
@@ -832,7 +838,7 @@ public class FindPopupPanel extends JBPanel implements FindUI, DataProvider {
boolean succeeded = !progressIndicatorWhenSearchStarted.isCanceled();
if (succeeded) {
ApplicationManager.getApplication().invokeLater(() -> {
if (progressIndicatorWhenSearchStarted == myResultsPreviewSearchProgress && !myResultsPreviewSearchProgress.isCanceled()) {
if (!isCancelled()) {
int occurrences = resultsCount.get();
int filesWithOccurrences = resultsFilesCount.get();
if (occurrences == 0) myResultsPreviewTable.getEmptyText().setText(UIBundle.message("message.nothingToShow"));
@@ -858,6 +864,10 @@ public class FindPopupPanel extends JBPanel implements FindUI, DataProvider {
}
}
boolean isCancelled() {
return progressIndicatorWhenSearchStarted != myResultsPreviewSearchProgress || progressIndicatorWhenSearchStarted.isCanceled();
}
@Override
public void onCanceled(@NotNull ProgressIndicator indicator) {
if (isShowing() && progressIndicatorWhenSearchStarted == myResultsPreviewSearchProgress) {