Search in sources :

Example 6 with TextEditingTarget

use of org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget in project rstudio by rstudio.

the class Source method openNotebook.

private void openNotebook(final FileSystemItem rmdFile, final SourceDocumentResult doc, final ResultCallback<EditingTarget, ServerError> resultCallback) {
    if (!StringUtil.isNullOrEmpty(doc.getDocPath())) {
        // this happens if we created the R Markdown file, or if the R Markdown
        // file on disk matched the one inside the notebook
        openFileFromServer(rmdFile, FileTypeRegistry.RMARKDOWN, resultCallback);
    } else if (!StringUtil.isNullOrEmpty(doc.getDocId())) {
        // this happens when we have to open an untitled buffer for the the
        // notebook (usually because the of a conflict between the Rmd on disk
        // and the one in the .nb.html file)
        server_.getSourceDocument(doc.getDocId(), new ServerRequestCallback<SourceDocument>() {

            @Override
            public void onResponseReceived(SourceDocument doc) {
                // create the editor
                EditingTarget target = addTab(doc, OPEN_INTERACTIVE);
                // show a warning bar 
                if (target instanceof TextEditingTarget) {
                    ((TextEditingTarget) target).showWarningMessage("This notebook has the same name as an R Markdown " + "file, but doesn't match it.");
                }
                resultCallback.onSuccess(target);
            }

            @Override
            public void onError(ServerError error) {
                globalDisplay_.showErrorMessage("Notebook Open Failed", "This notebook could not be opened. " + "If the error persists, try removing the " + "accompanying R Markdown file. \n\n" + error.getMessage());
                resultCallback.onFailure(error);
            }
        });
    }
}
Also used : ServerError(org.rstudio.studio.client.server.ServerError) SourceDocument(org.rstudio.studio.client.workbench.views.source.model.SourceDocument) TextEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget) EditingTarget(org.rstudio.studio.client.workbench.views.source.editors.EditingTarget) DataEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.data.DataEditingTarget) CodeBrowserEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.codebrowser.CodeBrowserEditingTarget) TextEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget) VoidServerRequestCallback(org.rstudio.studio.client.server.VoidServerRequestCallback) ServerRequestCallback(org.rstudio.studio.client.server.ServerRequestCallback)

Example 7 with TextEditingTarget

use of org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget in project rstudio by rstudio.

the class Source method onInsertSource.

public void onInsertSource(final InsertSourceEvent event) {
    if (activeEditor_ != null && activeEditor_ instanceof TextEditingTarget && commands_.executeCode().isEnabled()) {
        TextEditingTarget textEditor = (TextEditingTarget) activeEditor_;
        textEditor.insertCode(event.getCode(), event.isBlock());
    } else {
        newDoc(FileTypeRegistry.R, new ResultCallback<EditingTarget, ServerError>() {

            public void onSuccess(EditingTarget arg) {
                ((TextEditingTarget) arg).insertCode(event.getCode(), event.isBlock());
            }
        });
    }
}
Also used : ServerError(org.rstudio.studio.client.server.ServerError) TextEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget) TextEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget) EditingTarget(org.rstudio.studio.client.workbench.views.source.editors.EditingTarget) DataEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.data.DataEditingTarget) CodeBrowserEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.codebrowser.CodeBrowserEditingTarget)

Example 8 with TextEditingTarget

use of org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget in project rstudio by rstudio.

the class Source method showHelpAtCursor.

private void showHelpAtCursor() {
    if (activeEditor_ != null && activeEditor_ instanceof TextEditingTarget) {
        TextEditingTarget editor = (TextEditingTarget) activeEditor_;
        editor.showHelpAtCursor();
    }
}
Also used : TextEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget)

Example 9 with TextEditingTarget

use of org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget in project rstudio by rstudio.

the class Source method onNewDocumentWithCode.

public void onNewDocumentWithCode(final NewDocumentWithCodeEvent event) {
    // determine the type
    final EditableFileType docType;
    if (event.getType().equals(NewDocumentWithCodeEvent.R_SCRIPT))
        docType = FileTypeRegistry.R;
    else
        docType = FileTypeRegistry.RMARKDOWN;
    // command to create and run the new doc
    Command newDocCommand = new Command() {

        @Override
        public void execute() {
            newDoc(docType, new ResultCallback<EditingTarget, ServerError>() {

                public void onSuccess(EditingTarget arg) {
                    TextEditingTarget editingTarget = (TextEditingTarget) arg;
                    editingTarget.insertCode(event.getCode(), false);
                    if (event.getCursorPosition() != null) {
                        editingTarget.navigateToPosition(event.getCursorPosition(), false);
                    }
                    if (event.getExecute()) {
                        if (docType.equals(FileTypeRegistry.R)) {
                            commands_.executeToCurrentLine().execute();
                            commands_.activateSource().execute();
                        } else {
                            commands_.executePreviousChunks().execute();
                        }
                    }
                }
            });
        }
    };
    // do it
    if (docType.equals(FileTypeRegistry.R)) {
        newDocCommand.execute();
    } else {
        dependencyManager_.withRMarkdown("R Notebook", "Create R Notebook", newDocCommand);
    }
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) Command(com.google.gwt.user.client.Command) AppCommand(org.rstudio.core.client.command.AppCommand) ServerError(org.rstudio.studio.client.server.ServerError) TextEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget) EditingTarget(org.rstudio.studio.client.workbench.views.source.editors.EditingTarget) DataEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.data.DataEditingTarget) CodeBrowserEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.codebrowser.CodeBrowserEditingTarget) TextEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget) EditableFileType(org.rstudio.studio.client.common.filetypes.EditableFileType)

Example 10 with TextEditingTarget

use of org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget in project rstudio by rstudio.

the class Source method saveAndCloseActiveSourceDoc.

private void saveAndCloseActiveSourceDoc() {
    if (activeEditor_ != null && activeEditor_ instanceof TextEditingTarget) {
        TextEditingTarget target = (TextEditingTarget) activeEditor_;
        target.save(new Command() {

            @Override
            public void execute() {
                onCloseSourceDoc();
            }
        });
    }
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) Command(com.google.gwt.user.client.Command) AppCommand(org.rstudio.core.client.command.AppCommand) TextEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget)

Aggregations

TextEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget)13 EditingTarget (org.rstudio.studio.client.workbench.views.source.editors.EditingTarget)5 CodeBrowserEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.codebrowser.CodeBrowserEditingTarget)5 DataEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.data.DataEditingTarget)5 ServerError (org.rstudio.studio.client.server.ServerError)4 JsArrayString (com.google.gwt.core.client.JsArrayString)2 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)2 JSONString (com.google.gwt.json.client.JSONString)2 Command (com.google.gwt.user.client.Command)2 AppCommand (org.rstudio.core.client.command.AppCommand)2 VoidServerRequestCallback (org.rstudio.studio.client.server.VoidServerRequestCallback)2 InputEditorDisplay (org.rstudio.studio.client.workbench.views.console.shell.editor.InputEditorDisplay)2 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)1 CloseHandler (com.google.gwt.event.logical.shared.CloseHandler)1 SelectionHandler (com.google.gwt.event.logical.shared.SelectionHandler)1 ValueChangeHandler (com.google.gwt.event.logical.shared.ValueChangeHandler)1 NativePreviewHandler (com.google.gwt.user.client.Event.NativePreviewHandler)1 Handler (org.rstudio.core.client.command.Handler)1 EditableFileType (org.rstudio.studio.client.common.filetypes.EditableFileType)1 OpenSourceFileHandler (org.rstudio.studio.client.common.filetypes.events.OpenSourceFileHandler)1