use of org.eclipse.ui.texteditor.ITextEditor in project xtext-eclipse by eclipse.
the class ToggleSLCommentAction method update.
/**
* Implementation of the <code>IUpdate</code> prototype method discovers
* the operation through the current editor's
* <code>ITextOperationTarget</code> adapter, and sets the enabled state
* accordingly.
*/
@Override
public void update() {
super.update();
if (!canModifyEditor()) {
setEnabled(false);
return;
}
ITextEditor editor = getTextEditor();
if (fOperationTarget == null && editor != null)
fOperationTarget = (ITextOperationTarget) editor.getAdapter(ITextOperationTarget.class);
boolean isEnabled = (fOperationTarget != null && fOperationTarget.canDoOperation(ITextOperationTarget.PREFIX) && fOperationTarget.canDoOperation(ITextOperationTarget.STRIP_PREFIX));
setEnabled(isEnabled);
}
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();
}
use of org.eclipse.ui.texteditor.ITextEditor in project eclipse.platform.text by eclipse.
the class GotoLineTest method goToLine.
private void goToLine(int line, int expectedResult) {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
try {
IEditorPart part = IDE.openEditor(page, fFile);
if (part instanceof ITextEditor) {
ITextEditor editor = (ITextEditor) part;
IAction action = editor.getAction(ITextEditorActionConstants.GOTO_LINE);
Accessor accessor = new Accessor(action, GotoLineAction.class);
accessor.invoke("gotoLine", new Class[] { int.class }, new Integer[] { Integer.valueOf(line) });
Control control = part.getAdapter(Control.class);
if (control instanceof StyledText) {
int caretLine = -1;
StyledText styledText = (StyledText) control;
int caret = styledText.getCaretOffset();
try {
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
caretLine = document.getLineOfOffset(caret);
} catch (BadLocationException e1) {
fail();
}
assertEquals(expectedResult, caretLine);
} else
fail();
} else
fail();
} catch (PartInitException e) {
fail();
}
}
Aggregations