Search in sources :

Example 26 with MarkupLanguage

use of org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage in project mylyn.docs by eclipse.

the class TWikiLanguageTest method testDiscoverable.

public void testDiscoverable() {
    MarkupLanguage language = ServiceLocator.getInstance().getMarkupLanguage("TWiki");
    assertNotNull(language);
    assertTrue(language instanceof TWikiLanguage);
}
Also used : TWikiLanguage(org.eclipse.mylyn.wikitext.twiki.TWikiLanguage) MarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage)

Example 27 with MarkupLanguage

use of org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage in project mylyn.docs by eclipse.

the class HelpContent method getContent.

/**
 * Get the help content, which may be formatted using HTML markup. If HTML markup is used, the content must be
 * well-formed HTML.
 */
@SuppressWarnings("serial")
public String getContent() throws IOException {
    try {
        URL resource = getResource();
        String content = Resources.toString(resource, StandardCharsets.UTF_8);
        if (resourceContentLanguage == null || "html".equalsIgnoreCase(resourceContentLanguage)) {
            // $NON-NLS-1$
            return content;
        }
        MarkupLanguage markupLanguage = WikiText.getMarkupLanguage(resourceContentLanguage);
        if (markupLanguage == null) {
            throw new IOException(NLS.bind(Messages.HelpContent_noSuchMarkupLanguage, new Object[] { resourceContentLanguage }));
        }
        MarkupParser markupParser = new MarkupParser(markupLanguage);
        return markupParser.parseToHtml(content);
    } catch (final Exception e) {
        throw new IOException(NLS.bind(Messages.HelpContent_cannotAccessContent, new Object[] { provider.getSymbolicName(), resourcePath, e.getMessage() })) {

            @Override
            public Throwable getCause() {
                return e;
            }
        };
    }
}
Also used : MarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage) IOException(java.io.IOException) URL(java.net.URL) IOException(java.io.IOException) MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser)

Example 28 with MarkupLanguage

use of org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage in project mylyn.docs by eclipse.

the class AbstractMarkupResourceHandler method execute.

@SuppressWarnings("unchecked")
public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection currentSelection = selection;
    if (currentSelection == null) {
        try {
            currentSelection = computeSelection(event);
        } catch (Exception e) {
        // ignore
        }
    }
    if (currentSelection instanceof IStructuredSelection) {
        IStructuredSelection structuredSelection = (IStructuredSelection) currentSelection;
        Iterator<Object> it = structuredSelection.iterator();
        while (it.hasNext()) {
            Object o = it.next();
            IFile file = null;
            if (o instanceof IAdaptable) {
                file = ((IAdaptable) o).getAdapter(IFile.class);
            }
            if (file != null) {
                String name = file.getName();
                int idxOfDot = name.lastIndexOf('.');
                if (idxOfDot != -1) {
                    name = name.substring(0, idxOfDot);
                }
                // use a temporary so that the setting does not stick even if the handler is reused.
                MarkupLanguage prev = markupLanguage;
                try {
                    if (markupLanguage == null) {
                        markupLanguage = MarkupEditor.loadMarkupLanguagePreference(file);
                        if (markupLanguage == null) {
                            markupLanguage = WikiText.getMarkupLanguageForFilename(file.getName());
                        }
                        if (markupLanguage == null) {
                            MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Messages.AbstractMarkupResourceHandler_unexpectedError, NLS.bind(Messages.AbstractMarkupResourceHandler_markupLanguageMappingFailed, new Object[] { file.getName() }));
                            return null;
                        }
                    }
                    handleFile(event, file, name);
                } finally {
                    markupLanguage = prev;
                }
            }
        }
    }
    return null;
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) IFile(org.eclipse.core.resources.IFile) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) MarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 29 with MarkupLanguage

use of org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage in project mylyn.docs by eclipse.

the class WikiTextSourceEditor method updateOutline.

private void updateOutline() {
    if (!outlineDirty) {
        return;
    }
    if (getSourceViewer().getTextWidget().isDisposed()) {
        return;
    }
    // we maintain the outline even if the outline page is not in use, which allows us to use the outline for
    // content assist and other things
    MarkupLanguage markupLanguage = getMarkupLanguage();
    if (markupLanguage == null) {
        return;
    }
    final MarkupLanguage language = markupLanguage.clone();
    final Display display = getSourceViewer().getTextWidget().getDisplay();
    final String content = document.get();
    final int contentGeneration;
    synchronized (WikiTextSourceEditor.this) {
        contentGeneration = documentGeneration;
        initializeOutlineParser();
    }
    // we parse the outline in another thread so that the UI remains responsive
    Job parseOutlineJob = new // $NON-NLS-1$
    Job(// $NON-NLS-1$
    WikiTextSourceEditor.class.getSimpleName() + "#updateOutline") {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            outlineParser.setMarkupLanguage(language);
            if (shouldCancel()) {
                return Status.CANCEL_STATUS;
            }
            final OutlineItem rootItem = outlineParser.parse(content);
            if (shouldCancel()) {
                return Status.CANCEL_STATUS;
            }
            display.asyncExec(new Runnable() {

                public void run() {
                    updateOutline(contentGeneration, rootItem);
                }
            });
            return Status.OK_STATUS;
        }

        private boolean shouldCancel() {
            synchronized (WikiTextSourceEditor.this) {
                if (contentGeneration != documentGeneration) {
                    return true;
                }
            }
            return false;
        }
    };
    parseOutlineJob.setPriority(Job.INTERACTIVE);
    parseOutlineJob.setSystem(true);
    parseOutlineJob.schedule();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) AbstractMarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.AbstractMarkupLanguage) MarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage) Job(org.eclipse.core.runtime.jobs.Job) UIJob(org.eclipse.ui.progress.UIJob) Point(org.eclipse.swt.graphics.Point) Display(org.eclipse.swt.widgets.Display) OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)

Example 30 with MarkupLanguage

use of org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage in project mylyn.docs by eclipse.

the class WikiTextSourceEditor method setMarkupLanguage.

/**
 * set the markup language. If unspecified, it's assumed to be Textile.
 *
 * @since 3.0
 */
public void setMarkupLanguage(MarkupLanguage markupLanguage) {
    this.markupLanguage = markupLanguage;
    if (this.markupLanguage instanceof AbstractMarkupLanguage) {
        ((AbstractMarkupLanguage) this.markupLanguage).setEnableMacros(false);
    }
    sourceViewerConfiguration.setMarkupLanguage(markupLanguage);
    IDocumentProvider documentProvider = getDocumentProvider();
    if (documentProvider instanceof WikiTextDocumentProvider) {
        ((WikiTextDocumentProvider) documentProvider).setMarkupLanguage(markupLanguage);
    }
    if (getEditorInput() != null) {
        IDocument document = documentProvider.getDocument(getEditorInput());
        IDocumentPartitioner partitioner = document.getDocumentPartitioner();
        if (partitioner instanceof FastMarkupPartitioner) {
            final FastMarkupPartitioner fastMarkupPartitioner = (FastMarkupPartitioner) partitioner;
            fastMarkupPartitioner.setMarkupLanguage(markupLanguage);
        }
    }
    if (viewer != null) {
        viewer.getTextWidget().setData(MarkupLanguage.class.getName(), getMarkupLanguage());
    }
    if (getSourceViewer() != null) {
        getSourceViewer().invalidateTextPresentation();
    }
}
Also used : FastMarkupPartitioner(org.eclipse.mylyn.internal.wikitext.ui.editor.syntax.FastMarkupPartitioner) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) AbstractMarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.AbstractMarkupLanguage) MarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage) AbstractMarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.AbstractMarkupLanguage) IDocument(org.eclipse.jface.text.IDocument)

Aggregations

MarkupLanguage (org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage)60 Test (org.junit.Test)18 AbstractMarkupLanguage (org.eclipse.mylyn.wikitext.parser.markup.AbstractMarkupLanguage)15 MarkupParser (org.eclipse.mylyn.wikitext.parser.MarkupParser)8 File (java.io.File)7 BuildException (org.apache.tools.ant.BuildException)7 CoreException (org.eclipse.core.runtime.CoreException)7 MockMarkupLanguage (org.eclipse.mylyn.internal.wikitext.MockMarkupLanguage)7 StringWriter (java.io.StringWriter)6 HashMap (java.util.HashMap)5 DirectoryScanner (org.apache.tools.ant.DirectoryScanner)5 FileSet (org.apache.tools.ant.types.FileSet)5 OutlineItem (org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)5 Point (org.eclipse.swt.graphics.Point)5 IOException (java.io.IOException)4 IFile (org.eclipse.core.resources.IFile)4 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)4 TreeMap (java.util.TreeMap)3 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3