diff --git a/platform/platform-impl/src/com/intellij/openapi/progress/ProgressManagerListener.java b/platform/core-api/src/com/intellij/openapi/progress/ProgressManagerListener.java similarity index 56% rename from platform/platform-impl/src/com/intellij/openapi/progress/ProgressManagerListener.java rename to platform/core-api/src/com/intellij/openapi/progress/ProgressManagerListener.java index 42a02fbaf48d..a337ecafbf96 100644 --- a/platform/platform-impl/src/com/intellij/openapi/progress/ProgressManagerListener.java +++ b/platform/core-api/src/com/intellij/openapi/progress/ProgressManagerListener.java @@ -1,10 +1,8 @@ // Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.progress; -import com.intellij.openapi.progress.util.ProgressWindow; import com.intellij.util.messages.Topic; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; public interface ProgressManagerListener { @@ -12,11 +10,13 @@ public interface ProgressManagerListener { Topic.BroadcastDirection.NONE, true); - void onTaskRunnableCreated(@NotNull Task task, - @NotNull ProgressWindow indicator, - @Nullable Runnable continuation); + default void beforeTaskStart(@NotNull Task task, + @NotNull ProgressIndicator indicator) {} - void onTaskFinished(@NotNull Task task, - boolean canceled, - @Nullable Throwable error); + default void afterTaskStart(@NotNull Task task, + @NotNull ProgressIndicator indicator) {} + + default void beforeTaskFinished(@NotNull Task task) {} + + default void afterTaskFinished(@NotNull Task task) {} } diff --git a/platform/platform-impl/src/com/intellij/openapi/progress/impl/ProgressManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/progress/impl/ProgressManagerImpl.java index 58773617dd3b..8dfdd7f9f76a 100644 --- a/platform/platform-impl/src/com/intellij/openapi/progress/impl/ProgressManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/progress/impl/ProgressManagerImpl.java @@ -8,7 +8,6 @@ import com.intellij.openapi.progress.*; import com.intellij.openapi.progress.util.PingProgress; import com.intellij.openapi.progress.util.ProgressIndicatorBase; import com.intellij.openapi.progress.util.ProgressIndicatorUtils; -import com.intellij.openapi.progress.util.ProgressWindow; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.UserDataHolder; @@ -109,15 +108,16 @@ public class ProgressManagerImpl extends CoreProgressManager implements Disposab protected final void startTask(@NotNull Task task, @NotNull ProgressIndicator indicator, @Nullable Runnable continuation) { + ProgressManagerListener listener = getProjectManagerListener(); try { - super.startTask(task, indicator, continuation); + listener.beforeTaskStart(task, indicator); } finally { - if (indicator instanceof ProgressWindow) { - ApplicationManager.getApplication() - .getMessageBus() - .syncPublisher(ProgressManagerListener.TOPIC) - .onTaskRunnableCreated(task, (ProgressWindow)indicator, continuation); + try { + super.startTask(task, indicator, continuation); + } + finally { + listener.afterTaskStart(task, indicator); } } } @@ -153,14 +153,17 @@ public class ProgressManagerImpl extends CoreProgressManager implements Disposab protected final void finishTask(@NotNull Task task, boolean canceled, @Nullable Throwable error) { + ProgressManagerListener listener = getProjectManagerListener(); try { - super.finishTask(task, canceled, error); + listener.beforeTaskFinished(task); } finally { - ApplicationManager.getApplication() - .getMessageBus() - .syncPublisher(ProgressManagerListener.TOPIC) - .onTaskFinished(task, canceled, error); + try { + super.finishTask(task, canceled, error); + } + finally { + listener.afterTaskFinished(task); + } } } @@ -211,4 +214,10 @@ public class ProgressManagerImpl extends CoreProgressManager implements Disposab protected void prioritizingFinished() { removeCheckCanceledHook(mySleepHook); } + + private static @NotNull ProgressManagerListener getProjectManagerListener() { + return ApplicationManager.getApplication() + .getMessageBus() + .syncPublisher(ProgressManagerListener.TOPIC); + } }