Search in sources :

Example 1 with SourceDocumentResult

use of org.rstudio.studio.client.workbench.views.source.model.SourceDocumentResult in project rstudio by rstudio.

the class Source method openNotebook.

private void openNotebook(final FileSystemItem rnbFile, final TextFileType fileType, final ResultCallback<EditingTarget, ServerError> resultCallback) {
    // construct path to .Rmd
    final String rnbPath = rnbFile.getPath();
    final String rmdPath = FilePathUtils.filePathSansExtension(rnbPath) + ".Rmd";
    final FileSystemItem rmdFile = FileSystemItem.createFile(rmdPath);
    // TODO: should we perform conflict resolution here as well?
    if (openFileAlreadyOpen(rmdFile, resultCallback))
        return;
    // ask the server to extract the .Rmd, then open that
    Command extractRmdCommand = new Command() {

        @Override
        public void execute() {
            server_.extractRmdFromNotebook(rnbPath, new ServerRequestCallback<SourceDocumentResult>() {

                @Override
                public void onResponseReceived(SourceDocumentResult doc) {
                    openNotebook(rmdFile, doc, resultCallback);
                }

                @Override
                public void onError(ServerError error) {
                    globalDisplay_.showErrorMessage("Notebook Open Failed", "This notebook could not be opened. \n\n" + error.getMessage());
                    resultCallback.onFailure(error);
                }
            });
        }
    };
    dependencyManager_.withRMarkdown("R Notebook", "Using R Notebooks", extractRmdCommand);
}
Also used : SourceDocumentResult(org.rstudio.studio.client.workbench.views.source.model.SourceDocumentResult) FileSystemItem(org.rstudio.core.client.files.FileSystemItem) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) Command(com.google.gwt.user.client.Command) AppCommand(org.rstudio.core.client.command.AppCommand) ServerError(org.rstudio.studio.client.server.ServerError) JSONString(com.google.gwt.json.client.JSONString) JsArrayString(com.google.gwt.core.client.JsArrayString)

Aggregations

JsArrayString (com.google.gwt.core.client.JsArrayString)1 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 JSONString (com.google.gwt.json.client.JSONString)1 Command (com.google.gwt.user.client.Command)1 AppCommand (org.rstudio.core.client.command.AppCommand)1 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)1 ServerError (org.rstudio.studio.client.server.ServerError)1 SourceDocumentResult (org.rstudio.studio.client.workbench.views.source.model.SourceDocumentResult)1