use of org.rstudio.studio.client.rmarkdown.events.SendToChunkConsoleEvent in project rstudio by rstudio.
the class EditingTargetCodeExecution method executeRange.
private void executeRange(Range range, String functionWrapper, boolean onlyUseConsole) {
String code = codeExtractor_.extractCode(docDisplay_, range);
setLastExecuted(range.getStart(), range.getEnd());
// trim intelligently
code = code.trim();
if (code.length() == 0)
code = "\n";
// strip roxygen off the beginning of lines
if (isRoxygenExampleRange(range)) {
code = code.replaceFirst("^[ \\t]*#'[ \\t]?", "");
code = code.replaceAll("\n[ \\t]*#'[ \\t]?", "\n");
}
// if we're in a chunk with in-line output, execute it there instead
if (!onlyUseConsole && docDisplay_.showChunkOutputInline()) {
Scope scope = docDisplay_.getCurrentChunk(range.getStart());
if (scope != null) {
events_.fireEvent(new SendToChunkConsoleEvent(docId_, scope, range));
return;
}
}
if (functionWrapper != null) {
code = functionWrapper + "({" + code + "})";
}
// send to console
events_.fireEvent(new SendToConsoleEvent(code, true, prefs_.focusConsoleAfterExec().getValue()));
}
use of org.rstudio.studio.client.rmarkdown.events.SendToChunkConsoleEvent in project rstudio by rstudio.
the class EditingTargetInlineChunkExecution method execute.
public void execute(Range range) {
// synthesize an identifier for this chunk execution
final String chunkId = "i" + StringUtil.makeRandomId(12);
// are, remove it to make way for the new one
for (ChunkInlineOutput output : outputs_.values()) {
if (output.range().isEqualTo(range)) {
if (output.state() == ChunkInlineOutput.State.Finished) {
// remove old, completed output for this input
output.hide();
outputs_.remove(output.chunkId());
} else {
// unintended duplicate.
return;
}
}
}
// create dummy scope for execution
Scope scope = Scope.createRScopeNode(chunkId, range.getStart(), range.getEnd(), Scope.SCOPE_TYPE_CHUNK);
// create popup panel to host output
final ChunkInlineOutput output = new ChunkInlineOutput(chunkId, display_.createAnchoredSelection(range.getStart(), range.getEnd()));
// auto dismiss the panel when the cursor leaves the inline chunk
final Mutable<HandlerRegistration> cursorHandler = new Mutable<HandlerRegistration>();
cursorHandler.set(display_.addCursorChangedHandler(new CursorChangedHandler() {
@Override
public void onCursorChanged(CursorChangedEvent event) {
Position position = event.getPosition();
if (!output.range().contains(position)) {
output.hide();
}
}
}));
// when the popup is dismissed, clean up local state
output.addCloseHandler(new CloseHandler<PopupPanel>() {
@Override
public void onClose(CloseEvent<PopupPanel> event) {
outputs_.remove(chunkId);
cursorHandler.get().removeHandler();
}
});
// render offscreen until complete
output.setPopupPosition(-100000, -100000);
output.show();
outputs_.put(chunkId, output);
SendToChunkConsoleEvent event = new SendToChunkConsoleEvent(docId_, scope, range, NotebookQueueUnit.EXEC_SCOPE_INLINE);
events_.fireEvent(event);
}
Aggregations