diff options
author | Kevin Sawicki | 2011-10-27 21:47:36 +0000 |
---|---|---|
committer | Kevin Sawicki | 2011-10-27 21:47:36 +0000 |
commit | 526db549cd36fe58291b3733a04a19f072524022 (patch) | |
tree | 3a52ed7f5fb9a0beb59c01979b1ce8e35bca118c /org.eclipse.mylyn.github.ui | |
parent | 22f22afb77dd76f302c55970a09a96cab145d782 (diff) | |
download | egit-github-526db549cd36fe58291b3733a04a19f072524022.tar.gz egit-github-526db549cd36fe58291b3733a04a19f072524022.tar.xz egit-github-526db549cd36fe58291b3733a04a19f072524022.zip |
Prompt on Gist creation when multiple repositories exist.
The repository selected will be used to create the Gist.
Change-Id: I734d4cb4985438309b71a04f2e01229591484372
Signed-off-by: Kevin Sawicki <kevin@github.com>
Diffstat (limited to 'org.eclipse.mylyn.github.ui')
5 files changed, 123 insertions, 14 deletions
diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/RepositorySelectionWizardPage.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/RepositorySelectionWizardPage.java index a7c70e0a..b7096d4b 100644 --- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/RepositorySelectionWizardPage.java +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/RepositorySelectionWizardPage.java @@ -370,7 +370,8 @@ public class RepositorySelectionWizardPage extends WizardPage { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - GitHubClient client = new GitHubClient(); + GitHubClient client = GitHub + .configureClient(new GitHubClient()); client.setCredentials(user, password); RepositoryService service = new RepositoryService(client); OrganizationService orgs = new OrganizationService(client); diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/CreateGistHandler.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/CreateGistHandler.java index 624e62d1..14a0454f 100644 --- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/CreateGistHandler.java +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/CreateGistHandler.java @@ -28,7 +28,8 @@ import org.eclipse.egit.github.core.service.GistService; import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.mylyn.internal.github.core.GitHub; +import org.eclipse.jface.window.Window; +import org.eclipse.mylyn.internal.github.core.gist.GistConnector; import org.eclipse.mylyn.internal.github.ui.GitHubUi; import org.eclipse.mylyn.tasks.core.TaskRepository; import org.eclipse.ui.IEditorInput; @@ -64,9 +65,9 @@ public class CreateGistHandler extends AbstractHandler { * TODO replace this with HandlerUtil.getActiveEditorInput(ExecutionEvent) * as soon as we don't support Eclipse 3.6 anymore copied from HandlerUtil * in 3.7 to be able to run this on 3.6 - * + * * Return the input of the active editor. - * + * * @param event * The execution event that contains the application context * @return the input of the active editor, or <code>null</code>. @@ -116,7 +117,7 @@ public class CreateGistHandler extends AbstractHandler { } if (name == null) name = DEFAULT_FILENAME; - createGistJob(name, text.getText(), isPublic); + createGistJob(event, name, text.getText(), isPublic); } else if (selection instanceof IStructuredSelection) { IStructuredSelection structuredSelection = (IStructuredSelection) selection; Object obj = structuredSelection.getFirstElement(); @@ -126,19 +127,30 @@ public class CreateGistHandler extends AbstractHandler { else if (obj instanceof IAdaptable) file = (IFile) ((IAdaptable) obj).getAdapter(IFile.class); if (file != null) - createGistJob(file, isPublic); + createGistJob(event, file, isPublic); } return null; } - private void createGistJob(String name, String contents, boolean isPublic) { + private void createGistJob(ExecutionEvent event, String name, + String contents, boolean isPublic) { Set<TaskRepository> repositories = GistConnectorUi.getRepositories(); + if (repositories.isEmpty()) + return; - // only use the first repository, in the future provide a - // selection if multiple exist - TaskRepository repository = repositories.iterator().next(); - GitHubClient client = GitHub.configureClient(new GitHubClient()); - GitHub.addCredentials(client, repository); + TaskRepository repository = null; + // Prompt for repository selection if more than one + if (repositories.size() > 1) { + GistConnectorSelectionDialog dialog = new GistConnectorSelectionDialog( + HandlerUtil.getActiveShell(event), repositories); + if (Window.OK == dialog.open()) + repository = (TaskRepository) dialog.getResult()[0]; + } else + repository = repositories.iterator().next(); + if (repository == null) + return; + + GitHubClient client = GistConnector.createClient(repository); GistService service = new GistService(client); CreateGistJob job = new CreateGistJob( Messages.CreateGistHandler_CreateGistJobName, name, contents, @@ -146,7 +158,8 @@ public class CreateGistHandler extends AbstractHandler { job.schedule(); } - private void createGistJob(IFile file, boolean isPublic) { + private void createGistJob(ExecutionEvent event, IFile file, + boolean isPublic) { BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(file.getContents())); @@ -156,7 +169,7 @@ public class CreateGistHandler extends AbstractHandler { result.append(line).append('\n'); String contents = result.toString(); - createGistJob(file.getName(), contents, isPublic); + createGistJob(event, file.getName(), contents, isPublic); } catch (CoreException e) { GitHubUi.logError(e); } catch (IOException e) { diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistConnectorSelectionDialog.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistConnectorSelectionDialog.java new file mode 100644 index 00000000..955c4f6c --- /dev/null +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistConnectorSelectionDialog.java @@ -0,0 +1,87 @@ +/****************************************************************************** + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Kevin Sawicki (GitHub Inc.) - initial API and implementation + *****************************************************************************/ +package org.eclipse.mylyn.internal.github.ui.gist; + +import java.util.Collection; +import java.util.Collections; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.DecoratingLabelProvider; +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.IDoubleClickListener; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.mylyn.internal.tasks.ui.views.TaskRepositoryLabelProvider; +import org.eclipse.mylyn.tasks.core.TaskRepository; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.dialogs.SelectionDialog; + +/** + * Dialog to select a Gist task repository + */ +public class GistConnectorSelectionDialog extends SelectionDialog { + + private final Collection<TaskRepository> repos; + + /** + * @param parentShell + * @param repositories + */ + public GistConnectorSelectionDialog(Shell parentShell, + Collection<TaskRepository> repositories) { + super(parentShell); + setTitle(Messages.GistConnectorSelectionDialog_Title); + setMessage(Messages.GistConnectorSelectionDialog_Message); + repos = repositories; + } + + protected Control createDialogArea(Composite parent) { + Composite c = (Composite) super.createDialogArea(parent); + + createMessageArea(c); + + TableViewer viewer = new TableViewer(c, SWT.SINGLE | SWT.FULL_SELECTION + | SWT.V_SCROLL | SWT.H_SCROLL); + GridDataFactory.fillDefaults().grab(true, true) + .applyTo(viewer.getControl()); + viewer.setContentProvider(ArrayContentProvider.getInstance()); + viewer.setLabelProvider(new DecoratingLabelProvider( + new TaskRepositoryLabelProvider(), PlatformUI.getWorkbench() + .getDecoratorManager().getLabelDecorator())); + viewer.setInput(repos); + viewer.addDoubleClickListener(new IDoubleClickListener() { + + public void doubleClick(DoubleClickEvent event) { + Object selected = ((IStructuredSelection) event.getSelection()) + .getFirstElement(); + setResult(Collections.singletonList(selected)); + okPressed(); + } + }); + viewer.addSelectionChangedListener(new ISelectionChangedListener() { + + public void selectionChanged(SelectionChangedEvent event) { + Object selected = ((IStructuredSelection) event.getSelection()) + .getFirstElement(); + setResult(Collections.singletonList(selected)); + } + }); + + return c; + } +} diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/Messages.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/Messages.java index b31c941b..0faa211b 100644 --- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/Messages.java +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/Messages.java @@ -59,6 +59,12 @@ public class Messages extends NLS { public static String GistAttachmentPart_PartName; /** */ + public static String GistConnectorSelectionDialog_Message; + + /** */ + public static String GistConnectorSelectionDialog_Title; + + /** */ public static String GistConnectorUi_LabelTaskKind; /** */ diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/messages.properties b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/messages.properties index 9f905887..8d32f2dd 100644 --- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/messages.properties +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/messages.properties @@ -11,6 +11,8 @@ GistAttachmentPage_LabelBinaryWarning=Note: Binary content in Gist attachments i GistAttachmentPage_LabelFile=File: GistAttachmentPage_Title=File Settings GistAttachmentPart_PartName=Files +GistConnectorSelectionDialog_Message=Select a Gist task repository: +GistConnectorSelectionDialog_Title=Gist Repositories GistConnectorUi_LabelTaskKind=Gist GistNotificationPopup_GistLink=<a>Gist {0} created</a> GistNotificationPopup_GistTitle=Title: {0} |