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