Search in sources :

Example 21 with ITextViewerExtension5

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

the class TextViewerDeleteLineTarget method clipToVisibleRegion.

/**
 * Clips the given start and end offset to the visible viewer region.
 *
 * @param startOffset the start offset
 * @param endOffset the end offset
 * @return the clipped region
 * @since 3.3.2
 */
private IRegion clipToVisibleRegion(int startOffset, int endOffset) {
    ITextViewer viewer = fClipboard.getViewer();
    IRegion visibleRegion;
    if (viewer instanceof ITextViewerExtension5)
        visibleRegion = ((ITextViewerExtension5) viewer).getModelCoverage();
    else
        visibleRegion = viewer.getVisibleRegion();
    int visibleStart = visibleRegion.getOffset();
    int visibleLength = visibleRegion.getLength();
    startOffset = Math.max(startOffset, visibleStart);
    endOffset = Math.min(endOffset, visibleStart + visibleLength);
    return new Region(startOffset, endOffset - startOffset);
}
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) ITextViewer(org.eclipse.jface.text.ITextViewer)

Example 22 with ITextViewerExtension5

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

the class AbstractTemplatesPage method getOffset.

/**
 * Returns the document relative offset from the text widget relative point
 *
 * @param document the document
 * @param textWidget the text widget
 * @param point the point for which to get the offset
 * @return the offset
 * @throws BadLocationException if the document is accessed with an invalid line
 */
private int getOffset(IDocument document, StyledText textWidget, Point point) throws BadLocationException {
    int widgetCaret = fViewer.getTextWidget().getCaretOffset();
    if (fViewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 ext = (ITextViewerExtension5) fViewer;
        int widgetOffset = textWidget.getOffsetAtPoint(point);
        int offset = widgetOffset != -1 ? ext.widgetOffset2ModelOffset(textWidget.getOffsetAtPoint(point)) : -1;
        if (offset == -1) {
            int docLineIndex = ext.widgetLine2ModelLine(textWidget.getLineIndex(point.y));
            String lineDelimiter = document.getLineDelimiter(docLineIndex);
            int delimLength = lineDelimiter == null ? 0 : lineDelimiter.length();
            return document.getLineOffset(docLineIndex) + document.getLineLength(docLineIndex) - delimLength;
        }
        return offset;
    }
    IRegion visible = fViewer.getVisibleRegion();
    return widgetCaret + visible.getOffset();
}
Also used : ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) Point(org.eclipse.swt.graphics.Point) IRegion(org.eclipse.jface.text.IRegion)

Example 23 with ITextViewerExtension5

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

the class OverviewRuler method handleMouseScrolled.

/**
 * Handles mouse scrolls.
 *
 * @param event the mouse scrolled event
 */
private void handleMouseScrolled(MouseEvent event) {
    if (fTextViewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension = (ITextViewerExtension5) fTextViewer;
        StyledText textWidget = fTextViewer.getTextWidget();
        int topIndex = textWidget.getTopIndex();
        int newTopIndex = Math.max(0, topIndex - event.count);
        fTextViewer.setTopIndex(extension.widgetLine2ModelLine(newTopIndex));
    } else if (fTextViewer != null) {
        int topIndex = fTextViewer.getTopIndex();
        int newTopIndex = Math.max(0, topIndex - event.count);
        fTextViewer.setTopIndex(newTopIndex);
    }
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) Point(org.eclipse.swt.graphics.Point)

Example 24 with ITextViewerExtension5

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

the class VerticalRuler method doubleBufferPaint.

/**
 * Double buffer drawing.
 *
 * @param dest the GC to draw into
 */
private void doubleBufferPaint(GC dest) {
    Point size = fCanvas.getSize();
    if (size.x <= 0 || size.y <= 0)
        return;
    if (fBuffer != null) {
        Rectangle r = fBuffer.getBounds();
        if (r.width != size.x || r.height != size.y) {
            fBuffer.dispose();
            fBuffer = null;
        }
    }
    if (fBuffer == null)
        fBuffer = new Image(fCanvas.getDisplay(), size.x, size.y);
    GC gc = new GC(fBuffer);
    gc.setFont(fTextViewer.getTextWidget().getFont());
    try {
        gc.setBackground(fCanvas.getBackground());
        gc.fillRectangle(0, 0, size.x, size.y);
        if (fTextViewer instanceof ITextViewerExtension5)
            doPaint1(gc);
        else
            doPaint(gc);
    } finally {
        gc.dispose();
    }
    dest.drawImage(fBuffer, 0, 0);
}
Also used : ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Image(org.eclipse.swt.graphics.Image) GC(org.eclipse.swt.graphics.GC)

Example 25 with ITextViewerExtension5

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

the class VerticalRuler method widgetLine2ModelLine.

/**
 * Returns the line of the viewer's document that corresponds to the given widget line.
 *
 * @param viewer the viewer
 * @param widgetLine the widget line
 * @return the corresponding line of the viewer's document
 * @since 2.1
 */
protected static final int widgetLine2ModelLine(ITextViewer viewer, int widgetLine) {
    if (viewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
        return extension.widgetLine2ModelLine(widgetLine);
    }
    try {
        IRegion r = viewer.getVisibleRegion();
        IDocument d = viewer.getDocument();
        return widgetLine += d.getLineOfOffset(r.getOffset());
    } catch (BadLocationException x) {
    }
    return widgetLine;
}
Also used : ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) IRegion(org.eclipse.jface.text.IRegion) IDocument(org.eclipse.jface.text.IDocument) 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