Search in sources :

Example 11 with SendToConsoleEvent

use of org.rstudio.studio.client.workbench.views.console.events.SendToConsoleEvent in project rstudio by rstudio.

the class ConnectionsPresenter method disconnectConnection.

private void disconnectConnection(boolean prompt) {
    if (exploredConnection_ == null)
        return;
    // define connect operation
    final Operation connectOperation = new Operation() {

        @Override
        public void execute() {
            server_.getDisconnectCode(exploredConnection_.getId(), new SimpleRequestCallback<String>() {

                @Override
                public void onResponseReceived(String disconnectCode) {
                    eventBus_.fireEvent(new SendToConsoleEvent(disconnectCode, true));
                }
            });
        }
    };
    if (prompt) {
        StringBuilder builder = new StringBuilder();
        builder.append("Are you sure you want to disconnect from Spark?");
        globalDisplay_.showYesNoMessage(MessageDialog.QUESTION, "Disconnect", builder.toString(), connectOperation, true);
    } else {
        connectOperation.execute();
    }
}
Also used : SendToConsoleEvent(org.rstudio.studio.client.workbench.views.console.events.SendToConsoleEvent) Operation(org.rstudio.core.client.widget.Operation)

Example 12 with SendToConsoleEvent

use of org.rstudio.studio.client.workbench.views.console.events.SendToConsoleEvent in project rstudio by rstudio.

the class RCompletionManager method goToFunctionDefinition.

public void goToFunctionDefinition() {
    // check for a file-local definition (intra-file navigation -- using
    // the active scope tree)
    AceEditor editor = (AceEditor) docDisplay_;
    if (editor != null) {
        TokenCursor cursor = editor.getSession().getMode().getRCodeModel().getTokenCursor();
        if (cursor.moveToPosition(editor.getCursorPosition(), true)) {
            // token (obstensibly a funciton name)
            if (cursor.isLeftBracket())
                cursor.moveToPreviousToken();
            // navigate (as this isn't the 'full' function name)
            if (cursor.moveToPreviousToken()) {
                if (cursor.isExtractionOperator())
                    return;
                cursor.moveToNextToken();
            }
            // if this is a string, try resolving that string as a file name
            if (cursor.hasType("string")) {
                String tokenValue = cursor.currentValue();
                String path = tokenValue.substring(1, tokenValue.length() - 1);
                FileSystemItem filePath = FileSystemItem.createFile(path);
                // This will show a dialog error if no such file exists; this
                // seems the most appropriate action in such a case.
                fileTypeRegistry_.editFile(filePath);
            }
            String functionName = cursor.currentValue();
            JsArray<ScopeFunction> scopes = editor.getAllFunctionScopes();
            for (int i = 0; i < scopes.length(); i++) {
                ScopeFunction scope = scopes.get(i);
                if (scope.getFunctionName().equals(functionName)) {
                    navigableSourceEditor_.navigateToPosition(SourcePosition.create(scope.getPreamble().getRow(), scope.getPreamble().getColumn()), true);
                    return;
                }
            }
        }
    }
    // intra-file navigation failed -- hit the server and find a definition
    // in the project index
    // determine current line and cursor position
    InputEditorLineWithCursorPosition lineWithPos = InputEditorUtil.getLineWithCursorPosition(input_);
    // delayed progress indicator
    final GlobalProgressDelayer progress = new GlobalProgressDelayer(globalDisplay_, 1000, "Searching for function definition...");
    server_.getObjectDefinition(lineWithPos.getLine(), lineWithPos.getPosition(), new ServerRequestCallback<ObjectDefinition>() {

        @Override
        public void onResponseReceived(ObjectDefinition def) {
            // dismiss progress
            progress.dismiss();
            // if we got a hit
            if (def.getObjectName() != null) {
                // search locally if a function navigator was provided
                if (navigableSourceEditor_ != null) {
                    // try to search for the function locally
                    SourcePosition position = navigableSourceEditor_.findFunctionPositionFromCursor(def.getObjectName());
                    if (position != null) {
                        navigableSourceEditor_.navigateToPosition(position, true);
                        // we're done
                        return;
                    }
                }
                // navigate to the file/loc
                if (def.getObjectType() == FileFunctionDefinition.OBJECT_TYPE) {
                    FileFunctionDefinition fileDef = def.getObjectData().cast();
                    fileTypeRegistry_.editFile(fileDef.getFile(), fileDef.getPosition());
                } else // search path definition
                if (def.getObjectType() == SearchPathFunctionDefinition.OBJECT_TYPE) {
                    SearchPathFunctionDefinition searchDef = def.getObjectData().cast();
                    eventBus_.fireEvent(new CodeBrowserNavigationEvent(searchDef));
                } else // finally, check to see if it's a data frame
                if (def.getObjectType() == DataDefinition.OBJECT_TYPE) {
                    eventBus_.fireEvent(new SendToConsoleEvent("View(" + def.getObjectName() + ")", true, false));
                }
            }
        }

        @Override
        public void onError(ServerError error) {
            progress.dismiss();
            globalDisplay_.showErrorMessage("Error Searching for Function", error.getUserMessage());
        }
    });
}
Also used : SearchPathFunctionDefinition(org.rstudio.studio.client.workbench.codesearch.model.SearchPathFunctionDefinition) InputEditorLineWithCursorPosition(org.rstudio.studio.client.workbench.views.console.shell.editor.InputEditorLineWithCursorPosition) ServerError(org.rstudio.studio.client.server.ServerError) GlobalProgressDelayer(org.rstudio.studio.client.common.GlobalProgressDelayer) AceEditor(org.rstudio.studio.client.workbench.views.source.editors.text.AceEditor) ObjectDefinition(org.rstudio.studio.client.workbench.codesearch.model.ObjectDefinition) ScopeFunction(org.rstudio.studio.client.workbench.views.source.editors.text.ScopeFunction) TokenCursor(org.rstudio.studio.client.workbench.views.source.editors.text.ace.TokenCursor) FileSystemItem(org.rstudio.core.client.files.FileSystemItem) CodeBrowserNavigationEvent(org.rstudio.studio.client.workbench.views.source.events.CodeBrowserNavigationEvent) SourcePosition(org.rstudio.studio.client.workbench.views.source.model.SourcePosition) SendToConsoleEvent(org.rstudio.studio.client.workbench.views.console.events.SendToConsoleEvent) FileFunctionDefinition(org.rstudio.studio.client.workbench.codesearch.model.FileFunctionDefinition)

Example 13 with SendToConsoleEvent

use of org.rstudio.studio.client.workbench.views.console.events.SendToConsoleEvent in project rstudio by rstudio.

the class DesktopApplicationHeader method onDiagnosticsReport.

@Handler
void onDiagnosticsReport() {
    eventBus_.fireEvent(new SendToConsoleEvent("rstudioDiagnosticsReport()", true));
    new Timer() {

        @Override
        public void run() {
            Desktop.getFrame().showFolder("~/rstudio-diagnostics");
        }
    }.schedule(1000);
}
Also used : Timer(com.google.gwt.user.client.Timer) SendToConsoleEvent(org.rstudio.studio.client.workbench.views.console.events.SendToConsoleEvent) ShowFolderHandler(org.rstudio.studio.client.workbench.views.files.events.ShowFolderHandler) SessionInitHandler(org.rstudio.studio.client.workbench.events.SessionInitHandler) Handler(org.rstudio.core.client.command.Handler)

Example 14 with SendToConsoleEvent

use of org.rstudio.studio.client.workbench.views.console.events.SendToConsoleEvent in project rstudio by rstudio.

the class ConsoleDispatcher method executeCommandWithFileEncoding.

public void executeCommandWithFileEncoding(String command, String path, String encoding, boolean contentIsAscii) {
    String escapedPath = escapedPath(path);
    String systemEncoding = session_.getSessionInfo().getSystemEncoding();
    boolean isSystemEncoding = normalizeEncoding(encoding).equals(normalizeEncoding(systemEncoding));
    StringBuilder code = new StringBuilder();
    code.append(command + "(" + escapedPath);
    if (!isSystemEncoding && !contentIsAscii) {
        code.append(", encoding = '" + (!StringUtil.isNullOrEmpty(encoding) ? encoding : "UTF-8") + "'");
    }
    code.append(")");
    eventBus_.fireEvent(new SendToConsoleEvent(code.toString(), true));
}
Also used : SendToConsoleEvent(org.rstudio.studio.client.workbench.views.console.events.SendToConsoleEvent)

Example 15 with SendToConsoleEvent

use of org.rstudio.studio.client.workbench.views.console.events.SendToConsoleEvent in project rstudio by rstudio.

the class ConsoleDispatcher method executeCommand.

public void executeCommand(String command, String argument) {
    String code = command + "(\"" + argument + "\")";
    eventBus_.fireEvent(new SendToConsoleEvent(code, true));
}
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