Search in sources :

Example 1 with NewDocumentWithCodeEvent

use of org.rstudio.studio.client.workbench.views.source.events.NewDocumentWithCodeEvent in project rstudio by rstudio.

the class ConnectionsPresenter method onPerformConnection.

@Override
public void onPerformConnection(PerformConnectionEvent event) {
    String connectVia = event.getConnectVia();
    String connectCode = event.getConnectCode();
    if (connectVia.equals(ConnectionOptions.CONNECT_COPY_TO_CLIPBOARD)) {
        DomUtils.copyCodeToClipboard(connectCode);
    } else if (connectVia.equals(ConnectionOptions.CONNECT_R_CONSOLE)) {
        eventBus_.fireEvent(new SendToConsoleEvent(connectCode, true));
        display_.showConnectionProgress();
    } else if (connectVia.equals(ConnectionOptions.CONNECT_NEW_R_SCRIPT) || connectVia.equals(ConnectionOptions.CONNECT_NEW_R_NOTEBOOK)) {
        String type;
        String code = connectCode;
        SourcePosition cursorPosition = null;
        if (connectVia.equals(ConnectionOptions.CONNECT_NEW_R_SCRIPT)) {
            type = NewDocumentWithCodeEvent.R_SCRIPT;
            code = code + "\n\n";
        } else {
            type = NewDocumentWithCodeEvent.R_NOTEBOOK;
            int codeLength = code.split("\n").length;
            code = "---\n" + "title: \"R Notebook\"\n" + "output: html_notebook\n" + "---\n" + "\n" + "```{r setup, include=FALSE}\n" + code + "\n" + "```\n" + "\n" + "```{r}\n" + "\n" + "```\n";
            cursorPosition = SourcePosition.create(9 + codeLength, 0);
        }
        eventBus_.fireEvent(new NewDocumentWithCodeEvent(type, code, cursorPosition, true));
        display_.showConnectionProgress();
    }
}
Also used : SourcePosition(org.rstudio.studio.client.workbench.views.source.model.SourcePosition) NewDocumentWithCodeEvent(org.rstudio.studio.client.workbench.views.source.events.NewDocumentWithCodeEvent) SendToConsoleEvent(org.rstudio.studio.client.workbench.views.console.events.SendToConsoleEvent)

Aggregations

SendToConsoleEvent (org.rstudio.studio.client.workbench.views.console.events.SendToConsoleEvent)1 NewDocumentWithCodeEvent (org.rstudio.studio.client.workbench.views.source.events.NewDocumentWithCodeEvent)1 SourcePosition (org.rstudio.studio.client.workbench.views.source.model.SourcePosition)1