From 36e0c8eccc0038bfe8c37bba00aab03a7e795e0c Mon Sep 17 00:00:00 2001 From: "Ilia.Shulgin" Date: Mon, 13 Oct 2025 17:28:01 +0200 Subject: [PATCH] [vcs] IJPL-173924 Set `CommitChangesViewWithToolbarPanel.setBusy` reactively GitOrigin-RevId: 0d4b613443a2de05558e4279fe75881f2dfcc331 --- .../changes/CommitChangesViewWithToolbarPanel.kt | 13 +++++-------- .../platform/vcs/impl/shared/SingleTaskRunner.kt | 5 ++++- ...ackendCommitChangesViewWithToolbarInitializer.kt | 1 - 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/platform/vcs-impl/shared/src/com/intellij/openapi/vcs/changes/CommitChangesViewWithToolbarPanel.kt b/platform/vcs-impl/shared/src/com/intellij/openapi/vcs/changes/CommitChangesViewWithToolbarPanel.kt index a244a8fe7bb2..172865016025 100644 --- a/platform/vcs-impl/shared/src/com/intellij/openapi/vcs/changes/CommitChangesViewWithToolbarPanel.kt +++ b/platform/vcs-impl/shared/src/com/intellij/openapi/vcs/changes/CommitChangesViewWithToolbarPanel.kt @@ -27,7 +27,6 @@ import com.intellij.util.application import com.intellij.util.asDisposable import com.intellij.util.concurrency.annotations.RequiresBackgroundThread import com.intellij.util.concurrency.annotations.RequiresEdt -import com.intellij.util.ui.EdtInvocationManager.invokeLaterIfNeeded import kotlinx.coroutines.* import kotlinx.coroutines.flow.collectLatest import org.jetbrains.annotations.ApiStatus @@ -57,11 +56,11 @@ class CommitChangesViewWithToolbarPanel( init { refresher.start() - } - - @CalledInAny - fun setBusy(busy: Boolean) { - invokeLaterIfNeeded { changesView.setPaintBusy(busy) } + cs.launch(Dispatchers.UI) { + refresher.getPendingTasksFlow().collect { + isBusy -> changesView.setPaintBusy(isBusy) + } + } } @RequiresEdt @@ -120,7 +119,6 @@ class CommitChangesViewWithToolbarPanel( @CalledInAny private fun scheduleRefresh(withDelay: Boolean, @RequiresBackgroundThread callback: Runnable? = null) { - setBusy(true) if (withDelay) { refresher.request() } @@ -130,7 +128,6 @@ class CommitChangesViewWithToolbarPanel( cs.launch { refresher.awaitNotBusy() callback?.run() - setBusy(false) } } diff --git a/platform/vcs-impl/shared/src/com/intellij/platform/vcs/impl/shared/SingleTaskRunner.kt b/platform/vcs-impl/shared/src/com/intellij/platform/vcs/impl/shared/SingleTaskRunner.kt index dff47ebea0ed..057bb8296fe3 100644 --- a/platform/vcs-impl/shared/src/com/intellij/platform/vcs/impl/shared/SingleTaskRunner.kt +++ b/platform/vcs-impl/shared/src/com/intellij/platform/vcs/impl/shared/SingleTaskRunner.kt @@ -7,6 +7,7 @@ import com.intellij.openapi.diagnostic.logger import com.intellij.openapi.progress.checkCanceled import kotlinx.coroutines.* import kotlinx.coroutines.channels.Channel +import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.first @@ -29,6 +30,8 @@ class SingleTaskRunner( private val runNow = Channel(capacity = Channel.CONFLATED) + fun getPendingTasksFlow(): Flow = requested.combine(busy) { requested, busy -> !requested && !busy } + private val processorJob = cs.launch(Dispatchers.Default, CoroutineStart.LAZY) { try { while (true) { @@ -73,7 +76,7 @@ class SingleTaskRunner( * Await the state where the task is not executed and there are no requests to do so. */ suspend fun awaitNotBusy() { - requested.combine(busy) { requested, busy -> !requested && !busy }.first { it } + getPendingTasksFlow().first { it } } companion object { diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/BackendCommitChangesViewWithToolbarInitializer.kt b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/BackendCommitChangesViewWithToolbarInitializer.kt index 8cfc7c82c501..6166a61f9400 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/BackendCommitChangesViewWithToolbarInitializer.kt +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/BackendCommitChangesViewWithToolbarInitializer.kt @@ -38,7 +38,6 @@ internal class BackendCommitChangesViewWithToolbarInitializer : CommitChangesVie } override fun changedFileStatusChanged() { - panel.setBusy(false) panel.scheduleRefresh() val changeListManager = ChangeListManagerImpl.getInstanceImpl(panel.project) ChangesViewManager.getInstance(panel.project).updateProgressComponent(changeListManager.getAdditionalUpdateInfo())