use of org.rstudio.studio.client.server.ServerError in project rstudio by rstudio.
the class TextEditingTargetRMarkdownHelper method createDraftFromTemplate.
public void createDraftFromTemplate(final RmdChosenTemplate template) {
final String target = template.getDirectory() + "/" + template.getFileName();
final String targetFile = target + (template.createDir() ? "" : ".Rmd");
fileServer_.stat(targetFile, new ServerRequestCallback<FileSystemItem>() {
@Override
public void onResponseReceived(final FileSystemItem fsi) {
// the file doesn't exist--proceed
if (!fsi.exists()) {
createDraftFromTemplate(template, target);
return;
}
// the file exists--offer to clean it up and continue.
globalDisplay_.showYesNoMessage(GlobalDisplay.MSG_QUESTION, "Overwrite " + (template.createDir() ? "Directory" : "File"), targetFile + " exists. Overwrite it?", false, new Operation() {
@Override
public void execute() {
cleanAndCreateTemplate(template, target, fsi);
}
}, null, null, "Overwrite", "Cancel", false);
}
@Override
public void onError(ServerError error) {
// presumably the file doesn't exist, which is what we want.
createDraftFromTemplate(template, target);
}
});
}
use of org.rstudio.studio.client.server.ServerError in project rstudio by rstudio.
the class TextEditingTargetRMarkdownHelper method replaceOutputFormatOptions.
public void replaceOutputFormatOptions(final String yaml, final String format, final RmdFrontMatterOutputOptions options, final OperationWithInput<String> onCompleted) {
server_.convertToYAML(options, new ServerRequestCallback<RmdYamlResult>() {
@Override
public void onResponseReceived(RmdYamlResult result) {
boolean isDefault = options.getOptionList().length() == 0;
YamlTree yamlTree = new YamlTree(yaml);
YamlTree optionTree = new YamlTree(result.getYaml());
// add the output key if needed
if (!yamlTree.containsKey(RmdFrontMatter.OUTPUT_KEY)) {
yamlTree.addYamlValue(null, RmdFrontMatter.OUTPUT_KEY, RmdOutputFormat.OUTPUT_HTML_DOCUMENT);
}
String treeFormat = yamlTree.getKeyValue(RmdFrontMatter.OUTPUT_KEY);
if (treeFormat.equals(format)) {
if (isDefault) {
// 1-a: if all options are still at their defaults, leave
// untouched
} else {
// 1-b: not all options are at defaults; replace the simple
// format with an option list
yamlTree.setKeyValue(RmdFrontMatter.OUTPUT_KEY, "");
yamlTree.addYamlValue(RmdFrontMatter.OUTPUT_KEY, format, "");
yamlTree.setKeyValue(format, optionTree);
}
} else if (treeFormat.length() > 0) {
// changing it
if (isDefault) {
// case 2-a: change one simple format to another
yamlTree.setKeyValue(RmdFrontMatter.OUTPUT_KEY, format);
} else {
// case 2-b: change a simple format to a complex one
yamlTree.setKeyValue(RmdFrontMatter.OUTPUT_KEY, "");
yamlTree.addYamlValue(RmdFrontMatter.OUTPUT_KEY, format, "");
yamlTree.setKeyValue(format, optionTree);
}
} else {
// case 3: the output format is already not simple
treeFormat = yamlTree.getKeyValue(format);
if (treeFormat.equals(RmdFrontMatter.DEFAULT_FORMAT)) {
if (isDefault) {
// case 3-a: still at default settings
} else {
// case 3-b: default to complex
yamlTree.setKeyValue(format, optionTree);
}
} else {
if (isDefault) {
// case 3-c: complex to default
if (yamlTree.getChildKeys(RmdFrontMatter.OUTPUT_KEY).size() == 1) {
// case 3-c-i: only one format, and has default settings
yamlTree.clearChildren(RmdFrontMatter.OUTPUT_KEY);
yamlTree.setKeyValue(RmdFrontMatter.OUTPUT_KEY, format);
} else {
// case 3-c-i: multiple formats, this one's becoming
// the default
yamlTree.clearChildren(format);
yamlTree.setKeyValue(format, RmdFrontMatter.DEFAULT_FORMAT);
}
} else {
// case 3-d: complex to complex
if (!yamlTree.containsKey(format)) {
yamlTree.addYamlValue(RmdFrontMatter.OUTPUT_KEY, format, "");
}
yamlTree.setKeyValue(format, optionTree);
}
}
}
yamlTree.reorder(Arrays.asList(format));
onCompleted.execute(yamlTree.toString());
}
@Override
public void onError(ServerError error) {
// if we fail, return the unmodified YAML
onCompleted.execute(yaml);
}
});
}
use of org.rstudio.studio.client.server.ServerError in project rstudio by rstudio.
the class TextEditingTargetCompilePdfHelper method checkCompilers.
public void checkCompilers(final WarningBarDisplay display, TextFileType fileType) {
// for all tex files we need to parse magic comments and validate
// any explict latex proram directive
ArrayList<TexMagicComment> magicComments = null;
if (fileType.canCompilePDF()) {
magicComments = TexMagicComment.parseComments(docDisplay_.getCode());
String latexProgramDirective = detectLatexProgramDirective(magicComments);
if (latexProgramDirective != null) {
if (latexProgramRegistry_.findTypeIgnoreCase(latexProgramDirective) == null) {
// show warning and bail
display.showWarningBar("Unknown LaTeX program type '" + latexProgramDirective + "' specified (valid types are " + latexProgramRegistry_.getPrintableTypeNames() + ")");
return;
}
}
}
// for Rnw we first determine the RnwWeave type
RnwWeave rnwWeave = null;
RnwWeaveDirective rnwWeaveDirective = null;
if (fileType.isRnw()) {
rnwWeaveDirective = detectRnwWeaveDirective(magicComments);
if (rnwWeaveDirective != null) {
rnwWeave = rnwWeaveDirective.getRnwWeave();
if (rnwWeave == null) {
// show warning and bail
display.showWarningBar("Unknown Rnw weave method '" + rnwWeaveDirective.getName() + "' specified (valid types are " + rnwWeaveRegistry_.getPrintableTypeNames() + ")");
return;
}
} else {
rnwWeave = rnwWeaveRegistry_.findTypeIgnoreCase(prefs_.defaultSweaveEngine().getValue());
}
}
final SessionInfo sessionInfo = session_.getSessionInfo();
TexCapabilities texCap = sessionInfo.getTexCapabilities();
final boolean checkForTeX = fileType.canCompilePDF() && !texCap.isTexInstalled();
final boolean checkForRnwWeave = (rnwWeave != null) && !texCap.isRnwWeaveAvailable(rnwWeave);
if (checkForTeX || checkForRnwWeave) {
// alias variables to finals
final boolean hasRnwWeaveDirective = rnwWeaveDirective != null;
final RnwWeave fRnwWeave = rnwWeave;
server_.getTexCapabilities(new ServerRequestCallback<TexCapabilities>() {
@Override
public void onResponseReceived(TexCapabilities response) {
if (checkForTeX && !response.isTexInstalled()) {
String warning;
if (Desktop.isDesktop())
warning = "No TeX installation detected. Please install " + "TeX before compiling.";
else
warning = "This server does not have TeX installed. You " + "may not be able to compile.";
display.showWarningBar(warning);
} else if (checkForRnwWeave && !response.isRnwWeaveAvailable(fRnwWeave)) {
String forContext = "";
if (hasRnwWeaveDirective)
forContext = "this file";
else if (sessionInfo.getActiveProjectFile() != null)
forContext = "Rnw files for this project";
else
forContext = "Rnw files";
display.showWarningBar(fRnwWeave.getName() + " is configured to weave " + forContext + " " + "however the " + fRnwWeave.getPackageName() + " package is not installed.");
} else {
display.hideWarningBar();
}
}
@Override
public void onError(ServerError error) {
Debug.logError(error);
}
});
} else {
display.hideWarningBar();
}
}
use of org.rstudio.studio.client.server.ServerError in project rstudio by rstudio.
the class SVNReviewPresenter method updateDiff.
private void updateDiff() {
view_.hideSizeWarning();
final ArrayList<StatusAndPath> paths = view_.getChangelistTable().getSelectedItems();
if (paths.size() != 1) {
clearDiff();
return;
}
final StatusAndPath item = paths.get(0);
if (!item.getPath().equals(currentFilename_)) {
clearDiff();
currentFilename_ = item.getPath();
}
// bail if this is an undiffable status
if (undiffableStatuses_.contains(item.getStatus()))
return;
diffInvalidation_.invalidate();
final Token token = diffInvalidation_.getInvalidationToken();
server_.svnDiffFile(item.getPath(), view_.getContextLines().getValue(), overrideSizeWarning_, new SimpleRequestCallback<DiffResult>("Diff Error") {
@Override
public void onResponseReceived(DiffResult diffResult) {
if (token.isInvalid())
return;
String response = diffResult.getDecodedValue();
// Use lastResponse_ to prevent unnecessary flicker
if (response.equals(currentResponse_))
return;
currentResponse_ = response;
currentEncoding_ = diffResult.getSourceEncoding();
SVNDiffParser parser = new SVNDiffParser(response);
parser.nextFilePair();
ArrayList<ChunkOrLine> allLines = new ArrayList<ChunkOrLine>();
activeChunks_.clear();
for (DiffChunk chunk; null != (chunk = parser.nextChunk()); ) {
if (!chunk.shouldIgnore()) {
activeChunks_.add(chunk);
allLines.add(new ChunkOrLine(chunk));
}
for (Line line : chunk.getLines()) allLines.add(new ChunkOrLine(line));
}
view_.getLineTableDisplay().setShowActions(!"?".equals(item.getStatus()));
view_.setData(allLines);
}
@Override
public void onError(ServerError error) {
JSONNumber size = error.getClientInfo().isNumber();
if (size != null)
view_.showSizeWarning((long) size.doubleValue());
else
super.onError(error);
}
});
}
use of org.rstudio.studio.client.server.ServerError in project rstudio by rstudio.
the class SetupChunkOptionsPopupPanel method initOptions.
@Override
protected void initOptions(final Command afterInit) {
String chunkText = getChunkText();
server_.extractChunkOptions(chunkText, new ServerRequestCallback<JsObject>() {
@Override
public void onError(ServerError error) {
Debug.logError(error);
}
@Override
public void onResponseReceived(JsObject object) {
JsArrayString keys = object.keys();
for (String key : JsUtil.asIterable(keys)) chunkOptions_.put(key, object.getAsString(key));
afterInit.execute();
}
});
}
Aggregations