From 290dc663e2de7b7a295e756069ceafd7873fc621 Mon Sep 17 00:00:00 2001 From: Dmitry Zhuravlev Date: Wed, 22 Jan 2020 21:39:01 +0300 Subject: [PATCH] git-branches-dashboard: extract "checkout selected branch" action from branches tree double-click handler This will add ability to assign custom shortcut to this action or remove shortcut and completely disable such behavior if needed. GitOrigin-RevId: b493e7eae23eda5fad8c6f8e52c04d692b4e2771 --- .../git4idea/resources/META-INF/plugin.xml | 3 +++ .../resources/messages/GitBundle.properties | 2 ++ .../dashboard/BranchesDashboardActions.kt | 21 ++++++++++++------- .../branch/dashboard/BranchesDashboardUi.kt | 2 -- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/plugins/git4idea/resources/META-INF/plugin.xml b/plugins/git4idea/resources/META-INF/plugin.xml index f458a48eecbd..3479a2fd8bc3 100644 --- a/plugins/git4idea/resources/META-INF/plugin.xml +++ b/plugins/git4idea/resources/META-INF/plugin.xml @@ -45,6 +45,9 @@ + + + diff --git a/plugins/git4idea/resources/messages/GitBundle.properties b/plugins/git4idea/resources/messages/GitBundle.properties index 2491d3bb565a..12d5e8675d2e 100644 --- a/plugins/git4idea/resources/messages/GitBundle.properties +++ b/plugins/git4idea/resources/messages/GitBundle.properties @@ -278,6 +278,8 @@ action.Git.Fixup.To.Commit.text=Fixup... action.Git.Fixup.To.Commit.description=Create a fixup commit action.Git.Rename.Local.Branch.text=Rename... action.Git.Rename.Local.Branch.description=Rename a local branch +action.Git.Checkout.Branch.text=Checkout Selected... +action.Git.Checkout.Branch.description=Checkout selected branch action.Git.Reword.Commit.text=Edit Commit Message... action.Git.Reword.Commit.description=Change commit message via reword option of git rebase or amend action.Git.Uncommit.text=Undo Commit... diff --git a/plugins/git4idea/src/git4idea/ui/branch/dashboard/BranchesDashboardActions.kt b/plugins/git4idea/src/git4idea/ui/branch/dashboard/BranchesDashboardActions.kt index 583954cf9e89..b131c8018178 100644 --- a/plugins/git4idea/src/git4idea/ui/branch/dashboard/BranchesDashboardActions.kt +++ b/plugins/git4idea/src/git4idea/ui/branch/dashboard/BranchesDashboardActions.kt @@ -316,20 +316,25 @@ internal object BranchesDashboardActions { } } - object CheckoutLocalBranchOnDoubleClickHandler { - fun install(project: Project, treeComponent: BranchesTreeComponent) { - treeComponent.doubleClickHandler = { clickedNode -> doCheckout(clickedNode, project) } + class CheckoutSelectedBranchAction : BranchesActionBase() { + + override fun update(e: AnActionEvent, project: Project, branches: Collection) { + if (branches.size > 1) { + e.presentation.isEnabled = false + return + } } - private fun doCheckout(clickedNode: BranchTreeNode, project: Project) { - val branchInfo = clickedNode.getNodeDescriptor().branchInfo ?: return - if (branchInfo.isLocal) { + override fun actionPerformed(e: AnActionEvent) { + val project = e.project!! + val branch = e.getData(GIT_BRANCHES)!!.firstOrNull() ?: return + if (branch.isLocal) { GitBranchPopupActions.LocalBranchActions.CheckoutAction - .checkoutBranch(project, branchInfo.repositories, branchInfo.branchName) + .checkoutBranch(project, branch.repositories, branch.branchName) } else { GitBranchPopupActions.RemoteBranchActions.CheckoutRemoteBranchAction - .checkoutRemoteBranch(project, branchInfo.repositories, branchInfo.branchName) + .checkoutRemoteBranch(project, branch.repositories, branch.branchName) } } } diff --git a/plugins/git4idea/src/git4idea/ui/branch/dashboard/BranchesDashboardUi.kt b/plugins/git4idea/src/git4idea/ui/branch/dashboard/BranchesDashboardUi.kt index cefb5a763ec3..67f56fbbb0de 100644 --- a/plugins/git4idea/src/git4idea/ui/branch/dashboard/BranchesDashboardUi.kt +++ b/plugins/git4idea/src/git4idea/ui/branch/dashboard/BranchesDashboardUi.kt @@ -38,7 +38,6 @@ import com.intellij.vcs.log.ui.frame.VcsLogChangeProcessor import com.intellij.vcs.log.visible.VisiblePackRefresher import com.intellij.vcs.log.visible.VisiblePackRefresherImpl import com.intellij.vcs.log.visible.filters.VcsLogFilterObject -import git4idea.ui.branch.dashboard.BranchesDashboardActions.CheckoutLocalBranchOnDoubleClickHandler import git4idea.ui.branch.dashboard.BranchesDashboardActions.DeleteBranchAction import git4idea.ui.branch.dashboard.BranchesDashboardActions.FetchAction import git4idea.ui.branch.dashboard.BranchesDashboardActions.GroupByDirectoryAction @@ -121,7 +120,6 @@ internal class BranchesDashboardUi(val project: Project) : Disposable { } private fun initMainUi() { - CheckoutLocalBranchOnDoubleClickHandler.install(project, tree.component) val diffAction = ShowBranchDiffAction() diffAction.registerCustomShortcutSet(KeymapUtil.getActiveKeymapShortcuts("Diff.ShowDiff"), branchesTreeWithLogPanel)