From ae21cc374b7b2ffd8e76f7025b0f7ac03b0f4796 Mon Sep 17 00:00:00 2001 From: Dmitry Zhuravlev Date: Mon, 16 Dec 2019 18:38:17 +0300 Subject: [PATCH] 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 --- .../src/keymaps/$default.xml | 5 ++++ .../src/keymaps/Eclipse.xml | 3 +++ .../src/keymaps/NetBeans 6.5.xml | 3 +++ .../src/keymaps/ReSharper OSX.xml | 3 +++ .../src/keymaps/ReSharper.xml | 3 +++ .../platform-resources/src/keymaps/Xcode.xml | 4 ++++ .../com/intellij/keymap/KeymapsTestCase.java | 14 +++++------ .../git4idea/resources/META-INF/plugin.xml | 2 ++ .../dashboard/BranchesDashboardActions.kt | 23 ++++++++++++------- .../branch/dashboard/BranchesDashboardUi.kt | 2 -- .../ui/branch/dashboard/BranchesTree.kt | 15 ------------ 11 files changed, 45 insertions(+), 32 deletions(-) diff --git a/platform/platform-resources/src/keymaps/$default.xml b/platform/platform-resources/src/keymaps/$default.xml index 8a038759a9ae..dc6552b4540b 100644 --- a/platform/platform-resources/src/keymaps/$default.xml +++ b/platform/platform-resources/src/keymaps/$default.xml @@ -1115,6 +1115,11 @@ + + + + + diff --git a/platform/platform-resources/src/keymaps/Eclipse.xml b/platform/platform-resources/src/keymaps/Eclipse.xml index 2a53a7776989..a374e89726b0 100644 --- a/platform/platform-resources/src/keymaps/Eclipse.xml +++ b/platform/platform-resources/src/keymaps/Eclipse.xml @@ -367,6 +367,9 @@ + + + diff --git a/platform/platform-resources/src/keymaps/NetBeans 6.5.xml b/platform/platform-resources/src/keymaps/NetBeans 6.5.xml index 4c8372edf7e0..8f6c416d6edf 100644 --- a/platform/platform-resources/src/keymaps/NetBeans 6.5.xml +++ b/platform/platform-resources/src/keymaps/NetBeans 6.5.xml @@ -393,6 +393,9 @@ + + + diff --git a/platform/platform-resources/src/keymaps/ReSharper OSX.xml b/platform/platform-resources/src/keymaps/ReSharper OSX.xml index 8c48c55bc17d..1e642a1a4b73 100755 --- a/platform/platform-resources/src/keymaps/ReSharper OSX.xml +++ b/platform/platform-resources/src/keymaps/ReSharper OSX.xml @@ -172,6 +172,9 @@ + + + diff --git a/platform/platform-resources/src/keymaps/ReSharper.xml b/platform/platform-resources/src/keymaps/ReSharper.xml index e79f0a1ab0d8..f3150daa4e19 100755 --- a/platform/platform-resources/src/keymaps/ReSharper.xml +++ b/platform/platform-resources/src/keymaps/ReSharper.xml @@ -84,6 +84,9 @@ + + + diff --git a/platform/platform-resources/src/keymaps/Xcode.xml b/platform/platform-resources/src/keymaps/Xcode.xml index a031bcd1146d..d11d041bb485 100644 --- a/platform/platform-resources/src/keymaps/Xcode.xml +++ b/platform/platform-resources/src/keymaps/Xcode.xml @@ -609,6 +609,10 @@ + + + + diff --git a/platform/testFramework/extensions/src/com/intellij/keymap/KeymapsTestCase.java b/platform/testFramework/extensions/src/com/intellij/keymap/KeymapsTestCase.java index ef987182f41a..8e37bfa5b6b0 100644 --- a/platform/testFramework/extensions/src/com/intellij/keymap/KeymapsTestCase.java +++ b/platform/testFramework/extensions/src/com/intellij/keymap/KeymapsTestCase.java @@ -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"}, diff --git a/plugins/git4idea/resources/META-INF/plugin.xml b/plugins/git4idea/resources/META-INF/plugin.xml index c613aaacc7cf..357b98a7d2e8 100644 --- a/plugins/git4idea/resources/META-INF/plugin.xml +++ b/plugins/git4idea/resources/META-INF/plugin.xml @@ -50,6 +50,8 @@ description="Undo last commit and put its changes into selected changelist"/> + doRename(clickedNode, project) } + class RenameLocalBranch : BranchesActionBase() { + + override fun update(e: AnActionEvent, project: Project, branches: Collection) { + 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) } } } diff --git a/plugins/git4idea/src/git4idea/ui/branch/dashboard/BranchesDashboardUi.kt b/plugins/git4idea/src/git4idea/ui/branch/dashboard/BranchesDashboardUi.kt index 82e8818776a7..6fbbca07faf3 100644 --- a/plugins/git4idea/src/git4idea/ui/branch/dashboard/BranchesDashboardUi.kt +++ b/plugins/git4idea/src/git4idea/ui/branch/dashboard/BranchesDashboardUi.kt @@ -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) diff --git a/plugins/git4idea/src/git4idea/ui/branch/dashboard/BranchesTree.kt b/plugins/git4idea/src/git4idea/ui/branch/dashboard/BranchesTree.kt index 333968eda026..d545a8eba12f 100644 --- a/plugins/git4idea/src/git4idea/ui/branch/dashboard/BranchesTree.kt +++ b/plugins/git4idea/src/git4idea/ui/branch/dashboard/BranchesTree.kt @@ -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()