Search in sources :

Example 16 with ITextEditor

use of org.eclipse.ui.texteditor.ITextEditor in project eclipse.platform.text by eclipse.

the class SegmentedModeTest method testShowNothing.

/*
	 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=465684
	 */
@Test
public void testShowNothing() {
    IWorkbench workbench = PlatformUI.getWorkbench();
    IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
    try {
        while (Display.getDefault().readAndDispatch()) {
        }
        IEditorPart part = IDE.openEditor(page, fFile);
        try {
            if (part instanceof ITextEditor) {
                ITextEditor editor = (ITextEditor) part;
                editor.showHighlightRangeOnly(true);
                editor.setHighlightRange(0, 0, true);
                Control control = part.getAdapter(Control.class);
                if (control instanceof StyledText) {
                    StyledText styledText = (StyledText) control;
                    String text = styledText.getText();
                    assertEquals("", text);
                }
            }
        } finally {
            page.saveEditor(part, false);
        }
    } catch (PartInitException e) {
        assertTrue(false);
    }
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) Control(org.eclipse.swt.widgets.Control) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) StyledText(org.eclipse.swt.custom.StyledText) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) Test(org.junit.Test)

Example 17 with ITextEditor

use of org.eclipse.ui.texteditor.ITextEditor in project eclipse.platform.text by eclipse.

the class EditorAnnotationManager method getAnnotationModel.

private static IAnnotationModel getAnnotationModel(IWorkbenchPart part) {
    IAnnotationModel model = null;
    model = part.getAdapter(IAnnotationModel.class);
    if (model == null) {
        ITextEditor textEditor = null;
        if (part instanceof ITextEditor) {
            textEditor = (ITextEditor) part;
        }
        if (textEditor != null) {
            IDocumentProvider dp = textEditor.getDocumentProvider();
            if (dp != null)
                model = dp.getAnnotationModel(textEditor.getEditorInput());
        }
    }
    return model;
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel)

Example 18 with ITextEditor

use of org.eclipse.ui.texteditor.ITextEditor in project eclipse.platform.text by eclipse.

the class EditorAnnotationManager method getDocument.

private static IDocument getDocument(IWorkbenchPart part) {
    IDocument doc = null;
    doc = part.getAdapter(IDocument.class);
    if (doc == null) {
        ITextEditor textEditor = null;
        if (part instanceof ITextEditor) {
            textEditor = (ITextEditor) part;
        }
        if (textEditor != null) {
            IDocumentProvider dp = textEditor.getDocumentProvider();
            if (dp != null)
                doc = dp.getDocument(textEditor.getEditorInput());
        }
    }
    return doc;
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IDocument(org.eclipse.jface.text.IDocument)

Example 19 with ITextEditor

use of org.eclipse.ui.texteditor.ITextEditor in project eclipse.platform.text by eclipse.

the class RetrieverAction method extractSearchTextFromEditor.

protected final String extractSearchTextFromEditor(IEditorPart editor) {
    if (editor != null) {
        ITextSelection selection = null;
        ISelectionProvider provider = editor.getEditorSite().getSelectionProvider();
        if (provider != null) {
            ISelection s = provider.getSelection();
            if (s instanceof ITextSelection) {
                selection = (ITextSelection) s;
            }
        }
        if (selection != null) {
            if (selection.getLength() == 0) {
                ITextEditor txtEditor = getTextEditor(editor);
                if (txtEditor != null) {
                    IDocument document = txtEditor.getDocumentProvider().getDocument(txtEditor.getEditorInput());
                    selection = expandSelection(selection, document, null);
                }
            }
            if (selection.getLength() > 0 && selection.getText() != null) {
                return trimSearchString(selection.getText());
            }
        }
    }
    return null;
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ISelection(org.eclipse.jface.viewers.ISelection) ITextSelection(org.eclipse.jface.text.ITextSelection) IDocument(org.eclipse.jface.text.IDocument)

Example 20 with ITextEditor

use of org.eclipse.ui.texteditor.ITextEditor in project eclipse.platform.text by eclipse.

the class AnnotationManagerTest method testAddAnnotation.

@Test
public void testAddAnnotation() throws Exception {
    NewSearchUI.runQueryInForeground(null, fQuery1);
    AbstractTextSearchResult result = (AbstractTextSearchResult) fQuery1.getSearchResult();
    Object[] files = result.getElements();
    try {
        for (int i = 0; i < files.length; i++) {
            IFile file = (IFile) files[i];
            ITextEditor editor = (ITextEditor) SearchTestPlugin.openTextEditor(SearchPlugin.getActivePage(), file);
            IAnnotationModel annotationModel = editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
            annotationModel.getAnnotationIterator();
            HashSet<Position> positions = new HashSet<>();
            for (Iterator<Annotation> iter = annotationModel.getAnnotationIterator(); iter.hasNext(); ) {
                Annotation annotation = iter.next();
                if (annotation.getType().equals(fAnnotationTypeLookup.getAnnotationType(NewSearchUI.SEARCH_MARKER, IMarker.SEVERITY_INFO))) {
                    positions.add(annotationModel.getPosition(annotation));
                }
            }
            Match[] matches = result.getMatches(file);
            for (int j = 0; j < matches.length; j++) {
                Position position = new Position(matches[j].getOffset(), matches[j].getLength());
                // $NON-NLS-1$
                assertTrue("position not found at: " + j, positions.remove(position));
            }
            assertEquals(0, positions.size());
        }
    } finally {
        SearchPlugin.getActivePage().closeAllEditors(false);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) Position(org.eclipse.jface.text.Position) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) AbstractTextSearchResult(org.eclipse.search.ui.text.AbstractTextSearchResult) Annotation(org.eclipse.jface.text.source.Annotation) FileMatch(org.eclipse.search.internal.ui.text.FileMatch) Match(org.eclipse.search.ui.text.Match) HashSet(java.util.HashSet) Test(org.junit.Test)

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