use of org.rstudio.studio.client.workbench.views.source.editors.text.ChunkInlineOutput 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