Search in sources :

Example 1 with FileRefHyperlinkDetector

use of org.eclipse.mylyn.internal.wikitext.ui.editor.syntax.FileRefHyperlinkDetector 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 2 with FileRefHyperlinkDetector

use of org.eclipse.mylyn.internal.wikitext.ui.editor.syntax.FileRefHyperlinkDetector in project mylyn.docs by eclipse.

the class MarkupSourceViewerConfiguration method createCustomHyperlinkDetectors.

@Override
protected List<IHyperlinkDetector> createCustomHyperlinkDetectors(ISourceViewer sourceViewer) {
    List<IHyperlinkDetector> detectors = new ArrayList<>();
    if (markupHyperlinkDetector == null) {
        markupHyperlinkDetector = new MarkupHyperlinkDetector();
        markupHyperlinkDetector.setMarkupLanguage(markupLanguage);
        markupHyperlinkDetector.setFile(file);
    }
    if (fileRefHyperlinkDetector == null && file != null) {
        Map<String, List<String>> hyperlinkDectectorFileRefRegexes = WikiTextUiPlugin.getDefault().getHyperlinkDectectorFileRefRegexes();
        List<String> fileRefHyperlinkRegexes = hyperlinkDectectorFileRefRegexes.getOrDefault(markupLanguage.getName(), ImmutableList.of());
        fileRefHyperlinkDetector = new FileRefHyperlinkDetector(file.getParent(), fileRefHyperlinkRegexes);
    }
    detectors.add(markupHyperlinkDetector);
    detectors.add(fileRefHyperlinkDetector);
    detectors.add(markupHyperlinkDetector);
    detectors.addAll(super.createCustomHyperlinkDetectors(sourceViewer));
    return detectors;
}
Also used : FileRefHyperlinkDetector(org.eclipse.mylyn.internal.wikitext.ui.editor.syntax.FileRefHyperlinkDetector) IHyperlinkDetector(org.eclipse.jface.text.hyperlink.IHyperlinkDetector) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) MarkupHyperlinkDetector(org.eclipse.mylyn.internal.wikitext.ui.editor.syntax.MarkupHyperlinkDetector)

Example 3 with FileRefHyperlinkDetector

use of org.eclipse.mylyn.internal.wikitext.ui.editor.syntax.FileRefHyperlinkDetector in project mylyn.docs by eclipse.

the class FileRefHyperlinkDetectorTest method testFileDoesNotExist.

@Test
public void testFileDoesNotExist() 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("image::file-that-does-not-exist.png[]"));
    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 4 with FileRefHyperlinkDetector

use of org.eclipse.mylyn.internal.wikitext.ui.editor.syntax.FileRefHyperlinkDetector in project mylyn.docs by eclipse.

the class FileRefHyperlinkDetectorTest method testFindFileRefAndOpenHyperlink.

@Test
public void testFindFileRefAndOpenHyperlink() throws CoreException {
    String asciidocFileName = "simon-scholz.adoc";
    IFile file = project.getFile(asciidocFileName);
    file.create(new ByteArrayInputStream("== Writing tests is kinda documentation".getBytes()), true, new NullProgressMonitor());
    ImmutableList<String> fileRefPatterns = ImmutableList.of("include::(.+)\\[\\]", "image::(.+)\\[\\]");
    FileRefHyperlinkDetector fileRefHyperlinkDetector = new FileRefHyperlinkDetector(file.getParent(), fileRefPatterns);
    ITextViewer mockTextViewer = mock(ITextViewer.class);
    when(mockTextViewer.getDocument()).thenReturn(new Document("include::" + asciidocFileName + "[]"));
    IHyperlink[] detectHyperlinks = fileRefHyperlinkDetector.detectHyperlinks(mockTextViewer, new Region(9, 17), false);
    assertThat(detectHyperlinks.length, is(1));
    IHyperlink hyperlink = detectHyperlinks[0];
    hyperlink.open();
    IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    IEditorInput editorInput = activeEditor.getEditorInput();
    if (editorInput instanceof IFileEditorInput) {
        IFile editorFile = ((IFileEditorInput) editorInput).getFile();
        assertThat(file, equalTo(editorFile));
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) IEditorPart(org.eclipse.ui.IEditorPart) Document(org.eclipse.jface.text.Document) ITextViewer(org.eclipse.jface.text.ITextViewer) FileRefHyperlinkDetector(org.eclipse.mylyn.internal.wikitext.ui.editor.syntax.FileRefHyperlinkDetector) ByteArrayInputStream(java.io.ByteArrayInputStream) IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) IFileEditorInput(org.eclipse.ui.IFileEditorInput) Region(org.eclipse.jface.text.Region) IEditorInput(org.eclipse.ui.IEditorInput) Test(org.junit.Test)

Example 5 with FileRefHyperlinkDetector

use of org.eclipse.mylyn.internal.wikitext.ui.editor.syntax.FileRefHyperlinkDetector in project mylyn.docs by eclipse.

the class FileRefHyperlinkDetectorTest method testDeeperNestedFolderStructure.

@Test
public void testDeeperNestedFolderStructure() throws CoreException {
    IFolder folder = project.getFolder("AsciiDoctor Tutorial");
    if (!folder.exists()) {
        folder.create(IResource.NONE, true, new NullProgressMonitor());
    }
    IFolder nestedResourcesFolder = folder.getFolder("resources");
    if (!nestedResourcesFolder.exists()) {
        nestedResourcesFolder.create(IResource.NONE, true, new NullProgressMonitor());
    }
    IFile fileInNestedFolder = nestedResourcesFolder.getFile("nested-document.adoc");
    if (!fileInNestedFolder.exists()) {
        fileInNestedFolder.create(new ByteArrayInputStream("include::../../article.adoc[]".getBytes()), true, new NullProgressMonitor());
    }
    IFile articleFile = project.getFile("article.adoc");
    if (!articleFile.exists()) {
        articleFile.create(new ByteArrayInputStream("== Overview".getBytes()), true, new NullProgressMonitor());
    }
    ImmutableList<String> fileRefPatterns = ImmutableList.of("include::(.+)\\[\\]", "image::(.+)\\[\\]");
    FileRefHyperlinkDetector fileRefHyperlinkDetector = new FileRefHyperlinkDetector(fileInNestedFolder.getParent(), fileRefPatterns);
    ITextViewer mockTextViewer = mock(ITextViewer.class);
    when(mockTextViewer.getDocument()).thenReturn(new Document("include::../../article.adoc[]"));
    IHyperlink[] detectHyperlinks = fileRefHyperlinkDetector.detectHyperlinks(mockTextViewer, new Region(9, 17), false);
    assertThat(detectHyperlinks.length, is(1));
    IHyperlink hyperlink = detectHyperlinks[0];
    hyperlink.open();
    IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    IEditorInput editorInput = activeEditor.getEditorInput();
    if (editorInput instanceof IFileEditorInput) {
        IFile editorFile = ((IFileEditorInput) editorInput).getFile();
        assertThat(articleFile, equalTo(editorFile));
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) IEditorPart(org.eclipse.ui.IEditorPart) Document(org.eclipse.jface.text.Document) ITextViewer(org.eclipse.jface.text.ITextViewer) FileRefHyperlinkDetector(org.eclipse.mylyn.internal.wikitext.ui.editor.syntax.FileRefHyperlinkDetector) ByteArrayInputStream(java.io.ByteArrayInputStream) IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) IFileEditorInput(org.eclipse.ui.IFileEditorInput) Region(org.eclipse.jface.text.Region) IEditorInput(org.eclipse.ui.IEditorInput) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Aggregations

FileRefHyperlinkDetector (org.eclipse.mylyn.internal.wikitext.ui.editor.syntax.FileRefHyperlinkDetector)5 Document (org.eclipse.jface.text.Document)4 ITextViewer (org.eclipse.jface.text.ITextViewer)4 Region (org.eclipse.jface.text.Region)4 IHyperlink (org.eclipse.jface.text.hyperlink.IHyperlink)4 Test (org.junit.Test)4 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IFile (org.eclipse.core.resources.IFile)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 IEditorInput (org.eclipse.ui.IEditorInput)2 IEditorPart (org.eclipse.ui.IEditorPart)2 IFileEditorInput (org.eclipse.ui.IFileEditorInput)2 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 IFolder (org.eclipse.core.resources.IFolder)1 IHyperlinkDetector (org.eclipse.jface.text.hyperlink.IHyperlinkDetector)1 MarkupHyperlinkDetector (org.eclipse.mylyn.internal.wikitext.ui.editor.syntax.MarkupHyperlinkDetector)1