Search in sources :

Example 1 with RmdCreatedTemplate

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

the class TextEditingTargetRMarkdownHelper method createDraftFromTemplate.

private void createDraftFromTemplate(final RmdChosenTemplate template, final String target) {
    final ProgressIndicator progress = new GlobalProgressDelayer(globalDisplay_, 250, "Creating R Markdown Document...").getIndicator();
    server_.createRmdFromTemplate(target, template.getTemplatePath(), template.createDir(), new ServerRequestCallback<RmdCreatedTemplate>() {

        @Override
        public void onResponseReceived(RmdCreatedTemplate created) {
            // write a pref indicating this is the preferred template--
            // we'll default to it the next time we load the template list
            prefs_.rmdPreferredTemplatePath().setGlobalValue(template.getTemplatePath());
            prefs_.writeUIPrefs();
            FileSystemItem file = FileSystemItem.createFile(created.getPath());
            eventBus_.fireEvent(new FileEditEvent(file));
            progress.onCompleted();
        }

        @Override
        public void onError(ServerError error) {
            progress.onError("Couldn't create a template from " + template.getTemplatePath() + " at " + target + ".\n\n" + error.getMessage());
        }
    });
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) FileEditEvent(org.rstudio.studio.client.workbench.views.source.events.FileEditEvent) ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) ServerError(org.rstudio.studio.client.server.ServerError) GlobalProgressDelayer(org.rstudio.studio.client.common.GlobalProgressDelayer) RmdCreatedTemplate(org.rstudio.studio.client.rmarkdown.model.RmdCreatedTemplate)

Aggregations

FileSystemItem (org.rstudio.core.client.files.FileSystemItem)1 ProgressIndicator (org.rstudio.core.client.widget.ProgressIndicator)1 GlobalProgressDelayer (org.rstudio.studio.client.common.GlobalProgressDelayer)1 RmdCreatedTemplate (org.rstudio.studio.client.rmarkdown.model.RmdCreatedTemplate)1 ServerError (org.rstudio.studio.client.server.ServerError)1 FileEditEvent (org.rstudio.studio.client.workbench.views.source.events.FileEditEvent)1