Search in sources :

Example 1 with RmdSelectedTemplate

use of org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTargetRMarkdownHelper.RmdSelectedTemplate in project rstudio by rstudio.

the class TextEditingTarget method showFrontMatterEditorDialog.

private void showFrontMatterEditorDialog(String yaml, RmdYamlData data) {
    RmdSelectedTemplate selTemplate = rmarkdownHelper_.getTemplateFormat(yaml);
    if (selTemplate == null) {
        // we don't expect this to happen since we disable the dialog
        // entry point when we can't find an associated template
        globalDisplay_.showErrorMessage("Edit Format Failed", "Couldn't determine the format options from the YAML front " + "matter. Make sure the YAML defines a supported output " + "format in its 'output' field.");
        return;
    }
    RmdTemplateOptionsDialog dialog = new RmdTemplateOptionsDialog(selTemplate.template, selTemplate.format, data.getFrontMatter(), getPath() == null ? null : FileSystemItem.createFile(getPath()), selTemplate.isShiny, new OperationWithInput<RmdTemplateOptionsDialog.Result>() {

        @Override
        public void execute(RmdTemplateOptionsDialog.Result in) {
            // when the dialog is completed successfully, apply the new
            // front matter
            applyRmdFormatOptions(in.format, in.outputOptions);
        }
    }, new Operation() {

        @Override
        public void execute() {
            // when the dialog is cancelled, update the view's format list
            // (to cancel in-place changes)
            updateRmdFormatList();
        }
    });
    dialog.showModal();
}
Also used : RmdSelectedTemplate(org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTargetRMarkdownHelper.RmdSelectedTemplate) CppCompletionOperation(org.rstudio.studio.client.workbench.views.source.editors.text.cpp.CppCompletionOperation) RmdTemplateOptionsDialog(org.rstudio.studio.client.rmarkdown.ui.RmdTemplateOptionsDialog) CompileNotebookResult(org.rstudio.studio.client.notebook.CompileNotebookResult)

Example 2 with RmdSelectedTemplate

use of org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTargetRMarkdownHelper.RmdSelectedTemplate in project rstudio by rstudio.

the class TextEditingTarget method updateRmdFormatList.

private void updateRmdFormatList() {
    String formatUiName = "";
    List<String> formatList = new ArrayList<String>();
    List<String> valueList = new ArrayList<String>();
    List<String> extensionList = new ArrayList<String>();
    RmdSelectedTemplate selTemplate = getSelectedTemplate();
    if (selTemplate != null && selTemplate.isShiny) {
        view_.setIsShinyFormat(selTemplate.format != null, selTemplate.format != null && selTemplate.format.endsWith(RmdOutputFormat.OUTPUT_PRESENTATION_SUFFIX), isShinyPrerenderedDoc());
    } else // could be runtime: shiny with a custom format
    if (isShinyDoc()) {
        // no output options b/c no template
        view_.setIsShinyFormat(// no output options b/c no template
        false, // not a presentation (unknown format)
        false, isShinyPrerenderedDoc());
    } else {
        view_.setIsNotShinyFormat();
        if (selTemplate != null) {
            JsArray<RmdTemplateFormat> formats = selTemplate.template.getFormats();
            for (int i = 0; i < formats.length(); i++) {
                // skip notebook format (will enable it later if discovered)
                if (formats.get(i).getName() == RmdOutputFormat.OUTPUT_HTML_NOTEBOOK) {
                    continue;
                }
                String uiName = formats.get(i).getUiName();
                formatList.add(uiName);
                valueList.add(formats.get(i).getName());
                extensionList.add(formats.get(i).getExtension());
                if (formats.get(i).getName().equals(selTemplate.format)) {
                    formatUiName = uiName;
                }
            }
        }
        // add formats not in the selected template 
        boolean isNotebook = false;
        List<String> outputFormats = getOutputFormats();
        for (int i = 0; i < outputFormats.size(); i++) {
            String format = outputFormats.get(i);
            if (format == RmdOutputFormat.OUTPUT_HTML_NOTEBOOK) {
                if (i == 0)
                    isNotebook = true;
                formatList.add(0, "Notebook");
                valueList.add(0, format);
                extensionList.add(0, ".nb.html");
                continue;
            }
            if (!valueList.contains(format)) {
                String uiName = format;
                int nsLoc = uiName.indexOf("::");
                if (nsLoc != -1)
                    uiName = uiName.substring(nsLoc + 2);
                formatList.add(uiName);
                valueList.add(format);
                extensionList.add(null);
            }
        }
        view_.setFormatOptions(fileType_, // can choose output formats
        getCustomKnit().length() == 0, // can edit format options
        selTemplate != null, formatList, valueList, extensionList, formatUiName);
        // update notebook-specific options
        if (isNotebook) {
            // if the user manually set the output to console in a notebook,
            // respect that (even though it's weird)
            String outputType = RmdEditorOptions.getString(YamlFrontMatter.getFrontMatter(docDisplay_), TextEditingTargetNotebook.CHUNK_OUTPUT_TYPE, null);
            if (outputType != TextEditingTargetNotebook.CHUNK_OUTPUT_CONSOLE) {
                // chunk output should always be inline in notebooks
                outputType = docUpdateSentinel_.getProperty(TextEditingTargetNotebook.CHUNK_OUTPUT_TYPE);
                if (outputType != TextEditingTargetNotebook.CHUNK_OUTPUT_INLINE) {
                    docUpdateSentinel_.setProperty(TextEditingTargetNotebook.CHUNK_OUTPUT_TYPE, TextEditingTargetNotebook.CHUNK_OUTPUT_INLINE);
                }
            }
            view_.setIsNotebookFormat();
        }
    }
    if (isShinyDoc()) {
        // turn off inline output in Shiny documents (if it's not already)
        if (docDisplay_.showChunkOutputInline())
            docDisplay_.setShowChunkOutputInline(false);
    }
}
Also used : JsArray(com.google.gwt.core.client.JsArray) ArrayList(java.util.ArrayList) RmdSelectedTemplate(org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTargetRMarkdownHelper.RmdSelectedTemplate) ArrayList(java.util.ArrayList) List(java.util.List) JsArrayString(com.google.gwt.core.client.JsArrayString)

Aggregations

RmdSelectedTemplate (org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTargetRMarkdownHelper.RmdSelectedTemplate)2 JsArray (com.google.gwt.core.client.JsArray)1 JsArrayString (com.google.gwt.core.client.JsArrayString)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CompileNotebookResult (org.rstudio.studio.client.notebook.CompileNotebookResult)1 RmdTemplateOptionsDialog (org.rstudio.studio.client.rmarkdown.ui.RmdTemplateOptionsDialog)1 CppCompletionOperation (org.rstudio.studio.client.workbench.views.source.editors.text.cpp.CppCompletionOperation)1