Search in sources :

Example 96 with Command

use of com.google.gwt.user.client.Command in project rstudio by rstudio.

the class Source method saveChanges.

private void saveChanges(ArrayList<UnsavedChangesTarget> targets, Command onCompleted) {
    // convert back to editing targets
    ArrayList<EditingTarget> saveTargets = new ArrayList<EditingTarget>();
    for (UnsavedChangesTarget target : targets) {
        EditingTarget saveTarget = getEditingTargetForId(target.getId());
        if (saveTarget != null)
            saveTargets.add(saveTarget);
    }
    // execute the save
    cpsExecuteForEachEditor(// targets the user chose to save
    saveTargets, // save each editor
    new CPSEditingTargetCommand() {

        @Override
        public void execute(EditingTarget saveTarget, Command continuation) {
            saveTarget.save(continuation);
        }
    }, // onCompleted at the end
    onCompleted);
}
Also used : UnsavedChangesTarget(org.rstudio.studio.client.workbench.model.UnsavedChangesTarget) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) Command(com.google.gwt.user.client.Command) AppCommand(org.rstudio.core.client.command.AppCommand) ArrayList(java.util.ArrayList) 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 97 with Command

use of com.google.gwt.user.client.Command 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 98 with Command

use of com.google.gwt.user.client.Command 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)

Example 99 with Command

use of com.google.gwt.user.client.Command in project rstudio by rstudio.

the class Source method openNotebook.

private void openNotebook(final FileSystemItem rnbFile, final TextFileType fileType, final ResultCallback<EditingTarget, ServerError> resultCallback) {
    // construct path to .Rmd
    final String rnbPath = rnbFile.getPath();
    final String rmdPath = FilePathUtils.filePathSansExtension(rnbPath) + ".Rmd";
    final FileSystemItem rmdFile = FileSystemItem.createFile(rmdPath);
    // TODO: should we perform conflict resolution here as well?
    if (openFileAlreadyOpen(rmdFile, resultCallback))
        return;
    // ask the server to extract the .Rmd, then open that
    Command extractRmdCommand = new Command() {

        @Override
        public void execute() {
            server_.extractRmdFromNotebook(rnbPath, new ServerRequestCallback<SourceDocumentResult>() {

                @Override
                public void onResponseReceived(SourceDocumentResult doc) {
                    openNotebook(rmdFile, doc, resultCallback);
                }

                @Override
                public void onError(ServerError error) {
                    globalDisplay_.showErrorMessage("Notebook Open Failed", "This notebook could not be opened. \n\n" + error.getMessage());
                    resultCallback.onFailure(error);
                }
            });
        }
    };
    dependencyManager_.withRMarkdown("R Notebook", "Using R Notebooks", extractRmdCommand);
}
Also used : SourceDocumentResult(org.rstudio.studio.client.workbench.views.source.model.SourceDocumentResult) FileSystemItem(org.rstudio.core.client.files.FileSystemItem) 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) JSONString(com.google.gwt.json.client.JSONString) JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 100 with Command

use of com.google.gwt.user.client.Command in project rstudio by rstudio.

the class PinnedLineWidget method createEndAnchor.

private void createEndAnchor() {
    endAnchor_ = display_.createAnchor(Position.create(startAnchor_.getRow() + 1, 0));
    endAnchor_.addOnChangeHandler(new Command() {

        @Override
        public void execute() {
            syncEndAnchor();
        }
    });
}
Also used : Command(com.google.gwt.user.client.Command)

Aggregations

Command (com.google.gwt.user.client.Command)141 AppCommand (org.rstudio.core.client.command.AppCommand)39 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)38 RepeatingCommand (com.google.gwt.core.client.Scheduler.RepeatingCommand)21 JsArrayString (com.google.gwt.core.client.JsArrayString)16 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)11 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)11 ArrayList (java.util.ArrayList)11 ServerError (org.rstudio.studio.client.server.ServerError)11 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)10 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)10 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)9 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)8 MenuItem (com.google.gwt.user.client.ui.MenuItem)8 Handler (org.rstudio.core.client.command.Handler)8 TextEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget)8 Operation (org.rstudio.core.client.widget.Operation)7 EditingTarget (org.rstudio.studio.client.workbench.views.source.editors.EditingTarget)7 CodeBrowserEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.codebrowser.CodeBrowserEditingTarget)7 DataEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.data.DataEditingTarget)7