Search in sources :

Example 41 with ITextViewerExtension5

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

the class InlinedAnnotationSupport method getLineContentAnnotationAtPoint.

/**
 * Returns the {@link AbstractInlinedAnnotation} line content from the given point and null
 * otherwise.
 *
 * @param viewer the source viewer
 * @param point the origin of character bounding box relative to the origin of the widget client
 *            area.
 * @return the {@link AbstractInlinedAnnotation} line content from the given point and null
 *         otherwise.
 */
private static AbstractInlinedAnnotation getLineContentAnnotationAtPoint(ISourceViewer viewer, Point point) {
    StyledText styledText = viewer.getTextWidget();
    int offset = styledText.getOffsetAtPoint(point);
    if (offset == -1) {
        return null;
    }
    if (viewer instanceof ITextViewerExtension5) {
        offset = ((ITextViewerExtension5) viewer).widgetOffset2ModelOffset(offset);
    }
    AbstractInlinedAnnotation annotation = getInlinedAnnotationAtOffset(viewer, offset, 1);
    if (annotation instanceof LineContentAnnotation) {
        return annotation;
    }
    return null;
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) Point(org.eclipse.swt.graphics.Point)

Example 42 with ITextViewerExtension5

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

the class InformationPresenter method modelRange2WidgetRange.

/**
 * Translated the given range in the viewer's document into the corresponding
 * range of the viewer's widget.
 *
 * @param region the range in the viewer's document
 * @return the corresponding widget range
 * @since 2.1
 */
private IRegion modelRange2WidgetRange(IRegion region) {
    if (fTextViewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension = (ITextViewerExtension5) fTextViewer;
        return extension.modelRange2WidgetRange(region);
    }
    IRegion visibleRegion = fTextViewer.getVisibleRegion();
    int start = region.getOffset() - visibleRegion.getOffset();
    int end = start + region.getLength();
    if (end > visibleRegion.getLength())
        end = visibleRegion.getLength();
    return new Region(start, end - start);
}
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) Point(org.eclipse.swt.graphics.Point)

Example 43 with ITextViewerExtension5

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

the class AnnotationPainter method applyTextPresentation.

@Override
public void applyTextPresentation(TextPresentation tp) {
    Set<Entry<Annotation, Decoration>> decorations;
    synchronized (fHighlightedDecorationsMapLock) {
        if (fHighlightedDecorationsMap == null || fHighlightedDecorationsMap.isEmpty())
            return;
        decorations = new HashSet<>(fHighlightedDecorationsMap.entrySet());
    }
    IRegion region = tp.getExtent();
    if (DEBUG)
        // $NON-NLS-1$ //$NON-NLS-2$
        System.out.println("AP: applying text presentation offset: " + region.getOffset() + ", length= " + region.getLength());
    for (int layer = 0, maxLayer = 1; layer < maxLayer; layer++) {
        for (Entry<Annotation, Decoration> entry : decorations) {
            Annotation a = entry.getKey();
            if (a.isMarkedDeleted())
                continue;
            Decoration pp = entry.getValue();
            // dynamically update layer maximum
            maxLayer = Math.max(maxLayer, pp.fLayer + 1);
            if (// wrong layer: skip annotation
            pp.fLayer != layer)
                continue;
            Position p = pp.fPosition;
            if (fSourceViewer instanceof ITextViewerExtension5) {
                ITextViewerExtension5 extension3 = (ITextViewerExtension5) fSourceViewer;
                if (null == extension3.modelRange2WidgetRange(new Region(p.getOffset(), p.getLength())))
                    continue;
            } else if (!fSourceViewer.overlapsWithVisibleRegion(p.offset, p.length)) {
                continue;
            }
            int regionEnd = region.getOffset() + region.getLength();
            int pEnd = p.getOffset() + p.getLength();
            if (pEnd >= region.getOffset() && regionEnd > p.getOffset()) {
                int start = Math.max(p.getOffset(), region.getOffset());
                int end = Math.min(regionEnd, pEnd);
                int length = Math.max(end - start, 0);
                StyleRange styleRange = new StyleRange(start, length, null, null);
                ((ITextStyleStrategy) pp.fPaintingStrategy).applyTextStyle(styleRange, pp.fColor);
                tp.mergeStyleRange(styleRange);
            }
        }
    }
}
Also used : Position(org.eclipse.jface.text.Position) ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) StyleRange(org.eclipse.swt.custom.StyleRange) IRegion(org.eclipse.jface.text.IRegion) Point(org.eclipse.swt.graphics.Point) Entry(java.util.Map.Entry) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion)

Example 44 with ITextViewerExtension5

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

the class ChangeRulerColumn method computeVisibleModelLines.

/**
 * Computes the document based line range visible in the text widget.
 *
 * @return the document based line range visible in the text widget
 * @since 3.2
 */
private final ILineRange computeVisibleModelLines() {
    IDocument doc = fCachedTextViewer.getDocument();
    if (doc == null)
        return null;
    int topLine;
    IRegion coverage;
    if (fCachedTextViewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension = (ITextViewerExtension5) fCachedTextViewer;
        // ITextViewer.getTopIndex returns the fully visible line, but we want the partially
        // visible one
        int widgetTopLine = JFaceTextUtil.getPartialTopIndex(fCachedTextWidget);
        topLine = extension.widgetLine2ModelLine(widgetTopLine);
        coverage = extension.getModelCoverage();
    } else {
        topLine = JFaceTextUtil.getPartialTopIndex(fCachedTextViewer);
        coverage = fCachedTextViewer.getVisibleRegion();
    }
    int bottomLine = fCachedTextViewer.getBottomIndex();
    if (bottomLine != -1)
        ++bottomLine;
    // clip by coverage window
    try {
        int firstLine = doc.getLineOfOffset(coverage.getOffset());
        if (firstLine > topLine)
            topLine = firstLine;
        int lastLine = doc.getLineOfOffset(coverage.getOffset() + coverage.getLength());
        if (lastLine < bottomLine || bottomLine == -1)
            bottomLine = lastLine;
    } catch (BadLocationException x) {
        return null;
    }
    ILineRange visibleModelLines = new LineRange(topLine, bottomLine - topLine + 1);
    return visibleModelLines;
}
Also used : ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) IDocument(org.eclipse.jface.text.IDocument) Point(org.eclipse.swt.graphics.Point) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 45 with ITextViewerExtension5

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

the class LineNumberRulerColumn method handleMouseScrolled.

/**
 * Handles mouse scrolled events on the ruler by forwarding them to the text widget.
 *
 * @param e the mouse event
 * @since 3.10
 */
void handleMouseScrolled(MouseEvent e) {
    if (fCachedTextViewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension = (ITextViewerExtension5) fCachedTextViewer;
        StyledText textWidget = fCachedTextViewer.getTextWidget();
        int topIndex = textWidget.getTopIndex();
        int newTopIndex = Math.max(0, topIndex - e.count);
        fCachedTextViewer.setTopIndex(extension.widgetLine2ModelLine(newTopIndex));
    } else {
        int topIndex = fCachedTextViewer.getTopIndex();
        int newTopIndex = Math.max(0, topIndex - e.count);
        fCachedTextViewer.setTopIndex(newTopIndex);
    }
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) Point(org.eclipse.swt.graphics.Point)

Aggregations

ITextViewerExtension5 (org.eclipse.jface.text.ITextViewerExtension5)58 Point (org.eclipse.swt.graphics.Point)39 IRegion (org.eclipse.jface.text.IRegion)38 StyledText (org.eclipse.swt.custom.StyledText)23 Region (org.eclipse.jface.text.Region)17 BadLocationException (org.eclipse.jface.text.BadLocationException)14 IDocument (org.eclipse.jface.text.IDocument)14 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)7 ITextViewer (org.eclipse.jface.text.ITextViewer)6 Rectangle (org.eclipse.swt.graphics.Rectangle)6 Position (org.eclipse.jface.text.Position)5 GC (org.eclipse.swt.graphics.GC)5 StyleRange (org.eclipse.swt.custom.StyleRange)4 ITextViewerExtension2 (org.eclipse.jface.text.ITextViewerExtension2)3 ITypedRegion (org.eclipse.jface.text.ITypedRegion)3 ITextSelection (org.eclipse.jface.text.ITextSelection)2 Color (org.eclipse.swt.graphics.Color)2 Image (org.eclipse.swt.graphics.Image)2 Display (org.eclipse.swt.widgets.Display)2 Entry (java.util.Map.Entry)1