git-branches-dashboard: extract rename local branch action (IDEA-228598)

* make dedicated action for rename local branch instead of F2 key handler
* add standard keymaps for that action (e.g. F2, Shift F6)

GitOrigin-RevId: 2c58d40f2b7f3ae16b1fc61e6c267136ca4dc325
This commit is contained in:
Dmitry Zhuravlev
2019-12-25 11:37:26 +00:00
committed by intellij-monorepo-bot
parent f257538ca1
commit ae21cc374b
11 changed files with 45 additions and 32 deletions
@@ -1115,6 +1115,11 @@
<keyboard-shortcut first-keystroke="Shift F6"/>
</action>
<action id="Git.Rename.Local.Branch">
<keyboard-shortcut first-keystroke="F2" />
<keyboard-shortcut first-keystroke="Shift F6"/>
</action>
<action id="ChangesView.SetDefault">
<keyboard-shortcut first-keystroke="control SPACE" />
</action>
@@ -367,6 +367,9 @@
<action id="Git.Reword.Commit">
<keyboard-shortcut first-keystroke="shift alt R"/>
</action>
<action id="Git.Rename.Local.Branch">
<keyboard-shortcut first-keystroke="shift alt R"/>
</action>
<action id="ShelvedChanges.Rename">
<keyboard-shortcut first-keystroke="shift alt R"/>
</action>
@@ -393,6 +393,9 @@
<action id="Git.Reword.Commit">
<keyboard-shortcut first-keystroke="control R"/>
</action>
<action id="Git.Rename.Local.Branch">
<keyboard-shortcut first-keystroke="control R"/>
</action>
<action id="ChangesView.Rename">
<keyboard-shortcut first-keystroke="control R"/>
</action>
@@ -172,6 +172,9 @@
<action id="Git.Reword.Commit">
<keyboard-shortcut first-keystroke="control R" second-keystroke="R"/>
</action>
<action id="Git.Rename.Local.Branch">
<keyboard-shortcut first-keystroke="control R" second-keystroke="R"/>
</action>
<action id="ChangesView.Rename">
<keyboard-shortcut first-keystroke="control R" second-keystroke="R"/>
</action>
@@ -84,6 +84,9 @@
<action id="Git.Reword.Commit">
<keyboard-shortcut first-keystroke="control R" second-keystroke="R"/>
</action>
<action id="Git.Rename.Local.Branch">
<keyboard-shortcut first-keystroke="control R" second-keystroke="R"/>
</action>
<action id="ChangesView.Rename">
<keyboard-shortcut first-keystroke="control R" second-keystroke="R"/>
</action>
@@ -609,6 +609,10 @@
<keyboard-shortcut first-keystroke="control meta E"/>
<keyboard-shortcut first-keystroke="shift F6"/>
</action>
<action id="Git.Rename.Local.Branch">
<keyboard-shortcut first-keystroke="control meta E"/>
<keyboard-shortcut first-keystroke="shift F6"/>
</action>
<action id="Git.Commit.And.Push.Executor"/>
<action id="Hg.Commit.And.Push.Executor"/>
@@ -19,7 +19,7 @@ public abstract class KeymapsTestCase extends KeymapsTestCaseBase {
{ "ENTER", "Console.Execute", "Console.TableResult.EditValue", "DirDiffMenu.SynchronizeDiff", "EditorChooseLookupItem",
"EditorEnter", "Images.Thumbnails.EnterAction", "NextTemplateVariable",
"SearchEverywhere.SelectItem"},
{ "F2", "GotoNextError", "GuiDesigner.EditComponent", "GuiDesigner.EditGroup", "Console.TableResult.EditValue", "XDebugger.SetValue", "Arrangement.Rule.Edit", "Git.Reword.Commit", "ShelvedChanges.Rename", "ChangesView.Rename"},
{ "F2", "GotoNextError", "GuiDesigner.EditComponent", "GuiDesigner.EditGroup", "Console.TableResult.EditValue", "XDebugger.SetValue", "Arrangement.Rule.Edit", "Git.Reword.Commit", "Git.Rename.Local.Branch", "ShelvedChanges.Rename", "ChangesView.Rename"},
{ "alt ENTER", "ShowIntentionActions", "Console.TableResult.EditValue"},
{ "F5", "Graph.ApplyCurrentLayout", "CopyElement"},
{ "F7", "NextDiff", "StepInto"},
@@ -78,7 +78,7 @@ public abstract class KeymapsTestCase extends KeymapsTestCaseBase {
{ "shift DELETE", NO_DUPLICATES},
{ "shift ENTER", "CollapseExpandableComponent", "Console.TableResult.EditValueMaximized", "DatabaseView.PropertiesAction", "EditorStartNewLine", "ExpandExpandableComponent", "OpenElementInNewWindow", "JupyterRunCellSelectBelowAction"},
{ "shift F4", "Debugger.EditTypeSource", "EditSourceInNewWindow"},
{ "shift F6", "RenameElement", "Git.Reword.Commit", "ShelvedChanges.Rename", "ChangesView.Rename"},
{ "shift F6", "RenameElement", "Git.Reword.Commit", "Git.Rename.Local.Branch", "ShelvedChanges.Rename", "ChangesView.Rename"},
{ "shift F7", "PreviousDiff", "SmartStepInto"},
{ "shift TAB", "PreviousTemplateVariable", "PrevParameter", "EditorUnindentSelection", "PrevTemplateParameter", "SearchEverywhere.PrevTab"},
{ "shift alt ENTER", "Console.TableResult.EditValueMaximized", "JupyterDebugAction"},
@@ -268,7 +268,7 @@ public abstract class KeymapsTestCase extends KeymapsTestCaseBase {
{ "shift alt G", "RerunTests", "hg4idea.QGotoFromPatches"},
{ "shift alt L", "IntroduceVariable", "org.jetbrains.plugins.ruby.console.LoadInIrbConsoleAction", "context.load"},
{ "shift alt P", "hg4idea.QPushAction", "ImplementMethods"},
{ "shift alt R", "RenameElement", "Git.Reword.Commit", "ShelvedChanges.Rename", "ChangesView.Rename"},
{ "shift alt R", "RenameElement", "Git.Reword.Commit", "Git.Rename.Local.Branch", "ShelvedChanges.Rename", "ChangesView.Rename"},
{ "shift alt S", "ShowPopupMenu", "context.save"},
{ "shift alt T", "ShowPopupMenu", "tasks.switch"},
{ "shift control DOWN", "ResizeToolWindowDown", "MethodDown"},
@@ -296,7 +296,7 @@ public abstract class KeymapsTestCase extends KeymapsTestCaseBase {
{ "control DIVIDE", "CollapseRegionRecursively", "Images.Editor.ActualSize", "Graph.ActualSize"},
{ "control M", "Vcs.ShowMessageHistory", "Move"},
{ "control N", "NewElement", "FileChooser.NewFolder"},
{ "control R", "RenameElement", "org.jetbrains.plugins.ruby.rails.console.ReloadSources", "Git.Reword.Commit", "ShelvedChanges.Rename", "ChangesView.Rename"},
{ "control R", "RenameElement", "org.jetbrains.plugins.ruby.rails.console.ReloadSources", "Git.Reword.Commit", "Git.Rename.Local.Branch", "ShelvedChanges.Rename", "ChangesView.Rename"},
{ "control U", SECOND_STROKE, "CommanderSwapPanels"},
{ "control O", "GotoClass", "GotoChangedFile"},
{ "control PERIOD", "GotoNextError", "EditorChooseLookupItemDot"},
@@ -318,7 +318,7 @@ public abstract class KeymapsTestCase extends KeymapsTestCaseBase {
});
put("Eclipse (Mac OS X)", new String[][] {
{ "meta BACK_SPACE", "EditorDeleteToWordStart", "$Delete"},
{ "F2", "Console.TableResult.EditValue", "QuickJavaDoc", "XDebugger.SetValue", "Arrangement.Rule.Edit", "Git.Reword.Commit", "ShelvedChanges.Rename", "ChangesView.Rename"},
{ "F2", "Console.TableResult.EditValue", "QuickJavaDoc", "XDebugger.SetValue", "Arrangement.Rule.Edit", "Git.Reword.Commit", "Git.Rename.Local.Branch", "ShelvedChanges.Rename", "ChangesView.Rename"},
{ "F3", "GotoDeclaration", "EditSource"},
{ "F5", "StepInto", "Graph.ApplyCurrentLayout"},
{ "alt DOWN", "MoveStatementDown", "Arrangement.Rule.Match.Condition.Move.Down", "MethodOverloadSwitchDown", "ShowSearchHistory"},
@@ -346,7 +346,7 @@ public abstract class KeymapsTestCase extends KeymapsTestCaseBase {
{ "control shift alt Z", "Vcs.RollbackChangedLines", "ChangesView.Revert"},
});
put("Sublime Text", new String[][] {
{ "F2", "Arrangement.Rule.Edit", "ChangesView.Rename", "Console.TableResult.EditValue", "Git.Reword.Commit", "GotoNextBookmark", "GuiDesigner.EditComponent", "GuiDesigner.EditGroup", "ShelvedChanges.Rename", "XDebugger.SetValue"},
{ "F2", "Arrangement.Rule.Edit", "ChangesView.Rename", "Console.TableResult.EditValue", "Git.Reword.Commit", "Git.Rename.Local.Branch", "GotoNextBookmark", "GuiDesigner.EditComponent", "GuiDesigner.EditGroup", "ShelvedChanges.Rename", "XDebugger.SetValue"},
{ "ctrl ADD", "EditorIncreaseFontSize", "ExpandAll", "ExpandExpandableComponent"},
{ "ctrl D", "CompareTwoFiles", "Diff.ShowDiff", "FileChooser.GotoDesktop", "SelectNextOccurrence", "SendEOF"},
{ "ctrl ENTER", "Console.Execute.Multiline", "DirDiffMenu.SynchronizeDiff.All", "EditorStartNewLine", "JupyterRunCellAction", "PyExecuteCellAction", "ViewSource"},
@@ -368,7 +368,7 @@ public abstract class KeymapsTestCase extends KeymapsTestCaseBase {
{ "shift ctrl UP", "MoveLineUp", "ResizeToolWindowUp"}
});
put("Sublime Text (Mac OS X)", new String[][] {
{ "F2", "Arrangement.Rule.Edit", "ChangesView.Rename", "Console.TableResult.EditValue", "Git.Reword.Commit", "GotoNextBookmark", "GuiDesigner.EditComponent", "GuiDesigner.EditGroup", "ShelvedChanges.Rename", "XDebugger.SetValue"},
{ "F2", "Arrangement.Rule.Edit", "ChangesView.Rename", "Console.TableResult.EditValue", "Git.Reword.Commit", "Git.Rename.Local.Branch", "GotoNextBookmark", "GuiDesigner.EditComponent", "GuiDesigner.EditGroup", "ShelvedChanges.Rename", "XDebugger.SetValue"},
{ "meta ADD", "EditorIncreaseFontSize", "ExpandAll", "ExpandExpandableComponent"},
{ "meta BACK_SPACE", "EditorDeleteToLineStart", "$Delete"},
{ "meta D", "CompareTwoFiles", "Diff.ShowDiff", "FileChooser.GotoDesktop", "SelectNextOccurrence", "SendEOF"},
@@ -50,6 +50,8 @@
description="Undo last commit and put its changes into selected changelist"/>
<action id="Git.Reword.Commit" class="git4idea.rebase.GitRewordAction" text="Edit Commit Message..."
description="Change commit message via reword option of git rebase or amend" />
<action id="Git.Rename.Local.Branch" class="git4idea.ui.branch.dashboard.BranchesDashboardActions$RenameLocalBranch" text="Rename..."
description="Rename a local branch"/>
<action id="Git.Fixup.To.Commit" class="git4idea.rebase.GitCommitFixupBySubjectAction" text="Fixup..."
description="Create a fixup commit"/>
<action id="Git.Squash.Into.Commit" class="git4idea.rebase.GitCommitSquashBySubjectAction" text="Squash Into..."
@@ -319,16 +319,23 @@ internal object BranchesDashboardActions {
}
}
object RenameLocalBranchOnF2KeyPressHandler {
fun install(project: Project, treeComponent: BranchesTreeComponent) {
treeComponent.keyPressHandler = { clickedNode -> doRename(clickedNode, project) }
class RenameLocalBranch : BranchesActionBase() {
override fun update(e: AnActionEvent, project: Project, branches: Collection<BranchInfo>) {
if (branches.size > 1) {
e.presentation.isEnabled = false
return
}
val branch = branches.firstOrNull()
if (branch == null || !branch.isLocal || branch.repositories.any(Repository::isFresh)){
e.presentation.isEnabled = false
}
}
private fun doRename(clickedNode: BranchTreeNode, project: Project) {
val branchInfo = clickedNode.getNodeDescriptor().branchInfo ?: return
if (!branchInfo.isLocal || branchInfo.repositories.any(Repository::isFresh)) return
GitBranchPopupActions.LocalBranchActions.RenameBranchAction.rename(project, branchInfo.repositories, branchInfo.branchName)
override fun actionPerformed(e: AnActionEvent) {
val project = e.project!!
val branch = e.getData(GIT_BRANCHES)!!.firstOrNull() ?: return
GitBranchPopupActions.LocalBranchActions.RenameBranchAction.rename(project, branch.repositories, branch.branchName)
}
}
}
@@ -41,7 +41,6 @@ import git4idea.ui.branch.dashboard.BranchesDashboardActions.CheckoutLocalBranch
import git4idea.ui.branch.dashboard.BranchesDashboardActions.DeleteBranchAction
import git4idea.ui.branch.dashboard.BranchesDashboardActions.FetchAction
import git4idea.ui.branch.dashboard.BranchesDashboardActions.NewBranchAction
import git4idea.ui.branch.dashboard.BranchesDashboardActions.RenameLocalBranchOnF2KeyPressHandler
import git4idea.ui.branch.dashboard.BranchesDashboardActions.ShowBranchDiffAction
import git4idea.ui.branch.dashboard.BranchesDashboardActions.ShowMyBranchesAction
import git4idea.ui.branch.dashboard.BranchesDashboardActions.ToggleFavoriteAction
@@ -116,7 +115,6 @@ internal class BranchesDashboardUi(val project: Project) : Disposable {
private fun initMainUi() {
CheckoutLocalBranchOnDoubleClickHandler.install(project, tree.component)
RenameLocalBranchOnF2KeyPressHandler.install(project, tree.component)
val diffAction = ShowBranchDiffAction()
diffAction.registerCustomShortcutSet(KeymapUtil.getActiveKeymapShortcuts("Diff.ShowDiff"), branchesTreeWithLogPanel)
@@ -20,11 +20,9 @@ import git4idea.ui.branch.dashboard.BranchesDashboardActions.BranchesTreeActionG
import icons.DvcsImplIcons
import java.awt.GraphicsEnvironment
import java.awt.datatransfer.Transferable
import java.awt.event.KeyEvent
import java.awt.event.MouseEvent
import javax.swing.JComponent
import javax.swing.JTree
import javax.swing.KeyStroke
import javax.swing.TransferHandler
import javax.swing.border.Border
import javax.swing.event.TreeExpansionEvent
@@ -34,7 +32,6 @@ import javax.swing.tree.TreePath
internal class BranchesTreeComponent(project: Project) : DnDAwareTree(), DataProvider {
var doubleClickHandler: (BranchTreeNode) -> Unit = {}
var keyPressHandler: (BranchTreeNode) -> Unit = {}
var searchField: SearchTextField? = null
init {
@@ -43,7 +40,6 @@ internal class BranchesTreeComponent(project: Project) : DnDAwareTree(), DataPro
setShowsRootHandles(true)
isOpaque = false
installDoubleClickHandler()
installF2KeyPressHandler()
initDnD()
}
@@ -113,17 +109,6 @@ internal class BranchesTreeComponent(project: Project) : DnDAwareTree(), DataPro
}
}
private fun installF2KeyPressHandler() {
registerKeyboardAction({
val selectionPaths = selectionPaths ?: return@registerKeyboardAction
if (selectionPaths.size != 1) return@registerKeyboardAction
val node = selectionPaths.firstOrNull()?.lastPathComponent as? BranchTreeNode
if (node != null) {
keyPressHandler(node)
}
}, KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0), JComponent.WHEN_FOCUSED)
}
override fun getData(dataId: String): Any? {
if (GIT_BRANCHES.`is`(dataId)) {
return getSelectedBranches()