Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Sawicki2011-10-28 22:53:18 +0000
committerKevin Sawicki2011-10-28 22:57:21 +0000
commit206e0d34453ab84021593527be1b3e884e7f26e1 (patch)
tree492026ece3bff80e0a3198c030741c5f9954bc12
parent30c56db0e2b830410cbba887a114a8d85d515f53 (diff)
downloadegit-github-206e0d34453ab84021593527be1b3e884e7f26e1.tar.gz
egit-github-206e0d34453ab84021593527be1b3e884e7f26e1.tar.xz
egit-github-206e0d34453ab84021593527be1b3e884e7f26e1.zip
Add support for creating Gists from Console view
Change-Id: I882fbc5a50d2cb91f642c5166c5b0441dacc5900 Signed-off-by: Kevin Sawicki <kevin@github.com>
-rw-r--r--org.eclipse.mylyn.github.ui/plugin.xml28
-rw-r--r--org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/CreateGistHandler.java60
2 files changed, 69 insertions, 19 deletions
diff --git a/org.eclipse.mylyn.github.ui/plugin.xml b/org.eclipse.mylyn.github.ui/plugin.xml
index f4e61d2b..85796a37 100644
--- a/org.eclipse.mylyn.github.ui/plugin.xml
+++ b/org.eclipse.mylyn.github.ui/plugin.xml
@@ -166,6 +166,34 @@
</command>
</menu>
</menuContribution>
+ <menuContribution
+ allPopups="false"
+ locationURI="popup:org.eclipse.debug.ui.ProcessConsoleType.#ContextMenu?after=additions">
+ <menu
+ icon="icons/obj16/github.png"
+ label="%githubMenuLabel">
+ <command
+ commandId="org.eclipse.mylyn.github.ui.command.createGist"
+ icon="icons/obj16/gist_private.png"
+ label="%createPrivateGistLabel"
+ style="push">
+ <parameter
+ name="publicGist"
+ value="false">
+ </parameter>
+ </command>
+ <command
+ commandId="org.eclipse.mylyn.github.ui.command.createGist"
+ icon="icons/obj16/gist_public.png"
+ label="%createPublicGistLabel"
+ style="push">
+ <parameter
+ name="publicGist"
+ value="true">
+ </parameter>
+ </command>
+ </menu>
+ </menuContribution>
</extension>
<extension
point="org.eclipse.ui.handlers">
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 14a0454f..d522de52 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
@@ -14,6 +14,7 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URI;
+import java.util.Locale;
import java.util.Set;
import org.eclipse.core.commands.AbstractHandler;
@@ -33,10 +34,13 @@ 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;
+import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IPathEditorInput;
import org.eclipse.ui.ISources;
import org.eclipse.ui.IURIEditorInput;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchPart2;
import org.eclipse.ui.handlers.HandlerUtil;
/**
@@ -78,11 +82,24 @@ public class CreateGistHandler extends AbstractHandler {
return var instanceof IEditorInput ? (IEditorInput) var : null;
}
+ /**
+ * Get active part
+ *
+ * @param event
+ * @return part
+ */
+ private IWorkbenchPart getActivePart(ExecutionEvent event) {
+ Object var = HandlerUtil.getVariable(event, ISources.ACTIVE_PART_NAME);
+ return var instanceof IWorkbenchPart ? (IWorkbenchPart) var : null;
+
+ }
+
public Object execute(ExecutionEvent event) throws ExecutionException {
// TODO replace this with
// HandlerUtil.getActiveEditorInput(ExecutionEvent) as soon
// as we don't support Eclipse 3.6 anymore
IEditorInput input = getActiveEditorInput(event);
+ IWorkbenchPart part = getActivePart(event);
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection == null || selection.isEmpty())
selection = HandlerUtil.getActiveMenuSelection(event);
@@ -94,27 +111,32 @@ public class CreateGistHandler extends AbstractHandler {
if (selection instanceof ITextSelection) {
ITextSelection text = (ITextSelection) selection;
String name = null;
- if (input instanceof IFileEditorInput) {
- IFile file = ((IFileEditorInput) input).getFile();
- if (file != null)
- name = file.getName();
- }
- if (name == null && input instanceof IPathEditorInput) {
- IPath path = ((IPathEditorInput) input).getPath();
- if (path != null)
- name = path.lastSegment();
- }
- if (name == null && input instanceof IURIEditorInput) {
- URI uri = ((IURIEditorInput) input).getURI();
- if (uri != null) {
- String rawPath = uri.getRawPath();
- if (rawPath != null) {
- int lastSlash = rawPath.lastIndexOf('/') + 1;
- if (lastSlash > 0 && lastSlash < rawPath.length())
- name = rawPath.substring(lastSlash);
+ if (part == null || part instanceof IEditorPart) {
+ if (input instanceof IFileEditorInput) {
+ IFile file = ((IFileEditorInput) input).getFile();
+ if (file != null)
+ name = file.getName();
+ }
+ if (name == null && input instanceof IPathEditorInput) {
+ IPath path = ((IPathEditorInput) input).getPath();
+ if (path != null)
+ name = path.lastSegment();
+ }
+ if (name == null && input instanceof IURIEditorInput) {
+ URI uri = ((IURIEditorInput) input).getURI();
+ if (uri != null) {
+ String rawPath = uri.getRawPath();
+ if (rawPath != null) {
+ int lastSlash = rawPath.lastIndexOf('/') + 1;
+ if (lastSlash > 0 && lastSlash < rawPath.length())
+ name = rawPath.substring(lastSlash);
+ }
}
}
- }
+ } else if (part instanceof IWorkbenchPart2)
+ name = ((IWorkbenchPart2) part).getPartName().replace(" ", "")
+ .toLowerCase(Locale.US)
+ + ".txt";
if (name == null)
name = DEFAULT_FILENAME;
createGistJob(event, name, text.getText(), isPublic);

Back to the top