Search in sources :

Example 11 with MarkupLanguage

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

the class MarkupEditor method updateOutlineNow.

private void updateOutlineNow() {
    if (!outlineDirty) {
        return;
    }
    if (!isSourceViewerValid()) {
        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 String content = document.get();
    final int contentGeneration;
    synchronized (MarkupEditor.this) {
        contentGeneration = documentGeneration;
    }
    outlineParser.setMarkupLanguage(language);
    OutlineItem rootItem = outlineParser.parse(content);
    updateOutline(contentGeneration, rootItem);
}
Also used : AbstractMarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.AbstractMarkupLanguage) MarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage) Point(org.eclipse.swt.graphics.Point) OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)

Example 12 with MarkupLanguage

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

the class MarkupEditor method storeMarkupLanguagePreference.

private void storeMarkupLanguagePreference(MarkupLanguage markupLanguage) {
    if (markupLanguage == null) {
        throw new IllegalArgumentException();
    }
    IFile file = getFile();
    if (file != null) {
        MarkupLanguage defaultMarkupLanguage = WikiText.getMarkupLanguageForFilename(file.getName());
        String preference = markupLanguage.getName();
        if (defaultMarkupLanguage != null && defaultMarkupLanguage.getName().equals(preference)) {
            preference = null;
        }
        try {
            file.setPersistentProperty(new QualifiedName(WikiTextUiPlugin.getDefault().getPluginId(), MARKUP_LANGUAGE), preference);
        } catch (CoreException e) {
            WikiTextUiPlugin.getDefault().log(IStatus.ERROR, NLS.bind(Messages.MarkupEditor_markupPreferenceError2, new Object[] { preference }), e);
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) QualifiedName(org.eclipse.core.runtime.QualifiedName) AbstractMarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.AbstractMarkupLanguage) MarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage)

Example 13 with MarkupLanguage

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

the class MarkupEditor method setMarkupLanguage.

public void setMarkupLanguage(MarkupLanguage markupLanguage, boolean persistSetting) {
    if (markupLanguage instanceof AbstractMarkupLanguage) {
        ((AbstractMarkupLanguage) markupLanguage).setEnableMacros(false);
    }
    ((MarkupDocumentProvider) getDocumentProvider()).setMarkupLanguage(markupLanguage);
    IDocument document = getDocumentProvider().getDocument(getEditorInput());
    IDocumentPartitioner partitioner = document.getDocumentPartitioner();
    if (partitioner instanceof FastMarkupPartitioner) {
        final FastMarkupPartitioner fastMarkupPartitioner = (FastMarkupPartitioner) partitioner;
        fastMarkupPartitioner.setMarkupLanguage(markupLanguage);
    }
    sourceViewerConfiguration.setMarkupLanguage(markupLanguage);
    if (getSourceViewer() != null) {
        getSourceViewer().invalidateTextPresentation();
    }
    outlineDirty = true;
    scheduleOutlineUpdate();
    updateSourceTabLabel();
    if (viewer != null) {
        viewer.getTextWidget().setData(MarkupLanguage.class.getName(), getMarkupLanguage());
    }
    if (persistSetting && markupLanguage != null) {
        storeMarkupLanguagePreference(markupLanguage);
    }
    if (persistSetting) {
        ISourceViewer sourceViewer = getSourceViewer();
        if (sourceViewer instanceof MarkupProjectionViewer) {
            IReconciler reconciler = ((MarkupProjectionViewer) sourceViewer).getReconciler();
            if (reconciler instanceof MarkupMonoReconciler) {
                ((MarkupMonoReconciler) reconciler).forceReconciling();
            }
        }
    }
}
Also used : FastMarkupPartitioner(org.eclipse.mylyn.internal.wikitext.ui.editor.syntax.FastMarkupPartitioner) IReconciler(org.eclipse.jface.text.reconciler.IReconciler) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) MarkupMonoReconciler(org.eclipse.mylyn.internal.wikitext.ui.editor.reconciler.MarkupMonoReconciler) AbstractMarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.AbstractMarkupLanguage) MarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage) AbstractMarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.AbstractMarkupLanguage) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) MarkupDocumentProvider(org.eclipse.mylyn.internal.wikitext.ui.editor.syntax.MarkupDocumentProvider) IDocument(org.eclipse.jface.text.IDocument)

Example 14 with MarkupLanguage

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

the class MarkupEditor method editorContextMenuAboutToShow.

@Override
protected void editorContextMenuAboutToShow(IMenuManager menu) {
    super.editorContextMenuAboutToShow(menu);
    final MarkupLanguage markupLanguage = getMarkupLanguage();
    MenuManager markupLanguageMenu = new MenuManager(Messages.MarkupEditor_markupLanguage);
    for (String markupLanguageName : new TreeSet<>(WikiText.getMarkupLanguageNames())) {
        markupLanguageMenu.add(new SetMarkupLanguageAction(this, markupLanguageName, markupLanguage != null && markupLanguageName.equals(markupLanguage.getName())));
    }
    menu.prependToGroup(ITextEditorActionConstants.GROUP_SETTINGS, markupLanguageMenu);
    OutlineItem nearestOutlineItem = getNearestMatchingOutlineItem();
    if (nearestOutlineItem != null && !nearestOutlineItem.isRootItem()) {
        menu.appendToGroup(ITextEditorActionConstants.GROUP_OPEN, new PreviewOutlineItemAction(this, nearestOutlineItem));
    }
}
Also used : SetMarkupLanguageAction(org.eclipse.mylyn.internal.wikitext.ui.editor.actions.SetMarkupLanguageAction) PreviewOutlineItemAction(org.eclipse.mylyn.internal.wikitext.ui.editor.actions.PreviewOutlineItemAction) TreeSet(java.util.TreeSet) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) AbstractMarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.AbstractMarkupLanguage) MarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage) OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)

Example 15 with MarkupLanguage

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

the class MarkupEditor method initializeMarkupLanguage.

private void initializeMarkupLanguage(IEditorInput input) {
    MarkupLanguage markupLanguage = loadMarkupLanguagePreference();
    if (markupLanguage == null) {
        String name = input.getName();
        if (input instanceof IFileEditorInput) {
            name = ((IFileEditorInput) input).getFile().getName();
        } else if (input instanceof IPathEditorInput) {
            name = ((IPathEditorInput) input).getPath().lastSegment();
        }
        markupLanguage = WikiText.getMarkupLanguageForFilename(name);
        if (markupLanguage == null) {
            // $NON-NLS-1$
            markupLanguage = WikiText.getMarkupLanguage("Textile");
        }
    }
    setMarkupLanguage(markupLanguage, false);
}
Also used : IPathEditorInput(org.eclipse.ui.IPathEditorInput) IFileEditorInput(org.eclipse.ui.IFileEditorInput) AbstractMarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.AbstractMarkupLanguage) MarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage)

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