Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Keppler2019-08-03 13:13:39 -0400
committerMichael Keppler2019-08-15 01:39:16 -0400
commit3742c81bfc1e99c5ecaf558eace056a786e2aeaf (patch)
tree66d8ad543ce705e0edb616941fc439cd51dc6d4b /org.eclipse.egit.ui/src/org/eclipse
parente48ed04cd3f86f698c453ca6295621cde7501157 (diff)
downloadegit-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>
Diffstat (limited to 'org.eclipse.egit.ui/src/org/eclipse')
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/RenameBranchCommand.java32
1 files changed, 27 insertions, 5 deletions
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 ab38a8978..88d8c5569 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;
}
}

Back to the top