diff --git a/platform/execution-impl/src/com/intellij/execution/runToolbar/RunToolbarMainSlotActive.kt b/platform/execution-impl/src/com/intellij/execution/runToolbar/RunToolbarMainSlotActive.kt index 7bfc0c1fb51d..9944a272be59 100644 --- a/platform/execution-impl/src/com/intellij/execution/runToolbar/RunToolbarMainSlotActive.kt +++ b/platform/execution-impl/src/com/intellij/execution/runToolbar/RunToolbarMainSlotActive.kt @@ -83,7 +83,7 @@ private class RunToolbarMainSlotActive(presentation: Presentation) : SegmentedCu init { layout = MigLayout("ins 0 0 0 3, fill, ay center") val pane = JPanel().apply { - layout = MigLayout("ins 0, fill, novisualpadding, ay center, gap 0", "[pref!][min!]3[shp 1]3[]") + layout = MigLayout("ins 0, fill, novisualpadding, ay center, gap 0", "[pref!][min!]3[shp 1, push]3[]push") add(JPanel().apply { isOpaque = false add(arrow) @@ -102,7 +102,7 @@ private class RunToolbarMainSlotActive(presentation: Presentation) : SegmentedCu isOpaque = false } - add(pane) + add(pane, "growx") MouseListenerHelper.addListener(this, { doClick() }, { doShiftClick() }, { doRightClick() }) } diff --git a/platform/execution-impl/src/com/intellij/execution/runToolbar/RunToolbarMainSlotInfoAction.kt b/platform/execution-impl/src/com/intellij/execution/runToolbar/RunToolbarMainSlotInfoAction.kt index 40ceca39f668..64ab3288ce90 100644 --- a/platform/execution-impl/src/com/intellij/execution/runToolbar/RunToolbarMainSlotInfoAction.kt +++ b/platform/execution-impl/src/com/intellij/execution/runToolbar/RunToolbarMainSlotInfoAction.kt @@ -3,7 +3,6 @@ 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 @@ -25,8 +24,8 @@ class RunToolbarMainSlotInfoAction : SegmentedCustomAction(), RTRunConfiguration companion object { private val LOG = Logger.getInstance(RunToolbarMainSlotInfoAction::class.java) private val PROP_ACTIVE_PROCESS_COLOR = Key("ACTIVE_PROCESS_COLOR") - private val PROP_ACTIVE_PROCESSES_UPDATED = Key("PROP_ACTIVE_PROCESSES_UPDATED") - private val PROP_ACTIVE_PROCESSES = Key>>("PROP_ACTIVE_PROCESSES") + private val PROP_ACTIVE_PROCESSES_COUNT = Key("PROP_ACTIVE_PROCESSES_COUNT") + private val PROP_ACTIVE_PROCESSES = Key("PROP_ACTIVE_PROCESSES") } override fun getRightSideType(): RTBarAction.Type = RTBarAction.Type.FLEXIBLE @@ -42,18 +41,17 @@ 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.processes + val activeProcesses = manager.activeProcesses 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_COUNT, activeProcesses.getActiveCount()) e.presentation.putClientProperty(PROP_ACTIVE_PROCESSES, activeProcesses) - activeProcesses.isNotEmpty() + activeProcesses.processes.isNotEmpty() } ?: false if (!RunToolbarProcess.isExperimentalUpdatingEnabled) { @@ -71,10 +69,11 @@ 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 processComponents = mutableListOf() + private val migLayout = MigLayout("fill, hidemode 3, ins 0, novisualpadding, ay center, flowx, gapx 0") private val info = JPanel(migLayout) - private val processesComponents = mutableListOf() + private val one = ProcessesByType() init { layout = MigLayout("ins 0, fill, ay center") @@ -93,7 +92,11 @@ class RunToolbarMainSlotInfoAction : SegmentedCustomAction(), RTRunConfiguration background = UIManager.getColor("Separator.separatorColor") }) - add(info, "pushx, ay center, wmin 0") + add(JPanel(MigLayout("ins 0, fill, novisualpadding, ay center, gap 0, hidemode 3")).apply { + add(info, "growx") + add(one, "growx") + isOpaque = false + }, "pushx, ay center, wmin 0") isOpaque = false }, "growx, wmin 10") @@ -147,33 +150,49 @@ class RunToolbarMainSlotInfoAction : SegmentedCustomAction(), RTRunConfiguration } private fun updateActiveProcesses() { - presentation.getClientProperty(PROP_ACTIVE_PROCESSES)?.let { - if (it.isEmpty()) return + presentation.getClientProperty(PROP_ACTIVE_PROCESSES)?.let { activeProcesses -> + val processes = activeProcesses.processes + val keys = processes.keys.toList() + if (activeProcesses.getActiveCount() == 1) { + info.isVisible = false + one.isVisible = processes.keys.firstOrNull()?.let { process -> + processes[process]?.let { + one.update(process, it, false) + true + } + } ?: false - info.removeAll() - - var colConstr = "" - - while (processesComponents.size < it.size) { - processesComponents.add(ProcessesByType()) + return } + else { + info.isVisible = true + one.isVisible = false - 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++ + for (i in processComponents.size..processes.size) { + val component = ProcessesByType() + processComponents.add(component) + info.add(component, "w pref!") + } + + var constraint = "" + for (i in 0 until processComponents.size) { + constraint += "[]" + val component = processComponents[i] + if (i < keys.size) { + val key = keys[i] + processes[key]?.let { + component.isVisible = true + component.update(key, it, true) + } + } + else { + component.isVisible = false + } + } + constraint += "push" + migLayout.columnConstraints = constraint } - if (showCount) colConstr += "push" - migLayout.columnConstraints = colConstr } - - info.revalidate() - info.repaint() } private fun updateArrow() { diff --git a/platform/execution-impl/src/com/intellij/execution/runToolbar/RunToolbarProcessStartedAction.kt b/platform/execution-impl/src/com/intellij/execution/runToolbar/RunToolbarProcessStartedAction.kt index 21dfaf381443..6c172747102a 100644 --- a/platform/execution-impl/src/com/intellij/execution/runToolbar/RunToolbarProcessStartedAction.kt +++ b/platform/execution-impl/src/com/intellij/execution/runToolbar/RunToolbarProcessStartedAction.kt @@ -120,7 +120,7 @@ class RunToolbarProcessStartedAction : ComboBoxAction(), RTRunConfiguration { } private fun fill() { - layout = MigLayout("ins 0, novisualpadding, gap 0, fill", "4[shp 1]3[grow]4") + layout = MigLayout("ins 0 0 0 3, novisualpadding, gap 0, fill", "4[shp 1]3[grow]push") add(setting, "ay center, pushx, wmin 10") add(process, "ay center, pushx, wmin 0") diff --git a/platform/execution-impl/src/com/intellij/execution/runToolbar/RunToolbarRunConfigurationsAction.kt b/platform/execution-impl/src/com/intellij/execution/runToolbar/RunToolbarRunConfigurationsAction.kt index 2b4d84c9d15d..d3dcd4409426 100644 --- a/platform/execution-impl/src/com/intellij/execution/runToolbar/RunToolbarRunConfigurationsAction.kt +++ b/platform/execution-impl/src/com/intellij/execution/runToolbar/RunToolbarRunConfigurationsAction.kt @@ -115,7 +115,7 @@ open class RunToolbarRunConfigurationsAction : RunConfigurationsComboBoxAction() } private fun fill() { - layout = MigLayout("ins 0, novisualpadding, gap 0, fill, hidemode 3", "4[][min!]2") + layout = MigLayout("ins 0 0 0 3, novisualpadding, gap 0, fill, hidemode 3", "4[][min!]") add(setting, "ay center, growx, wmin 10") add(arrow) diff --git a/platform/execution-impl/src/com/intellij/execution/runToolbar/RunToolbarSlotManager.kt b/platform/execution-impl/src/com/intellij/execution/runToolbar/RunToolbarSlotManager.kt index ee673a5a4c0e..fac72f840300 100644 --- a/platform/execution-impl/src/com/intellij/execution/runToolbar/RunToolbarSlotManager.kt +++ b/platform/execution-impl/src/com/intellij/execution/runToolbar/RunToolbarSlotManager.kt @@ -229,7 +229,7 @@ class RunToolbarSlotManager(val project: Project) { } private fun updateState() { - state = when (activeProcesses.getEnvironmentCount()) { + state = when (activeProcesses.getActiveCount()) { 0 -> State.INACTIVE 1 -> { mainSlotData.environment?.let { @@ -481,7 +481,7 @@ class ActiveProcesses { val processes = mutableMapOf>() private var activeCount = 0 - fun getEnvironmentCount(): Int = activeCount + fun getActiveCount(): Int = activeCount fun getText(): String? { return when { diff --git a/platform/execution-impl/src/com/intellij/execution/runToolbar/components/ProcessesByType.kt b/platform/execution-impl/src/com/intellij/execution/runToolbar/components/ProcessesByType.kt index 05d519ea82a3..080e59b3310a 100644 --- a/platform/execution-impl/src/com/intellij/execution/runToolbar/components/ProcessesByType.kt +++ b/platform/execution-impl/src/com/intellij/execution/runToolbar/components/ProcessesByType.kt @@ -31,7 +31,7 @@ class ProcessesByType : JPanel() { } init { - layout = MigLayout("novisualpadding, ins 0, gap 0", "[min!][push]") + layout = MigLayout("fill, novisualpadding, ins 0, gap 0", "[min!][fill]") add(processLabel) add(settingLabel, "wmin 10") @@ -39,7 +39,7 @@ class ProcessesByType : JPanel() { isOpaque = false } - fun update(process: RunToolbarProcess, environment: List, onlyCount: Boolean = false) { + fun update(process: RunToolbarProcess, environment: MutableList, onlyCount: Boolean = false) { this.process = process this.environment = environment this.onlyCount = onlyCount diff --git a/platform/execution-impl/src/com/intellij/execution/runToolbar/components/TrimmedMiddleLabel.kt b/platform/execution-impl/src/com/intellij/execution/runToolbar/components/TrimmedMiddleLabel.kt index 736b784b9b20..9326c6c9abf5 100644 --- a/platform/execution-impl/src/com/intellij/execution/runToolbar/components/TrimmedMiddleLabel.kt +++ b/platform/execution-impl/src/com/intellij/execution/runToolbar/components/TrimmedMiddleLabel.kt @@ -8,8 +8,10 @@ import java.awt.Graphics2D import javax.swing.JLabel open class TrimmedMiddleLabel : JLabel() { + private val magicConst = 5 + override fun paintComponent(g: Graphics) { - val fm = g.getFontMetrics(g.font) + val fm = getFontMetrics(font) g as Graphics2D UISettings.setupAntialiasing(g) val textW = fm.stringWidth(text) @@ -17,10 +19,11 @@ open class TrimmedMiddleLabel : JLabel() { var x = insets.left icon?.let { x += iconTextGap + it.iconWidth + availableWidth -= x } val ellipsisWidth = fm.stringWidth(StringUtil.ELLIPSIS) - if (textW < availableWidth || width < 3 * ellipsisWidth) { + if (textW <= availableWidth + (icon?.let { 0 } ?: magicConst) || width < ellipsisWidth) { super.paintComponent(g) } else { @@ -28,14 +31,13 @@ open class TrimmedMiddleLabel : JLabel() { icon.paintIcon(this, g, insets.left, 0) } - availableWidth -= (x + ellipsisWidth) - val charArray = text.toCharArray() val stringLength = charArray.size var w = 0 + val avW = availableWidth - ellipsisWidth for (nChars in 0 until stringLength) { w += fm.charWidth(charArray[nChars]) - if (w > availableWidth) { + if (w > avW) { g.drawString(StringUtil.trimMiddle(text, nChars - 1), x, fm.ascent) return }