Search in sources :

Example 16 with ITextViewerExtension5

use of org.eclipse.jface.text.ITextViewerExtension5 in project eclipse.platform.text by eclipse.

the class LinkedModeUI method select.

private void select() {
    ITextViewer viewer = fCurrentTarget.getViewer();
    if (viewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension5 = (ITextViewerExtension5) viewer;
        extension5.exposeModelRange(new Region(fFramePosition.offset, fFramePosition.length));
    } else if (!viewer.overlapsWithVisibleRegion(fFramePosition.offset, fFramePosition.length)) {
        viewer.resetVisibleRegion();
    }
    viewer.revealRange(fFramePosition.offset, fFramePosition.length);
    viewer.setSelectedRange(fFramePosition.offset, fFramePosition.length);
}
Also used : ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) IRegion(org.eclipse.jface.text.IRegion) Region(org.eclipse.jface.text.Region) ITextViewer(org.eclipse.jface.text.ITextViewer)

Example 17 with ITextViewerExtension5

use of org.eclipse.jface.text.ITextViewerExtension5 in project eclipse.platform.text by eclipse.

the class AbstractTextEditor method isVisible.

/**
 * Tells whether the given region is visible in the given source viewer.
 *
 * @param viewer the source viewer
 * @param offset the offset of the region
 * @param length the length of the region
 * @return <code>true</code> if visible
 * @since 2.1
 */
protected static final boolean isVisible(ISourceViewer viewer, int offset, int length) {
    if (viewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
        IRegion overlap = extension.modelRange2WidgetRange(new Region(offset, length));
        return overlap != null;
    }
    return viewer.overlapsWithVisibleRegion(offset, length);
}
Also used : ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) IRegion(org.eclipse.jface.text.IRegion)

Example 18 with ITextViewerExtension5

use of org.eclipse.jface.text.ITextViewerExtension5 in project eclipse.platform.text by eclipse.

the class MarkRegionTarget method isVisible.

/**
 * Tells whether the given offset is visible in the given text viewer.
 *
 * @param viewer the text viewer
 * @param offset the offset to check
 * @return <code>true</code> if the given offset is visible in the given text viewer
 *
 * @since 2.1
 */
protected static final boolean isVisible(ITextViewer viewer, int offset) {
    if (viewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
        return extension.modelOffset2WidgetOffset(offset) >= 0;
    }
    IRegion region = viewer.getVisibleRegion();
    int vOffset = region.getOffset();
    return (vOffset <= offset && offset <= vOffset + region.getLength());
}
Also used : ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) IRegion(org.eclipse.jface.text.IRegion) Point(org.eclipse.swt.graphics.Point)

Example 19 with ITextViewerExtension5

use of org.eclipse.jface.text.ITextViewerExtension5 in project eclipse.platform.text by eclipse.

the class MoveLinesAction method containedByVisibleRegion.

/**
 * Checks if <code>selection</code> is contained by the visible region of <code>viewer</code>.
 * As a special case, a selection is considered contained even if it extends over the visible
 * region, but the extension stays on a partially contained line and contains only white space.
 *
 * @param selection the selection to be checked
 * @param viewer the viewer displaying a visible region of <code>selection</code>'s document.
 * @return <code>true</code>, if <code>selection</code> is contained, <code>false</code> otherwise.
 */
private boolean containedByVisibleRegion(ITextSelection selection, ITextViewer viewer) {
    int min = selection.getOffset();
    int max = min + selection.getLength();
    IDocument document = viewer.getDocument();
    IRegion visible;
    if (viewer instanceof ITextViewerExtension5)
        visible = ((ITextViewerExtension5) viewer).getModelCoverage();
    else
        visible = viewer.getVisibleRegion();
    int visOffset = visible.getOffset();
    try {
        if (visOffset > min) {
            if (document.getLineOfOffset(visOffset) != selection.getStartLine())
                return false;
            if (!isWhitespace(document.get(min, visOffset - min))) {
                showStatus();
                return false;
            }
        }
        int visEnd = visOffset + visible.getLength();
        if (visEnd < max) {
            if (document.getLineOfOffset(visEnd) != selection.getEndLine())
                return false;
            if (!isWhitespace(document.get(visEnd, max - visEnd))) {
                showStatus();
                return false;
            }
        }
        return true;
    } catch (BadLocationException e) {
    }
    return false;
}
Also used : ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) IDocument(org.eclipse.jface.text.IDocument) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 20 with ITextViewerExtension5

use of org.eclipse.jface.text.ITextViewerExtension5 in project eclipse.platform.text by eclipse.

the class MoveLinesAction method runWithEvent.

/*
	 * @see org.eclipse.jface.action.IAction#run()
	 */
@Override
public void runWithEvent(Event event) {
    if (fTextViewer == null)
        return;
    if (!validateEditorInputState())
        return;
    // get involved objects
    IDocument document = fTextViewer.getDocument();
    if (document == null)
        return;
    StyledText widget = fTextViewer.getTextWidget();
    if (widget == null)
        return;
    // get selection
    ITextSelection sel = (ITextSelection) fTextViewer.getSelectionProvider().getSelection();
    if (sel.isEmpty())
        return;
    ITextSelection skippedLine = getSkippedLine(document, sel);
    if (skippedLine == null)
        return;
    try {
        ITextSelection movingArea = getMovingSelection(document, sel, fTextViewer);
        // visible area, bail out
        if (!containedByVisibleRegion(movingArea, fTextViewer) || !containedByVisibleRegion(skippedLine, fTextViewer))
            return;
        // get the content to be moved around: the moving (selected) area and the skipped line
        String moving = movingArea.getText();
        String skipped = skippedLine.getText();
        if (moving == null || skipped == null || document.getLength() == 0)
            return;
        String delim;
        String insertion;
        int offset, deviation;
        if (fUpwards) {
            delim = document.getLineDelimiter(skippedLine.getEndLine());
            if (fCopy) {
                delim = TextUtilities.getDefaultLineDelimiter(document);
                insertion = moving + delim;
                offset = movingArea.getOffset();
                deviation = 0;
            } else {
                Assert.isNotNull(delim);
                insertion = moving + delim + skipped;
                offset = skippedLine.getOffset();
                deviation = -skippedLine.getLength() - delim.length();
            }
        } else {
            delim = document.getLineDelimiter(movingArea.getEndLine());
            if (fCopy) {
                if (delim == null) {
                    delim = TextUtilities.getDefaultLineDelimiter(document);
                    insertion = delim + moving;
                } else {
                    insertion = moving + delim;
                }
                offset = skippedLine.getOffset();
                deviation = movingArea.getLength() + delim.length();
            } else {
                Assert.isNotNull(delim);
                insertion = skipped + delim + moving;
                offset = movingArea.getOffset();
                deviation = skipped.length() + delim.length();
            }
        }
        // modify the document
        beginCompoundEdit();
        if (fCopy) {
            // fDescription= new EditDescription(offset, 0, insertion.length());
            document.replace(offset, 0, insertion);
        } else {
            // fDescription= new EditDescription(offset, insertion.length(), insertion.length());
            document.replace(offset, insertion.length(), insertion);
        }
        // move the selection along
        int selOffset = movingArea.getOffset() + deviation;
        int selLength = movingArea.getLength() + (fAddDelimiter ? delim.length() : 0);
        if (!(fTextViewer instanceof ITextViewerExtension5))
            selLength = Math.min(selLength, fTextViewer.getVisibleRegion().getOffset() + fTextViewer.getVisibleRegion().getLength() - selOffset);
        else {
        // TODO need to check what is necessary in the projection case
        }
        selectAndReveal(fTextViewer, selOffset, selLength);
    } catch (BadLocationException x) {
        // won't happen without concurrent modification - bail out
        return;
    }
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) IDocument(org.eclipse.jface.text.IDocument) ITextSelection(org.eclipse.jface.text.ITextSelection) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

ITextViewerExtension5 (org.eclipse.jface.text.ITextViewerExtension5)32 IRegion (org.eclipse.jface.text.IRegion)22 Point (org.eclipse.swt.graphics.Point)21 BadLocationException (org.eclipse.jface.text.BadLocationException)11 Region (org.eclipse.jface.text.Region)10 IDocument (org.eclipse.jface.text.IDocument)9 StyledText (org.eclipse.swt.custom.StyledText)9 Position (org.eclipse.jface.text.Position)5 Rectangle (org.eclipse.swt.graphics.Rectangle)5 ITextViewer (org.eclipse.jface.text.ITextViewer)2 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)2 GC (org.eclipse.swt.graphics.GC)2 Image (org.eclipse.swt.graphics.Image)2 Entry (java.util.Map.Entry)1 IFindReplaceTargetExtension (org.eclipse.jface.text.IFindReplaceTargetExtension)1 ITextSelection (org.eclipse.jface.text.ITextSelection)1 ITextViewerExtension (org.eclipse.jface.text.ITextViewerExtension)1 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)1 ILineRange (org.eclipse.jface.text.source.ILineRange)1 LineRange (org.eclipse.jface.text.source.LineRange)1