use of org.rstudio.studio.client.workbench.views.source.editors.EditingTarget 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.workbench.views.source.editors.EditingTarget 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 org.rstudio.studio.client.workbench.views.source.editors.EditingTarget 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.workbench.views.source.editors.EditingTarget 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.EditingTarget in project rstudio by rstudio.
the class Source method openFile.
// top-level wrapper for opening files. takes care of:
// - making sure the view is visible
// - checking whether it is already open and re-selecting its tab
// - prohibit opening very large files (>500KB)
// - confirmation of opening large files (>100KB)
// - finally, actually opening the file from the server
// via the call to the lower level openFile method
private void openFile(final FileSystemItem file, final TextFileType fileType, final ResultCallback<EditingTarget, ServerError> resultCallback) {
ensureVisible(true);
if (fileType.isRNotebook()) {
openNotebook(file, fileType, resultCallback);
return;
}
if (file == null) {
newDoc(fileType, resultCallback);
return;
}
if (openFileAlreadyOpen(file, resultCallback))
return;
EditingTarget target = editingTargetSource_.getEditingTarget(fileType);
if (file.getLength() > target.getFileSizeLimit()) {
if (resultCallback != null)
resultCallback.onCancelled();
showFileTooLargeWarning(file, target.getFileSizeLimit());
} else if (file.getLength() > target.getLargeFileSize()) {
confirmOpenLargeFile(file, new Operation() {
public void execute() {
openFileFromServer(file, fileType, resultCallback);
}
}, new Operation() {
public void execute() {
// user (wisely) cancelled
if (resultCallback != null)
resultCallback.onCancelled();
}
});
} else {
openFileFromServer(file, fileType, resultCallback);
}
}
Aggregations