Skip to content

Commit aaa8884

Browse files
Walingarintellij-monorepo-bot
authored andcommitted
[execution] IJPL-181190: Use StateFlow instead of handmade ReactiveProperty
GitOrigin-RevId: 974109e7262ba8ef03cc02f4f7302668f17fc875
1 parent 22487db commit aaa8884

3 files changed

Lines changed: 27 additions & 79 deletions

File tree

platform/execution-impl/src/com/intellij/execution/ui/RunContentManagerImpl.kt

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import com.intellij.openapi.Disposable
2323
import com.intellij.openapi.actionSystem.PlatformCoreDataKeys
2424
import com.intellij.openapi.application.AppUIExecutor
2525
import com.intellij.openapi.application.ApplicationManager
26+
import com.intellij.openapi.application.EDT
2627
import com.intellij.openapi.components.serviceIfCreated
2728
import com.intellij.openapi.options.advanced.AdvancedSettings
2829
import com.intellij.openapi.project.Project
@@ -47,6 +48,9 @@ import com.intellij.util.SmartList
4748
import com.intellij.util.application
4849
import com.intellij.util.ui.EmptyIcon
4950
import com.intellij.util.ui.UIUtil
51+
import kotlinx.coroutines.Dispatchers
52+
import kotlinx.coroutines.launch
53+
import kotlinx.coroutines.withContext
5054
import org.jetbrains.annotations.ApiStatus
5155
import java.awt.KeyboardFocusManager
5256
import java.util.concurrent.ConcurrentLinkedDeque
@@ -274,9 +278,11 @@ class RunContentManagerImpl(private val project: Project) : RunContentManager {
274278
content.putUserData(EXECUTOR_KEY, executor)
275279
content.displayName = descriptor.displayName
276280

277-
descriptor.displayNameProperty.afterChange(descriptor) {
278-
application.invokeLater {
279-
content.displayName = it
281+
descriptor.coroutineScope.launch {
282+
descriptor.displayNameProperty.collect {
283+
withContext(Dispatchers.EDT) {
284+
content.displayName = it
285+
}
280286
}
281287
}
282288

@@ -307,9 +313,12 @@ class RunContentManagerImpl(private val project: Project) : RunContentManager {
307313
content.description = ExecutionBundle.message("process.id.tooltip", pid)
308314
}
309315
}
310-
descriptor.iconProperty.afterChange(descriptor) {
311-
UIUtil.invokeLaterIfNeeded {
312-
content.icon = getLiveIndicator(it)
316+
317+
descriptor.coroutineScope.launch {
318+
descriptor.iconProperty.collect {
319+
withContext(Dispatchers.EDT) {
320+
content.icon = getLiveIndicator(it)
321+
}
313322
}
314323
}
315324
}
@@ -333,9 +342,11 @@ class RunContentManagerImpl(private val project: Project) : RunContentManager {
333342
Disposer.register(disposer, Disposable { processHandler.removeProcessListener(processAdapter) })
334343
}
335344
} else {
336-
descriptor.iconProperty.afterChange(descriptor) {
337-
application.invokeLater {
338-
content.icon = it ?: executor.toolWindowIcon
345+
descriptor.coroutineScope.launch {
346+
descriptor.iconProperty.collect {
347+
withContext(Dispatchers.EDT) {
348+
content.icon = it ?: executor.toolWindowIcon
349+
}
339350
}
340351
}
341352
}

platform/execution/src/com/intellij/execution/ui/ReactiveProperty.kt

Lines changed: 0 additions & 66 deletions
This file was deleted.

platform/execution/src/com/intellij/execution/ui/RunContentDescriptor.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
import com.intellij.openapi.util.NlsContexts.TabTitle;
1616
import com.intellij.ui.content.Content;
1717
import kotlinx.coroutines.CoroutineScope;
18+
import kotlinx.coroutines.flow.MutableStateFlow;
19+
import kotlinx.coroutines.flow.StateFlow;
20+
import kotlinx.coroutines.flow.StateFlowKt;
1821
import org.jetbrains.annotations.ApiStatus;
1922
import org.jetbrains.annotations.NotNull;
2023
import org.jetbrains.annotations.Nullable;
@@ -34,8 +37,8 @@ public class RunContentDescriptor implements Disposable {
3437
private ExecutionConsole myExecutionConsole;
3538
private ProcessHandler myProcessHandler;
3639
private JComponent myComponent;
37-
private final MutableReactiveProperty<@TabTitle @Nullable String> myDisplayNameView = new MutableReactiveProperty<>(null);
38-
private final MutableReactiveProperty<@Nullable Icon> myIconView = new MutableReactiveProperty<>(null);
40+
private final MutableStateFlow<@TabTitle @Nullable String> myDisplayNameView = StateFlowKt.MutableStateFlow(null);
41+
private final MutableStateFlow<@Nullable Icon> myIconView = StateFlowKt.MutableStateFlow(null);
3942
private final String myHelpId;
4043
private RunnerLayoutUi myRunnerLayoutUi = null;
4144
private RunContentDescriptorReusePolicy myReusePolicy = RunContentDescriptorReusePolicy.DEFAULT;
@@ -169,7 +172,7 @@ public void dispose() {
169172
* @return the icon property that can be observed for the most recent icon value.
170173
*/
171174
@ApiStatus.Experimental
172-
public ReactiveProperty<Icon> getIconProperty() {
175+
public StateFlow<Icon> getIconProperty() {
173176
return myIconView;
174177
}
175178

@@ -211,7 +214,7 @@ public JComponent getComponent() {
211214
* @return the title property that can be observed for the most recent title value.
212215
*/
213216
@ApiStatus.Experimental
214-
public ReactiveProperty<@Nullable @BuildEventsNls.Title String> getDisplayNameProperty() {
217+
public StateFlow<@Nullable @BuildEventsNls.Title String> getDisplayNameProperty() {
215218
return myDisplayNameView;
216219
}
217220

0 commit comments

Comments
 (0)