use of org.eclipse.egit.ui.internal.revision.FileRevisionEditorInput in project egit by eclipse.
the class EgitUiEditorUtils method openTextEditor.
/**
* Opens a text editor on a revision
*
* @param page
* the page
* @param revision
* the revision
* @param monitor
* a progress monitor, may be null
* @throws CoreException
* upon failure
*/
public static void openTextEditor(IWorkbenchPage page, IFileRevision revision, IProgressMonitor monitor) throws CoreException {
SubMonitor progress = SubMonitor.convert(monitor, 1);
FileRevisionEditorInput fileRevEditorInput = FileRevisionEditorInput.createEditorInputFor(revision, progress.newChild(1));
openEditor(page, fileRevEditorInput, EditorsUI.DEFAULT_TEXT_EDITOR_ID);
}
use of org.eclipse.egit.ui.internal.revision.FileRevisionEditorInput in project egit by eclipse.
the class EgitUiEditorUtils method openEditor.
/**
* @param page
* @param revision
* @param monitor
* @return the part
* @throws CoreException
*/
public static IEditorPart openEditor(IWorkbenchPage page, IFileRevision revision, IProgressMonitor monitor) throws CoreException {
SubMonitor progress = SubMonitor.convert(monitor, 2);
IStorage file = revision.getStorage(progress.newChild(1));
if (file instanceof IFile) {
// if this is the current workspace file, open it
return IDE.openEditor(page, (IFile) file, OpenStrategy.activateOnOpen());
} else {
FileRevisionEditorInput fileRevEditorInput = FileRevisionEditorInput.createEditorInputFor(revision, progress.newChild(1));
IEditorPart part = openEditor(page, fileRevEditorInput);
return part;
}
}
use of org.eclipse.egit.ui.internal.revision.FileRevisionEditorInput in project egit by eclipse.
the class BlameOperation method openEditor.
private void openEditor(final RevisionInformation info) {
IEditorPart editorPart;
try {
if (storage instanceof IFile) {
editorPart = RevisionAnnotationController.openEditor(page, (IFile) storage);
} else {
FileRevisionEditorInput editorInput = new FileRevisionEditorInput(fileRevision, storage);
editorPart = EgitUiEditorUtils.openEditor(page, editorInput);
if (editorPart instanceof MultiPageEditorPart) {
MultiPageEditorPart multiEditor = (MultiPageEditorPart) editorPart;
for (IEditorPart part : multiEditor.findEditors(editorInput)) {
if (part instanceof AbstractDecoratedTextEditor) {
multiEditor.setActiveEditor(part);
editorPart = part;
break;
}
}
}
}
} catch (CoreException e) {
// $NON-NLS-1$
Activator.handleError(// $NON-NLS-1$
"Error displaying blame annotations", // $NON-NLS-1$
e, false);
return;
}
if (!(editorPart instanceof AbstractDecoratedTextEditor)) {
return;
}
AbstractDecoratedTextEditor editor = (AbstractDecoratedTextEditor) editorPart;
// IRevisionRulerColumn would also be possible but using
// IVerticalRulerInfo seems to work in more situations.
IVerticalRulerInfo rulerInfo = AdapterUtils.adapt(editor, IVerticalRulerInfo.class);
BlameInformationControlCreator creator = new BlameInformationControlCreator(rulerInfo);
info.setHoverControlCreator(creator);
info.setInformationPresenterControlCreator(creator);
editor.showRevisionInformation(info, // $NON-NLS-1$
"org.eclipse.egit.ui.internal.decorators.GitQuickDiffProvider");
if (lineNumberToReveal >= 0) {
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
int offset;
try {
offset = document.getLineOffset(lineNumberToReveal);
editor.selectAndReveal(offset, 0);
} catch (BadLocationException e) {
Activator.logError("Error revealing line " + lineNumberToReveal, // $NON-NLS-1$
e);
}
}
IRevisionRulerColumn revisionRuler = AdapterUtils.adapt(editor, IRevisionRulerColumn.class);
if (revisionRuler instanceof IRevisionRulerColumnExtension)
((IRevisionRulerColumnExtension) revisionRuler).getRevisionSelectionProvider().addSelectionChangedListener(new RevisionSelectionHandler(repository, path, storage));
}
use of org.eclipse.egit.ui.internal.revision.FileRevisionEditorInput in project egit by eclipse.
the class SelectionUtils method getSelectionFromEditorInput.
private static IStructuredSelection getSelectionFromEditorInput(IEvaluationContext context) {
Object part = context.getVariable(ISources.ACTIVE_PART_NAME);
if (!(part instanceof IEditorPart)) {
return StructuredSelection.EMPTY;
}
Object object = context.getVariable(ISources.ACTIVE_EDITOR_INPUT_NAME);
Object editor = context.getVariable(ISources.ACTIVE_EDITOR_NAME);
if (editor instanceof MultiPageEditorPart) {
Object nestedEditor = ((MultiPageEditorPart) editor).getSelectedPage();
if (nestedEditor instanceof IEditorPart) {
object = ((IEditorPart) nestedEditor).getEditorInput();
}
}
if (!(object instanceof IEditorInput) && (editor instanceof IEditorPart)) {
object = ((IEditorPart) editor).getEditorInput();
}
if (object instanceof IEditorInput) {
IEditorInput editorInput = (IEditorInput) object;
// Note that there is both a getResource(IEditorInput) as well as a
// getResource(Object), which don't do the same thing. We explicitly
// want the first here.
IResource resource = org.eclipse.ui.ide.ResourceUtil.getResource(editorInput);
if (resource != null)
return new StructuredSelection(resource);
if (editorInput instanceof FileRevisionEditorInput) {
FileRevisionEditorInput fileRevisionEditorInput = (FileRevisionEditorInput) editorInput;
IFileRevision fileRevision = fileRevisionEditorInput.getFileRevision();
if (fileRevision != null)
return new StructuredSelection(fileRevision);
}
}
return StructuredSelection.EMPTY;
}
Aggregations