RIDER-77734 Compound run configs are duplicated if it's started out of the toolbar
[idea/community.git] / platform / execution-impl / src / com / intellij / execution / runToolbar / RunToolbarRerunAction.kt
1 // Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
2 package com.intellij.execution.runToolbar
3
4 import com.intellij.execution.ExecutionBundle
5 import com.intellij.execution.runners.ExecutionEnvironment
6 import com.intellij.execution.runners.FakeRerunAction
7 import com.intellij.execution.ui.RunContentDescriptor
8 import com.intellij.openapi.actionSystem.AnActionEvent
9 import com.intellij.openapi.actionSystem.ShortcutSet
10 import com.intellij.openapi.project.DumbAware
11
12 open class RunToolbarRerunAction : FakeRerunAction(), RTBarAction, DumbAware {
13   override fun getRightSideType(): RTBarAction.Type = RTBarAction.Type.RIGHT_FLEXIBLE
14
15   override fun checkMainSlotVisibility(state: RunToolbarMainSlotState): Boolean {
16     return state == RunToolbarMainSlotState.PROCESS
17   }
18
19   override fun update(e: AnActionEvent) {
20     e.presentation.text = ExecutionBundle.message("run.dashboard.rerun.action.name")
21     e.presentation.isVisible = e.isActiveProcess()
22
23     e.presentation.isEnabled = !e.isProcessTerminating()
24
25     if (!RunToolbarProcess.isExperimentalUpdatingEnabled) {
26       e.mainState()?.let {
27         e.presentation.isVisible = e.presentation.isVisible && checkMainSlotVisibility(it)
28       }
29     }
30   }
31
32   override fun setShortcutSet(shortcutSet: ShortcutSet) {}
33
34   override fun getEnvironment(event: AnActionEvent): ExecutionEnvironment? {
35     return event.environment()
36   }
37
38   override fun getDescriptor(event: AnActionEvent): RunContentDescriptor? {
39     return getEnvironment(event)?.contentToReuse
40   }
41 }