[vcs] IJPL-173924 Set CommitChangesViewWithToolbarPanel.setBusy reactively

GitOrigin-RevId: 0d4b613443a2de05558e4279fe75881f2dfcc331
This commit is contained in:
Ilia.Shulgin
2025-10-20 19:19:33 +00:00
committed by intellij-monorepo-bot
parent b653201351
commit 36e0c8eccc
3 changed files with 9 additions and 10 deletions
@@ -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)
}
}
@@ -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<Unit>(capacity = Channel.CONFLATED)
fun getPendingTasksFlow(): Flow<Boolean> = 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 {
@@ -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())