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;
}
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);
}
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);
}
});
}
}
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;
}
}
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);
}
}
Aggregations