use of org.rstudio.studio.client.workbench.views.console.events.SendToConsoleEvent in project rstudio by rstudio.
the class ProjectPreferencesDialog method emitPackratConsoleActions.
private void emitPackratConsoleActions(RProjectPackratOptions options) {
String packratFunction = null;
String packratArgs = null;
// case: enabling packrat
if (options.getUsePackrat() && !initialPackratOptions_.getUsePackrat()) {
packratFunction = "init";
String optionArgs = packratArgs(options);
if (optionArgs.length() > 0)
packratArgs = "options = list(" + optionArgs + ")";
} else // case: disabling packart
if (!options.getUsePackrat() && initialPackratOptions_.getUsePackrat()) {
packratFunction = "disable";
} else // case: changing packrat options
{
packratArgs = packratArgs(options);
if (!StringUtil.isNullOrEmpty(packratArgs))
packratFunction = "set_opts";
}
if (packratFunction != null) {
// build the call
StringBuilder b = new StringBuilder();
b.append("packrat::");
b.append(packratFunction);
b.append("(");
String projectArg = pPackratUtil_.get().packratProjectArg();
if (projectArg.length() > 0) {
b.append(projectArg);
if (packratArgs != null)
b.append(", ");
}
if (packratArgs != null)
b.append(packratArgs);
b.append(")");
pEventBus_.get().fireEvent(new SendToConsoleEvent(b.toString(), true, true));
}
}
use of org.rstudio.studio.client.workbench.views.console.events.SendToConsoleEvent 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.workbench.views.console.events.SendToConsoleEvent in project rstudio by rstudio.
the class DesktopHooks method evaluateRCmd.
void evaluateRCmd(final String cmd) {
// inject a 100ms delay between execution of commands to prevent
// issues with commands being delivered out of order by cocoa
// networking to the server (it appears as if when you put e.g. 10
// requests in flight simultaneously it's not guarnateed that they
// will be received in the order they were sent).
commandQueue_.addCommand(new SerializedCommand() {
@Override
public void onExecute(final Command continuation) {
// execute the code
events_.fireEvent(new SendToConsoleEvent(cmd, true));
// wait 100ms to execute the next command in the queue
new Timer() {
@Override
public void run() {
continuation.execute();
}
}.schedule(100);
;
}
});
// make sure the queue is running
commandQueue_.run();
}
use of org.rstudio.studio.client.workbench.views.console.events.SendToConsoleEvent in project rstudio by rstudio.
the class TextEditingTarget method executeChunks.
public void executeChunks(final Position position, int which) {
if (docDisplay_.showChunkOutputInline()) {
executeChunksNotebookMode(position, which);
return;
}
// HACK: This is just to force the entire function tree to be built.
// It's the easiest way to make sure getCurrentScope() returns
// a Scope with an end.
docDisplay_.getScopeTree();
// execute the chunks
Scope[] previousScopes = scopeHelper_.getSweaveChunks(position, which);
StringBuilder builder = new StringBuilder();
for (Scope scope : previousScopes) {
if (isRChunk(scope) && isExecutableChunk(scope)) {
builder.append("# " + scope.getLabel() + "\n");
builder.append(scopeHelper_.getSweaveChunkText(scope));
builder.append("\n\n");
}
}
final String code = builder.toString().trim();
if (fileType_.isRmd()) {
docUpdateSentinel_.withSavedDoc(new Command() {
@Override
public void execute() {
rmarkdownHelper_.prepareForRmdChunkExecution(docUpdateSentinel_.getId(), docUpdateSentinel_.getContents(), new Command() {
@Override
public void execute() {
events_.fireEvent(new SendToConsoleEvent(code, true));
}
});
}
});
} else {
events_.fireEvent(new SendToConsoleEvent(code, true));
}
}
use of org.rstudio.studio.client.workbench.views.console.events.SendToConsoleEvent in project rstudio by rstudio.
the class ConsoleDispatcher method executeSourceCommand.
public void executeSourceCommand(String path, TextFileType fileType, String encoding, boolean contentKnownToBeAscii, boolean echo, boolean focus, boolean debug) {
StringBuilder code = new StringBuilder();
if (fileType.isCpp()) {
// use a relative path if possible
String relativePath = FileSystemItem.createFile(path).getPathRelativeTo(workbenchContext_.getCurrentWorkingDir());
if (relativePath != null)
path = relativePath;
code.append("Rcpp::sourceCpp(" + escapedPath(path) + ")");
} else {
String escapedPath = escapedPath(path);
String systemEncoding = session_.getSessionInfo().getSystemEncoding();
boolean isSystemEncoding = normalizeEncoding(encoding).equals(normalizeEncoding(systemEncoding));
if (contentKnownToBeAscii || isSystemEncoding)
code.append((debug ? "debugSource" : "source") + "(" + escapedPath);
else {
code.append((debug ? "debugSource" : "source") + "(" + escapedPath + ", encoding = '" + (!StringUtil.isNullOrEmpty(encoding) ? encoding : "UTF-8") + "'");
}
if (echo)
code.append(", echo=TRUE");
code.append(")");
}
eventBus_.fireEvent(new SendToConsoleEvent(code.toString(), true));
if (focus)
commands_.activateConsole().execute();
}
Aggregations