Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Sawicki2011-05-17 00:46:29 +0000
committerKevin Sawicki2011-05-17 00:46:29 +0000
commitab16916d510898ce61f3675fa013ac57995adb23 (patch)
tree6c832ef999d93197d40a2ce3004571be3ffc4532
parent26c3ac9ab5f5c96214dedd383fb9eb8df61d1149 (diff)
downloadegit-github-ab16916d510898ce61f3675fa013ac57995adb23.tar.gz
egit-github-ab16916d510898ce61f3675fa013ac57995adb23.tar.xz
egit-github-ab16916d510898ce61f3675fa013ac57995adb23.zip
Disable clone gist action when already cloned.
Change-Id: Ia2e1dfae4a95c20540ecd4f2532bf3e9c40c1339 Signed-off-by: Kevin Sawicki <kevin@github.com>
-rw-r--r--org.eclipse.mylyn.github.ui/plugin.xml8
-rw-r--r--org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/CloneGistHandler.java94
-rw-r--r--org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistTaskEditorPage.java59
3 files changed, 109 insertions, 52 deletions
diff --git a/org.eclipse.mylyn.github.ui/plugin.xml b/org.eclipse.mylyn.github.ui/plugin.xml
index 076b3a20..848634ce 100644
--- a/org.eclipse.mylyn.github.ui/plugin.xml
+++ b/org.eclipse.mylyn.github.ui/plugin.xml
@@ -111,5 +111,11 @@
name="%importRepositoriesWizardName">
</wizard>
</extension>
-
+ <extension
+ point="org.eclipse.ui.commandImages">
+ <image
+ commandId="org.eclipse.mylyn.github.ui.command.cloneGist"
+ icon="platform:/plugin/org.eclipse.egit.ui/icons/obj16/cloneGit.gif">
+ </image>
+ </extension>
</plugin>
diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/CloneGistHandler.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/CloneGistHandler.java
index e1e508e0..7a6bfaa5 100644
--- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/CloneGistHandler.java
+++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/CloneGistHandler.java
@@ -14,13 +14,17 @@ import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.text.MessageFormat;
+import java.util.Collections;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.HandlerEvent;
+import org.eclipse.core.expressions.IEvaluationContext;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
@@ -46,6 +50,7 @@ import org.eclipse.mylyn.commons.net.AuthenticationCredentials;
import org.eclipse.mylyn.commons.net.AuthenticationType;
import org.eclipse.mylyn.internal.github.core.gist.GistAttribute;
import org.eclipse.mylyn.internal.github.core.gist.GistConnector;
+import org.eclipse.mylyn.tasks.core.ITask;
import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.core.data.TaskData;
import org.eclipse.mylyn.tasks.ui.TasksUi;
@@ -62,10 +67,52 @@ import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
public class CloneGistHandler extends AbstractHandler {
/**
+ * Get gist name for task data used to create projects and Git repositories
+ *
+ * @param data
+ * @return name
+ */
+ public static String getGistName(TaskData data) {
+ return "gist-" + data.getTaskId(); //$NON-NLS-1$
+ }
+
+ private static IWorkspaceRoot getWorkspaceRoot() {
+ return ResourcesPlugin.getWorkspace().getRoot();
+ }
+
+ private static RepositoryUtil getRepoUtil() {
+ return org.eclipse.egit.core.Activator.getDefault().getRepositoryUtil();
+ }
+
+ /**
* ID
*/
public static final String ID = "org.eclipse.mylyn.github.ui.command.cloneGist"; //$NON-NLS-1$
+ private IEvaluationContext context;
+
+ @Override
+ public void setEnabled(Object evaluationContext) {
+ context = evaluationContext instanceof IEvaluationContext ? (IEvaluationContext) evaluationContext
+ : null;
+ }
+
+ @Override
+ public boolean isEnabled() {
+ if (!super.isEnabled())
+ return false;
+ if (context == null)
+ return false;
+ ExecutionEvent event = new ExecutionEvent(null, Collections.EMPTY_MAP,
+ null, context);
+ TaskData data = getTaskData(event);
+ if (data == null)
+ return false;
+ String id = getGistName(data);
+ return !getWorkspaceRoot().getProject(id).exists()
+ && !getRepoUtil().getConfiguredRepositories().contains(id);
+ }
+
private File getParentDirectory() {
String destinationDir = Activator.getDefault().getPreferenceStore()
.getString(UIPreferences.DEFAULT_REPO_DIR);
@@ -102,9 +149,8 @@ public class CloneGistHandler extends AbstractHandler {
project.open(IResource.BACKGROUND_REFRESH, monitor);
monitor.setTaskName(Messages.CloneGistHandler_TaskConnectingProject);
- ConnectProviderOperation cpo = new ConnectProviderOperation(project,
- repository.getDirectory());
- cpo.execute(monitor);
+ new ConnectProviderOperation(project, repository.getDirectory())
+ .execute(monitor);
}
private CloneOperation createCloneOperation(TaskData data, String name)
@@ -138,16 +184,12 @@ public class CloneGistHandler extends AbstractHandler {
}
}
- private RepositoryUtil getRepoUtil() {
- return org.eclipse.egit.core.Activator.getDefault().getRepositoryUtil();
- }
-
private Job createCloneJob(final ExecutionEvent event, final TaskData data) {
Job job = new Job(Messages.CloneGistHandler_TaskCloning) {
protected IStatus run(IProgressMonitor monitor) {
try {
- final String name = "gist-" + data.getTaskId(); //$NON-NLS-1$
+ final String name = getGistName(data);
CloneOperation operation = createCloneOperation(data, name);
updateCredentials(data, operation);
@@ -188,6 +230,9 @@ public class CloneGistHandler extends AbstractHandler {
} catch (Exception e) {
displayError(event, e);
Activator.logError("Error cloning gist", e); //$NON-NLS-1$
+ } finally {
+ fireHandlerChanged(new HandlerEvent(CloneGistHandler.this,
+ true, false));
}
return Status.OK_STATUS;
}
@@ -211,13 +256,12 @@ public class CloneGistHandler extends AbstractHandler {
}
/**
- * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ * Get task data from event
+ *
+ * @param event
+ * @return task data
*/
- public Object execute(ExecutionEvent event) throws ExecutionException {
- IWorkbenchSite activeSite = HandlerUtil.getActiveSite(event);
- IWorkbenchSiteProgressService service = (IWorkbenchSiteProgressService) activeSite
- .getService(IWorkbenchSiteProgressService.class);
-
+ protected TaskData getTaskData(ExecutionEvent event) {
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection == null || selection.isEmpty())
selection = HandlerUtil.getActiveMenuSelection(event);
@@ -225,8 +269,28 @@ public class CloneGistHandler extends AbstractHandler {
if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
Object first = ((IStructuredSelection) selection).getFirstElement();
if (first instanceof TaskData)
- service.schedule(createCloneJob(event, (TaskData) first));
+ return (TaskData) first;
+ else if (first instanceof ITask)
+ try {
+ return TasksUi.getTaskDataManager().getTaskData(
+ (ITask) first);
+ } catch (CoreException e) {
+ return null;
+ }
}
return null;
}
+
+ /**
+ * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ */
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ IWorkbenchSite activeSite = HandlerUtil.getActiveSite(event);
+ IWorkbenchSiteProgressService service = (IWorkbenchSiteProgressService) activeSite
+ .getService(IWorkbenchSiteProgressService.class);
+ TaskData data = getTaskData(event);
+ if (data != null)
+ service.schedule(createCloneJob(event, data));
+ return null;
+ }
}
diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistTaskEditorPage.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistTaskEditorPage.java
index 867b9286..ed22d510 100644
--- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistTaskEditorPage.java
+++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistTaskEditorPage.java
@@ -20,14 +20,19 @@ import org.eclipse.core.commands.NotEnabledException;
import org.eclipse.core.commands.NotHandledException;
import org.eclipse.core.commands.common.NotDefinedException;
import org.eclipse.core.expressions.IEvaluationContext;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.egit.core.Activator;
+import org.eclipse.egit.github.core.Gist;
import org.eclipse.egit.ui.UIIcons;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.mylyn.internal.github.core.gist.GistAttribute;
+import org.eclipse.mylyn.internal.github.core.gist.GistConnector;
import org.eclipse.mylyn.internal.github.ui.issue.IssueSummaryPart;
import org.eclipse.mylyn.internal.tasks.ui.editors.TaskEditorActionPart;
+import org.eclipse.mylyn.tasks.ui.TasksUiUtil;
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPage;
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPart;
import org.eclipse.mylyn.tasks.ui.editors.TaskEditor;
@@ -37,6 +42,8 @@ import org.eclipse.ui.ISources;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.handlers.IHandlerService;
+import org.eclipse.ui.menus.CommandContributionItem;
+import org.eclipse.ui.menus.CommandContributionItemParameter;
/**
* Gist task editor page class
@@ -53,47 +60,27 @@ public class GistTaskEditorPage extends AbstractTaskEditorPage {
setNeedsSubmitButton(true);
}
+ private CommandContributionItem createCommandContributionItem(
+ String commandId) {
+ CommandContributionItemParameter parameter = new CommandContributionItemParameter(
+ getSite(), commandId, commandId,
+ CommandContributionItem.STYLE_PUSH);
+ return new CommandContributionItem(parameter);
+ }
+
+ private void addCloneAction(IToolBarManager manager) {
+ if (TasksUiUtil.isOutgoingNewTask(getTask(), GistConnector.KIND))
+ return;
+ manager.prependToGroup(
+ "open", createCommandContributionItem(CloneGistHandler.ID)); //$NON-NLS-1$
+ }
+
/**
* @see org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPage#fillToolBar(org.eclipse.jface.action.IToolBarManager)
*/
public void fillToolBar(IToolBarManager toolBarManager) {
super.fillToolBar(toolBarManager);
-
- Action cloneGist = new Action(
- Messages.GistTaskEditorPage_LabelCloneGistAction,
- UIIcons.CLONEGIT) {
-
- public void run() {
- ICommandService srv = (ICommandService) getSite().getService(
- ICommandService.class);
- IHandlerService hsrv = (IHandlerService) getSite().getService(
- IHandlerService.class);
- Command command = srv.getCommand(CloneGistHandler.ID);
-
- ExecutionEvent event = hsrv.createExecutionEvent(command, null);
- if (event.getApplicationContext() instanceof IEvaluationContext) {
- IEvaluationContext context = (IEvaluationContext) event
- .getApplicationContext();
- IStructuredSelection selection = new StructuredSelection(
- getModel().getTaskData());
- context.addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME,
- selection);
- try {
- command.executeWithChecks(event);
- } catch (ExecutionException ignored) {
- // Ignored
- } catch (NotDefinedException ignored) {
- // Ignored
- } catch (NotEnabledException ignored) {
- // Ignored
- } catch (NotHandledException ignored) {
- // Ignored
- }
- }
- }
-
- };
- toolBarManager.prependToGroup("open", cloneGist); //$NON-NLS-1$
+ addCloneAction(toolBarManager);
}
/**

Back to the top