diff options
author | Robin Stocker | 2014-09-08 11:20:25 +0000 |
---|---|---|
committer | Robin Stocker | 2014-09-12 16:39:09 +0000 |
commit | 265e5a1cf7530a3a8a46a7d0958d03b02b565bd6 (patch) | |
tree | c40d9790c4d89933fb562f15fc93b1e613a9b75a | |
parent | bd72d84eceaa4dac16cf8fd32d8cb2b32d023baf (diff) | |
download | egit-265e5a1cf7530a3a8a46a7d0958d03b02b565bd6.tar.gz egit-265e5a1cf7530a3a8a46a7d0958d03b02b565bd6.tar.xz egit-265e5a1cf7530a3a8a46a7d0958d03b02b565bd6.zip |
Add "Repository" submenu in Team menu of files and folders
Allows to access repository-wide actions such as Push, Pull, Fetch and
Switch To in the context menu of files and folders.
Hopefully, having these actions be in a submenu named "Repository"
should make it clear that they don't only act on the selected resource,
but the whole repository.
Bug: 302078
Change-Id: I0045efde5832ad94bbfe0f7b43f654640040ba54
Signed-off-by: Robin Stocker <robin@nibor.org>
-rw-r--r-- | org.eclipse.egit.ui/plugin.properties | 1 | ||||
-rw-r--r-- | org.eclipse.egit.ui/plugin.xml | 86 | ||||
-rw-r--r-- | org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/selection/SelectionPropertyTester.java | 68 |
3 files changed, 118 insertions, 37 deletions
diff --git a/org.eclipse.egit.ui/plugin.properties b/org.eclipse.egit.ui/plugin.properties index e0e4b5b7eb..766bddcacf 100644 --- a/org.eclipse.egit.ui/plugin.properties +++ b/org.eclipse.egit.ui/plugin.properties @@ -279,6 +279,7 @@ RepoViewPullCommand.name = Pull TeamPullCommand.name = Pull PullIntoCurrentBranch.tooltip = Pull changes from upstream into current branch RemoteSubMenu.label = R&emote +RepositorySubMenu.label = &Repository PushToUpstreamAction.label = &Push to Upstream PushToUpstreamAction.tooltip = Push current branch to upstream if configured or start push branch wizard FetchFromUpstreamAction.label = &Fetch from Upstream diff --git a/org.eclipse.egit.ui/plugin.xml b/org.eclipse.egit.ui/plugin.xml index 386b82e457..4d3ee37b7a 100644 --- a/org.eclipse.egit.ui/plugin.xml +++ b/org.eclipse.egit.ui/plugin.xml @@ -1192,7 +1192,7 @@ </class> <activeWhen> <or> - <test property="GitSelection.projectSingleRepository"> + <test property="GitSelection.resourcesSingleRepository"> </test> <and> <count @@ -3875,6 +3875,74 @@ name="org.eclipse.egit.ui.AdvancedSeparator"> </separator> <menu + label="%RepositorySubMenu.label"> + <visibleWhen + checkEnabled="false"> + <test + property="GitSelection.fileOrFolderInRepository"> + </test> + </visibleWhen> + <separator + name="group1" + visible="true"> + </separator> + <command + commandId="org.eclipse.egit.ui.team.SimplePush" + label="%PushToUpstreamAction.label" + style="push"> + </command> + <command + commandId="org.eclipse.egit.ui.team.SimpleFetch" + label="%FetchFromUpstreamAction.label" + style="push"> + </command> + <dynamic + class="org.eclipse.egit.ui.internal.actions.PushMenu" + id="org.eclipse.egit.ui.team.popup.Push"> + </dynamic> + <command + commandId="org.eclipse.egit.ui.team.Pull" + label="%RepoViewPullMenu.label" + style="push"> + </command> + <command + commandId="org.eclipse.egit.ui.PushHeadToGerrit" + label="%PushToGerritMenu.label" + style="push"> + <visibleWhen + checkEnabled="false"> + <test + property="GitSelection.fileOrFolderInRepository" + args="hasGerritConfiguration"> + </test> + </visibleWhen> + </command> + <command + commandId="org.eclipse.egit.ui.FetchGerritChange" + label="%FetchFromGerritCommand.label" + style="push"> + <visibleWhen + checkEnabled="false"> + <test + property="GitSelection.fileOrFolderInRepository" + args="hasGerritConfiguration"> + </test> + </visibleWhen> + </command> + <separator + name="group2" + visible="true"> + </separator> + <menu + label="%SwitchToMenu.label" + icon="icons/obj16/branches_obj.gif"> + <dynamic + class="org.eclipse.egit.ui.internal.actions.SwitchToMenu" + id="org.eclipse.egit.ui.switchToMenu"> + </dynamic> + </menu> + </menu> + <menu label="%AdvancedMenu.label"> <command commandId="org.eclipse.egit.ui.team.RenameBranch" @@ -4173,20 +4241,6 @@ </test> </visibleWhen> </command> - <menu - label="Repository"> - <visibleWhen - checkEnabled="false"> - <test - property="Foo.bar"> - </test> - </visibleWhen> - <command - commandId="org.eclipse.egit.ui.team.SimplePush" - label="%PushToUpstreamAction.label" - style="push"> - </command> - </menu> </menu> </menuContribution> <menuContribution @@ -4792,7 +4846,7 @@ class="org.eclipse.egit.ui.internal.selection.SelectionPropertyTester" id="org.eclipse.egit.ui.SelectionTester" namespace="GitSelection" - properties="projectSingleRepository,projectsWithRepositories,resourcesSingleRepository" + properties="projectSingleRepository,projectsWithRepositories,resourcesSingleRepository,fileOrFolderInRepository" type="java.util.Collection"> </propertyTester> </extension> diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/selection/SelectionPropertyTester.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/selection/SelectionPropertyTester.java index 78b078a4be..3527f524f5 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/selection/SelectionPropertyTester.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/selection/SelectionPropertyTester.java @@ -12,6 +12,8 @@ import java.util.ArrayList; import java.util.Collection; import org.eclipse.core.expressions.PropertyTester; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IAdaptable; @@ -32,37 +34,21 @@ public class SelectionPropertyTester extends PropertyTester { public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { Collection<?> collection = (Collection<?>) receiver; + if (collection.isEmpty()) + return false; if ("projectSingleRepository".equals(property)) { //$NON-NLS-1$ if (collection.size() != 1) return false; Repository repository = getRepositoryOfProjects(collection, true); - if (repository == null) - return false; - - for (Object arg : args) { - String s = (String) arg; - if (!ResourcePropertyTester.testRepositoryState(repository, s)) - return false; - } - return true; + return testRepositoryProperties(repository, args); } else if ("projectsWithRepositories".equals(property)) { //$NON-NLS-1$ Repository repository = getRepositoryOfProjects(collection, false); return repository != null; } else if ("resourcesSingleRepository".equals(property)) { //$NON-NLS-1$ - if (collection.isEmpty()) - return false; - - Object firstElement = collection.iterator().next(); - IStructuredSelection selection; - if (collection.size() == 1 && firstElement instanceof ITextSelection) { - selection = SelectionUtils.getStructuredSelection((ITextSelection) firstElement); - } else { - selection = new StructuredSelection(new ArrayList<Object>( - collection)); - } + IStructuredSelection selection = getStructuredSelection(collection); // It may seem like we could just use SelectionUtils.getRepository // here. The problem: It would also return a repository for a node @@ -70,11 +56,51 @@ public class SelectionPropertyTester extends PropertyTester { IResource[] resources = SelectionUtils .getSelectedResources(selection); Repository repository = getRepositoryOfResources(resources); - return repository != null; + return testRepositoryProperties(repository, args); + + } else if ("fileOrFolderInRepository".equals(property)) { //$NON-NLS-1$ + if (collection.size() != 1) + return false; + + IStructuredSelection selection = getStructuredSelection(collection); + if (selection.size() != 1) + return false; + + Object firstElement = selection.getFirstElement(); + IResource resource = AdapterUtils.adapt(firstElement, + IResource.class); + if (resource instanceof IFile || resource instanceof IFolder) { + RepositoryMapping m = RepositoryMapping.getMapping(resource); + if (m != null) + return testRepositoryProperties(m.getRepository(), args); + } } return false; } + private static IStructuredSelection getStructuredSelection( + Collection<?> collection) { + Object firstElement = collection.iterator().next(); + if (collection.size() == 1 && firstElement instanceof ITextSelection) + return SelectionUtils + .getStructuredSelection((ITextSelection) firstElement); + else + return new StructuredSelection(new ArrayList<Object>(collection)); + } + + private static boolean testRepositoryProperties(Repository repository, + Object[] properties) { + if (repository == null) + return false; + + for (Object arg : properties) { + String s = (String) arg; + if (!ResourcePropertyTester.testRepositoryState(repository, s)) + return false; + } + return true; + } + /** * @param collection * the selected elements |