diff options
author | Michael Keppler | 2019-08-03 17:13:39 +0000 |
---|---|---|
committer | Michael Keppler | 2019-08-15 05:39:16 +0000 |
commit | 3742c81bfc1e99c5ecaf558eace056a786e2aeaf (patch) | |
tree | 66d8ad543ce705e0edb616941fc439cd51dc6d4b | |
parent | e48ed04cd3f86f698c453ca6295621cde7501157 (diff) | |
download | egit-3742c81bfc1e99c5ecaf558eace056a786e2aeaf.tar.gz egit-3742c81bfc1e99c5ecaf558eace056a786e2aeaf.tar.xz egit-3742c81bfc1e99c5ecaf558eace056a786e2aeaf.zip |
Bind F2 on repo node to rename of current branch
Add the ability to use F2 directly on the repository node to rename the
current branch instead of first having to expand all nodes to the
current branch.
It would have been possible to use the existing eclipse.ui.edit.rename
command (and just to add to the existing activeWhen expression), but
that has the bad side effect of the command still being labeled "Rename"
in Ctrl-3, when invoked on the repository. Therefore the old rename
handler has been attached to the rename branch command instead and a
separate key binding has been added to the repositry view, to override
the generic F2 rename binding there.
Bug: 545290
Change-Id: Idf7fd3fd6f9fba00954d6b7318b11182dcd4cb69
Signed-off-by: Michael Keppler <Michael.Keppler@gmx.de>
-rw-r--r-- | org.eclipse.egit.ui/plugin.xml | 30 | ||||
-rw-r--r-- | org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/RenameBranchCommand.java | 32 |
2 files changed, 51 insertions, 11 deletions
diff --git a/org.eclipse.egit.ui/plugin.xml b/org.eclipse.egit.ui/plugin.xml index ff9d36fbbe..a8705ab8af 100644 --- a/org.eclipse.egit.ui/plugin.xml +++ b/org.eclipse.egit.ui/plugin.xml @@ -1940,14 +1940,26 @@ </activeWhen> </handler> <handler - commandId="org.eclipse.ui.edit.rename"> + commandId="org.eclipse.egit.ui.team.RenameBranch"> <class class="org.eclipse.egit.ui.internal.repository.tree.command.RenameBranchCommand"> </class> - <activeWhen> - <reference - definitionId="org.eclipse.egit.ui.singleRefNode"> - </reference> + <activeWhen> + <or> + <reference + definitionId="org.eclipse.egit.ui.singleRefNode"> + </reference> + <and> + <count + value="1"> + </count> + <iterate> + <instanceof + value="org.eclipse.egit.ui.internal.repository.tree.RepositoryNode"> + </instanceof> + </iterate> + </and> + </or> </activeWhen> </handler> <handler @@ -3684,7 +3696,7 @@ <visibleWhen checkEnabled="true" /> </command> <command - commandId="org.eclipse.ui.edit.rename" + commandId="org.eclipse.egit.ui.team.RenameBranch" icon="icons/obj16/editconfig.png" label="%RepoViewRenameBranch.label" style="push"> @@ -6694,6 +6706,12 @@ schemeId="org.eclipse.ui.defaultAcceleratorConfiguration" sequence="M1+C"> </key> + <key + commandId="org.eclipse.egit.ui.team.RenameBranch" + contextId="org.eclipse.egit.ui.RepositoriesView" + schemeId="org.eclipse.ui.defaultAcceleratorConfiguration" + sequence="F2"> + </key> </extension> <extension name="%HistoryViewCommands.extension.name" diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/RenameBranchCommand.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/RenameBranchCommand.java index ab38a8978a..88d8c55698 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/RenameBranchCommand.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/RenameBranchCommand.java @@ -13,26 +13,48 @@ *******************************************************************************/ package org.eclipse.egit.ui.internal.repository.tree.command; +import java.io.IOException; import java.util.List; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; +import org.eclipse.egit.ui.Activator; import org.eclipse.egit.ui.internal.dialogs.BranchRenameDialog; import org.eclipse.egit.ui.internal.repository.tree.RefNode; +import org.eclipse.egit.ui.internal.repository.tree.RepositoryNode; +import org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode; +import org.eclipse.jgit.lib.Constants; +import org.eclipse.jgit.lib.Ref; +import org.eclipse.jgit.lib.Repository; import org.eclipse.swt.widgets.Shell; /** * Renames a branch */ public class RenameBranchCommand extends - RepositoriesViewCommandHandler<RefNode> { + RepositoriesViewCommandHandler<RepositoryTreeNode> { @Override public Object execute(ExecutionEvent event) throws ExecutionException { - final List<RefNode> nodes = getSelectedNodes(event); - RefNode refNode = nodes.get(0); + final List<RepositoryTreeNode> nodes = getSelectedNodes(event); + RepositoryTreeNode node = nodes.get(0); - Shell shell = getShell(event); - new BranchRenameDialog(shell, refNode.getRepository(), refNode.getObject()).open(); + Repository repository = node.getRepository(); + Ref branch = null; + if (node instanceof RefNode) { + branch = (Ref) node.getObject(); + } else if (node instanceof RepositoryNode) { + try { + branch = repository + .exactRef(Constants.R_HEADS + repository.getBranch()); + } catch (IOException e) { + Activator.logError("Cannot rename branch", e); //$NON-NLS-1$ + } + } + + if (branch != null) { + Shell shell = getShell(event); + new BranchRenameDialog(shell, repository, branch).open(); + } return null; } } |