Search in sources :

Example 46 with ITextEditor

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

the class AnnotationManagerTest method testRemoveQuery.

@Test
public void testRemoveQuery() throws Exception {
    NewSearchUI.runQueryInForeground(null, fQuery1);
    AbstractTextSearchResult result = (AbstractTextSearchResult) fQuery1.getSearchResult();
    Object[] files = result.getElements();
    InternalSearchUI.getInstance().removeQuery(fQuery1);
    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());
            int annotationCount = 0;
            for (Iterator<Annotation> annotations = annotationModel.getAnnotationIterator(); annotations.hasNext(); ) {
                Annotation annotation = annotations.next();
                if (annotation.getType().equals(fAnnotationTypeLookup.getAnnotationType(NewSearchUI.SEARCH_MARKER, IMarker.SEVERITY_INFO))) {
                    annotationCount++;
                }
            }
            assertEquals(0, annotationCount);
        }
    } finally {
        SearchPlugin.getActivePage().closeAllEditors(false);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) AbstractTextSearchResult(org.eclipse.search.ui.text.AbstractTextSearchResult) Annotation(org.eclipse.jface.text.source.Annotation) Test(org.junit.Test)

Example 47 with ITextEditor

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

the class AnnotationManagerTest method testSwitchQuery.

@Test
public void testSwitchQuery() throws Exception {
    NewSearchUI.runQueryInForeground(null, fQuery1);
    AbstractTextSearchResult result = (AbstractTextSearchResult) fQuery1.getSearchResult();
    Object[] files = result.getElements();
    NewSearchUI.runQueryInForeground(null, fQuery2);
    SearchTestPlugin.getDefault().getSearchView().showSearchResult(result);
    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());
            int annotationCount = 0;
            IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
            for (Iterator<Annotation> annotations = annotationModel.getAnnotationIterator(); annotations.hasNext(); ) {
                Annotation annotation = annotations.next();
                if (annotation.getType().equals(fAnnotationTypeLookup.getAnnotationType(NewSearchUI.SEARCH_MARKER, IMarker.SEVERITY_INFO))) {
                    Position p = annotationModel.getPosition(annotation);
                    String text = document.get(p.getOffset(), p.getLength());
                    assertTrue(text.equalsIgnoreCase(fQuery1.getSearchString()));
                }
            }
            assertEquals(0, annotationCount);
        }
    } 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) IDocument(org.eclipse.jface.text.IDocument) Annotation(org.eclipse.jface.text.source.Annotation) Test(org.junit.Test)

Example 48 with ITextEditor

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

the class EditorOpener method openAndSelect.

public IEditorPart openAndSelect(IWorkbenchPage wbPage, IFile file, int offset, int length, boolean activate) throws PartInitException {
    String editorId = null;
    IEditorDescriptor desc = IDE.getEditorDescriptor(file, true, true);
    if (desc == null || !desc.isInternal()) {
        // $NON-NLS-1$
        editorId = "org.eclipse.ui.DefaultTextEditor";
    } else {
        editorId = desc.getId();
    }
    IEditorPart editor;
    if (NewSearchUI.reuseEditor()) {
        editor = showWithReuse(file, wbPage, editorId, activate);
    } else {
        editor = showWithoutReuse(file, wbPage, editorId, activate);
    }
    if (editor instanceof ITextEditor) {
        ITextEditor textEditor = (ITextEditor) editor;
        textEditor.selectAndReveal(offset, length);
    } else if (editor != null) {
        showWithMarker(editor, file, offset, length);
    }
    return editor;
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) IEditorPart(org.eclipse.ui.IEditorPart)

Example 49 with ITextEditor

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

the class TextSearchVisitor method evalNonFileBufferDocuments.

/**
 * Returns a map from IFile to IDocument for all open, dirty editors. After creation this map
 * is not modified, so returning a non-synchronized map is ok.
 *
 * @return a map from IFile to IDocument for all open, dirty editors
 */
private Map<IFile, IDocument> evalNonFileBufferDocuments() {
    Map<IFile, IDocument> result = new HashMap<>();
    IWorkbench workbench = SearchPlugin.getDefault().getWorkbench();
    IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();
    for (IWorkbenchWindow window : windows) {
        IWorkbenchPage[] pages = window.getPages();
        for (IWorkbenchPage page : pages) {
            IEditorReference[] editorRefs = page.getEditorReferences();
            for (IEditorReference editorRef : editorRefs) {
                IEditorPart ep = editorRef.getEditor(false);
                if (ep instanceof ITextEditor && ep.isDirty()) {
                    // only dirty editors
                    evaluateTextEditor(result, ep);
                }
            }
        }
    }
    return result;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IFile(org.eclipse.core.resources.IFile) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) HashMap(java.util.HashMap) IEditorPart(org.eclipse.ui.IEditorPart) IWorkbench(org.eclipse.ui.IWorkbench) IEditorReference(org.eclipse.ui.IEditorReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IDocument(org.eclipse.jface.text.IDocument)

Example 50 with ITextEditor

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

the class SegmentedModeTest method testSegmentation.

/*
	 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=70934
	 */
@Test
public void testSegmentation() {
    IWorkbench workbench = PlatformUI.getWorkbench();
    IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
    try {
        IEditorPart part = IDE.openEditor(page, fFile);
        try {
            if (part instanceof ITextEditor) {
                ITextEditor editor = (ITextEditor) part;
                editor.showHighlightRangeOnly(true);
                editor.setHighlightRange(5, 0, true);
                Control control = part.getAdapter(Control.class);
                if (control instanceof StyledText) {
                    StyledText styledText = (StyledText) control;
                    int caret = styledText.getCaretOffset();
                    styledText.replaceTextRange(caret, 0, "really ");
                    StringBuffer buffer = new StringBuffer(getOriginalContent());
                    buffer.insert(5, "really ");
                    IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
                    assertEquals(buffer.toString(), document.get());
                }
            }
        } 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) IDocument(org.eclipse.jface.text.IDocument) Test(org.junit.Test)

Aggregations

ITextEditor (org.eclipse.ui.texteditor.ITextEditor)62 IEditorPart (org.eclipse.ui.IEditorPart)27 IDocument (org.eclipse.jface.text.IDocument)24 Test (org.junit.Test)21 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)13 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)12 IFile (org.eclipse.core.resources.IFile)10 BadLocationException (org.eclipse.jface.text.BadLocationException)9 ISelection (org.eclipse.jface.viewers.ISelection)9 PartInitException (org.eclipse.ui.PartInitException)9 AbstractQueuedBuildDataTest (org.eclipse.xtend.ide.tests.builder.AbstractQueuedBuildDataTest)9 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)9 TextSelection (org.eclipse.jface.text.TextSelection)6 Annotation (org.eclipse.jface.text.source.Annotation)6 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)6 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)5 Position (org.eclipse.jface.text.Position)5 AbstractTextSearchResult (org.eclipse.search.ui.text.AbstractTextSearchResult)5 IWorkbench (org.eclipse.ui.IWorkbench)5 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)5