use of org.eclipse.jface.text.source.ISourceViewerExtension2 in project eclipse.platform.text by eclipse.
the class TextEditor method handlePreferenceStoreChanged.
@Override
protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
if (event.getProperty().equals(SpellingService.PREFERENCE_SPELLING_ENABLED)) {
ISourceViewer viewer = getSourceViewer();
if (!(viewer instanceof ISourceViewerExtension2))
// cannot unconfigure - do nothing
return;
// XXX: this is pretty heavy-weight
((ISourceViewerExtension2) viewer).unconfigure();
viewer.configure(getSourceViewerConfiguration());
if (Boolean.FALSE.equals(event.getNewValue()))
SpellingProblem.removeAll(getSourceViewer(), null);
IAction quickAssistAction = getAction(ITextEditorActionConstants.QUICK_ASSIST);
if (quickAssistAction instanceof IUpdate)
((IUpdate) quickAssistAction).update();
return;
}
super.handlePreferenceStoreChanged(event);
}
use of org.eclipse.jface.text.source.ISourceViewerExtension2 in project eclipse.platform.text by eclipse.
the class MarkerAnnotationHover method getHoverInfo2.
@Override
public List<IMarker> getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) {
if (!(textViewer instanceof ISourceViewerExtension2)) {
return null;
}
List<MarkerAnnotation> annotations = findMarkerAnnotations((ISourceViewerExtension2) textViewer, hoverRegion);
if (annotations.isEmpty()) {
return null;
}
List<IMarker> markers = new ArrayList<>(annotations.size());
for (MarkerAnnotation annotation : annotations) {
markers.add(annotation.getMarker());
}
return markers;
}
use of org.eclipse.jface.text.source.ISourceViewerExtension2 in project eclipse.platform.text by eclipse.
the class ProjectionAnnotationHover method getProjectionTextAtLine.
private String getProjectionTextAtLine(ISourceViewer viewer, int line, int numberOfLines) {
IAnnotationModel model = null;
if (viewer instanceof ISourceViewerExtension2) {
ISourceViewerExtension2 viewerExtension = (ISourceViewerExtension2) viewer;
IAnnotationModel visual = viewerExtension.getVisualAnnotationModel();
if (visual instanceof IAnnotationModelExtension) {
IAnnotationModelExtension modelExtension = (IAnnotationModelExtension) visual;
model = modelExtension.getAnnotationModel(ProjectionSupport.PROJECTION);
}
}
if (model != null) {
try {
IDocument document = viewer.getDocument();
Iterator<Annotation> e = model.getAnnotationIterator();
while (e.hasNext()) {
ProjectionAnnotation annotation = (ProjectionAnnotation) e.next();
if (!annotation.isCollapsed())
continue;
Position position = model.getPosition(annotation);
if (position == null)
continue;
if (isCaptionLine(position, document, line))
return getText(document, position.getOffset(), position.getLength(), numberOfLines);
}
} catch (BadLocationException x) {
}
}
return null;
}
use of org.eclipse.jface.text.source.ISourceViewerExtension2 in project eclipse.platform.text by eclipse.
the class MarkerAnnotationHover method getHoverRegion.
@Override
public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
if (!(textViewer instanceof ISourceViewerExtension2)) {
return null;
}
ISourceViewerExtension2 viewer = (ISourceViewerExtension2) textViewer;
List<MarkerAnnotation> annotations = findMarkerAnnotations(viewer, new Region(offset, 0));
if (annotations.isEmpty()) {
return null;
}
// find intersection of regions
int highestOffsetStart = 0;
int lowestOffsetEnd = Integer.MAX_VALUE;
IAnnotationModel annotationModel = viewer.getVisualAnnotationModel();
for (Annotation annotation : annotations) {
Position position = annotationModel.getPosition(annotation);
highestOffsetStart = Math.max(highestOffsetStart, position.getOffset());
lowestOffsetEnd = Math.min(lowestOffsetEnd, position.getOffset() + position.getLength());
}
return new Region(highestOffsetStart, Math.max(0, lowestOffsetEnd - highestOffsetStart));
}
Aggregations