RIDER-70060 info state

GitOrigin-RevId: 9d5e74e91894b4e41819fb4575a703b09455b7e7
This commit is contained in:
anna.gromova
2021-12-03 12:42:35 +00:00
committed by intellij-monorepo-bot
parent aff8419812
commit f70b02b76d
13 changed files with 216 additions and 145 deletions
@@ -2,6 +2,7 @@
package com.intellij.execution.runToolbar
import com.intellij.execution.runToolbar.RunToolbarProcessStartedAction.Companion.PROP_ACTIVE_ENVIRONMENT
import com.intellij.execution.runToolbar.components.MouseListenerHelper
import com.intellij.execution.runToolbar.components.TrimmedMiddleLabel
import com.intellij.icons.AllIcons
import com.intellij.idea.ActionsBundle
@@ -12,16 +13,16 @@ import com.intellij.openapi.actionSystem.impl.segmentedActionBar.SegmentedCustom
import com.intellij.openapi.actionSystem.impl.segmentedActionBar.SegmentedCustomPanel
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.util.Key
import com.intellij.ui.JBColor
import com.intellij.util.ui.JBDimension
import com.intellij.util.ui.UIUtil
import net.miginfocom.swing.MigLayout
import java.awt.Dimension
import java.awt.Font
import java.awt.event.MouseAdapter
import java.awt.event.MouseEvent
import java.beans.PropertyChangeEvent
import javax.swing.*
import javax.swing.Icon
import javax.swing.JLabel
import javax.swing.JPanel
import javax.swing.UIManager
class RunToolbarMainSlotActive : SegmentedCustomAction(), RTBarAction {
companion object {
@@ -76,7 +77,7 @@ private class RunToolbarMainSlotActive(presentation: Presentation) : SegmentedCu
return UIUtil.getToolbarFont()
}
}.apply {
foreground = JBColor.namedColor("infoPanelForeground", JBColor(0x808080, 0x8C8C8C))
foreground = UIUtil.getLabelInfoForeground()
}
init {
@@ -102,23 +103,7 @@ private class RunToolbarMainSlotActive(presentation: Presentation) : SegmentedCu
}
add(pane)
addMouseListener(object : MouseAdapter() {
override fun mousePressed(e: MouseEvent) {
if (SwingUtilities.isLeftMouseButton(e)) {
e.consume()
if (e.isShiftDown) {
doShiftClick()
}
else {
doClick()
}
}
else if (SwingUtilities.isRightMouseButton(e)) {
doRightClick()
}
}
})
MouseListenerHelper.addListener(this, { doClick() }, { doShiftClick() }, { doRightClick() })
}
fun doRightClick() {
@@ -1,6 +1,9 @@
// 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.
package com.intellij.execution.runToolbar
import com.intellij.execution.runToolbar.components.MouseListenerHelper
import com.intellij.execution.runToolbar.components.ProcessesByType
import com.intellij.execution.runners.ExecutionEnvironment
import com.intellij.icons.AllIcons
import com.intellij.idea.ActionsBundle
import com.intellij.openapi.actionSystem.ActionToolbar
@@ -11,22 +14,19 @@ import com.intellij.openapi.actionSystem.impl.segmentedActionBar.SegmentedCustom
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.util.Key
import com.intellij.util.ui.JBDimension
import com.intellij.util.ui.UIUtil
import net.miginfocom.swing.MigLayout
import java.awt.Color
import java.awt.Font
import java.awt.event.MouseAdapter
import java.awt.event.MouseEvent
import java.beans.PropertyChangeEvent
import javax.swing.JLabel
import javax.swing.JPanel
import javax.swing.SwingUtilities
import javax.swing.UIManager
class RunToolbarMainSlotInfoAction : SegmentedCustomAction(), RTRunConfiguration {
companion object {
private val LOG = Logger.getInstance(RunToolbarMainSlotInfoAction::class.java)
private val PROP_ACTIVE_PROCESS_COLOR = Key<Color>("ACTIVE_PROCESS_COLOR")
private val PROP_ACTIVE_PROCESSES_UPDATED = Key<Boolean>("PROP_ACTIVE_PROCESSES_UPDATED")
private val PROP_ACTIVE_PROCESSES = Key<MutableMap<RunToolbarProcess, MutableList<ExecutionEnvironment>>>("PROP_ACTIVE_PROCESSES")
}
override fun getRightSideType(): RTBarAction.Type = RTBarAction.Type.FLEXIBLE
@@ -42,20 +42,18 @@ class RunToolbarMainSlotInfoAction : SegmentedCustomAction(), RTRunConfiguration
override fun update(e: AnActionEvent) {
e.presentation.isVisible = e.project?.let { project ->
val manager = RunToolbarSlotManager.getInstance(project)
val activeProcesses = manager.activeProcesses
val activeProcesses = manager.activeProcesses.processes
manager.getMainOrFirstActiveProcess()?.let {
e.presentation.putClientProperty(PROP_ACTIVE_PROCESS_COLOR, it.pillColor)
}
e.presentation.putClientProperty(RunToolbarMainSlotActive.ARROW_DATA, e.arrowIcon())
val value = e.presentation.getClientProperty(PROP_ACTIVE_PROCESSES_UPDATED) ?: false
e.presentation.putClientProperty(PROP_ACTIVE_PROCESSES_UPDATED, !value)
e.presentation.putClientProperty(PROP_ACTIVE_PROCESSES, activeProcesses)
activeProcesses.getText()?.let {
e.presentation.setText(it, false)
true
} ?: false
activeProcesses.isNotEmpty()
} ?: false
if (!RunToolbarProcess.isExperimentalUpdatingEnabled) {
@@ -73,46 +71,35 @@ class RunToolbarMainSlotInfoAction : SegmentedCustomAction(), RTRunConfiguration
private class RunToolbarMainSlotInfo(presentation: Presentation) : SegmentedCustomPanel(presentation), PopupControllerComponent {
private val arrow = JLabel()
private val migLayout = MigLayout("fill, hidemode 3, ins 0, novisualpadding, ay center, flowx, gapx 0")
private val setting = object : JLabel() {
override fun getFont(): Font {
return UIUtil.getToolbarFont()
}
}
private val info = JPanel(migLayout)
private val processesComponents = mutableListOf<ProcessesByType>()
init {
layout = MigLayout("ins 0, fill, novisualpadding, ay center, gap 0", "[pref!][min!]5[]")
add(JPanel().apply {
layout = MigLayout("ins 0, fill, ay center")
add(JPanel(MigLayout("ins 0, fill, novisualpadding, ay center, gap 0", "[pref!][min!]5[fill]5")).apply {
add(JPanel().apply {
isOpaque = false
add(arrow)
val d = preferredSize
d.width = FixWidthSegmentedActionToolbarComponent.ARROW_WIDTH
preferredSize = d
})
add(JPanel().apply {
preferredSize = JBDimension(1, 12)
minimumSize = JBDimension(1, 12)
background = UIManager.getColor("Separator.separatorColor")
})
add(info, "pushx, ay center, wmin 0")
isOpaque = false
add(arrow)
val d = preferredSize
d.width = FixWidthSegmentedActionToolbarComponent.ARROW_WIDTH
preferredSize = d
})
add(JPanel().apply {
preferredSize = JBDimension(1, 12)
minimumSize = JBDimension(1, 12)
background = UIManager.getColor("Separator.separatorColor")
})
add(setting)
}, "growx, wmin 10")
addMouseListener(object : MouseAdapter() {
override fun mousePressed(e: MouseEvent) {
if (SwingUtilities.isLeftMouseButton(e)) {
e.consume()
if (e.isShiftDown) {
doShiftClick()
}
else {
doClick()
}
}
else if (SwingUtilities.isRightMouseButton(e)) {
doRightClick()
}
}
})
info.isOpaque = false
MouseListenerHelper.addListener(this, { doClick() }, { doShiftClick() }, { doRightClick() })
}
fun doRightClick() {
@@ -144,15 +131,49 @@ class RunToolbarMainSlotInfoAction : SegmentedCustomAction(), RTRunConfiguration
}
override fun presentationChanged(event: PropertyChangeEvent) {
updateState()
}
private fun updateState() {
updateArrow()
setting.icon = presentation.icon
setting.text = presentation.text
presentation.getClientProperty(PROP_ACTIVE_PROCESS_COLOR)?.let {
background = it
} ?: kotlin.run {
isOpaque = false
}
updateActiveProcesses()
}
private fun updateActiveProcesses() {
presentation.getClientProperty(PROP_ACTIVE_PROCESSES)?.let {
if (it.isEmpty()) return
info.removeAll()
var colConstr = ""
while (processesComponents.size < it.size) {
processesComponents.add(ProcessesByType())
}
var i = 0
var showCount = false
for (entry in it) {
showCount = showCount || entry.value.size > 1 || it.size > 1
val processesByType = processesComponents[i]
processesByType.update(entry.key, entry.value, showCount)
info.add(processesByType, "wmin 0")
colConstr += if (showCount) "[pref!]" else "[fill]"
i++
}
if (showCount) colConstr += "push"
migLayout.columnConstraints = colConstr
}
info.revalidate()
info.repaint()
}
private fun updateArrow() {
@@ -19,7 +19,6 @@ import javax.swing.event.AncestorListener
class RunToolbarPopupController(val project: Project,
val mainWidgetComponent: RunToolbarMainWidgetComponent) : PopupControllerComponentListener, Disposable {
private val manager = RunToolbarSlotManager.getInstance(project)
private var popup: JBPopup? = null
private var pane: RunToolbarExtraSlotPane = RunToolbarExtraSlotPane(project, {mainWidgetComponent.width})
@@ -1,6 +1,7 @@
// 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.
package com.intellij.execution.runToolbar
import com.intellij.execution.runToolbar.components.MouseListenerHelper
import com.intellij.execution.runToolbar.components.TrimmedMiddleLabel
import com.intellij.execution.runners.ExecutionEnvironment
import com.intellij.idea.ActionsBundle
@@ -16,12 +17,9 @@ import com.intellij.util.ui.UIUtil
import net.miginfocom.swing.MigLayout
import java.awt.Dimension
import java.awt.Font
import java.awt.event.MouseAdapter
import java.awt.event.MouseEvent
import java.beans.PropertyChangeEvent
import javax.swing.JComponent
import javax.swing.JLabel
import javax.swing.SwingUtilities
class RunToolbarProcessStartedAction : ComboBoxAction(), RTRunConfiguration {
companion object {
@@ -89,22 +87,7 @@ class RunToolbarProcessStartedAction : ComboBoxAction(), RTRunConfiguration {
}
init {
addMouseListener(object : MouseAdapter() {
override fun mousePressed(e: MouseEvent) {
if (SwingUtilities.isLeftMouseButton(e)) {
e.consume()
if (e.isShiftDown) {
doShiftClick()
}
else {
showPopup()
}
}
else if (SwingUtilities.isRightMouseButton(e)) {
doRightClick()
}
}
})
MouseListenerHelper.addListener(this, { showPopup() }, { doShiftClick() }, { doRightClick() })
fill()
}
@@ -5,6 +5,7 @@ import com.intellij.execution.*
import com.intellij.execution.actions.RunConfigurationsComboBoxAction
import com.intellij.execution.impl.EditConfigurationsDialog
import com.intellij.execution.runToolbar.components.ComboBoxArrowComponent
import com.intellij.execution.runToolbar.components.MouseListenerHelper
import com.intellij.execution.runToolbar.components.TrimmedMiddleLabel
import com.intellij.ide.DataManager
import com.intellij.ide.HelpTooltip
@@ -25,8 +26,6 @@ import com.intellij.util.ui.UIUtil
import net.miginfocom.swing.MigLayout
import java.awt.Dimension
import java.awt.Font
import java.awt.event.MouseAdapter
import java.awt.event.MouseEvent
import java.beans.PropertyChangeEvent
import javax.swing.JComponent
import javax.swing.SwingUtilities
@@ -98,23 +97,7 @@ open class RunToolbarRunConfigurationsAction : RunConfigurationsComboBoxAction()
private val arrow = ComboBoxArrowComponent().getView()
init {
addMouseListener(object : MouseAdapter() {
override fun mousePressed(e: MouseEvent) {
if (SwingUtilities.isLeftMouseButton(e)) {
e.consume()
if (e.isShiftDown) {
doShiftClick()
}
else {
doClick()
}
}
else if (SwingUtilities.isRightMouseButton(e)) {
doRightClick()
}
}
})
MouseListenerHelper.addListener(this, { doClick() }, { doShiftClick() }, { doRightClick() })
fill()
background = JBColor.namedColor("ComboBoxButton.background", Gray.xDF)
@@ -124,7 +107,9 @@ open class RunToolbarRunConfigurationsAction : RunConfigurationsComboBoxAction()
setting.icon = presentation.icon
setting.text = presentation.text
isEnabled = true
isEnabled = presentation.isEnabled
setting.isEnabled = isEnabled
arrow.isVisible = isEnabled
toolTipText = presentation.description
}
@@ -0,0 +1,33 @@
// 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.
package com.intellij.execution.runToolbar.components
import java.awt.Component
import java.awt.event.MouseAdapter
import java.awt.event.MouseEvent
import javax.swing.SwingUtilities
class MouseListenerHelper {
companion object {
fun addListener(component: Component, doClick: () -> Unit, doShiftClick: () -> Unit, doRightClick: () -> Unit) {
component.addMouseListener(object : MouseAdapter() {
override fun mousePressed(e: MouseEvent) {
if (!component.isEnabled) return
if (SwingUtilities.isLeftMouseButton(e)) {
e.consume()
if (e.isShiftDown) {
doShiftClick()
}
else {
doClick()
}
}
else if (SwingUtilities.isRightMouseButton(e)) {
doRightClick()
}
}
})
}
}
}
@@ -0,0 +1,59 @@
// 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.
package com.intellij.execution.runToolbar.components
import com.intellij.execution.runToolbar.RunToolbarProcess
import com.intellij.execution.runners.ExecutionEnvironment
import com.intellij.util.ui.UIUtil
import net.miginfocom.swing.MigLayout
import java.awt.Font
import javax.swing.JLabel
import javax.swing.JPanel
class ProcessesByType : JPanel() {
private var onlyCount = true
private var environment = emptyList<ExecutionEnvironment>()
private var process = RunToolbarProcess.getProcesses()[0]
private val settingLabel = object : TrimmedMiddleLabel() {
override fun getFont(): Font {
return UIUtil.getToolbarFont()
}
}
private val processLabel = object : JLabel() {
override fun getFont(): Font {
return UIUtil.getToolbarFont()
}
}.apply {
foreground = UIUtil.getLabelInfoForeground()
}
init {
layout = MigLayout("novisualpadding, ins 0, gap 0", "[min!][push]")
add(processLabel)
add(settingLabel, "wmin 10")
isOpaque = false
}
fun update(process: RunToolbarProcess, environment: List<ExecutionEnvironment>, onlyCount: Boolean = false) {
this.process = process
this.environment = environment
this.onlyCount = onlyCount
update()
}
private fun update() {
processLabel.text = "${process.shortName}: "
settingLabel.text = if (environment.size > 1 || onlyCount) {
environment.size.toString()
}
else {
environment[0].contentToReuse?.displayName ?: ""
}
}
}
@@ -19,14 +19,16 @@ open class TrimmedMiddleLabel : JLabel() {
x += iconTextGap + it.iconWidth
}
if (textW < availableWidth) {
val ellipsisWidth = fm.stringWidth(StringUtil.ELLIPSIS)
if (textW < availableWidth || width < 3 * ellipsisWidth) {
super.paintComponent(g)
}
else {
icon?.let {
icon.paintIcon(this, g, insets.left, 0)
}
availableWidth -= (x + fm.stringWidth(StringUtil.ELLIPSIS))
availableWidth -= (x + ellipsisWidth)
val charArray = text.toCharArray()
val stringLength = charArray.size
@@ -588,11 +588,14 @@ project.startup.task.table.name.column=Run Configuration
project.startup.task.table.is.shared.column=Shared
label.project.path.on.target=Project path on target:
run.toolbar.debug=Debugging
run.toolbar.debugging=Debugging
run.toolbar.running=Running
run.toolbar.debug=Debug
run.toolbar.attached=Attached
run.toolbar.attach=Attach
run.toolbar.run=Running
run.toolbar.run=Run
run.toolbar.started = {0}: {1}
run.toolbar.started={0}: {1}
module.not.specified=module not specified
sdk.of.0.module=SDK of ''{0}'' module
@@ -44,6 +44,7 @@ interface RunToolbarProcess {
val ID: String
val executorId: String
val name: @Nls String
val shortName: @Nls String
val actionId: String
fun getMainActionId(): String = "main$actionId"
@@ -8,12 +8,13 @@ import com.intellij.ui.JBColor
class RunToolbarRunProcess : RunToolbarProcess {
override val ID: String = ToolWindowId.RUN
override val executorId: String = ToolWindowId.RUN
override val name: String = ExecutionBundle.message("run.toolbar.run")
override val name: String = ExecutionBundle.message("run.toolbar.running")
override val shortName: String = ExecutionBundle.message("run.toolbar.run")
override val actionId: String = "RunToolbarRunProcess"
override val moreActionSubGroupName: String = "RunToolbarRunMoreActionSubGroupName"
override val showInBar: Boolean = true
override val pillColor: JBColor = JBColor.namedColor("RunToolbar.Run.activeBackground", JBColor(0xBAEEBA, 0x375E37))
override val pillColor: JBColor = JBColor.namedColor("RunToolbar.Run.activeBackground", JBColor(0xBAEEBA, 0x375E37))
}
@@ -2,7 +2,6 @@
package com.intellij.openapi.actionSystem.impl.segmentedActionBar
import com.intellij.ide.ui.laf.darcula.DarculaUIUtil
import com.intellij.ide.ui.laf.darcula.ui.DarculaButtonUI
import com.intellij.openapi.actionSystem.ActionButtonComponent
import com.intellij.openapi.rd.paint2DLine
import com.intellij.ui.Gray
@@ -22,6 +21,24 @@ import kotlin.math.roundToInt
internal class SegmentedBarPainter {
companion object {
private val strokeWidth = 1.0
private val bw = 0f
private val lw = DarculaUIUtil.LW.float
fun getGradientPaint(component: Component): Paint {
return GradientPaint(bw, bw,
JBColor.namedColor(
"Button.startBorderColor",
JBColor.namedColor("Button.darcula.outlineStartColor", 0xbfbfbf)),
bw, component.height - (bw * 2),
JBColor
.namedColor("Button.endBorderColor",
JBColor.namedColor(
"Button.darcula.outlineEndColor",
0xb8b8b8)))
}
fun paintButtonDecorations(g: Graphics2D, c: JComponent, paint: Paint): Boolean {
if (!(c as AbstractButton).isContentAreaFilled) {
return true
@@ -41,10 +58,11 @@ internal class SegmentedBarPainter {
if (MacUIUtil.USE_QUARTZ) RenderingHints.VALUE_STROKE_PURE else RenderingHints.VALUE_STROKE_NORMALIZE)
g2.translate(r.x, r.y)
val arc = DarculaUIUtil.BUTTON_ARC.float
val bw: Float = if (DarculaButtonUI.isSmallVariant(c)) 0f else DarculaUIUtil.BW.float
val bw: Float = 0f //if (DarculaButtonUI.isSmallVariant(c)) 0f else DarculaUIUtil.BW.float
if (c.isEnabled()) {
g2.paint = paint
c.getClientProperty(SegmentedActionToolbarComponent.CONTROL_BAR_PROPERTY)?.let {
paintComponent(g2, Rectangle(c.getSize()), it.toString())
} ?: g2.fill(RoundRectangle2D.Float(bw, bw, r.width - bw * 2, r.height - bw * 2, arc, arc))
@@ -65,7 +83,6 @@ internal class SegmentedBarPainter {
val wdth = r.width.toFloat()
val offs = arc * 2
val bw = 0f
val area = when (position) {
SegmentedActionToolbarComponent.CONTROL_BAR_FIRST -> {
@@ -107,9 +124,6 @@ internal class SegmentedBarPainter {
}
fun paintActionBarBorder(component: JComponent, g: Graphics) {
val lw = DarculaUIUtil.LW.float
val bw = 0f
val g2 = g.create() as Graphics2D
try {
@@ -118,23 +132,12 @@ internal class SegmentedBarPainter {
if (MacUIUtil.USE_QUARTZ) RenderingHints.VALUE_STROKE_PURE else RenderingHints.VALUE_STROKE_NORMALIZE)
val paint = GradientPaint(bw, bw,
JBColor.namedColor(
"Button.startBorderColor",
JBColor.namedColor("Button.darcula.outlineStartColor", 0xbfbfbf)),
bw, component.height - (bw * 2),
JBColor
.namedColor("Button.endBorderColor",
JBColor.namedColor(
"Button.darcula.outlineEndColor",
0xb8b8b8)))
val paint = getGradientPaint(component)
for(i in 0 until component.componentCount - 1) {
val comp = component.getComponent(i)
val bounds = comp.bounds
val strokeWidth = 1.0
g2.paint2DLine(bounds.maxX - strokeWidth, bw.toDouble(), bounds.maxX - strokeWidth, (component.height - (bw * 2)).toDouble(),
LinePainter2D.StrokeType.INSIDE,
strokeWidth,
@@ -152,8 +155,6 @@ internal class SegmentedBarPainter {
g2.paint = paint
g2.fill(border)
}
finally {
g2.dispose()
@@ -161,8 +162,6 @@ internal class SegmentedBarPainter {
}
private fun componentBorder(g: Graphics, h: Int, shape: Shape) {
val bw = 0f
val g2 = g.create() as Graphics2D
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)
g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
@@ -187,8 +186,6 @@ internal class SegmentedBarPainter {
}
fun paintActionBarBackground(component: JComponent, g: Graphics) {
val bw = 0f
val g2 = g.create() as Graphics2D
try {
@@ -9,20 +9,22 @@ import com.intellij.ui.JBColor
class RunToolbarDebugProcess : RunToolbarProcess {
override val ID: String = ToolWindowId.DEBUG
override val executorId: String = ID
override val name: String = ExecutionBundle.message("run.toolbar.debug")
override val name: String = ExecutionBundle.message("run.toolbar.debugging")
override val shortName: String = ExecutionBundle.message("run.toolbar.debug")
override val actionId: String = "RunToolbarDebugProcess"
override val moreActionSubGroupName: String = "RunToolbarDebugMoreActionSubGroupName"
override val showInBar: Boolean = true
override val pillColor: JBColor = JBColor.namedColor("RunToolbar.Debug.activeBackground", JBColor(0xFAD576, 0x69541C))
override val pillColor: JBColor = JBColor.namedColor("RunToolbar.Debug.activeBackground", JBColor(0xFAD576, 0x69541C))
}
class RunToolbarAttachDebugProcess : RunToolbarProcess {
override val ID: String = "ProcessAttachDebug"
override val executorId: String = ID
override val name: String = ExecutionBundle.message("run.toolbar.attach")
override val name: String = ExecutionBundle.message("run.toolbar.attached")
override val shortName: String = name
override val actionId: String = "RunToolbarAttachDebugProcess"
override val moreActionSubGroupName: String = "RunToolbarAttachDebugMoreActionSubGroupName"
@@ -31,5 +33,5 @@ class RunToolbarAttachDebugProcess : RunToolbarProcess {
override fun isTemporaryProcess(): Boolean = true
override val pillColor: JBColor = JBColor.namedColor("RunToolbar.Debug.activeBackground", JBColor(0xFAD576, 0x69541C))
override val pillColor: JBColor = JBColor.namedColor("RunToolbar.Debug.activeBackground", JBColor(0xFAD576, 0x69541C))
}