use of org.eclipse.ui.texteditor.ITextEditor in project xtext-xtend by eclipse.
the class OpenEditorAction method run.
@Override
public void run() {
if (inputFile == null) {
return;
}
IWorkbenchPartSite workbenchPartSite = derivedSourceView.getSite();
IWorkbenchPage workbenchPage = workbenchPartSite.getPage();
try {
IEditorPart editorPart = workbenchPage.openEditor(new FileEditorInput(inputFile), COMPILATION_UNIT_EDITOR_ID, true, IWorkbenchPage.MATCH_ID | IWorkbenchPage.MATCH_INPUT);
if (selectedRegion != null) {
((ITextEditor) editorPart).selectAndReveal(selectedRegion.getOffset(), selectedRegion.getLength());
}
} catch (PartInitException partInitException) {
throw new WrappedRuntimeException(partInitException);
}
}
use of org.eclipse.ui.texteditor.ITextEditor in project xtext-xtend by eclipse.
the class AbstractNewXtendElementWizard method performFinish.
@Override
public boolean performFinish() {
final int size = this.page.createType();
final IResource resource = page.getResource();
if (resource != null) {
selectAndReveal(resource);
final Display display = getShell().getDisplay();
display.asyncExec(new Runnable() {
@Override
public void run() {
IEditorPart editor;
try {
editor = IDE.openEditor(JavaPlugin.getActivePage(), (IFile) resource);
if (editor instanceof ITextEditor) {
((ITextEditor) editor).selectAndReveal(size - 2, 0);
}
} catch (PartInitException e) {
throw new RuntimeException(e);
}
}
});
return true;
} else {
return false;
}
}
use of org.eclipse.ui.texteditor.ITextEditor 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.ITextEditor in project linuxtools by eclipse.
the class ProfileUIUtils method openEditorAndSelect.
/**
* Open a file in the Editor at the specified offset, highlighting the given length
*
* @param path : Absolute path pointing to the file which will be opened.
* @param offset : Offset of the function to be highlighted.
* @param length : Length of the function to be highlighted.
* @throws PartInitException if the editor could not be initialized
*/
public static void openEditorAndSelect(String path, int offset, int length) throws PartInitException {
Path p = new Path(path);
if (p.toFile().exists()) {
IWorkbenchPage activePage = ProfileUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
IFileStore fileStore = EFS.getLocalFileSystem().getStore(p);
IEditorPart editor = IDE.openEditorOnFileStore(activePage, fileStore);
if (editor instanceof ITextEditor) {
ITextEditor text = (ITextEditor) editor;
text.selectAndReveal(offset, length);
}
}
}
use of org.eclipse.ui.texteditor.ITextEditor 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());
}
}
}
}
Aggregations