use of org.eclipse.ui.texteditor.IDocumentProvider in project eclipse.platform.text by eclipse.
the class ReconcilerTest method performTestOnEditor.
private void performTestOnEditor(String startingText, ExtensionBasedTextEditor textEditor, String expectedText) throws Exception {
IDocumentProvider dp = textEditor.getDocumentProvider();
IDocument doc = dp.getDocument(textEditor.getEditorInput());
doc.set(startingText);
new DisplayHelper() {
@Override
protected boolean condition() {
try {
return doc.get(0, doc.getLineLength(0)).contains(expectedText);
} catch (BadLocationException e) {
return false;
}
}
}.waitForCondition(Display.getDefault().getActiveShell().getDisplay(), 2000);
Assert.assertTrue("file was not affected by reconciler", doc.get().contains(expectedText));
}
use of org.eclipse.ui.texteditor.IDocumentProvider in project linuxtools by eclipse.
the class STLink2SourceSupport method openFileImpl.
private static boolean openFileImpl(IProject project, IPath sourceLoc, int lineNumber) {
if (sourceLoc == null || "??".equals(sourceLoc.toString())) {
// $NON-NLS-1$
return false;
}
try {
IEditorInput editorInput = getEditorInput(sourceLoc, project);
IWorkbenchPage p = CUIPlugin.getActivePage();
if (p != null) {
if (editorInput == null) {
p.openEditor(new STCSourceNotFoundEditorInput(project, sourceLoc, lineNumber), STCSourceNotFoundEditor.ID, true);
} else {
IEditorPart editor = p.openEditor(editorInput, CUIPlugin.EDITOR_ID, true);
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);
IWorkbenchPage page = editor.getSite().getPage();
page.activate(editor);
return true;
} catch (BadLocationException x) {
// ignore
}
}
}
}
} catch (PartInitException e) {
}
return false;
}
use of org.eclipse.ui.texteditor.IDocumentProvider in project linuxtools by eclipse.
the class ProfileUIUtils method openEditorAndSelect.
/**
* Opens the specified file in an editor (or selects an already open
* editor) and highlights the specified line.
* @param result - result of performing source lookup with a org.eclipse.debug.core.model.ISourceLocator
* @param line - line number to select, 0 to not select a line
* @throws PartInitException - Failed to open editor
* @throws BadLocationException - Line number not valid in file
* @see DebugUITools#lookupSource(Object, org.eclipse.debug.core.model.ISourceLocator)
*/
public static void openEditorAndSelect(ISourceLookupResult result, int line) throws PartInitException, BadLocationException {
IEditorInput input = result.getEditorInput();
String editorID = result.getEditorId();
if (input == null || editorID == null) {
// Consult the CDT DebugModelPresentation
Object sourceElement = result.getSourceElement();
if (sourceElement != null) {
// Resolve IResource in case we get a LocalFileStorage object
if (sourceElement instanceof LocalFileStorage) {
IPath filePath = ((LocalFileStorage) sourceElement).getFullPath();
URI fileURI = URIUtil.toURI(filePath);
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IFile[] files = root.findFilesForLocationURI(fileURI);
if (files.length > 0) {
// Take the first match
sourceElement = files[0];
}
}
IDebugModelPresentation pres = DebugUITools.newDebugModelPresentation(CDebugCorePlugin.getUniqueIdentifier());
input = pres.getEditorInput(sourceElement);
editorID = pres.getEditorId(input, sourceElement);
pres.dispose();
}
}
if (input != null && editorID != null) {
// Open the editor
IWorkbenchPage activePage = ProfileUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart editor = IDE.openEditor(activePage, input, editorID);
// Select the line
if (editor instanceof ITextEditor) {
ITextEditor textEditor = (ITextEditor) editor;
if (line > 0) {
IDocumentProvider provider = textEditor.getDocumentProvider();
IDocument document = provider.getDocument(textEditor.getEditorInput());
// zero-indexed
IRegion lineRegion = document.getLineInformation(line - 1);
textEditor.selectAndReveal(lineRegion.getOffset(), lineRegion.getLength());
}
}
}
}
use of org.eclipse.ui.texteditor.IDocumentProvider in project linuxtools by eclipse.
the class ProfileUIUtils method openEditorAndSelect.
/**
* Opens an editor on the given file and selects the line.
* @param file The file to open.
* @param line The line to select.
* @throws PartInitException If opening editor failed.
* @throws BadLocationException If line number is invalid.
*
* @since 2.0
*/
public static void openEditorAndSelect(IFile file, int line) throws PartInitException, BadLocationException {
if (file.exists()) {
IWorkbenchPage activePage = ProfileUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart editor = IDE.openEditor(activePage, file);
if (editor instanceof ITextEditor) {
ITextEditor textEditor = (ITextEditor) editor;
if (line > 0) {
IDocumentProvider provider = textEditor.getDocumentProvider();
IDocument document = provider.getDocument(textEditor.getEditorInput());
// zero-indexed
int start = document.getLineOffset(line - 1);
textEditor.selectAndReveal(start, 0);
}
}
}
}
use of org.eclipse.ui.texteditor.IDocumentProvider in project linuxtools by eclipse.
the class IndentHandler method getDocument.
/**
* Returns the document currently displayed in the editor, or
* <code>null</code> if none can be obtained.
*
* @return the current document or <code>null</code>
*/
private IDocument getDocument(ITextEditor editor) {
if (editor != null) {
IDocumentProvider provider = editor.getDocumentProvider();
IEditorInput input = editor.getEditorInput();
if (provider != null && input != null)
return provider.getDocument(input);
}
return null;
}
Aggregations