diff --git a/platform/platform-impl/src/com/intellij/openapi/progress/util/ProgressIndicatorUtils.java b/platform/platform-impl/src/com/intellij/openapi/progress/util/ProgressIndicatorUtils.java
index dadd49495563..15c96efc1f83 100644
--- a/platform/platform-impl/src/com/intellij/openapi/progress/util/ProgressIndicatorUtils.java
+++ b/platform/platform-impl/src/com/intellij/openapi/progress/util/ProgressIndicatorUtils.java
@@ -22,9 +22,7 @@ import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.application.ex.ApplicationEx;
import com.intellij.openapi.application.ex.ApplicationManagerEx;
-import com.intellij.openapi.progress.ProcessCanceledException;
-import com.intellij.openapi.progress.ProgressIndicator;
-import com.intellij.openapi.progress.ProgressManager;
+import com.intellij.openapi.progress.*;
import com.intellij.openapi.util.EmptyRunnable;
import com.intellij.openapi.util.Ref;
import com.intellij.util.ui.EdtInvocationManager;
@@ -88,7 +86,7 @@ public class ProgressIndicatorUtils {
* This method attempts to run provided action synchronously in a read action, so that, if possible, it wouldn't impact any pending,
* executing or future write actions (for this to work effectively the action should invoke {@link ProgressManager#checkCanceled()} or
* {@link ProgressIndicator#checkCanceled()} often enough).
- * It returns true if action was executed successfully. It returns false if the action was not
+ * It returns {@code true} if action was executed successfully. It returns {@code false} if the action was not
* executed successfully, i.e. if:
*
* - write action was in progress when the method was called
@@ -104,7 +102,7 @@ public class ProgressIndicatorUtils {
}
public static boolean runWithWriteActionPriority(@NotNull final Runnable action,
- @NotNull final ProgressIndicator progressIndicator) {
+ @NotNull final ProgressIndicator progressIndicator) {
final ApplicationEx application = (ApplicationEx)ApplicationManager.getApplication();
if (application.isWriteActionPending()) {
@@ -235,4 +233,18 @@ public class ProgressIndicatorUtils {
public static void yieldToPendingWriteActions() {
ApplicationManager.getApplication().invokeAndWait(EmptyRunnable.INSTANCE, ModalityState.any());
}
+
+ public static boolean isInNonCancelableSection() {
+ ProgressIndicator indicator = ProgressIndicatorProvider.getGlobalProgressIndicator();
+ while (indicator != null) {
+ if (indicator instanceof NonCancelableSection) return true;
+ if (indicator instanceof WrappedProgressIndicator) {
+ indicator = ((WrappedProgressIndicator)indicator).getOriginalProgressIndicator();
+ }
+ else {
+ break;
+ }
+ }
+ return false;
+ }
}
diff --git a/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.java
index f0b527d8b72a..ef924b969e05 100644
--- a/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.java
+++ b/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.java
@@ -32,6 +32,7 @@ import com.intellij.openapi.components.impl.stores.StorageUtil;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.progress.*;
+import com.intellij.openapi.progress.util.ProgressIndicatorUtils;
import com.intellij.openapi.project.*;
import com.intellij.openapi.project.ex.ProjectManagerEx;
import com.intellij.openapi.startup.StartupManager;
@@ -386,8 +387,7 @@ public class ProjectManagerImpl extends ProjectManagerEx implements Disposable {
}
private static boolean canCancelProjectLoading() {
- ProgressIndicator indicator = ProgressIndicatorProvider.getGlobalProgressIndicator();
- return !(indicator instanceof NonCancelableSection);
+ return !ProgressIndicatorUtils.isInNonCancelableSection();
}
@Override