Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2019-06-24 20:27:21 +0000
committerThomas Wolf2019-06-24 21:04:18 +0000
commit58ba9fb83ae041fabed390261a79a7f34f40f9f3 (patch)
treed6cb213b3766cac4fed51e0e09e2f8959b1002e2 /org.eclipse.egit.ui
parent2a6d24376833d10036f81a79d8423be4a5c59b3c (diff)
downloadegit-58ba9fb83ae041fabed390261a79a7f34f40f9f3.tar.gz
egit-58ba9fb83ae041fabed390261a79a7f34f40f9f3.tar.xz
egit-58ba9fb83ae041fabed390261a79a7f34f40f9f3.zip
Enable the "Switch To..." menu for submodule folders
Commits 1f69fad3 and e4dc3eaf from the multi-repository branch switch had the effect that the "Switch To..." menu didn't work anymore for submodule folders in the package or project explorer. Add a new operation SelectionUtils.getAllRepositories() and use it in SwitchToMenu. Changing the existing SelectionUtils.getRepositories() to also return repositories for folders was deemed too risky since that would have changed the behavior of the multi-repository pull, which has always worked only for folders. Enabling that to also handle submodule folders might be an idea for a future commit, but might need more tests. Add a new test. The test only verifies that the menu has content by trying to invoke "New Branch..." and then closing the resulting "Create Branch" dialog. Interestingly this test succeeds even without the fix, which matches the experience described in the bug report: the problem could only be observed in official packages, but not in my development setup. Change verified manually by actually building EGit and installing it into standard Eclipse packages. Bug: 548158 Change-Id: Ic67578b46a89687a6bcfe73ef3d2d3d71d2a39e0 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.egit.ui')
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/SwitchToMenu.java2
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/selection/SelectionPropertyTester.java2
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/selection/SelectionUtils.java56
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>
*/

Back to the top