Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Blewitt2010-06-04 00:15:50 +0000
committerMatthias Sohn2010-06-04 12:01:41 +0000
commit2854822da4c717e8df745486b440000639f80d49 (patch)
treec8d0a860e16b84b958436d11e85861ab8dc11e69
parent540bf4168ba8f133f7386e340c3d3e91c44414e5 (diff)
downloadegit-2854822da4c717e8df745486b440000639f80d49.tar.gz
egit-2854822da4c717e8df745486b440000639f80d49.tar.xz
egit-2854822da4c717e8df745486b440000639f80d49.zip
Allow Git repository to be pre-filled from clipboard
If the user has copied a clipboard already, then we can access that from the SWT clipboard. If it looks like a transport we know about (as reported by Transport.canHandleProtocol) then we pre-fill the connection dialog with that as the URI. Since we need to fill in the user/port combinations, refactor out the code which does this on keypress and instead call that function, but only once, and only after all the fields have been created. Bug: 315589 Change-Id: I2fd6f0d68b4908f938eb5b2df8cd4f99e674e74d Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/RepositorySelectionPage.java117
1 files changed, 71 insertions, 46 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/RepositorySelectionPage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/RepositorySelectionPage.java
index e080a5f10c..f5d89526ec 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/RepositorySelectionPage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/RepositorySelectionPage.java
@@ -32,10 +32,13 @@ import org.eclipse.jface.fieldassist.TextContentAdapter;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.transport.RemoteConfig;
+import org.eclipse.jgit.transport.Transport;
import org.eclipse.jgit.transport.URIish;
import org.eclipse.jgit.util.FS;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
@@ -49,6 +52,7 @@ import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.DirectoryDialog;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
@@ -161,7 +165,20 @@ public class RepositorySelectionPage extends BaseWizardPage {
this.uri = new URIish();
this.sourceSelection = sourceSelection;
- this.presetUri = presetUri;
+
+ String preset = null;
+ if (presetUri == null) {
+ Clipboard clippy = new Clipboard(Display.getCurrent());
+ String text = (String) clippy.getContents(TextTransfer.getInstance());
+ try {
+ if(Transport.canHandleProtocol(new URIish(text))) {
+ preset = text;
+ }
+ } catch (URISyntaxException e) {
+ preset = null;
+ }
+ }
+ this.presetUri = preset;
this.configuredRemotes = getUsableConfigs(configuredRemotes);
this.remoteConfig = selectDefaultRemoteConfig();
@@ -221,6 +238,9 @@ public class RepositorySelectionPage extends BaseWizardPage {
createUriPanel(panel);
+ if(presetUri != null)
+ updateFields(presetUri);
+
updateRemoteAndURIPanels();
setControl(panel);
@@ -299,51 +319,7 @@ public class RepositorySelectionPage extends BaseWizardPage {
uriText.setLayoutData(createFieldGridData());
uriText.addModifyListener(new ModifyListener() {
public void modifyText(final ModifyEvent e) {
- try {
- eventDepth++;
- if (eventDepth != 1)
- return;
-
- final URIish u = new URIish(uriText.getText());
- safeSet(hostText, u.getHost());
- safeSet(pathText, u.getPath());
- safeSet(userText, u.getUser());
- safeSet(passText, u.getPass());
-
- if (u.getPort() > 0)
- portText.setText(Integer.toString(u.getPort()));
- else
- portText.setText(""); //$NON-NLS-1$
-
- if (isFile(u))
- scheme.select(S_FILE);
- else if (isSSH(u))
- scheme.select(S_SSH);
- else {
- for (int i = 0; i < DEFAULT_SCHEMES.length; i++) {
- if (DEFAULT_SCHEMES[i].equals(u.getScheme())) {
- scheme.select(i);
- break;
- }
- }
- }
-
- updateAuthGroup();
- uri = u;
- } catch (URISyntaxException err) {
- // leave uriText as it is, but clean up underlying uri and
- // decomposed fields
- uri = new URIish();
- hostText.setText(""); //$NON-NLS-1$
- pathText.setText(""); //$NON-NLS-1$
- userText.setText(""); //$NON-NLS-1$
- passText.setText(""); //$NON-NLS-1$
- portText.setText(""); //$NON-NLS-1$
- scheme.select(0);
- } finally {
- eventDepth--;
- }
- checkPage();
+ updateFields(uriText.getText());
}
});
@@ -399,6 +375,7 @@ public class RepositorySelectionPage extends BaseWizardPage {
setURI(uri.setPath(nullString(pathText.getText())));
}
});
+
}
private Group createAuthenticationGroup(final Composite parent) {
@@ -917,4 +894,52 @@ public class RepositorySelectionPage extends BaseWizardPage {
.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
}
+
+ private void updateFields(final String text) {
+ try {
+ eventDepth++;
+ if (eventDepth != 1)
+ return;
+
+ final URIish u = new URIish(text);
+ safeSet(hostText, u.getHost());
+ safeSet(pathText, u.getPath());
+ safeSet(userText, u.getUser());
+ safeSet(passText, u.getPass());
+
+ if (u.getPort() > 0)
+ portText.setText(Integer.toString(u.getPort()));
+ else
+ portText.setText(""); //$NON-NLS-1$
+
+ if (isFile(u))
+ scheme.select(S_FILE);
+ else if (isSSH(u))
+ scheme.select(S_SSH);
+ else {
+ for (int i = 0; i < DEFAULT_SCHEMES.length; i++) {
+ if (DEFAULT_SCHEMES[i].equals(u.getScheme())) {
+ scheme.select(i);
+ break;
+ }
+ }
+ }
+
+ updateAuthGroup();
+ uri = u;
+ } catch (URISyntaxException err) {
+ // leave uriText as it is, but clean up underlying uri and
+ // decomposed fields
+ uri = new URIish();
+ hostText.setText(""); //$NON-NLS-1$
+ pathText.setText(""); //$NON-NLS-1$
+ userText.setText(""); //$NON-NLS-1$
+ passText.setText(""); //$NON-NLS-1$
+ portText.setText(""); //$NON-NLS-1$
+ scheme.select(0);
+ } finally {
+ eventDepth--;
+ }
+ checkPage();
+ }
}

Back to the top