Search in sources :

Example 6 with RevisionRange

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

the class RevisionPainter method updateOverviewAnnotations.

/**
 * Shows (or hides) the overview annotations.
 */
private void updateOverviewAnnotations() {
    if (fAnnotationModel == null)
        return;
    Revision revision = fFocusRevision != null ? fFocusRevision : fSelectedRevision;
    Map<Annotation, Position> added = null;
    if (revision != null) {
        added = new HashMap<>();
        for (RevisionRange range : revision.getRegions()) {
            try {
                IRegion charRegion = toCharRegion(range);
                Position position = new Position(charRegion.getOffset(), charRegion.getLength());
                Annotation annotation = new RevisionAnnotation(revision.getId());
                added.put(annotation, position);
            } catch (BadLocationException x) {
            // ignore - document was changed, show no annotations
            }
        }
    }
    if (fAnnotationModel instanceof IAnnotationModelExtension) {
        IAnnotationModelExtension ext = (IAnnotationModelExtension) fAnnotationModel;
        ext.replaceAnnotations(fAnnotations.toArray(new Annotation[fAnnotations.size()]), added);
    } else {
        for (Annotation annotation : fAnnotations) {
            fAnnotationModel.removeAnnotation(annotation);
        }
        if (added != null) {
            for (Entry<Annotation, Position> entry : added.entrySet()) {
                fAnnotationModel.addAnnotation(entry.getKey(), entry.getValue());
            }
        }
    }
    fAnnotations.clear();
    if (added != null)
        fAnnotations.addAll(added.keySet());
}
Also used : Revision(org.eclipse.jface.text.revisions.Revision) Position(org.eclipse.jface.text.Position) RevisionRange(org.eclipse.jface.text.revisions.RevisionRange) IAnnotationModelExtension(org.eclipse.jface.text.source.IAnnotationModelExtension) Annotation(org.eclipse.jface.text.source.Annotation) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 7 with RevisionRange

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

the class RevisionPainter method getRanges.

/**
 * Returns the sublist of all <code>RevisionRange</code>s that intersect with the given lines.
 *
 * @param lines the model based lines of interest
 * @return elementType: RevisionRange
 */
private List<RevisionRange> getRanges(ILineRange lines) {
    List<RevisionRange> ranges = getRangeCache();
    // return the interesting subset
    int end = end(lines);
    int first = -1, last = -1;
    for (int i = 0; i < ranges.size(); i++) {
        RevisionRange range = ranges.get(i);
        int rangeEnd = end(range);
        if (first == -1 && rangeEnd > lines.getStartLine())
            first = i;
        if (first != -1 && rangeEnd > end) {
            last = i;
            break;
        }
    }
    if (first == -1)
        return Collections.emptyList();
    if (last == -1)
        // bottom index may be one too much
        last = ranges.size() - 1;
    return ranges.subList(first, last + 1);
}
Also used : RevisionRange(org.eclipse.jface.text.revisions.RevisionRange) Point(org.eclipse.swt.graphics.Point)

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