Search in sources :

Example 1 with IRevisionRulerColumn

use of org.eclipse.jface.text.revisions.IRevisionRulerColumn 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)

Aggregations

IFile (org.eclipse.core.resources.IFile)1 CoreException (org.eclipse.core.runtime.CoreException)1 FileRevisionEditorInput (org.eclipse.egit.ui.internal.revision.FileRevisionEditorInput)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 IEditorPart (org.eclipse.ui.IEditorPart)1 MultiPageEditorPart (org.eclipse.ui.part.MultiPageEditorPart)1 AbstractDecoratedTextEditor (org.eclipse.ui.texteditor.AbstractDecoratedTextEditor)1