use of org.rstudio.studio.client.server.ServerError 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.server.ServerError in project rstudio by rstudio.
the class Source method openFileFromServer.
private void openFileFromServer(final FileSystemItem file, final TextFileType fileType, final ResultCallback<EditingTarget, ServerError> resultCallback) {
final Command dismissProgress = globalDisplay_.showProgress("Opening file...");
server_.openDocument(file.getPath(), fileType.getTypeId(), uiPrefs_.defaultEncoding().getValue(), new ServerRequestCallback<SourceDocument>() {
@Override
public void onError(ServerError error) {
dismissProgress.execute();
pMruList_.get().remove(file.getPath());
Debug.logError(error);
if (resultCallback != null)
resultCallback.onFailure(error);
}
@Override
public void onResponseReceived(SourceDocument document) {
dismissProgress.execute();
pMruList_.get().add(document.getPath());
EditingTarget target = addTab(document, OPEN_INTERACTIVE);
if (resultCallback != null)
resultCallback.onSuccess(target);
}
});
}
use of org.rstudio.studio.client.server.ServerError in project rstudio by rstudio.
the class Source method onNewSweaveDoc.
@Handler
public void onNewSweaveDoc() {
// set concordance value if we need to
String concordance = new String();
if (uiPrefs_.alwaysEnableRnwConcordance().getValue()) {
RnwWeave activeWeave = rnwWeaveRegistry_.findTypeIgnoreCase(uiPrefs_.defaultSweaveEngine().getValue());
if (activeWeave.getInjectConcordance())
concordance = "\\SweaveOpts{concordance=TRUE}\n";
}
final String concordanceValue = concordance;
// show progress
final ProgressIndicator indicator = new GlobalProgressDelayer(globalDisplay_, 500, "Creating new document...").getIndicator();
// get the template
server_.getSourceTemplate("", "sweave.Rnw", new ServerRequestCallback<String>() {
@Override
public void onResponseReceived(String templateContents) {
indicator.onCompleted();
// add in concordance if necessary
final boolean hasConcordance = concordanceValue.length() > 0;
if (hasConcordance) {
String beginDoc = "\\begin{document}\n";
templateContents = templateContents.replace(beginDoc, beginDoc + concordanceValue);
}
newDoc(FileTypeRegistry.SWEAVE, templateContents, new ResultCallback<EditingTarget, ServerError>() {
@Override
public void onSuccess(EditingTarget target) {
int startRow = 4 + (hasConcordance ? 1 : 0);
target.setCursorPosition(Position.create(startRow, 0));
}
});
}
@Override
public void onError(ServerError error) {
indicator.onError(error.getUserMessage());
}
});
}
use of org.rstudio.studio.client.server.ServerError in project rstudio by rstudio.
the class Source method newSourceDocWithTemplate.
private void newSourceDocWithTemplate(final TextFileType fileType, String name, String template, final Position cursorPosition, final CommandWithArg<EditingTarget> onSuccess, final TransformerCommand<String> contentTransformer) {
final ProgressIndicator indicator = new GlobalProgressDelayer(globalDisplay_, 500, "Creating new document...").getIndicator();
server_.getSourceTemplate(name, template, new ServerRequestCallback<String>() {
@Override
public void onResponseReceived(String templateContents) {
indicator.onCompleted();
if (contentTransformer != null)
templateContents = contentTransformer.transform(templateContents);
newDoc(fileType, templateContents, new ResultCallback<EditingTarget, ServerError>() {
@Override
public void onSuccess(EditingTarget target) {
if (cursorPosition != null)
target.setCursorPosition(cursorPosition);
if (onSuccess != null)
onSuccess.execute(target);
}
});
}
@Override
public void onError(ServerError error) {
indicator.onError(error.getUserMessage());
}
});
}
use of org.rstudio.studio.client.server.ServerError 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);
}
}
Aggregations