in org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/CreateGistHandler.java [102:164]
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);
if (selection == null || selection.isEmpty())
return null;
boolean isPublic = Boolean
.parseBoolean(event.getParameter(PUBLIC_GIST));
if (selection instanceof ITextSelection) {
ITextSelection text = (ITextSelection) selection;
String name = null;
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(" ", "") //$NON-NLS-1$ //$NON-NLS-2$
.toLowerCase(Locale.US)
+ ".txt"; //$NON-NLS-1$
if (name == null)
name = DEFAULT_FILENAME;
createGistJob(event, name, text.getText(), isPublic);
} else if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
Object obj = structuredSelection.getFirstElement();
IResource file = null;
if (obj instanceof IResource)
file = (IResource) obj;
else if (obj instanceof IAdaptable) {
file = ((IAdaptable) obj)
.getAdapter(IResource.class);
if (file == null)
file = ((IAdaptable) obj).getAdapter(IFile.class);
}
if (file instanceof IFile)
createGistJob(event, (IFile) file, isPublic);
}
return null;
}