use of org.eclipse.ui.texteditor.ITextEditor in project KaiZen-OpenAPI-Editor by RepreZen.
the class TextDocumentMarkerResolution method openTextEditor.
protected ITextEditor openTextEditor(IFile file) throws CoreException {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart part;
try {
part = IDE.openEditor(page, file, true);
} catch (PartInitException e) {
throw new CoreException(createStatus(e, "Cannot open editor"));
}
if (!(part instanceof ITextEditor)) {
throw new CoreException(createStatus(null, "The editor is not TextEditor: " + part));
}
return (ITextEditor) part;
}
use of org.eclipse.ui.texteditor.ITextEditor in project KaiZen-OpenAPI-Editor by RepreZen.
the class TextDocumentMarkerResolution method run.
public void run(IMarker marker) {
try {
IResource resource = marker.getResource();
if (resource.getType() != IResource.FILE) {
throw new CoreException(createStatus(null, "The editor is not a File: " + resource.getName()));
}
IFile file = (IFile) resource;
ITextEditor editor = openTextEditor(file);
IDocument document = editor.getDocumentProvider().getDocument(new FileEditorInput(file));
if (document == null) {
throw new CoreException(createStatus(null, "The document is null"));
}
IRegion region = processFix(document, marker);
if (region != null) {
editor.selectAndReveal(region.getOffset(), region.getLength());
}
} catch (CoreException e) {
Activator.getDefault().getLog().log(e.getStatus());
}
}
use of org.eclipse.ui.texteditor.ITextEditor in project eclipse.platform.text by eclipse.
the class TextEditorActionContributor method doSetActiveEditor.
/**
* Internally sets the active editor to the actions provided by this contributor.
* Cannot be overridden by subclasses.
*
* @param part the editor
*/
private void doSetActiveEditor(final IEditorPart part) {
ITextEditor textEditor = null;
if (part instanceof ITextEditor)
textEditor = (ITextEditor) part;
/**
* The global actions to be connected with editor actions
*/
IActionBars actionBars = getActionBars();
actionBars.setGlobalActionHandler(IDEActionFactory.ADD_TASK.getId(), getAction(textEditor, IDEActionFactory.ADD_TASK.getId()));
actionBars.setGlobalActionHandler(IDEActionFactory.BOOKMARK.getId(), getAction(textEditor, IDEActionFactory.BOOKMARK.getId()));
IAction action = getAction(textEditor, ITextEditorActionConstants.NEXT);
actionBars.setGlobalActionHandler(ITextEditorActionDefinitionIds.GOTO_NEXT_ANNOTATION, action);
actionBars.setGlobalActionHandler(ITextEditorActionConstants.NEXT, action);
action = getAction(textEditor, ITextEditorActionConstants.PREVIOUS);
actionBars.setGlobalActionHandler(ITextEditorActionDefinitionIds.GOTO_PREVIOUS_ANNOTATION, action);
actionBars.setGlobalActionHandler(ITextEditorActionConstants.PREVIOUS, action);
action = getAction(textEditor, ITextEditorActionConstants.REFRESH);
actionBars.setGlobalActionHandler(ITextEditorActionConstants.REFRESH, action);
fChangeEncodingAction.setAction(getAction(textEditor, ITextEditorActionConstants.CHANGE_ENCODING));
IAction quickAssistAction = getAction(textEditor, ITextEditorActionConstants.QUICK_ASSIST);
fQuickAssistAction.setAction(quickAssistAction);
if (textEditor == null)
return;
// Update Quick Assist menu entry - for now don't show disabled entry
IMenuManager menuMgr = textEditor.getEditorSite().getActionBars().getMenuManager();
IMenuManager editMenu = menuMgr.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
if (editMenu != null) {
boolean isEnabled = quickAssistAction != null && quickAssistAction.isEnabled();
fQuickAssistMenuEntry.setVisible(isEnabled);
editMenu.update(true);
}
fRetargetShowInformationAction.setAction(getAction(textEditor, ITextEditorActionConstants.SHOW_INFORMATION));
}
use of org.eclipse.ui.texteditor.ITextEditor in project eclipse.platform.text by eclipse.
the class LastSaveReferenceProvider method readDocument.
/**
* Reads in the saved document into <code>fReference</code>.
*
* @param monitor a progress monitor, or <code>null</code>
* @param force <code>true</code> if the reference document should also
* be read if the current document is <code>null</code>,<code>false</code>
* if it should only be updated if it already existed.
*/
private void readDocument(IProgressMonitor monitor, boolean force) {
// protect against concurrent disposal
IDocumentProvider prov = fDocumentProvider;
IEditorInput inp = fEditorInput;
IDocument doc = fReference;
ITextEditor editor = fEditor;
if (prov instanceof IStorageDocumentProvider && inp instanceof IStorageEditorInput) {
IStorageEditorInput input = (IStorageEditorInput) inp;
IStorageDocumentProvider provider = (IStorageDocumentProvider) prov;
if (doc == null)
if (force || fDocumentRead)
doc = new Document();
else
return;
IJobManager jobMgr = Job.getJobManager();
try {
IStorage storage = input.getStorage();
// check for null for backward compatibility (we used to check before...)
if (storage == null)
return;
fProgressMonitor = monitor;
ISchedulingRule rule = getSchedulingRule(storage);
// delay for any other job requiring the lock on file
try {
lockDocument(monitor, jobMgr, rule);
String encoding;
if (storage instanceof IEncodedStorage)
encoding = ((IEncodedStorage) storage).getCharset();
else
encoding = null;
boolean skipUTF8BOM = isUTF8BOM(encoding, storage);
setDocumentContent(doc, storage, encoding, monitor, skipUTF8BOM);
} finally {
unlockDocument(jobMgr, rule);
fProgressMonitor = null;
}
} catch (CoreException e) {
return;
}
if (monitor != null && monitor.isCanceled())
return;
// update state
synchronized (fLock) {
if (fDocumentProvider == provider && fEditorInput == input) {
// only update state if our provider / input pair has not
// been updated in between (dispose or setActiveEditor)
fReference = doc;
fDocumentRead = true;
addElementStateListener(editor, prov);
}
}
}
}
use of org.eclipse.ui.texteditor.ITextEditor in project eclipse.platform.text by eclipse.
the class QuickDiffRestoreAction method run.
@Override
public void run() {
ITextEditor editor = getTextEditor();
if (editor == null || !validateEditorInputState())
return;
IRewriteTarget target = editor.getAdapter(IRewriteTarget.class);
if (target != null)
target.beginCompoundChange();
runCompoundChange();
if (target != null)
target.endCompoundChange();
}
Aggregations