[platform] more customizable messages in ProgressManagerListener

GitOrigin-RevId: dfa5dd91a14576ad0929bc0c7b8cf4e94a81f8e7
This commit is contained in:
Andrew Kozlov
2021-03-24 22:50:46 +00:00
committed by intellij-monorepo-bot
parent 74a14542eb
commit 8e045b6473
2 changed files with 29 additions and 20 deletions
@@ -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) {}
}
@@ -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);
}
}