diff options
Diffstat (limited to 'org.eclipse.egit.ui')
3 files changed, 57 insertions, 3 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/SwitchToMenu.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/SwitchToMenu.java index 11b06f065c..e6341b24f8 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/SwitchToMenu.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/SwitchToMenu.java @@ -95,7 +95,7 @@ public class SwitchToMenu extends ContributionItem implements return; Repository[] repositories = SelectionUtils - .getRepositories(handlerService.getCurrentState()); + .getAllRepositories(handlerService.getCurrentState()); if (repositories.length > 0) { createDynamicMenu(menu, repositories); 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 9f20713764..5b77d43a9f 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 @@ -148,7 +148,7 @@ public class SelectionPropertyTester extends AbstractPropertyTester { private boolean selectionContainsMoreThanOneRepository( Collection<?> collection, Object[] args) { IStructuredSelection selection = getStructuredSelection(collection); - Repository[] repos = SelectionUtils.getRepositories(selection); + Repository[] repos = SelectionUtils.getAllRepositories(selection); return testMultipleRepositoryProperties(Arrays.asList(repos), args); } diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/selection/SelectionUtils.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/selection/SelectionUtils.java index 338ccc273d..a550cfd48b 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/selection/SelectionUtils.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/selection/SelectionUtils.java @@ -83,7 +83,7 @@ public class SelectionUtils { * Retrieves all the repositories associated with the current selection. It * attempts to first identify the selections as projects and if that yields * an empty result, it then changes to adapt the selections to the - * repository class + * repository class. * * @param selection * @return array of repositories @@ -115,6 +115,60 @@ public class SelectionUtils { } /** + * Retrieves all the repositories associated with the current selection, + * even if associated with a folder instead of a project. If no repository + * can be determined for any object in the selection, returns an empty + * array. + * + * @param evaluationContext + * @return array of selected repositories + */ + @NonNull + public static Repository[] getAllRepositories( + @Nullable IEvaluationContext evaluationContext) { + return getAllRepositories(getSelection(evaluationContext)); + } + + /** + * Retrieves all the repositories associated with the current selection, + * even if associated with a folder instead of a project. If no repository + * can be determined for any object in the selection, returns an empty + * array. + * + * @param selection + * @return array of repositories; may include submodule or nested + * repositories + */ + @NonNull + public static Repository[] getAllRepositories( + @NonNull IStructuredSelection selection) { + if (selection.isEmpty()) { + return new Repository[0]; + } + Set<Object> elements = getSelectionContents(selection); + Set<Repository> repos = new LinkedHashSet<>(); + for (Object location : elements) { + Repository repo = null; + if (location instanceof Repository) { + repo = (Repository) location; + } else if (location instanceof IResource) { + repo = ResourceUtil.getRepository((IResource) location); + } else if (location instanceof IPath) { + repo = ResourceUtil.getRepository((IPath) location); + } else { + repo = Adapters.adapt(location, Repository.class); + } + if (repo != null) { + repos.add(repo); + } else { + // no repository found for one of the objects! + return new Repository[0]; + } + } + return repos.toArray(new Repository[0]); + } + + /** * @param evaluationContext * @return the single selected repository, or <code>null</code> */ |