use of org.rstudio.core.client.command.Handler 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.core.client.command.Handler in project rstudio by rstudio.
the class Presentation method onClearPresentationCache.
@Handler
void onClearPresentationCache() {
globalDisplay_.showYesNoMessage(MessageDialog.INFO, "Clear Knitr Cache", "Clearing the Knitr cache will discard previously cached " + "output and re-run all of the R code chunks within the " + "presentation.\n\n" + "Are you sure you want to clear the cache now?", false, new ProgressOperation() {
@Override
public void execute(final ProgressIndicator indicator) {
indicator.onProgress("Clearing Knitr Cache...");
server_.clearPresentationCache(new ServerRequestCallback<Void>() {
@Override
public void onResponseReceived(Void response) {
indicator.onCompleted();
refreshPresentation();
}
@Override
public void onError(ServerError error) {
indicator.onCompleted();
globalDisplay_.showErrorMessage("Error Clearing Cache", getErrorMessage(error));
}
});
}
}, new ProgressOperation() {
@Override
public void execute(ProgressIndicator indicator) {
indicator.onCompleted();
}
}, true);
}
use of org.rstudio.core.client.command.Handler in project rstudio by rstudio.
the class Source method onNewRMarkdownDoc.
@Handler
public void onNewRMarkdownDoc() {
SessionInfo sessionInfo = session_.getSessionInfo();
boolean useRMarkdownV2 = sessionInfo.getRMarkdownPackageAvailable();
if (useRMarkdownV2)
newRMarkdownV2Doc();
else
newRMarkdownV1Doc();
}
use of org.rstudio.core.client.command.Handler in project rstudio by rstudio.
the class TextEditingTarget method onUnfold.
@Handler
void onUnfold() {
if (useScopeTreeFolding()) {
Range range = Range.fromPoints(docDisplay_.getSelectionStart(), docDisplay_.getSelectionEnd());
if (range.isEmpty()) {
// If no selection, either:
//
// 1) Unfold a fold containing the cursor, or
// 2) Unfold the closest fold on the current row.
Position pos = docDisplay_.getCursorPosition();
AceFold containingCandidate = null;
AceFold startCandidate = null;
AceFold endCandidate = null;
for (AceFold f : JsUtil.asIterable(docDisplay_.getFolds())) {
// Check to see whether this fold contains the cursor position.
if (f.getRange().contains(pos)) {
if (containingCandidate == null || containingCandidate.getRange().contains(f.getRange())) {
containingCandidate = f;
}
}
if (startCandidate == null && f.getStart().getRow() == pos.getRow() && f.getStart().getColumn() >= pos.getColumn()) {
startCandidate = f;
}
if (startCandidate == null && f.getEnd().getRow() == pos.getRow() && f.getEnd().getColumn() <= pos.getColumn()) {
endCandidate = f;
}
}
if (containingCandidate != null) {
docDisplay_.unfold(containingCandidate);
} else if (startCandidate == null ^ endCandidate == null) {
docDisplay_.unfold(startCandidate != null ? startCandidate : endCandidate);
} else if (startCandidate != null && endCandidate != null) {
// Both are candidates; see which is closer
int startDelta = startCandidate.getStart().getColumn() - pos.getColumn();
int endDelta = pos.getColumn() - endCandidate.getEnd().getColumn();
docDisplay_.unfold(startDelta <= endDelta ? startCandidate : endCandidate);
}
} else {
// If selection, unfold the selection
docDisplay_.unfold(range);
}
} else {
int row = docDisplay_.getSelectionStart().getRow();
docDisplay_.unfold(row);
}
}
use of org.rstudio.core.client.command.Handler in project rstudio by rstudio.
the class TextEditingTarget method onSetWorkingDirToActiveDoc.
@Handler
public void onSetWorkingDirToActiveDoc() {
// get path
String activeDocPath = docUpdateSentinel_.getPath();
if (activeDocPath != null) {
FileSystemItem wdPath = FileSystemItem.createFile(activeDocPath).getParentPath();
consoleDispatcher_.executeSetWd(wdPath, true);
} else {
globalDisplay_.showMessage(MessageDialog.WARNING, "Source File Not Saved", "The currently active source file is not saved so doesn't " + "have a directory to change into.");
return;
}
}
Aggregations