Search in sources :

Example 41 with ITextEditor

use of org.eclipse.ui.texteditor.ITextEditor in project linuxtools by eclipse.

the class OpenSourceFileAction method openAnnotatedSourceFile.

public static void openAnnotatedSourceFile(IProject project, IFile binary, SourceFile sourceFile, IPath realLocation, int lineNumber) {
    PlatformUI.getWorkbench().getDisplay().syncExec(() -> {
        IWorkbenchPage page = CUIPlugin.getActivePage();
        if (page != null) {
            IFileStore fs = getFileStore(project, realLocation);
            if (fs == null && !realLocation.isAbsolute() && binary != null) {
                IPath p = binary.getProjectRelativePath().removeLastSegments(1);
                fs = getFileStore(project, p.append(realLocation));
            }
            if (fs == null) {
                try {
                    page.openEditor(new STAnnotatedSourceNotFoundEditorInput(project, sourceFile, realLocation, lineNumber), STAnnotatedSourceNotFoundEditor.ID, true);
                } catch (PartInitException e) {
                    Status s = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.OpenSourceFileAction_open_error, e);
                    Activator.getDefault().getLog().log(s);
                }
            } else {
                try {
                    IEditorPart editor = IDE.openEditorOnFileStore(page, fs);
                    if (lineNumber > 0 && editor instanceof ITextEditor) {
                        IDocumentProvider provider = ((ITextEditor) editor).getDocumentProvider();
                        IDocument document = provider.getDocument(editor.getEditorInput());
                        try {
                            int start = document.getLineOffset(lineNumber - 1);
                            ((ITextEditor) editor).selectAndReveal(start, 0);
                        } catch (BadLocationException e) {
                        // ignore
                        }
                        IWorkbenchPage p = editor.getSite().getPage();
                        p.activate(editor);
                    }
                } catch (PartInitException e) {
                    Status s = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.OpenSourceFileAction_open_error, e);
                    Activator.getDefault().getLog().log(s);
                }
            }
        }
    });
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IPath(org.eclipse.core.runtime.IPath) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IFileStore(org.eclipse.core.filesystem.IFileStore) PartInitException(org.eclipse.ui.PartInitException) IEditorPart(org.eclipse.ui.IEditorPart) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 42 with ITextEditor

use of org.eclipse.ui.texteditor.ITextEditor in project erlide_eclipse by erlang.

the class DoubleClickListener method higlightCodePart.

public void higlightCodePart(final DuplicatedCodeInstanceElement codePart) {
    final ITextEditor textEditor = (ITextEditor) WranglerUtils.openFile(codePart.getContainingFile());
    WranglerUtils.highlightOffsetSelection(codePart.getStartOffset(), codePart.getEndOffset(), textEditor);
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor)

Example 43 with ITextEditor

use of org.eclipse.ui.texteditor.ITextEditor in project erlide_eclipse by erlang.

the class EditorTracker method clearAnnotations.

public void clearAnnotations(final IWorkbenchPart part) {
    if (part != null) {
        log.info(part.getTitle());
    }
    if (part instanceof ITextEditor) {
        final ITextEditor editor = (ITextEditor) part;
        final IAnnotationModel annMod = editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
        @SuppressWarnings("rawtypes") final Iterator it = annMod.getAnnotationIterator();
        while (it.hasNext()) {
            final Annotation annotation = (Annotation) it.next();
            if (annotation.getType().equals(CoverageTypes.FULL_COVERAGE) || annotation.getType().equals(CoverageTypes.NO_COVERAGE)) {
                annMod.removeAnnotation(annotation);
            }
        }
    }
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) Iterator(java.util.Iterator) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) Annotation(org.eclipse.jface.text.source.Annotation)

Example 44 with ITextEditor

use of org.eclipse.ui.texteditor.ITextEditor in project erlide_eclipse by erlang.

the class EditorTracker method removeAnnotationsFragment.

/**
 * Removes coverage annotations from a fragment of file
 *
 * @param fileName
 * @param start
 * @param end
 */
public void removeAnnotationsFragment(final String fileName, final int start, final int end) {
    final IEditorPart currentEditor = workbench.getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    if (currentEditor.getTitle().equals(fileName) && currentEditor instanceof ITextEditor) {
        final ITextEditor editor = (ITextEditor) currentEditor;
        final IAnnotationModel annMod = editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
        final Set<LineResult> list = coverage.getLineSet(editor.getTitle());
        for (final LineResult lr : list) {
            if (lr.getLineNum() < start || end != -1 && lr.getLineNum() > end) {
                continue;
            }
            log.info(lr.getLineNum());
            if (coverage.containsAnnotation(editor.getTitle(), lr)) {
                final Annotation ann = coverage.getAnnotation(editor.getTitle(), lr);
                annMod.removeAnnotation(ann);
                coverage.removeAnnotation(editor.getTitle(), lr);
            }
        }
    }
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) LineResult(org.erlide.cover.views.model.LineResult) IEditorPart(org.eclipse.ui.IEditorPart) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) Annotation(org.eclipse.jface.text.source.Annotation)

Example 45 with ITextEditor

use of org.eclipse.ui.texteditor.ITextEditor in project erlide_eclipse by erlang.

the class ErlangAbstractHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final ITextEditor textEditor = (ITextEditor) HandlerUtil.getActiveEditor(event);
    if (!validateEditorInputState(textEditor)) {
        return null;
    }
    final ISelection sel = textEditor.getSelectionProvider().getSelection();
    if (sel == null || sel.isEmpty() || !(sel instanceof ITextSelection)) {
        return null;
    }
    ErlideEventTracer.getInstance().traceOperationStart(this);
    try {
        final IRunnableWithProgress myRunnableWithProgress = new IRunnableWithProgress() {

            @Override
            public void run(final IProgressMonitor monitor0) {
                final IProgressMonitor monitor = monitor0 != null ? monitor0 : new NullProgressMonitor();
                try {
                    monitor.beginTask("Processing " + textEditor.getEditorInput().getName(), IProgressMonitor.UNKNOWN);
                    doAction(sel, textEditor);
                } finally {
                    monitor.done();
                }
            }
        };
        try {
            PlatformUI.getWorkbench().getProgressService().busyCursorWhile(myRunnableWithProgress);
        } catch (final InvocationTargetException e) {
        } catch (final InterruptedException e) {
        }
    } finally {
        ErlideEventTracer.getInstance().traceOperationEnd(this);
    }
    return null;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) ISelection(org.eclipse.jface.viewers.ISelection) ITextSelection(org.eclipse.jface.text.ITextSelection) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Aggregations

ITextEditor (org.eclipse.ui.texteditor.ITextEditor)233 IEditorPart (org.eclipse.ui.IEditorPart)91 IDocument (org.eclipse.jface.text.IDocument)73 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)39 ITextSelection (org.eclipse.jface.text.ITextSelection)34 IFile (org.eclipse.core.resources.IFile)33 Test (org.junit.Test)31 BadLocationException (org.eclipse.jface.text.BadLocationException)27 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)25 PartInitException (org.eclipse.ui.PartInitException)23 ISelection (org.eclipse.jface.viewers.ISelection)19 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)17 IRegion (org.eclipse.jface.text.IRegion)16 Annotation (org.eclipse.jface.text.source.Annotation)16 ArrayList (java.util.ArrayList)15 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)15 IResource (org.eclipse.core.resources.IResource)14 IEditorInput (org.eclipse.ui.IEditorInput)14 CoreException (org.eclipse.core.runtime.CoreException)13 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)12