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);
}
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);
}
}
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();
}
});
}
}
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);
}
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();
}
});
}
Aggregations