From 4989493636deab261ab9357e110fb2d068c227fd Mon Sep 17 00:00:00 2001 From: Konstantin Kolosovsky Date: Mon, 14 Oct 2019 01:55:53 +0300 Subject: [PATCH] vcs: non-modal: Show current change list author after "Commit" button GitOrigin-RevId: 10562addaf302d3cbea81debca7f5fb03c27a868 --- .../vcs/commit/ChangesViewCommitPanel.kt | 14 +++++- .../ChangesViewCommitWorkflowHandler.kt | 1 + .../vcs/commit/ChangesViewCommitWorkflowUi.kt | 3 ++ .../vcs/commit/CommitAuthorComponent.kt | 46 +++++++++++++++++++ 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 platform/vcs-impl/src/com/intellij/vcs/commit/CommitAuthorComponent.kt diff --git a/platform/vcs-impl/src/com/intellij/vcs/commit/ChangesViewCommitPanel.kt b/platform/vcs-impl/src/com/intellij/vcs/commit/ChangesViewCommitPanel.kt index f8c6b42dfada..95e955dfe93b 100644 --- a/platform/vcs-impl/src/com/intellij/vcs/commit/ChangesViewCommitPanel.kt +++ b/platform/vcs-impl/src/com/intellij/vcs/commit/ChangesViewCommitPanel.kt @@ -36,6 +36,7 @@ import com.intellij.ui.components.JBOptionButton import com.intellij.ui.components.JBOptionButton.Companion.getDefaultShowPopupShortcut import com.intellij.ui.components.JBPanel import com.intellij.ui.components.panels.HorizontalLayout +import com.intellij.ui.components.panels.NonOpaquePanel import com.intellij.util.EventDispatcher import com.intellij.util.IJSwingUtilities.updateComponentTreeUI import com.intellij.util.ui.JBUI.Borders.empty @@ -45,6 +46,7 @@ import com.intellij.util.ui.JBUI.scale import com.intellij.util.ui.UIUtil.getTreeBackground import com.intellij.util.ui.components.BorderLayoutPanel import com.intellij.util.ui.tree.TreeUtil.* +import com.intellij.vcs.log.VcsUser import java.awt.Point import java.awt.event.ActionEvent import java.awt.event.InputEvent @@ -122,6 +124,7 @@ class ChangesViewCommitPanel(private val changesView: ChangesListView, private v override fun isDefaultButton(): Boolean = IdeFocusManager.getInstance(project).getFocusedDescendantFor(rootComponent) != null } + private val commitAuthorComponent = CommitAuthorComponent() private val commitLegendCalculator = ChangeInfoCalculator() private val commitLegend = CommitLegendPanel(commitLegendCalculator) @@ -169,7 +172,10 @@ class ChangesViewCommitPanel(private val changesView: ChangesListView, private v createHorizontalPanel().apply { background = BACKGROUND_COLOR - add(commitButton) + add(NonOpaquePanel(HorizontalLayout(scale(4))).apply { + add(commitButton) + add(commitAuthorComponent) + }) add(CurrentBranchComponent(project, changesView, this@ChangesViewCommitPanel)) add(commitLegend.component) add(toolbarPanel) @@ -242,6 +248,12 @@ class ChangesViewCommitPanel(private val changesView: ChangesListView, private v override fun setCustomCommitActions(actions: List) = commitButton.setOptions(actions) + override var commitAuthor: VcsUser? + get() = commitAuthorComponent.commitAuthor + set(value) { + commitAuthorComponent.commitAuthor = value + } + override val isActive: Boolean get() = isVisible override fun activate(): Boolean { diff --git a/platform/vcs-impl/src/com/intellij/vcs/commit/ChangesViewCommitWorkflowHandler.kt b/platform/vcs-impl/src/com/intellij/vcs/commit/ChangesViewCommitWorkflowHandler.kt index 4018ce1447ee..98f4b1b9cdf3 100644 --- a/platform/vcs-impl/src/com/intellij/vcs/commit/ChangesViewCommitWorkflowHandler.kt +++ b/platform/vcs-impl/src/com/intellij/vcs/commit/ChangesViewCommitWorkflowHandler.kt @@ -185,6 +185,7 @@ class ChangesViewCommitWorkflowHandler( setCommitMessage(newCommitMessage) newChangeList?.let { commitOptions.changeListChanged(it) } + ui.commitAuthor = (newChangeList?.data as? ChangeListData)?.author } override fun inclusionChanged() { diff --git a/platform/vcs-impl/src/com/intellij/vcs/commit/ChangesViewCommitWorkflowUi.kt b/platform/vcs-impl/src/com/intellij/vcs/commit/ChangesViewCommitWorkflowUi.kt index a12076df3625..4fb3be5b7927 100644 --- a/platform/vcs-impl/src/com/intellij/vcs/commit/ChangesViewCommitWorkflowUi.kt +++ b/platform/vcs-impl/src/com/intellij/vcs/commit/ChangesViewCommitWorkflowUi.kt @@ -5,6 +5,7 @@ import com.intellij.openapi.actionSystem.AnAction import com.intellij.openapi.actionSystem.DataContext import com.intellij.openapi.vcs.changes.InclusionModel import com.intellij.openapi.vcs.changes.LocalChangeList +import com.intellij.vcs.log.VcsUser interface ChangesViewCommitWorkflowUi : CommitWorkflowUi { val isActive: Boolean @@ -13,6 +14,8 @@ interface ChangesViewCommitWorkflowUi : CommitWorkflowUi { var isDefaultCommitActionEnabled: Boolean fun setCustomCommitActions(actions: List) + var commitAuthor: VcsUser? + var inclusionModel: InclusionModel? fun select(item: Any) diff --git a/platform/vcs-impl/src/com/intellij/vcs/commit/CommitAuthorComponent.kt b/platform/vcs-impl/src/com/intellij/vcs/commit/CommitAuthorComponent.kt new file mode 100644 index 000000000000..9e0c1d5512d0 --- /dev/null +++ b/platform/vcs-impl/src/com/intellij/vcs/commit/CommitAuthorComponent.kt @@ -0,0 +1,46 @@ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.intellij.vcs.commit + +import com.intellij.openapi.util.text.StringUtil.escapeXmlEntities +import com.intellij.openapi.util.text.StringUtil.unescapeXmlEntities +import com.intellij.ui.components.JBLabel +import com.intellij.ui.components.labels.LinkLabel +import com.intellij.ui.components.panels.HorizontalLayout +import com.intellij.ui.components.panels.NonOpaquePanel +import com.intellij.util.ui.JBUI.Borders.emptyRight +import com.intellij.util.ui.UIUtil.getInactiveTextColor +import com.intellij.vcs.log.VcsUser +import com.intellij.vcs.log.util.VcsUserUtil.getShortPresentation +import kotlin.properties.Delegates.observable + +class CommitAuthorComponent : NonOpaquePanel(HorizontalLayout(0)) { + private val viewer: VcsUserViewer = VcsUserViewer() + + var commitAuthor by observable(null) { _, oldValue, newValue -> + if (oldValue == newValue) return@observable + + isVisible = newValue != null + viewer.user = newValue + } + + init { + isVisible = false + + add(JBLabel("by").apply { + foreground = getInactiveTextColor() + border = emptyRight(4) + }) + add(viewer) + } +} + +private class VcsUserViewer : LinkLabel(null, null) { + var user by observable(null) { _, oldValue, newValue -> + if (oldValue == newValue) return@observable + + text = newValue?.let { getShortPresentation(it) } + toolTipText = newValue?.let { escapeXmlEntities(it.toString()) } + } + + override fun getStatusBarText(): String = unescapeXmlEntities(super.getStatusBarText()) +} \ No newline at end of file