Search in sources :

Example 1 with RevisionRange

use of org.eclipse.jface.text.revisions.RevisionRange in project eclipse.platform.text by eclipse.

the class RevisionPainter method paint.

/**
 * Delegates the painting of the quick diff colors to this painter. The painter will draw the
 * color boxes onto the passed {@link GC} for all model (document) lines in
 * <code>visibleModelLines</code>.
 *
 * @param gc the {@link GC} to draw onto
 * @param visibleLines the lines (in document offsets) that are currently (perhaps only
 *        partially) visible
 */
public void paint(GC gc, ILineRange visibleLines) {
    connectIfNeeded();
    if (!isConnected())
        return;
    // and author
    if (fShowAuthor && fShowRevision) {
        char[] string = new char[fRevisionIdChars + 1];
        Arrays.fill(string, '9');
        if (string.length > 1) {
            string[0] = '.';
            string[1] = ' ';
        }
        fAuthorInset = gc.stringExtent(new String(string)).x;
    }
    // recompute colors (show intense colors if ruler is narrow)
    int width = getWidth();
    if (width != fLastWidth) {
        fColorTool.setInfo(fRevisionInfo);
        fLastWidth = width;
    }
    // draw change regions
    List<RevisionRange> ranges = getRanges(visibleLines);
    for (RevisionRange region : ranges) {
        paintRange(region, gc);
    }
}
Also used : RevisionRange(org.eclipse.jface.text.revisions.RevisionRange) Point(org.eclipse.swt.graphics.Point)

Example 2 with RevisionRange

use of org.eclipse.jface.text.revisions.RevisionRange in project eclipse.platform.text by eclipse.

the class RevisionPainter method handleMouseWheel.

/**
 * Handles a mouse wheel event.
 *
 * @param event the mouse wheel event
 */
private void handleMouseWheel(Event event) {
    boolean up = event.count > 0;
    int documentHoverLine = fFocusLine;
    ILineRange nextWidgetRange = null;
    ILineRange last = null;
    List<RevisionRange> ranges = fFocusRevision.getRegions();
    if (up) {
        for (RevisionRange range : ranges) {
            ILineRange widgetRange = modelLinesToWidgetLines(range);
            if (contains(range, documentHoverLine)) {
                nextWidgetRange = last;
                break;
            }
            if (widgetRange != null)
                last = widgetRange;
        }
    } else {
        for (ListIterator<RevisionRange> it = ranges.listIterator(ranges.size()); it.hasPrevious(); ) {
            RevisionRange range = it.previous();
            ILineRange widgetRange = modelLinesToWidgetLines(range);
            if (contains(range, documentHoverLine)) {
                nextWidgetRange = last;
                break;
            }
            if (widgetRange != null)
                last = widgetRange;
        }
    }
    if (nextWidgetRange == null)
        return;
    int widgetCurrentFocusLine = modelLinesToWidgetLines(new LineRange(documentHoverLine, 1)).getStartLine();
    int widgetNextFocusLine = nextWidgetRange.getStartLine();
    int newTopPixel = fWidget.getTopPixel() + JFaceTextUtil.computeLineHeight(fWidget, widgetCurrentFocusLine, widgetNextFocusLine, widgetNextFocusLine - widgetCurrentFocusLine);
    fWidget.setTopPixel(newTopPixel);
    if (newTopPixel < 0) {
        Point cursorLocation = fWidget.getDisplay().getCursorLocation();
        cursorLocation.y += newTopPixel;
        fWidget.getDisplay().setCursorLocation(cursorLocation);
    } else {
        int topPixel = fWidget.getTopPixel();
        if (topPixel < newTopPixel) {
            Point cursorLocation = fWidget.getDisplay().getCursorLocation();
            cursorLocation.y += newTopPixel - topPixel;
            fWidget.getDisplay().setCursorLocation(cursorLocation);
        }
    }
    updateFocusLine(toDocumentLineNumber(fWidget.toControl(fWidget.getDisplay().getCursorLocation()).y));
    immediateUpdate();
}
Also used : ILineRange(org.eclipse.jface.text.source.ILineRange) RevisionRange(org.eclipse.jface.text.revisions.RevisionRange) Point(org.eclipse.swt.graphics.Point) LineRange(org.eclipse.jface.text.source.LineRange) ILineRange(org.eclipse.jface.text.source.ILineRange) Point(org.eclipse.swt.graphics.Point)

Example 3 with RevisionRange

use of org.eclipse.jface.text.revisions.RevisionRange in project eclipse.platform.text by eclipse.

the class RevisionPainter method onFocusLineChanged.

/**
 * Handles a changing focus line.
 *
 * @param previousLine the old focus line (-1 for no focus)
 * @param nextLine the new focus line (-1 for no focus)
 */
private void onFocusLineChanged(int previousLine, int nextLine) {
    if (DEBUG)
        // $NON-NLS-1$ //$NON-NLS-2$
        System.out.println("line: " + previousLine + " > " + nextLine);
    fFocusLine = nextLine;
    RevisionRange region = getRange(nextLine);
    updateFocusRange(region);
}
Also used : RevisionRange(org.eclipse.jface.text.revisions.RevisionRange)

Example 4 with RevisionRange

use of org.eclipse.jface.text.revisions.RevisionRange in project eclipse.platform.text by eclipse.

the class RevisionPainter method getRange.

/**
 * Returns the revision range that contains the given line, or
 * <code>null</code> if there is none.
 *
 * @param line the line of interest
 * @return the corresponding <code>RevisionRange</code> or <code>null</code>
 */
private RevisionRange getRange(int line) {
    List<RevisionRange> ranges = getRangeCache();
    if (ranges.isEmpty() || line == -1)
        return null;
    for (RevisionRange range : ranges) {
        if (contains(range, line))
            return range;
    }
    // line may be right after the last region
    RevisionRange lastRegion = ranges.get(ranges.size() - 1);
    if (line == end(lastRegion))
        return lastRegion;
    return null;
}
Also used : RevisionRange(org.eclipse.jface.text.revisions.RevisionRange)

Example 5 with RevisionRange

use of org.eclipse.jface.text.revisions.RevisionRange in project eclipse.platform.text by eclipse.

the class RevisionPainter method getRevision.

/**
 * Returns the revision at a certain document offset, or <code>null</code> for none.
 *
 * @param offset the document offset
 * @return the revision at offset, or <code>null</code> for none
 */
Revision getRevision(int offset) {
    IDocument document = fViewer.getDocument();
    int line;
    try {
        line = document.getLineOfOffset(offset);
    } catch (BadLocationException x) {
        return null;
    }
    if (line != -1) {
        RevisionRange range = getRange(line);
        if (range != null)
            return range.getRevision();
    }
    return null;
}
Also used : RevisionRange(org.eclipse.jface.text.revisions.RevisionRange) IDocument(org.eclipse.jface.text.IDocument) Point(org.eclipse.swt.graphics.Point) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

RevisionRange (org.eclipse.jface.text.revisions.RevisionRange)7 Point (org.eclipse.swt.graphics.Point)4 BadLocationException (org.eclipse.jface.text.BadLocationException)2 IDocument (org.eclipse.jface.text.IDocument)1 IRegion (org.eclipse.jface.text.IRegion)1 Position (org.eclipse.jface.text.Position)1 Revision (org.eclipse.jface.text.revisions.Revision)1 Annotation (org.eclipse.jface.text.source.Annotation)1 IAnnotationModelExtension (org.eclipse.jface.text.source.IAnnotationModelExtension)1 ILineRange (org.eclipse.jface.text.source.ILineRange)1 LineRange (org.eclipse.jface.text.source.LineRange)1