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);
}
}
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);
}
}
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;
}
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;
}
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);
}
}
Aggregations