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;
}
}
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;
}
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);
}
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);
}
}
}
}
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;
}
Aggregations