From 35feefa4387b485fa5fd297cd730ab0cbf2d5af5 Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 27 Oct 2015 13:37:50 +0100 Subject: [PATCH] finish dumb mode in any modality state (IDEA-146640) --- .../openapi/project/DumbServiceImpl.java | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/project/DumbServiceImpl.java b/platform/platform-impl/src/com/intellij/openapi/project/DumbServiceImpl.java index b47b9f75a37f..788864eaabb4 100644 --- a/platform/platform-impl/src/com/intellij/openapi/project/DumbServiceImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/project/DumbServiceImpl.java @@ -145,7 +145,7 @@ public class DumbServiceImpl extends DumbService implements Disposable, Modifica myPublisher.enteredDumbMode(); } else { - updateFinished(); + updateFinished(true); } } @@ -188,7 +188,7 @@ public class DumbServiceImpl extends DumbService implements Disposable, Modifica return; } - invokeLaterIfNeeded(application, new DumbAwareRunnable() { + UIUtil.invokeLaterIfNeeded(new Runnable() { @Override public void run() { if (myProject.isDisposed()) { @@ -242,25 +242,16 @@ public class DumbServiceImpl extends DumbService implements Disposable, Modifica startBackgroundProcess(modal); } catch (Throwable e) { - updateFinished(); + updateFinished(modal); LOG.error("Failed to start background index update task", e); } } - }, myProject.getDisposed()); + }, ModalityState.any(), myProject.getDisposed()); } } }); } - private static void invokeLaterIfNeeded(Application application, DumbAwareRunnable runnable) { - if (application.isDispatchThread()) { - runnable.run(); - } - else { - application.invokeLater(runnable, ModalityState.any()); - } - } - @Nullable private DumbModePermission getEdtPermission() { DumbModePermission permission = getExplicitPermission(); @@ -294,7 +285,7 @@ public class DumbServiceImpl extends DumbService implements Disposable, Modifica }; } - private void updateFinished() { + private void updateFinished(boolean modal) { myDumb = false; myDumbStart = null; myModificationCount++; @@ -302,6 +293,16 @@ public class DumbServiceImpl extends DumbService implements Disposable, Modifica if (ApplicationManager.getApplication().isInternal()) LOG.info("updateFinished"); + // some listeners might start yet another dumb mode + // allow that whatever the current modality is, because it won't harm anyone + allowStartingDumbModeInside(modal ? DumbModePermission.MAY_START_MODAL : DumbModePermission.MAY_START_BACKGROUND, new Runnable() { + public void run() { + notifyUpdateFinished(); + } + }); + } + + private void notifyUpdateFinished() { try { myPublisher.exitDumbMode(); FileEditorManagerEx.getInstanceEx(myProject).refreshIcons(); @@ -430,7 +431,7 @@ public class DumbServiceImpl extends DumbService implements Disposable, Modifica DumbModeTask task = null; while (true) { - Pair pair = getNextTask(task); + Pair pair = getNextTask(task, modal); if (pair == null) break; task = pair.first; @@ -491,7 +492,7 @@ public class DumbServiceImpl extends DumbService implements Disposable, Modifica }, taskIndicator); } - @Nullable private Pair getNextTask(@Nullable final DumbModeTask prevTask) { + @Nullable private Pair getNextTask(@Nullable final DumbModeTask prevTask, final boolean modal) { final Ref> result = Ref.create(); invokeAndWaitIfNeeded(new Runnable() { @Override @@ -503,7 +504,7 @@ public class DumbServiceImpl extends DumbService implements Disposable, Modifica while (true) { if (myUpdatesQueue.isEmpty()) { - updateFinished(); + updateFinished(modal); return; } @@ -528,10 +529,9 @@ public class DumbServiceImpl extends DumbService implements Disposable, Modifica } else { try { - ApplicationManager.getApplication().invokeAndWait(runnable, ModalityState.defaultModalityState()); + SwingUtilities.invokeAndWait(runnable); } - catch (ProcessCanceledException ignore) { - // thrown instead of InterruptedException by semaphore in invokeAndWait + catch (InterruptedException ignore) { } catch (Exception e) { LOG.error(e);