From 9b45a0189ebb550324176ab68edd2131790d2aa9 Mon Sep 17 00:00:00 2001 From: Thomas Wolf Date: Sat, 26 Oct 2019 23:34:52 +0200 Subject: [repo view] Bind "Rename Repository Group..." to standard rename Use the standard rename for this command handler, and also for the "Rename Branch..." when a Ref node is selected. These show up in Quick Access as "Rename the selected item...", which makes sense, and are bound to F2. Use the special RenameBranch command only when a repository node is selected. Add a key binding for F2 in a special context, and activate it only when a single repository is selected to avoid conflicts with the standard binding. This command shows up in Quick Access as "Rename Branch...". Change-Id: If95b79e83436afaa956593f0c971552eeddc5441 Signed-off-by: Thomas Wolf --- org.eclipse.egit.ui/META-INF/MANIFEST.MF | 1 + org.eclipse.egit.ui/plugin.properties | 2 - org.eclipse.egit.ui/plugin.xml | 81 ++++++++++++---------- .../ui/internal/repository/RepositoriesView.java | 58 +++++++++++++--- 4 files changed, 93 insertions(+), 49 deletions(-) diff --git a/org.eclipse.egit.ui/META-INF/MANIFEST.MF b/org.eclipse.egit.ui/META-INF/MANIFEST.MF index 74ea01a2a3..62525f3379 100644 --- a/org.eclipse.egit.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.egit.ui/META-INF/MANIFEST.MF @@ -32,6 +32,7 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.12.0,4.0.0)", org.eclipse.osgi.services;bundle-version="[3.5.100,4.0.0)", org.eclipse.e4.core.contexts;bundle-version="[1.5.1,2.0.0)", org.eclipse.e4.ui.workbench;bundle-version="[1.4.0,2.0.0)", + org.eclipse.ui.workbench;bundle-version="[3.108.0,4.0.0)", org.apache.ant;bundle-version="[1.10.5,2.0.0)" Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.8 diff --git a/org.eclipse.egit.ui/plugin.properties b/org.eclipse.egit.ui/plugin.properties index a267684e69..a341477a9e 100644 --- a/org.eclipse.egit.ui/plugin.properties +++ b/org.eclipse.egit.ui/plugin.properties @@ -296,9 +296,7 @@ CreateRepositoryGroupCommand.name = Create a Repository Group CreateRepositoryGroupCommand.label = Create a Repository &Group... CreateRepositoryGroupCommand.description = Create a repository group for structuring repositories in the Git Repositories view DeleteRepositoryGroupCommand.label = &Delete Repository Group... -RenameRepositoryGroupCommand.name = Rename Repository Group... RenameRepositoryGroupCommand.label = &Rename Repository Group... -RenameRepositoryGroupCommand.description = Change the name of the repository group RepositoryGroupMenu.label = Repository &Groups RepoViewAddRepository.tooltip = Add an existing local Git Repository to this view RepoViewCloneRepository.tooltip = Clone a Git Repository and add the clone to this view diff --git a/org.eclipse.egit.ui/plugin.xml b/org.eclipse.egit.ui/plugin.xml index 435fbfde68..4de2676861 100644 --- a/org.eclipse.egit.ui/plugin.xml +++ b/org.eclipse.egit.ui/plugin.xml @@ -1946,27 +1946,29 @@ + + + + + + + + - - - - - - - - - - - - + + + + + + + commandId="org.eclipse.ui.edit.rename"> @@ -3735,25 +3737,24 @@ style="push"> + - - - - - - - - - + + + + + + - + + + + + + - - @@ -6940,6 +6940,11 @@ name="%RepositoriesViewContext.name" parentId="org.eclipse.ui.contexts.window"> + + repositories = new HashSet<>(); @@ -264,6 +271,10 @@ public class RepositoriesView extends CommonNavigator implements IShowInSource, private final IPreferenceChangeListener configurationListener; + private IContextActivation renameContext; + + private IContextService ctxSrv; + /** * The default constructor */ @@ -496,6 +507,22 @@ public class RepositoriesView extends CommonNavigator implements IShowInSource, executeOpenCommand(element); } }); + ctxSrv = CommonUtils.getService(getSite(), IContextService.class); + viewer.addSelectionChangedListener(event -> { + handleSingleRepositoryContext(event.getSelection(), viewer); + }); + viewer.getTree().addFocusListener(new FocusListener() { + + @Override + public void focusLost(FocusEvent e) { + handleSingleRepositoryContext(null, viewer); + } + + @Override + public void focusGained(FocusEvent e) { + handleSingleRepositoryContext(viewer.getSelection(), viewer); + } + }); // react on selection changes ISelectionService srv = CommonUtils.getService(getSite(), ISelectionService.class); srv.addPostSelectionListener(selectionChangedListener); @@ -503,7 +530,7 @@ public class RepositoriesView extends CommonNavigator implements IShowInSource, repositoryUtil.getPreferences().addPreferenceChangeListener( configurationListener); initRepositoriesAndListeners(); - activateContextService(); + ctxSrv.activateContext(VIEW_ID); // link with editor viewer.addPostSelectionChangedListener(event -> { if (!((Boolean) reactOnSelection.getValue()).booleanValue()) { @@ -523,6 +550,7 @@ public class RepositoriesView extends CommonNavigator implements IShowInSource, showEditor((FileNode) selected); } }); + emptyArea.setBackground(viewer.getControl().getBackground()); if (!repositories.isEmpty()) layout.topControl = viewer.getControl(); @@ -532,6 +560,25 @@ public class RepositoriesView extends CommonNavigator implements IShowInSource, return viewer; } + private void handleSingleRepositoryContext(ISelection selection, + CommonViewer viewer) { + boolean activate = false; + if (selection != null && !selection.isEmpty() + && (selection instanceof StructuredSelection)) { + StructuredSelection sel = (StructuredSelection) selection; + Object item = sel.getFirstElement(); + activate = sel.size() == 1 && (item instanceof RepositoryNode); + } + if (!activate) { + if (renameContext != null) { + ctxSrv.deactivateContext(renameContext); + renameContext = null; + } + } else if (viewer.getTree().isFocusControl() && renameContext == null) { + renameContext = ctxSrv.activateContext(SINGLE_REPO_CONTEXT_ID); + } + } + private void executeOpenCommandWithConfirmation(RepositoryTreeNode element, String refName) { if (!BranchOperationUI.checkoutWillShowQuestionDialog(refName)) { @@ -581,13 +628,6 @@ public class RepositoriesView extends CommonNavigator implements IShowInSource, new StructuredSelection(node)); } - private void activateContextService() { - IContextService contextService = CommonUtils.getService(getSite(), IContextService.class); - if (contextService != null) { - contextService.activateContext(VIEW_ID); - } - } - private void initRepositoriesAndListeners() { synchronized (repositories) { repositories.clear(); -- cgit v1.2.3