use of org.eclipse.jface.text.ITextSelection in project xtext-eclipse by eclipse.
the class AbstractOpenHierarchyHandler method execute.
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
Object _xblockexpression = null;
{
final XtextEditor editor = EditorUtils.getActiveXtextEditor(event);
Object _xifexpression = null;
if ((editor != null)) {
Object _xblockexpression_1 = null;
{
final ISelection selection = editor.getSelectionProvider().getSelection();
Object _xifexpression_1 = null;
if ((selection instanceof ITextSelection)) {
Object _xblockexpression_2 = null;
{
final IWorkbenchWindow workbenchWindow = editor.getSite().getWorkbenchWindow();
final IUnitOfWork<Object, XtextResource> _function = (XtextResource it) -> {
Object _xblockexpression_3 = null;
{
this.openHierarchy(this._eObjectAtOffsetHelper.resolveElementAt(it, ((ITextSelection) selection).getOffset()), workbenchWindow);
_xblockexpression_3 = null;
}
return _xblockexpression_3;
};
_xblockexpression_2 = editor.getDocument().<Object>priorityReadOnly(_function);
}
_xifexpression_1 = _xblockexpression_2;
}
_xblockexpression_1 = _xifexpression_1;
}
_xifexpression = _xblockexpression_1;
}
_xblockexpression = _xifexpression;
}
return _xblockexpression;
}
use of org.eclipse.jface.text.ITextSelection in project xtext-eclipse by eclipse.
the class AbstractJvmElementHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final XtextEditor editor = EditorUtils.getActiveXtextEditor(event);
if (editor != null) {
final ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
editor.getDocument().priorityReadOnly(new IUnitOfWork<Void, XtextResource>() {
@Override
public java.lang.Void exec(XtextResource resource) throws Exception {
JvmIdentifiableElement jvmIdentifiable = jvmElementAtOffsetHelper.getJvmIdentifiableElement(resource, selection.getOffset());
if (jvmIdentifiable != null) {
IJavaElement javaType = javaElementFinder.findElementFor(jvmIdentifiable);
if (javaType != null)
openPresentation(editor, javaType, jvmIdentifiable);
}
return null;
}
});
}
return null;
}
use of org.eclipse.jface.text.ITextSelection in project xtext-eclipse by eclipse.
the class ToggleSLCommentAction method isSelectionCommented.
/**
* Is the given selection single-line commented?
*
* @param selection Selection to check
* @return <code>true</code> iff all selected lines are commented
* @since 2.1
*/
protected boolean isSelectionCommented(ISelection selection) {
if (!(selection instanceof ITextSelection))
return false;
ITextSelection textSelection = (ITextSelection) selection;
if (textSelection.getStartLine() < 0 || textSelection.getEndLine() < 0)
return false;
IDocument document = getTextEditor().getDocumentProvider().getDocument(getTextEditor().getEditorInput());
try {
IRegion block = getTextBlockFromSelection(textSelection, document);
ITypedRegion[] regions = TextUtilities.computePartitioning(document, fDocumentPartitioning, block.getOffset(), block.getLength(), false);
// [startline, endline, startline, endline, ...]
int[] lines = new int[regions.length * 2];
for (int i = 0, j = 0; i < regions.length; i++, j += 2) {
// start line of region
lines[j] = getFirstCompleteLineOfRegion(regions[i], document);
// end line of region
int length = regions[i].getLength();
int offset = regions[i].getOffset() + length;
if (length > 0)
offset--;
lines[j + 1] = (lines[j] == -1 ? -1 : document.getLineOfOffset(offset));
}
// Perform the check
for (int i = 0, j = 0; i < regions.length; i++, j += 2) {
String[] prefixes = fPrefixesMap.get(regions[i].getType());
if (prefixes != null && prefixes.length > 0 && lines[j] >= 0 && lines[j + 1] >= 0)
if (!isBlockCommented(lines[j], lines[j + 1], prefixes, document))
return false;
}
return true;
} catch (BadLocationException x) {
// should not happen
log.error(x.getMessage(), x);
}
return false;
}
use of org.eclipse.jface.text.ITextSelection in project xtext-eclipse by eclipse.
the class OutlineWithEditorLinker method selectInTreeView.
protected void selectInTreeView(ISelection selection) {
if (selection instanceof ITextSelection && !treeViewer.getTree().isDisposed()) {
ITextSelection textSelection = (ITextSelection) selection;
ITextRegion selectedTextRegion = new TextRegion(textSelection.getOffset(), textSelection.getLength());
Object input = treeViewer.getInput();
if (input instanceof IOutlineNode) {
try {
IOutlineNode nodeToBeSelected = findBestNode((IOutlineNode) input, selectedTextRegion);
if (nodeToBeSelected != null)
treeViewer.setSelection(new StructuredSelection(nodeToBeSelected));
} catch (Exception exc) {
// ignore, editor can have a different state than the tree
}
}
}
}
use of org.eclipse.jface.text.ITextSelection in project xtext-eclipse by eclipse.
the class ExpressionUtil method trimSelection.
protected ITextSelection trimSelection(XtextResource resource, ITextSelection selection) {
IParseResult parseResult = resource.getParseResult();
if (parseResult != null) {
String model = parseResult.getRootNode().getText();
String selectedText = model.substring(selection.getOffset(), selection.getOffset() + selection.getLength());
String trimmedSelection = selectedText.trim();
return new TextSelection(selection.getOffset() + selectedText.indexOf(trimmedSelection), trimmedSelection.length());
}
return null;
}
Aggregations