Search in sources :

Example 1 with ISourceViewerExtension2

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);
}
Also used : IAction(org.eclipse.jface.action.IAction) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) IUpdate(org.eclipse.ui.texteditor.IUpdate) ISourceViewerExtension2(org.eclipse.jface.text.source.ISourceViewerExtension2)

Example 2 with ISourceViewerExtension2

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;
}
Also used : MarkerAnnotation(org.eclipse.ui.texteditor.MarkerAnnotation) ArrayList(java.util.ArrayList) IMarker(org.eclipse.core.resources.IMarker) ISourceViewerExtension2(org.eclipse.jface.text.source.ISourceViewerExtension2)

Example 3 with ISourceViewerExtension2

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;
}
Also used : Position(org.eclipse.jface.text.Position) IAnnotationModelExtension(org.eclipse.jface.text.source.IAnnotationModelExtension) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IDocument(org.eclipse.jface.text.IDocument) Annotation(org.eclipse.jface.text.source.Annotation) BadLocationException(org.eclipse.jface.text.BadLocationException) ISourceViewerExtension2(org.eclipse.jface.text.source.ISourceViewerExtension2)

Example 4 with ISourceViewerExtension2

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));
}
Also used : MarkerAnnotation(org.eclipse.ui.texteditor.MarkerAnnotation) Position(org.eclipse.jface.text.Position) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) MarkerAnnotation(org.eclipse.ui.texteditor.MarkerAnnotation) Annotation(org.eclipse.jface.text.source.Annotation) ISourceViewerExtension2(org.eclipse.jface.text.source.ISourceViewerExtension2)

Aggregations

ISourceViewerExtension2 (org.eclipse.jface.text.source.ISourceViewerExtension2)4 Position (org.eclipse.jface.text.Position)2 Annotation (org.eclipse.jface.text.source.Annotation)2 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)2 MarkerAnnotation (org.eclipse.ui.texteditor.MarkerAnnotation)2 ArrayList (java.util.ArrayList)1 IMarker (org.eclipse.core.resources.IMarker)1 IAction (org.eclipse.jface.action.IAction)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 IDocument (org.eclipse.jface.text.IDocument)1 IRegion (org.eclipse.jface.text.IRegion)1 Region (org.eclipse.jface.text.Region)1 IAnnotationModelExtension (org.eclipse.jface.text.source.IAnnotationModelExtension)1 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)1 IUpdate (org.eclipse.ui.texteditor.IUpdate)1