Search in sources :

Example 1 with FileRevisionEditorInput

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);
}
Also used : SubMonitor(org.eclipse.core.runtime.SubMonitor) FileRevisionEditorInput(org.eclipse.egit.ui.internal.revision.FileRevisionEditorInput)

Example 2 with FileRevisionEditorInput

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;
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) SubMonitor(org.eclipse.core.runtime.SubMonitor) FileRevisionEditorInput(org.eclipse.egit.ui.internal.revision.FileRevisionEditorInput) IEditorPart(org.eclipse.ui.IEditorPart) IStorage(org.eclipse.core.resources.IStorage)

Example 3 with FileRevisionEditorInput

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));
}
Also used : IFile(org.eclipse.core.resources.IFile) MultiPageEditorPart(org.eclipse.ui.part.MultiPageEditorPart) IEditorPart(org.eclipse.ui.IEditorPart) IRevisionRulerColumnExtension(org.eclipse.jface.text.revisions.IRevisionRulerColumnExtension) IRevisionRulerColumn(org.eclipse.jface.text.revisions.IRevisionRulerColumn) AbstractDecoratedTextEditor(org.eclipse.ui.texteditor.AbstractDecoratedTextEditor) CoreException(org.eclipse.core.runtime.CoreException) FileRevisionEditorInput(org.eclipse.egit.ui.internal.revision.FileRevisionEditorInput) IVerticalRulerInfo(org.eclipse.jface.text.source.IVerticalRulerInfo) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 4 with FileRevisionEditorInput

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;
}
Also used : MultiPageEditorPart(org.eclipse.ui.part.MultiPageEditorPart) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IFileRevision(org.eclipse.team.core.history.IFileRevision) FileRevisionEditorInput(org.eclipse.egit.ui.internal.revision.FileRevisionEditorInput) IEditorPart(org.eclipse.ui.IEditorPart) IEditorInput(org.eclipse.ui.IEditorInput) IResource(org.eclipse.core.resources.IResource)

Aggregations

FileRevisionEditorInput (org.eclipse.egit.ui.internal.revision.FileRevisionEditorInput)4 IEditorPart (org.eclipse.ui.IEditorPart)3 IFile (org.eclipse.core.resources.IFile)2 SubMonitor (org.eclipse.core.runtime.SubMonitor)2 MultiPageEditorPart (org.eclipse.ui.part.MultiPageEditorPart)2 IResource (org.eclipse.core.resources.IResource)1 IStorage (org.eclipse.core.resources.IStorage)1 CoreException (org.eclipse.core.runtime.CoreException)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 IDocument (org.eclipse.jface.text.IDocument)1 IRevisionRulerColumn (org.eclipse.jface.text.revisions.IRevisionRulerColumn)1 IRevisionRulerColumnExtension (org.eclipse.jface.text.revisions.IRevisionRulerColumnExtension)1 IVerticalRulerInfo (org.eclipse.jface.text.source.IVerticalRulerInfo)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 IFileRevision (org.eclipse.team.core.history.IFileRevision)1 IEditorInput (org.eclipse.ui.IEditorInput)1 AbstractDecoratedTextEditor (org.eclipse.ui.texteditor.AbstractDecoratedTextEditor)1