use of org.eclipse.jface.text.ITextSelection in project erlide_eclipse by erlang.
the class FilteredModulesSelectionDialog method open.
@Override
public int open() {
if (getInitialPattern() == null) {
final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window != null) {
final ISelection selection = window.getSelectionService().getSelection();
if (selection instanceof ITextSelection) {
String text = ((ITextSelection) selection).getText();
if (text != null) {
text = text.trim();
if (!text.isEmpty()) {
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
final IStatus result = workspace.validateName(text, IResource.FILE);
if (result.isOK()) {
setInitialPattern(text);
}
}
}
}
}
}
return super.open();
}
use of org.eclipse.jface.text.ITextSelection in project erlide_eclipse by erlang.
the class IndentHandler method doAction.
@Override
protected void doAction(final ISelection sel, final ITextEditor textEditor) {
final IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
final ITextSelection selection = ErlangAbstractHandler.extendSelectionToWholeLines(document, (ITextSelection) sel);
final ITextSelection getSelection = getTextSelection(document, selection, textEditor);
String text;
OtpErlangObject r1 = null;
try {
text = document.get(getSelection.getOffset(), getSelection.getLength());
// call erlang, with selection within text
r1 = callErlang(selection.getOffset() - getSelection.getOffset(), selection.getLength(), text);
} catch (final Exception e) {
ErlLogger.error(e);
}
final String newText = Util.stringValue(r1);
if (newText == null) {
final String msg = "call to " + getClass().getSimpleName() + " timed out; try a smaller selection.";
final Status status = new Status(IStatus.ERROR, ErlangCore.PLUGIN_ID, ErlangStatus.INTERNAL_ERROR.getValue(), msg, null);
ErlLogger.error("INTERNAL ERROR: " + msg);
ErrorDialog.openError(textEditor.getSite().getShell(), ActionMessages.IndentAction_error_message, "Internal error", status);
return;
}
final Display display = textEditor.getEditorSite().getShell().getDisplay();
display.syncExec(() -> {
final IRewriteTarget target = textEditor.getAdapter(IRewriteTarget.class);
if (target != null) {
target.beginCompoundChange();
target.setRedraw(false);
}
try {
if (!document.get(selection.getOffset(), selection.getLength()).equals(newText)) {
document.replace(selection.getOffset(), selection.getLength(), newText);
}
} catch (final BadLocationException e) {
ErlLogger.warn(e);
}
if (target != null) {
target.endCompoundChange();
target.setRedraw(true);
}
});
}
use of org.eclipse.jface.text.ITextSelection in project xtext-eclipse by eclipse.
the class AbstractAutoEditTest method assertState.
protected void assertState(XtextEditor editor, String string) {
int cursor = string.indexOf('|');
assertEquals(string.replace("|", ""), editor.getDocument().get());
ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
assertEquals("unexpected cursor position:", cursor, selection.getOffset());
}
use of org.eclipse.jface.text.ITextSelection in project xtext-eclipse by eclipse.
the class AbstractCursorHandlingTest method assertState.
protected void assertState(String string, XtextEditor editor) {
int cursor = string.indexOf('|');
assertEquals(string.replace("|", ""), editor.getDocument().get());
ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
assertEquals("unexpected cursor position:", cursor, selection.getOffset());
}
use of org.eclipse.jface.text.ITextSelection in project xtext-eclipse by eclipse.
the class AbstractEditorDoubleClickTextSelectionTest method assertSelectedText.
protected void assertSelectedText(AbstractTextEditor textEditor, CharSequence expectedSelectedText) {
ISelection selection = textEditor.getSelectionProvider().getSelection();
String actualSelectedText = ((ITextSelection) selection).getText();
assertEquals(expectedSelectedText, actualSelectedText);
}
Aggregations