Search in sources :

Example 1 with RmdPreviewParams

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

the class RmdOutput method notifyRmdOutputClosed.

// when the window is closed, remember our position within it
private void notifyRmdOutputClosed(JavaScriptObject closeParams) {
    // save anchor location for presentations and scroll position for 
    // documents
    RmdPreviewParams params = closeParams.cast();
    cacheDocPosition(params.getResult(), params.getScrollPosition(), params.getAnchor());
    // if this is a Shiny document, stop the associated process
    if (params.isShinyDocument() && !restarting_) {
        server_.terminateRenderRmd(true, new VoidServerRequestCallback());
    }
    shinyDoc_ = null;
}
Also used : VoidServerRequestCallback(org.rstudio.studio.client.server.VoidServerRequestCallback) RmdPreviewParams(org.rstudio.studio.client.rmarkdown.model.RmdPreviewParams)

Example 2 with RmdPreviewParams

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

the class RmdOutput method reRenderPreview.

private void reRenderPreview(String targetFile) {
    if (outputFrame_ == null)
        return;
    livePreviewRenderInProgress_ = true;
    RmdPreviewParams params = outputFrame_.getPreviewParams();
    if (targetFile == null)
        targetFile = params.getTargetFile();
    RenderRmdEvent renderEvent = new RenderRmdEvent(targetFile, 1, params.getResult().getFormatName(), params.getResult().getTargetEncoding(), null, false, RmdOutput.TYPE_STATIC, null, null, null);
    events_.fireEvent(renderEvent);
}
Also used : RmdPreviewParams(org.rstudio.studio.client.rmarkdown.model.RmdPreviewParams) RenderRmdEvent(org.rstudio.studio.client.rmarkdown.events.RenderRmdEvent)

Example 3 with RmdPreviewParams

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

the class RmdOutput method onWebsiteFileSaved.

@Override
public void onWebsiteFileSaved(WebsiteFileSavedEvent event) {
    // skip if there is a build in progress
    if (workbenchContext_.isBuildInProgress())
        return;
    // skip if there is a render in progress
    if (renderInProgress_)
        return;
    // skip if there was a quit initiated since the last render
    if (quitInitiatedAfterLastRender_)
        return;
    // is there an output frame?
    if (outputFrame_ == null || outputFrame_.getWindowObject() == null)
        return;
    // is it showing a page from the current site?
    String websiteDir = session_.getSessionInfo().getBuildTargetDir();
    final RmdPreviewParams params = outputFrame_.getPreviewParams();
    if (!params.getTargetFile().startsWith(websiteDir))
        return;
    // is the changed file one that should always produce a rebuild?
    FileSystemItem file = event.getFileSystemItem();
    TextFileType fileType = fileTypeRegistry_.getTextTypeForFile(file);
    String typeId = fileType.getTypeId();
    if (fileType.isR() || typeId.equals(FileTypeRegistry.HTML.getTypeId()) || typeId.equals(FileTypeRegistry.YAML.getTypeId()) || typeId.equals(FileTypeRegistry.JSON.getTypeId())) {
        reRenderPreview();
    } else // is the changed file a markdown document
    if (fileType.isMarkdown()) {
        // included Rmd files always produce a rebuild of the current file
        if (file.getStem().startsWith("_"))
            reRenderPreview();
        // files in subdirectories are also includes so re-render them also
        if (!file.getParentPathString().equals(websiteDir))
            reRenderPreview();
    // ...otherwise leave it alone (requires a knit)
    } else // see if this should result in a copy + refresh
    {
        server_.maybeCopyWebsiteAsset(file.getPath(), new SimpleRequestCallback<Boolean>() {

            @Override
            public void onResponseReceived(Boolean copied) {
                if (copied)
                    outputFrame_.showRmdPreview(params, true);
            }
        });
    }
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) TextFileType(org.rstudio.studio.client.common.filetypes.TextFileType) RmdPreviewParams(org.rstudio.studio.client.rmarkdown.model.RmdPreviewParams) SimpleRequestCallback(org.rstudio.studio.client.common.SimpleRequestCallback)

Example 4 with RmdPreviewParams

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

the class RmdOutput method onViewerTypeChanged.

// Private methods ---------------------------------------------------------
private void onViewerTypeChanged(int newViewerType) {
    if (outputFrame_ != null && outputFrame_.getWindowObject() != null && newViewerType != outputFrame_.getViewerType()) {
        // close the existing frame
        RmdPreviewParams params = outputFrame_.getPreviewParams();
        outputFrame_.closeOutputFrame(true);
        // reset the scroll position (as it will vary with the document width,
        // which will change)
        params.setScrollPosition(0);
        // open a new one with the same parameters
        outputFrame_ = createOutputFrame(newViewerType);
        outputFrame_.showRmdPreview(params, true);
    } else if (outputFrame_ != null && outputFrame_.getWindowObject() == null && outputFrame_.getViewerType() != newViewerType) {
        // output frame exists but doesn't have a loaded doc, clear it so we'll
        // create the frame appropriate to this type on next render
        outputFrame_ = null;
    }
}
Also used : RmdPreviewParams(org.rstudio.studio.client.rmarkdown.model.RmdPreviewParams)

Example 5 with RmdPreviewParams

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

the class RmdOutput method displayHTMLRenderResult.

private void displayHTMLRenderResult(RmdRenderResult result) {
    // find the last known position for this file
    int scrollPosition = 0;
    String anchor = "";
    if (scrollPositions_.containsKey(keyFromResult(result))) {
        scrollPosition = scrollPositions_.get(keyFromResult(result));
    }
    if (anchors_.containsKey(keyFromResult(result))) {
        anchor = anchors_.get(keyFromResult(result));
    }
    final RmdPreviewParams params = RmdPreviewParams.create(result, scrollPosition, anchor);
    // get the default viewer type from prefs
    int viewerType = prefs_.rmdViewerType().getValue();
    // apply override from result, if any
    if (result.getViewerType() == RmdEditorOptions.PREVIEW_IN_VIEWER)
        viewerType = RMD_VIEWER_TYPE_PANE;
    else if (result.getViewerType() == RmdEditorOptions.PREVIEW_IN_WINDOW)
        viewerType = RMD_VIEWER_TYPE_WINDOW;
    else if (result.getViewerType() == RmdEditorOptions.PREVIEW_IN_NONE)
        viewerType = RMD_VIEWER_TYPE_NONE;
    // slides well without help
    if (result.isHtmlPresentation() && viewerType == RMD_VIEWER_TYPE_PANE)
        viewerType = RMD_VIEWER_TYPE_WINDOW;
    final int newViewerType = viewerType;
    // we don't disturb the publish flow with a window popping up
    if (newViewerType == RMD_VIEWER_TYPE_WINDOW && RSConnectPublishButton.isAnyRmdRenderPending()) {
        return;
    }
    // get the window object if available
    WindowEx win = null;
    boolean needsReopen = false;
    if (outputFrame_ != null) {
        win = outputFrame_.getWindowObject();
        if (outputFrame_.getViewerType() != newViewerType)
            needsReopen = true;
    }
    // close it so that we can create a new one better suited to this doc type
    if (needsReopen || (win != null && result_ != null && !result_.getFormatName().equals(result.getFormatName()))) {
        outputFrame_.closeOutputFrame(false);
        outputFrame_ = null;
        win = null;
        // let window finish closing before continuing
        Scheduler.get().scheduleDeferred(new ScheduledCommand() {

            @Override
            public void execute() {
                displayRenderResult(null, newViewerType, params);
            }
        });
    } else {
        displayRenderResult(win, newViewerType, params);
    }
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) WindowEx(org.rstudio.core.client.dom.WindowEx) RmdPreviewParams(org.rstudio.studio.client.rmarkdown.model.RmdPreviewParams)

Aggregations

RmdPreviewParams (org.rstudio.studio.client.rmarkdown.model.RmdPreviewParams)5 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 WindowEx (org.rstudio.core.client.dom.WindowEx)1 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)1 SimpleRequestCallback (org.rstudio.studio.client.common.SimpleRequestCallback)1 TextFileType (org.rstudio.studio.client.common.filetypes.TextFileType)1 RenderRmdEvent (org.rstudio.studio.client.rmarkdown.events.RenderRmdEvent)1 VoidServerRequestCallback (org.rstudio.studio.client.server.VoidServerRequestCallback)1