Search in sources :

Example 6 with ITextViewer

use of org.eclipse.jface.text.ITextViewer in project eclipse.platform.text by eclipse.

the class LinkedModeUI method ensureAnnotationModelInstalled.

private void ensureAnnotationModelInstalled() {
    LinkedPositionAnnotations lpa = fCurrentTarget.fAnnotationModel;
    if (lpa != null) {
        ITextViewer viewer = fCurrentTarget.getViewer();
        if (viewer instanceof ISourceViewer) {
            ISourceViewer sv = (ISourceViewer) viewer;
            IAnnotationModel model = sv.getAnnotationModel();
            if (model instanceof IAnnotationModelExtension) {
                IAnnotationModelExtension ext = (IAnnotationModelExtension) model;
                IAnnotationModel ourModel = ext.getAnnotationModel(getUniqueKey());
                if (ourModel == null) {
                    ext.addAnnotationModel(getUniqueKey(), lpa);
                }
            }
        }
    }
}
Also used : IAnnotationModelExtension(org.eclipse.jface.text.source.IAnnotationModelExtension) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) ITextViewer(org.eclipse.jface.text.ITextViewer)

Example 7 with ITextViewer

use of org.eclipse.jface.text.ITextViewer in project eclipse.platform.text by eclipse.

the class LinkedModeUI method select.

private void select() {
    ITextViewer viewer = fCurrentTarget.getViewer();
    if (viewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension5 = (ITextViewerExtension5) viewer;
        extension5.exposeModelRange(new Region(fFramePosition.offset, fFramePosition.length));
    } else if (!viewer.overlapsWithVisibleRegion(fFramePosition.offset, fFramePosition.length)) {
        viewer.resetVisibleRegion();
    }
    viewer.revealRange(fFramePosition.offset, fFramePosition.length);
    viewer.setSelectedRange(fFramePosition.offset, fFramePosition.length);
}
Also used : ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) IRegion(org.eclipse.jface.text.IRegion) Region(org.eclipse.jface.text.Region) ITextViewer(org.eclipse.jface.text.ITextViewer)

Example 8 with ITextViewer

use of org.eclipse.jface.text.ITextViewer in project mylyn.docs by eclipse.

the class FileRefHyperlinkDetectorTest method testNoHyperlinkInDocument.

@Test
public void testNoHyperlinkInDocument() throws CoreException {
    ImmutableList<String> fileRefPatterns = ImmutableList.of("include::(.+)\\[\\]", "image::(.+)\\[\\]");
    FileRefHyperlinkDetector fileRefHyperlinkDetector = new FileRefHyperlinkDetector(project, fileRefPatterns);
    ITextViewer mockTextViewer = mock(ITextViewer.class);
    when(mockTextViewer.getDocument()).thenReturn(new Document("Some contents without hyperlink in it."));
    IHyperlink[] detectHyperlinks = fileRefHyperlinkDetector.detectHyperlinks(mockTextViewer, new Region(7, 15), false);
    assertThat(detectHyperlinks, is(nullValue()));
}
Also used : FileRefHyperlinkDetector(org.eclipse.mylyn.internal.wikitext.ui.editor.syntax.FileRefHyperlinkDetector) IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) Region(org.eclipse.jface.text.Region) Document(org.eclipse.jface.text.Document) ITextViewer(org.eclipse.jface.text.ITextViewer) Test(org.junit.Test)

Example 9 with ITextViewer

use of org.eclipse.jface.text.ITextViewer in project mylyn.docs by eclipse.

the class IncrementalFindHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    ITextViewer viewer = getTextViewer(event);
    if (viewer != null) {
        IFindReplaceTarget findReplaceTarget = viewer.getFindReplaceTarget();
        if (findReplaceTarget.canPerformFind()) {
            if (findReplaceTarget instanceof IFindReplaceTargetExtension) {
                IFindReplaceTargetExtension extension = (IFindReplaceTargetExtension) findReplaceTarget;
                extension.beginSession();
            }
        }
    }
    return null;
}
Also used : IFindReplaceTarget(org.eclipse.jface.text.IFindReplaceTarget) IFindReplaceTargetExtension(org.eclipse.jface.text.IFindReplaceTargetExtension) ITextViewer(org.eclipse.jface.text.ITextViewer)

Example 10 with ITextViewer

use of org.eclipse.jface.text.ITextViewer in project n4js by eclipse.

the class HyperlinkXpectMethod method hyperlinks.

/**
 * @param expectation
 *            a list of expected URIs to jump to by this hyperlink
 * @param resource
 *            the resource under test
 * @param region
 *            the offset where hyperlinking should be invoked
 * @throws Exception
 *             some exceptions
 */
@ParameterParser(syntax = "('at' arg2=STRING)?")
@Xpect
public void hyperlinks(// arg0
@CommaSeparatedValuesExpectation ICommaSeparatedValuesExpectation expectation, // arg1
@ThisResource XtextResource resource, // arg2
RegionWithCursor region) throws Exception {
    ContentAssistProcessorTestBuilder fixture = n4ContentAssistProcessorTestBuilderHelper.createTestBuilderForResource(resource);
    String currentModelToParse = resource.getParseResult().getRootNode().getText();
    IXtextDocument xtextDocument = fixture.getDocument(resource, currentModelToParse);
    // in case of cross-file hyperlinks, we have to make sure the target resources are fully resolved
    final ResourceSet resSet = resource.getResourceSet();
    for (Resource currRes : new ArrayList<>(resSet.getResources())) N4JSResource.postProcess(currRes);
    ITextViewer sourceViewer = fixture.getSourceViewer(currentModelToParse, xtextDocument);
    IHyperlink[] hyperlinks = hyperlinkDetector.detectHyperlinks(sourceViewer, new Region(region.getGlobalCursorOffset(), 0), true);
    // cleaned up resource, otherwise #createTestBuilder() above will fail next time this method is called
    XtextResourceCleanUtil.cleanXtextResource(resource);
    ArrayList<String> result = Lists.newArrayList();
    if (hyperlinks != null) {
        for (IHyperlink hyperlink : hyperlinks) {
            result.add(getTargetDescription(resource, hyperlink));
        }
    }
    expectation.assertEquals(result);
}
Also used : ContentAssistProcessorTestBuilder(org.eclipse.xtext.ui.testing.ContentAssistProcessorTestBuilder) IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) ThisResource(org.eclipse.xpect.xtext.lib.setup.ThisResource) XtextResource(org.eclipse.xtext.resource.XtextResource) N4JSResource(org.eclipse.n4js.resource.N4JSResource) Resource(org.eclipse.emf.ecore.resource.Resource) ArrayList(java.util.ArrayList) Region(org.eclipse.jface.text.Region) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) ITextViewer(org.eclipse.jface.text.ITextViewer) Xpect(org.eclipse.xpect.runner.Xpect) ParameterParser(org.eclipse.xpect.parameter.ParameterParser)

Aggregations

ITextViewer (org.eclipse.jface.text.ITextViewer)75 BadLocationException (org.eclipse.jface.text.BadLocationException)13 IDocument (org.eclipse.jface.text.IDocument)13 Region (org.eclipse.jface.text.Region)13 StyledText (org.eclipse.swt.custom.StyledText)13 IRegion (org.eclipse.jface.text.IRegion)11 ArrayList (java.util.ArrayList)9 Point (org.eclipse.swt.graphics.Point)9 Test (org.junit.Test)9 ITextSelection (org.eclipse.jface.text.ITextSelection)8 IEditorPart (org.eclipse.ui.IEditorPart)8 ITextViewerExtension5 (org.eclipse.jface.text.ITextViewerExtension5)6 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)6 Document (org.eclipse.jface.text.Document)5 IHyperlink (org.eclipse.jface.text.hyperlink.IHyperlink)5 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)5 Display (org.eclipse.swt.widgets.Display)5 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)5 List (java.util.List)4 ITextViewerExtension (org.eclipse.jface.text.ITextViewerExtension)4