Search in sources :

Example 76 with ITextSelection

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;
}
Also used : TextRegion(org.eclipse.xtext.util.TextRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion) ITextSelection(org.eclipse.jface.text.ITextSelection)

Example 77 with ITextSelection

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);
                }
            }
        }
    }
}
Also used : ITextRegion(org.eclipse.xtext.util.ITextRegion) TextRegion(org.eclipse.xtext.util.TextRegion) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ITextSelection(org.eclipse.jface.text.ITextSelection) IOutlineNode(org.eclipse.xtext.ui.editor.outline.IOutlineNode)

Example 78 with ITextSelection

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);
    }
}
Also used : IDocumentExtension4(org.eclipse.jface.text.IDocumentExtension4) ITextSelection(org.eclipse.jface.text.ITextSelection) IRegion(org.eclipse.jface.text.IRegion) DocumentRewriteSession(org.eclipse.jface.text.DocumentRewriteSession) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) ITypedRegion(org.eclipse.jface.text.ITypedRegion) Map(java.util.Map) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 79 with ITextSelection

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());
}
Also used : ITextSelection(org.eclipse.jface.text.ITextSelection)

Example 80 with ITextSelection

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;
}
Also used : SQLHyperlinkDetector(org.jkiss.dbeaver.ui.editors.sql.syntax.SQLHyperlinkDetector) IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) ITextSelection(org.eclipse.jface.text.ITextSelection) IRegion(org.eclipse.jface.text.IRegion) IEditorStatusLine(org.eclipse.ui.texteditor.IEditorStatusLine)

Aggregations

ITextSelection (org.eclipse.jface.text.ITextSelection)205 ISelection (org.eclipse.jface.viewers.ISelection)65 IDocument (org.eclipse.jface.text.IDocument)52 BadLocationException (org.eclipse.jface.text.BadLocationException)46 IRegion (org.eclipse.jface.text.IRegion)34 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)34 Region (org.eclipse.jface.text.Region)31 IEditorPart (org.eclipse.ui.IEditorPart)29 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)25 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)21 ArrayList (java.util.ArrayList)18 TextSelection (org.eclipse.jface.text.TextSelection)17 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)14 Point (org.eclipse.swt.graphics.Point)13 IResource (org.eclipse.core.resources.IResource)12 XtextEditor (org.eclipse.xtext.ui.editor.XtextEditor)12 IFile (org.eclipse.core.resources.IFile)11 StyledText (org.eclipse.swt.custom.StyledText)11 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)11 Template (org.eclipse.jface.text.templates.Template)10