From 84a4df2deee9c0a0593ebfdd0a21bbdfd02e43b9 Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Mon, 11 Jul 2022 11:36:06 +0200 Subject: [PATCH] vcs: cleanup GitOrigin-RevId: 7c1cc5307a4712666f5c171443b8044f76b655d9 --- .../vcs/changes/ui/CurrentBranchComponent.kt | 10 +++--- .../ui/DefaultCommitChangeListDialog.kt | 10 +++--- .../vcs/commit/ChangesViewCommitPanel.kt | 33 ++++++++----------- .../vcs/commit/CommitTabTitleUpdater.kt | 11 ++++--- 4 files changed, 31 insertions(+), 33 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CurrentBranchComponent.kt b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CurrentBranchComponent.kt index 1d2ba621c1af..153657944806 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CurrentBranchComponent.kt +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CurrentBranchComponent.kt @@ -30,7 +30,8 @@ import javax.swing.event.ChangeEvent import javax.swing.event.ChangeListener import kotlin.properties.Delegates.observable -class CurrentBranchComponent(private val tree: ChangesTree) : JBLabel(), Disposable { +class CurrentBranchComponent(private val tree: ChangesTree, + private val pathsProvider: () -> Iterable) : JBLabel(), Disposable { private val changeEventDispatcher = EventDispatcher.create(ChangeListener::class.java) private var branches: Set by observable(setOf()) { _, oldValue, newValue -> @@ -51,10 +52,6 @@ class CurrentBranchComponent(private val tree: ChangesTree) : JBLabel(), Disposa val project: Project get() = tree.project - var pathsProvider: () -> Iterable by observable({ emptyList() }) { _, _, _ -> - refresh() - } - init { isVisible = false icon = AllIcons.Vcs.Branch @@ -67,6 +64,8 @@ class CurrentBranchComponent(private val tree: ChangesTree) : JBLabel(), Disposa } tree.addPropertyChangeListener(treeChangeListener) Disposer.register(this, Disposable { tree.removePropertyChangeListener(treeChangeListener) }) + + refresh() } fun addChangeListener(block: () -> Unit, parent: Disposable) = @@ -89,6 +88,7 @@ class CurrentBranchComponent(private val tree: ChangesTree) : JBLabel(), Disposa get() = namedDouble("VersionControl.RefLabel.backgroundBrightness", 0.08) private val BACKGROUND_BASE_COLOR = namedColor("VersionControl.RefLabel.backgroundBase", JBColor(Color.BLACK, Color.WHITE)) + @JvmField val TEXT_COLOR: JBColor = namedColor("VersionControl.RefLabel.foreground", JBColor(Color(0x7a7a7a), Color(0x909090))) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/DefaultCommitChangeListDialog.kt b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/DefaultCommitChangeListDialog.kt index 4124f3ca850c..ddf54b1d4966 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/DefaultCommitChangeListDialog.kt +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/DefaultCommitChangeListDialog.kt @@ -12,8 +12,9 @@ import com.intellij.util.ui.JBUI.Borders.emptyRight import com.intellij.util.ui.JBUI.Panels.simplePanel import com.intellij.util.ui.UIUtil.addBorder import com.intellij.util.ui.UIUtil.getRegularPanelInsets -import com.intellij.vcs.commit.* import com.intellij.vcs.commit.NonModalCommitPromoter +import com.intellij.vcs.commit.SingleChangeListCommitWorkflow +import com.intellij.vcs.commit.SingleChangeListCommitWorkflowUi import com.intellij.vcs.commit.getDisplayedPaths import java.awt.Dimension import javax.swing.JComponent @@ -30,10 +31,9 @@ class DefaultCommitChangeListDialog(workflow: SingleChangeListCommitWorkflow) : init { LineStatusTrackerManager.getInstanceImpl(project).resetExcludedFromCommitMarkers() - val branchComponent = CurrentBranchComponent(browser.viewer).apply { - Disposer.register(this@DefaultCommitChangeListDialog, this) - pathsProvider = { getDisplayedPaths() } - } + val branchComponent = CurrentBranchComponent(browser.viewer, pathsProvider = { getDisplayedPaths() }) + Disposer.register(this, branchComponent) + addBorder(branchComponent, emptyRight(16)) browserBottomPanel.add(branchComponent) 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 0f24cea3d318..dcd0fcf78653 100644 --- a/platform/vcs-impl/src/com/intellij/vcs/commit/ChangesViewCommitPanel.kt +++ b/platform/vcs-impl/src/com/intellij/vcs/commit/ChangesViewCommitPanel.kt @@ -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.vcs.commit +import com.intellij.openapi.Disposable import com.intellij.openapi.actionSystem.DataContext import com.intellij.openapi.ui.popup.JBPopup import com.intellij.openapi.util.Disposer @@ -66,10 +67,8 @@ class ChangesViewCommitPanel(private val changesViewHost: ChangesViewPanel) : support.installSearch(commitMessage.editorField, commitMessage.editorField) } - with(changesView) { - setInclusionListener { fireInclusionChanged() } - isShowCheckboxes = true - } + changesView.setInclusionListener { fireInclusionChanged() } + changesView.isShowCheckboxes = true changesViewHost.statusComponent = CommitStatusPanel(this).apply { border = emptyRight(6) @@ -77,7 +76,7 @@ class ChangesViewCommitPanel(private val changesViewHost: ChangesViewPanel) : addToLeft(toolbarPanel) } - ChangesViewCommitTabTitleUpdater(this).start() + ChangesViewCommitTabTitleUpdater(changesView, this, this).start() commitActionsPanel.isCommitButtonDefault = { !progressPanel.isDumbMode && @@ -210,10 +209,8 @@ class ChangesViewCommitPanel(private val changesViewHost: ChangesViewPanel) : override fun dispose() { changesViewHost.statusComponent = null - with(changesView) { - isShowCheckboxes = false - setInclusionListener(null) - } + changesView.isShowCheckboxes = false + changesView.setInclusionListener(null) } } @@ -236,17 +233,15 @@ private class ChangesViewCommitProgressPanel( } } -private class ChangesViewCommitTabTitleUpdater(private val commitPanel: ChangesViewCommitPanel) : - CommitTabTitleUpdater(commitPanel.changesView, LOCAL_CHANGES, { message("local.changes.tab") }), - ChangesViewContentManagerListener { - +private class ChangesViewCommitTabTitleUpdater(tree: ChangesTree, workflowUi: CommitWorkflowUi, disposable: Disposable) + : CommitTabTitleUpdater(tree, LOCAL_CHANGES, { message("local.changes.tab") }, + pathsProvider = { + val singleRoot = ProjectLevelVcsManager.getInstance(tree.project).allVersionedRoots.singleOrNull() + if (singleRoot != null) listOf(getFilePath(singleRoot)) else workflowUi.getDisplayedPaths() + }), + ChangesViewContentManagerListener { init { - Disposer.register(commitPanel, this) - - pathsProvider = { - val singleRoot = ProjectLevelVcsManager.getInstance(project).allVersionedRoots.singleOrNull() - if (singleRoot != null) listOf(getFilePath(singleRoot)) else commitPanel.getDisplayedPaths() - } + Disposer.register(disposable, this) } override fun start() { diff --git a/platform/vcs-impl/src/com/intellij/vcs/commit/CommitTabTitleUpdater.kt b/platform/vcs-impl/src/com/intellij/vcs/commit/CommitTabTitleUpdater.kt index 92bb10f44f93..f3a28180532b 100644 --- a/platform/vcs-impl/src/com/intellij/vcs/commit/CommitTabTitleUpdater.kt +++ b/platform/vcs-impl/src/com/intellij/vcs/commit/CommitTabTitleUpdater.kt @@ -12,13 +12,16 @@ import com.intellij.openapi.vcs.changes.ui.CurrentBranchComponent import com.intellij.ui.content.Content import com.intellij.util.ui.update.UiNotifyConnector.doWhenFirstShown -open class CommitTabTitleUpdater(val tree: ChangesTree, val tabName: String, val defaultTitle: () -> String?) : Disposable { - private val branchComponent = CurrentBranchComponent(tree).also { Disposer.register(this, it) } +open class CommitTabTitleUpdater(val tree: ChangesTree, + val tabName: String, + val defaultTitle: () -> String?, + pathsProvider: () -> Iterable) : Disposable { + private val branchComponent = CurrentBranchComponent(tree, pathsProvider).also { + Disposer.register(this, it) + } val project: Project get() = tree.project - var pathsProvider: () -> Iterable by branchComponent::pathsProvider - open fun start() { doWhenFirstShown(tree) { updateTab() } // as UI components could be created before tool window `Content`