Search in sources :

Example 6 with ITextViewerExtension5

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

the class JavaEditor method adjustHighlightRange.

@Override
protected void adjustHighlightRange(int offset, int length) {
    ISourceViewer viewer = getSourceViewer();
    if (viewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
        extension.exposeModelRange(new Region(offset, length));
    }
}
Also used : ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) Region(org.eclipse.jface.text.Region) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer)

Example 7 with ITextViewerExtension5

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

the class RevisionPainter method modelLinesToWidgetLines.

/**
 * Returns the visible extent of a document line range in widget lines.
 *
 * @param range the document line range
 * @return the visible extent of <code>range</code> in widget lines
 */
private ILineRange modelLinesToWidgetLines(ILineRange range) {
    int widgetStartLine = -1;
    int widgetEndLine = -1;
    if (fViewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension = (ITextViewerExtension5) fViewer;
        int modelEndLine = end(range);
        for (int modelLine = range.getStartLine(); modelLine < modelEndLine; modelLine++) {
            int widgetLine = extension.modelLine2WidgetLine(modelLine);
            if (widgetLine != -1) {
                if (widgetStartLine == -1)
                    widgetStartLine = widgetLine;
                widgetEndLine = widgetLine;
            }
        }
    } else {
        IRegion region = fViewer.getVisibleRegion();
        IDocument document = fViewer.getDocument();
        try {
            int visibleStartLine = document.getLineOfOffset(region.getOffset());
            int visibleEndLine = document.getLineOfOffset(region.getOffset() + region.getLength());
            widgetStartLine = Math.max(0, range.getStartLine() - visibleStartLine);
            widgetEndLine = Math.min(visibleEndLine, end(range) - 1);
        } catch (BadLocationException x) {
        // ignore and return null
        }
    }
    if (widgetStartLine == -1 || widgetEndLine == -1)
        return null;
    return new LineRange(widgetStartLine, widgetEndLine - widgetStartLine + 1);
}
Also used : ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) LineRange(org.eclipse.jface.text.source.LineRange) ILineRange(org.eclipse.jface.text.source.ILineRange) Point(org.eclipse.swt.graphics.Point) IRegion(org.eclipse.jface.text.IRegion) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 8 with ITextViewerExtension5

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

the class AnnotationBarHoverManager method getWidgetLineNumber.

/**
 * Returns for the widget line number for the given document line number.
 *
 * @param line the absolute line number
 * @return the line number relative to the viewer's visible region
 * @throws BadLocationException if <code>line</code> is not valid in the viewer's document
 */
private int getWidgetLineNumber(int line) throws BadLocationException {
    if (fSourceViewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension = (ITextViewerExtension5) fSourceViewer;
        return extension.modelLine2WidgetLine(line);
    }
    IRegion region = fSourceViewer.getVisibleRegion();
    int firstLine = fSourceViewer.getDocument().getLineOfOffset(region.getOffset());
    return line - firstLine;
}
Also used : ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) IRegion(org.eclipse.jface.text.IRegion) Point(org.eclipse.swt.graphics.Point)

Example 9 with ITextViewerExtension5

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

the class AnnotationBarHoverManager method adaptLineRangeToFolding.

/**
 * Adapts a given line range so that the result is a line range that does
 * not overlap with any collapsed region of the attached viewer.
 *
 * @param lineRange the original line range
 * @param line the anchor line
 * @return the adapted line range
 * @since 3.0
 */
private ILineRange adaptLineRangeToFolding(ILineRange lineRange, int line) {
    if (fSourceViewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension = (ITextViewerExtension5) fSourceViewer;
        try {
            IRegion region = convertToRegion(lineRange);
            IRegion[] coverage = extension.getCoveredModelRanges(region);
            if (coverage != null && coverage.length > 0) {
                IRegion container = findRegionContainingLine(coverage, line);
                if (container != null)
                    return convertToLineRange(container);
            }
        } catch (BadLocationException x) {
        }
        return null;
    }
    return lineRange;
}
Also used : ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 10 with ITextViewerExtension5

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

the class AnnotationPainter method getWidgetRange.

/**
 * Returns the widget region that corresponds to the
 * given offset and length in the viewer's document.
 *
 * The returned object can be the fReusableRegion and may used
 * only to read the return values and must not used to store
 * the region.
 *
 * @param modelOffset the model offset
 * @param modelLength the model length
 * @return the corresponding widget region
 */
private IRegion getWidgetRange(int modelOffset, int modelLength) {
    if (modelOffset == Integer.MAX_VALUE)
        return null;
    if (fSourceViewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension = (ITextViewerExtension5) fSourceViewer;
        fReusableRegion.setOffset(modelOffset);
        fReusableRegion.setLength(modelLength);
        return extension.modelRange2WidgetRange(fReusableRegion);
    }
    IRegion region = fSourceViewer.getVisibleRegion();
    int offset = region.getOffset();
    int length = region.getLength();
    if (regionsTouchOrOverlap(modelOffset, modelLength, offset, length)) {
        int p1 = Math.max(offset, modelOffset);
        int p2 = Math.min(offset + length, modelOffset + modelLength);
        fReusableRegion.setOffset(p1 - offset);
        fReusableRegion.setLength(p2 - p1);
        return fReusableRegion;
    }
    return null;
}
Also used : ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) IRegion(org.eclipse.jface.text.IRegion) Point(org.eclipse.swt.graphics.Point)

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