Search in sources :

Example 26 with ITextViewerExtension5

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

the class InlinedAnnotationSupport method getInlinedAnnotationAtLine.

/**
 * Returns the {@link AbstractInlinedAnnotation} from the given line index and null otherwise.
 *
 * @param viewer the source viewer
 * @param lineIndex the line index.
 * @return the {@link AbstractInlinedAnnotation} from the given line index and null otherwise.
 */
private static AbstractInlinedAnnotation getInlinedAnnotationAtLine(ISourceViewer viewer, int lineIndex) {
    if (viewer == null) {
        return null;
    }
    IAnnotationModel annotationModel = viewer.getAnnotationModel();
    if (annotationModel == null) {
        return null;
    }
    IDocument document = viewer.getDocument();
    int lineNumber = lineIndex;
    if (lineNumber > document.getNumberOfLines()) {
        return null;
    }
    try {
        if (viewer instanceof ITextViewerExtension5) {
            lineNumber = ((ITextViewerExtension5) viewer).widgetLine2ModelLine(lineNumber);
        }
        IRegion line = document.getLineInformation(lineNumber);
        return getInlinedAnnotationAtOffset(viewer, line.getOffset(), line.getLength());
    } catch (BadLocationException e) {
        return null;
    }
}
Also used : ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) 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 27 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 28 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 29 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 30 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)

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