Search in sources :

Example 1 with RmdTemplateFormatOption

use of org.rstudio.studio.client.rmarkdown.model.RmdTemplateFormatOption in project rstudio by rstudio.

the class RmdTemplateOptionsWidget method findOption.

private RmdTemplateFormatOption findOption(String formatName, String optionName) {
    RmdTemplateFormatOption result = null;
    for (int i = 0; i < options_.length(); i++) {
        RmdTemplateFormatOption option = options_.get(i);
        // Not the option we're looking for 
        if (!option.getName().equals(optionName))
            continue;
        String optionFormatName = option.getFormatName();
        if (optionFormatName.length() > 0) {
            // otherwise keep looking
            if (optionFormatName.equals(formatName))
                return option;
            else
                continue;
        }
        result = option;
    }
    return result;
}
Also used : RmdTemplateFormatOption(org.rstudio.studio.client.rmarkdown.model.RmdTemplateFormatOption) JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 2 with RmdTemplateFormatOption

use of org.rstudio.studio.client.rmarkdown.model.RmdTemplateFormatOption in project rstudio by rstudio.

the class RmdTemplateOptionsWidget method addFormatOptions.

private void addFormatOptions(RmdTemplateFormat format) {
    if (format.getNotes().length() > 0 && allowFormatChange_) {
        labelFormatNotes_.setText(format.getNotes());
        labelFormatNotes_.setVisible(true);
    } else {
        labelFormatNotes_.setVisible(false);
    }
    optionWidgets_ = new ArrayList<RmdFormatOption>();
    JsArrayString options = format.getOptions();
    for (int i = 0; i < options.length(); i++) {
        RmdFormatOption optionWidget;
        RmdTemplateFormatOption option = findOption(format.getName(), options.get(i));
        if (option == null)
            continue;
        String initialValue = option.getDefaultValue();
        // check to see whether a value for this format and option were
        // specified in the front matter
        String frontMatterValue = getFrontMatterDefault(format.getName(), option.getName());
        if (frontMatterValue != null)
            initialValue = frontMatterValue;
        optionWidget = createWidgetForOption(option, initialValue);
        if (optionWidget == null)
            continue;
        optionWidget.asWidget().addStyleName(style.optionWidget());
        FlowPanel panel = null;
        String category = option.getCategory();
        if (tabs_.containsKey(category)) {
            panel = tabs_.get(category);
        } else {
            ScrollPanel scrollPanel = new ScrollPanel();
            panel = new FlowPanel();
            scrollPanel.add(panel);
            optionsTabs_.add(scrollPanel, new Label(category));
            tabs_.put(category, panel);
        }
        panel.add(optionWidget);
        optionWidgets_.add(optionWidget);
    }
    // we need to center the tabs and overlay them on the top edge of the
    // content; to do this, it is necessary to nuke a couple of the inline
    // styles used by the default GWT tab panel. 
    Element tabOuter = (Element) optionsTabs_.getElement().getChild(1);
    tabOuter.getStyle().setOverflow(Overflow.VISIBLE);
    Element tabInner = (Element) tabOuter.getFirstChild();
    tabInner.getStyle().clearWidth();
}
Also used : RmdTemplateFormatOption(org.rstudio.studio.client.rmarkdown.model.RmdTemplateFormatOption) Element(com.google.gwt.dom.client.Element) FlowPanel(com.google.gwt.user.client.ui.FlowPanel) Label(com.google.gwt.user.client.ui.Label) JsArrayString(com.google.gwt.core.client.JsArrayString) JsArrayString(com.google.gwt.core.client.JsArrayString) ScrollPanel(com.google.gwt.user.client.ui.ScrollPanel)

Example 3 with RmdTemplateFormatOption

use of org.rstudio.studio.client.rmarkdown.model.RmdTemplateFormatOption in project rstudio by rstudio.

the class RmdTemplateOptionsWidget method applyFrontMatter.

private void applyFrontMatter(RmdFrontMatter frontMatter) {
    frontMatter_ = frontMatter;
    frontMatterCache_ = new HashMap<String, String>();
    ensureOptionsCache();
    JsArrayString formats = frontMatter.getFormatList();
    for (int i = 0; i < formats.length(); i++) {
        String format = formats.get(i);
        RmdFrontMatterOutputOptions options = frontMatter.getOutputOption(format);
        JsArrayString optionList = options.getOptionList();
        for (int j = 0; j < optionList.length(); j++) {
            String option = optionList.get(j);
            String value = options.getOptionValue(option);
            frontMatterCache_.put(format + ":" + option, value);
            if (optionCache_.containsKey(option)) {
                // If the option is specifically labeled as transferable
                // between formats, add a generic key to be applied to other
                // formats
                RmdTemplateFormatOption formatOption = optionCache_.get(option);
                if (formatOption.isTransferable()) {
                    frontMatterCache_.put(option, value);
                }
            }
        }
    }
}
Also used : RmdTemplateFormatOption(org.rstudio.studio.client.rmarkdown.model.RmdTemplateFormatOption) JsArrayString(com.google.gwt.core.client.JsArrayString) JsArrayString(com.google.gwt.core.client.JsArrayString) RmdFrontMatterOutputOptions(org.rstudio.studio.client.rmarkdown.model.RmdFrontMatterOutputOptions)

Example 4 with RmdTemplateFormatOption

use of org.rstudio.studio.client.rmarkdown.model.RmdTemplateFormatOption in project rstudio by rstudio.

the class RmdTemplateOptionsWidget method ensureOptionsCache.

private void ensureOptionsCache() {
    if (optionCache_ != null)
        return;
    optionCache_ = new HashMap<String, RmdTemplateFormatOption>();
    for (int i = 0; i < options_.length(); i++) {
        RmdTemplateFormatOption option = options_.get(i);
        if (option.getFormatName().length() > 0)
            continue;
        optionCache_.put(option.getName(), option);
    }
}
Also used : RmdTemplateFormatOption(org.rstudio.studio.client.rmarkdown.model.RmdTemplateFormatOption) JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 5 with RmdTemplateFormatOption

use of org.rstudio.studio.client.rmarkdown.model.RmdTemplateFormatOption in project rstudio by rstudio.

the class TextEditingTargetRMarkdownHelper method transferOptions.

private RmdFrontMatterOutputOptions transferOptions(RmdFrontMatter frontMatter, RmdTemplate template, String format) {
    RmdFrontMatterOutputOptions result = RmdFrontMatterOutputOptions.create();
    // loop over each option applicable to the new format; if it's
    // transferable, try to find it in one of the other formats 
    JsArrayString options = template.getFormat(format).getOptions();
    for (int i = 0; i < options.length(); i++) {
        String optionName = options.get(i);
        RmdTemplateFormatOption option = template.getOption(optionName);
        if (!option.isTransferable())
            continue;
        // option is transferable, is it present in another front matter entry?
        JsArrayString formats = frontMatter.getFormatList();
        for (int j = 0; j < formats.length(); j++) {
            RmdFrontMatterOutputOptions outOptions = frontMatter.getOutputOption(formats.get(j));
            if (outOptions == null)
                continue;
            String val = outOptions.getOptionValue(optionName);
            if (val != null)
                result.setOptionValue(option, val);
        }
    }
    return result;
}
Also used : RmdTemplateFormatOption(org.rstudio.studio.client.rmarkdown.model.RmdTemplateFormatOption) RmdFrontMatterOutputOptions(org.rstudio.studio.client.rmarkdown.model.RmdFrontMatterOutputOptions) JsArrayString(com.google.gwt.core.client.JsArrayString) JsArrayString(com.google.gwt.core.client.JsArrayString)

Aggregations

JsArrayString (com.google.gwt.core.client.JsArrayString)5 RmdTemplateFormatOption (org.rstudio.studio.client.rmarkdown.model.RmdTemplateFormatOption)5 RmdFrontMatterOutputOptions (org.rstudio.studio.client.rmarkdown.model.RmdFrontMatterOutputOptions)2 Element (com.google.gwt.dom.client.Element)1 FlowPanel (com.google.gwt.user.client.ui.FlowPanel)1 Label (com.google.gwt.user.client.ui.Label)1 ScrollPanel (com.google.gwt.user.client.ui.ScrollPanel)1