use of org.eclipse.jface.text.ITextSelection in project xtext-xtend by eclipse.
the class DerivedSourceView method mapTextRegion.
private TextRegion mapTextRegion(IWorkbenchPartSelection workbenchPartSelection) {
ITextSelection textSelection = (ITextSelection) workbenchPartSelection.getSelection();
TextRegion localRegion = new TextRegion(textSelection.getOffset(), textSelection.getLength());
return localRegion;
}
use of org.eclipse.jface.text.ITextSelection in project xtext-xtend by eclipse.
the class XtendOutlineWithEditorLinker method selectInTreeView.
@Override
public void selectInTreeView(final ISelection selection) {
if (((selection instanceof ITextSelection) && (!this.treeViewer.getTree().isDisposed()))) {
final ITextSelection textSelection = ((ITextSelection) selection);
int _offset = textSelection.getOffset();
int _length = textSelection.getLength();
final TextRegion selectedTextRegion = new TextRegion(_offset, _length);
final Object input = this.treeViewer.getInput();
if ((input instanceof IOutlineNode)) {
final List<IOutlineNode> matchingNodes = CollectionLiterals.<IOutlineNode>newArrayList();
this.findNodesInRange(((IOutlineNode) input), selectedTextRegion, matchingNodes);
boolean _isEmpty = matchingNodes.isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
final Function1<IOutlineNode, Integer> _function = (IOutlineNode it) -> {
return Integer.valueOf(it.getFullTextRegion().getLength());
};
final Integer smallestMatch = IterableExtensions.<Integer>min(ListExtensions.<IOutlineNode, Integer>map(matchingNodes, _function));
final Function1<IOutlineNode, Boolean> _function_1 = (IOutlineNode it) -> {
int _length_1 = it.getFullTextRegion().getLength();
return Boolean.valueOf((_length_1 == (smallestMatch).intValue()));
};
final Iterable<IOutlineNode> nodesToBeSelected = IterableExtensions.<IOutlineNode>filter(matchingNodes, _function_1);
boolean _isEmpty_1 = IterableExtensions.isEmpty(nodesToBeSelected);
boolean _not_1 = (!_isEmpty_1);
if (_not_1) {
Object[] _array = IterableExtensions.<IOutlineNode>toList(nodesToBeSelected).toArray();
StructuredSelection _structuredSelection = new StructuredSelection(_array);
this.treeViewer.setSelection(_structuredSelection);
}
}
}
}
}
use of org.eclipse.jface.text.ITextSelection in project xtext-xtend by eclipse.
the class RichStringAwareSourceViewer method shift.
@SuppressWarnings("deprecation")
@Override
protected void shift(boolean useDefaultPrefixes, boolean right, boolean ignoreWhitespace) {
if (useDefaultPrefixes && ignoreWhitespace) {
// let's assume we toggled comments
if (fUndoManager != null)
fUndoManager.beginCompoundChange();
IDocument d = getDocument();
Map<String, IDocumentPartitioner> partitioners = null;
DocumentRewriteSession rewriteSession = null;
try {
ITextSelection selection = (ITextSelection) getSelection();
IRegion block = copiedGetTextBlockFromSelection(selection);
ITypedRegion[] regions = TextUtilities.computePartitioning(d, getDocumentPartitioning(), block.getOffset(), block.getLength(), false);
regions = merger.merge(regions);
int lineCount = 0;
// [start line, end line, start line, end line, ...]
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] = copiedGetFirstCompleteLineOfRegion(regions[i]);
// 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 : d.getLineOfOffset(offset));
lineCount += lines[j + 1] - lines[j] + 1;
}
if (d instanceof IDocumentExtension4) {
IDocumentExtension4 extension = (IDocumentExtension4) d;
rewriteSession = extension.startRewriteSession(DocumentRewriteSessionType.SEQUENTIAL);
} else {
setRedraw(false);
startSequentialRewriteMode(true);
}
if (lineCount >= 20)
partitioners = TextUtilities.removeDocumentPartitioners(d);
// Perform the shift operation.
@SuppressWarnings("rawtypes") Map map = fDefaultPrefixChars;
for (int i = 0, j = 0; i < regions.length; i++, j += 2) {
String[] prefixes = (String[]) copiedSelectContentTypePlugin(regions[i].getType(), map);
if (prefixes != null && prefixes.length > 0 && lines[j] >= 0 && lines[j + 1] >= 0) {
if (right)
copiedShiftRight(lines[j], lines[j + 1], prefixes[0]);
else
copiedShiftLeft(lines[j], lines[j + 1], prefixes, ignoreWhitespace);
}
}
} catch (BadLocationException x) {
log.debug(x.getMessage(), x);
} finally {
if (partitioners != null)
TextUtilities.addDocumentPartitioners(d, partitioners);
if (d instanceof IDocumentExtension4) {
IDocumentExtension4 extension = (IDocumentExtension4) d;
extension.stopRewriteSession(rewriteSession);
} else {
stopSequentialRewriteMode();
setRedraw(true);
}
if (fUndoManager != null)
fUndoManager.endCompoundChange();
}
} else {
super.shift(useDefaultPrefixes, right, ignoreWhitespace);
}
}
use of org.eclipse.jface.text.ITextSelection in project dbeaver by dbeaver.
the class SQLEditorSourceViewer method refreshTextSelection.
void refreshTextSelection() {
ITextSelection selection = (ITextSelection) getSelection();
fireSelectionChanged(selection.getOffset(), selection.getLength());
}
use of org.eclipse.jface.text.ITextSelection in project dbeaver by dbeaver.
the class SQLEditorHandlerNavigateObject method getCurrentHyperlink.
private IHyperlink getCurrentHyperlink(SQLEditorBase editor) {
SQLHyperlinkDetector hyperlinkDetector = editor.getViewerConfiguration().getHyperlinkDetector();
ITextSelection selection = (ITextSelection) editor.getTextViewer().getSelection();
IRegion curRegion = new Region(selection.getOffset(), 0);
IHyperlink[] hyperLinks = hyperlinkDetector.detectHyperlinks(editor.getTextViewer(), curRegion, false);
if (!ArrayUtils.isEmpty(hyperLinks)) {
return hyperLinks[0];
}
String lastKeyword = hyperlinkDetector.getLastKeyword();
if (!CommonUtils.isEmpty(lastKeyword)) {
IEditorStatusLine statusLine = editor.getAdapter(IEditorStatusLine.class);
if (statusLine != null) {
statusLine.setMessage(true, "Can't find metadata object for name '" + lastKeyword + "'", (Image) null);
}
editor.getEditorControl().getDisplay().beep();
}
return null;
}
Aggregations