Search in sources :

Example 1 with SendToConsoleEvent

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));
    }
}
Also used : SendToConsoleEvent(org.rstudio.studio.client.workbench.views.console.events.SendToConsoleEvent) JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 2 with SendToConsoleEvent

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()));
}
Also used : Scope(org.rstudio.studio.client.workbench.views.source.editors.text.Scope) SendToChunkConsoleEvent(org.rstudio.studio.client.rmarkdown.events.SendToChunkConsoleEvent) SendToConsoleEvent(org.rstudio.studio.client.workbench.views.console.events.SendToConsoleEvent)

Example 3 with SendToConsoleEvent

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();
}
Also used : SerializedCommand(org.rstudio.core.client.SerializedCommand) Timer(com.google.gwt.user.client.Timer) SerializedCommand(org.rstudio.core.client.SerializedCommand) AppCommand(org.rstudio.core.client.command.AppCommand) Command(com.google.gwt.user.client.Command) SendToConsoleEvent(org.rstudio.studio.client.workbench.views.console.events.SendToConsoleEvent)

Example 4 with SendToConsoleEvent

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));
    }
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) RepeatingCommand(com.google.gwt.core.client.Scheduler.RepeatingCommand) Command(com.google.gwt.user.client.Command) AppCommand(org.rstudio.core.client.command.AppCommand) SendToConsoleEvent(org.rstudio.studio.client.workbench.views.console.events.SendToConsoleEvent) JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 5 with SendToConsoleEvent

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();
}
Also used : SendToConsoleEvent(org.rstudio.studio.client.workbench.views.console.events.SendToConsoleEvent)

Aggregations

SendToConsoleEvent (org.rstudio.studio.client.workbench.views.console.events.SendToConsoleEvent)27 JsArrayString (com.google.gwt.core.client.JsArrayString)8 Command (com.google.gwt.user.client.Command)6 AppCommand (org.rstudio.core.client.command.AppCommand)5 RepeatingCommand (com.google.gwt.core.client.Scheduler.RepeatingCommand)4 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)4 Handler (org.rstudio.core.client.command.Handler)4 Operation (org.rstudio.core.client.widget.Operation)3 Timer (com.google.gwt.user.client.Timer)2 EnsureHeightHandler (org.rstudio.core.client.events.EnsureHeightHandler)2 EnsureVisibleHandler (org.rstudio.core.client.events.EnsureVisibleHandler)2 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)2 ChangeFontSizeHandler (org.rstudio.studio.client.application.events.ChangeFontSizeHandler)2 FileChangeHandler (org.rstudio.studio.client.workbench.views.files.events.FileChangeHandler)2 CppCompletionOperation (org.rstudio.studio.client.workbench.views.source.editors.text.cpp.CppCompletionOperation)2 HideMessageHandler (org.rstudio.studio.client.workbench.views.source.editors.text.status.StatusBar.HideMessageHandler)2 RecordNavigationPositionHandler (org.rstudio.studio.client.workbench.views.source.events.RecordNavigationPositionHandler)2 SourcePosition (org.rstudio.studio.client.workbench.views.source.model.SourcePosition)2 KeyDownHandler (com.google.gwt.event.dom.client.KeyDownHandler)1 ValueChangeHandler (com.google.gwt.event.logical.shared.ValueChangeHandler)1