From c86317db9d702c856c8c07c3c5c8a49f7e2e0e56 Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Wed, 30 Dec 2009 17:10:00 +0100 Subject: [PATCH] Fix sharing wizard page "Select Git Repository Location" Enable selection of alternative repository mappings and highlight the selected row fully. Selection was not possible since treeItem didn't show selectable text in first column for alternative repository mappings (bug 296807). Re-establish multi-selection by displaying most likely mapping on tree top level and avoiding tree if only one git dir found (bug 297139). Fix rendering of git directory in column Repository - on Windows the relative path was prefixed with the device name e.g. C:.git instead of .git - on Windows backslash was used as separator before .git which is inconsistent: e.g. src/org\.git instead of src/org/.git Bug: 296807, 297139 Change-Id: Ie64d9e82609a62e4a117ed9e35156837b5d7b5b2 Signed-off-by: Matthias Sohn Signed-off-by: Stefan Lay --- .../egit/core/project/RepositoryMapping.java | 9 ++- .../ui/internal/sharing/ExistingOrNewPage.java | 69 +++++++++++++++------- 2 files changed, 55 insertions(+), 23 deletions(-) diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/project/RepositoryMapping.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/project/RepositoryMapping.java index c09a5955..6c399836 100644 --- a/org.eclipse.egit.core/src/org/eclipse/egit/core/project/RepositoryMapping.java +++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/project/RepositoryMapping.java @@ -83,8 +83,13 @@ public class RepositoryMapping { containerPath = container.getProjectRelativePath().toPortableString(); if (cLoc.isPrefixOf(gLoc)) { - gitdirPath = gLoc.removeFirstSegments( - gLoc.matchingFirstSegments(cLoc)).toPortableString(); + int matchingSegments = gLoc.matchingFirstSegments(cLoc); + IPath remainder = gLoc.removeFirstSegments(matchingSegments); + String device = remainder.getDevice(); + if (device == null) + gitdirPath = remainder.toPortableString(); + else + gitdirPath = remainder.toPortableString().substring(device.length()); } else if (gLocParent.isPrefixOf(cLoc)) { cnt = cLoc.segmentCount() - cLoc.matchingFirstSegments(gLocParent); p = ""; diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/sharing/ExistingOrNewPage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/sharing/ExistingOrNewPage.java index d880b814..a480d1ea 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/sharing/ExistingOrNewPage.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/sharing/ExistingOrNewPage.java @@ -14,8 +14,10 @@ import java.io.IOException; import java.net.URI; import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.Map; +import java.util.Set; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; @@ -31,7 +33,9 @@ import org.eclipse.egit.ui.UIText; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.jgit.lib.Repository; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.GridLayout; @@ -44,7 +48,6 @@ import org.eclipse.swt.widgets.Text; import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.TreeColumn; import org.eclipse.swt.widgets.TreeItem; -import org.eclipse.jgit.lib.Repository; /** * Wizard page for connecting projects to Git repositories. @@ -69,10 +72,34 @@ class ExistingOrNewPage extends WizardPage { Group g = new Group(parent, SWT.NONE); g.setLayout(new GridLayout(3,false)); g.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create()); - tree = new Tree(g, SWT.BORDER|SWT.MULTI); + tree = new Tree(g, SWT.BORDER|SWT.MULTI|SWT.FULL_SELECTION); tree.setHeaderVisible(true); tree.setLayout(new GridLayout()); tree.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).span(3,1).create()); + tree.addSelectionListener(new SelectionAdapter() { + + public void widgetSelected(SelectionEvent e) { + TreeItem t = (TreeItem) e.item; + for(TreeItem ti : t.getItems()) + tree.deselect(ti); + if (t.getParentItem() != null) { + tree.deselect(t.getParentItem()); + for(TreeItem ti : t.getParentItem().getItems()) + if (ti != t) + tree.deselect(ti); + } + Set projects = new HashSet(); + for (TreeItem treeItem : tree.getSelection()) { + if (treeItem.getData() == null && treeItem.getParentItem() != null) { + treeItem = treeItem.getParentItem(); + } + final IProject project = (IProject) treeItem.getData(); + if (projects.contains(project)) + tree.deselect(treeItem); + projects.add(project); + } + } + }); TreeColumn c1 = new TreeColumn(tree,SWT.NONE); c1.setText(UIText.ExistingOrNewPage_HeaderProject); c1.setWidth(100); @@ -88,27 +115,24 @@ class ExistingOrNewPage extends WizardPage { treeItem.setText(0, project.getName()); treeItem.setText(1, project.getLocation().toOSString()); RepositoryFinder repositoryFinder = new RepositoryFinder(project); - Collection find; + Collection mappings; try { - find = repositoryFinder.find(new NullProgressMonitor()); - Iterator mi = find.iterator(); - - // special case for a git repository in the project's root - final File gitDirInProjectRoot = project.getLocation().append( - ".git").toFile(); //$NON-NLS-1$ - if (!gitDirInProjectRoot.isDirectory()) { - // '.git/' isn't there, enable repository creation + mappings = repositoryFinder.find(new NullProgressMonitor()); + Iterator mi = mappings.iterator(); + RepositoryMapping m = mi.hasNext() ? mi.next() : null; + if (m == null) { + // no mapping found, enable repository creation treeItem.setText(2, ""); //$NON-NLS-1$ } else { - // '.git/' is there - fillTreeItemWithGitDirectory(mi.next(), treeItem); + // at least one mapping found + fillTreeItemWithGitDirectory(m, treeItem, false); } - while (mi.hasNext()) { - RepositoryMapping m = mi.next(); + while (mi.hasNext()) { // fill in additional mappings + m = mi.next(); TreeItem treeItem2 = new TreeItem(treeItem, SWT.NONE); treeItem2.setData(m.getContainer().getProject()); - fillTreeItemWithGitDirectory(m, treeItem2); + fillTreeItemWithGitDirectory(m, treeItem2, true); } } catch (CoreException e) { TreeItem treeItem2 = new TreeItem(treeItem, SWT.BOLD|SWT.ITALIC); @@ -183,14 +207,17 @@ class ExistingOrNewPage extends WizardPage { setControl(g); } - private void fillTreeItemWithGitDirectory(RepositoryMapping m, TreeItem treeItem2) { + private void fillTreeItemWithGitDirectory(RepositoryMapping m, TreeItem treeItem2, boolean isAlternative) { if (m.getGitDir() == null) treeItem2.setText(2, UIText.ExistingOrNewPage_SymbolicValueEmptyMapping); else { - String container = m.getContainerPath().toString(); - if (container.length() > 0) - container += File.separator; - treeItem2.setText(2, container + m.getGitDir()); + IPath container = m.getContainerPath(); + if (!container.isEmpty()) + container = container.addTrailingSeparator(); + IPath relativePath = container.append(m.getGitDir()); + if (isAlternative) + treeItem2.setText(0, relativePath.removeLastSegments(1).addTrailingSeparator().toString()); + treeItem2.setText(2, relativePath.toString()); } } -- 2.11.4.GIT