use of org.rstudio.studio.client.workbench.views.source.events.SourceFileSavedEvent in project rstudio by rstudio.
the class TextEditingTarget method saveNewFileWithEncoding.
private void saveNewFileWithEncoding(String suggestedPath, final String encoding, final Command executeOnSuccess) {
view_.ensureVisible();
FileSystemItem fsi;
if (suggestedPath != null)
fsi = FileSystemItem.createFile(suggestedPath);
else
fsi = getSaveFileDefaultDir();
fileDialogs_.saveFile("Save File - " + getName().getValue(), fileContext_, fsi, fileType_.getDefaultExtension(), false, new ProgressOperationWithInput<FileSystemItem>() {
public void execute(final FileSystemItem saveItem, ProgressIndicator indicator) {
if (saveItem == null)
return;
try {
workbenchContext_.setDefaultFileDialogDir(saveItem.getParentPath());
final TextFileType fileType = fileTypeRegistry_.getTextTypeForFile(saveItem);
final Command saveCommand = new Command() {
@Override
public void execute() {
if (!getPath().equals(saveItem.getPath())) {
// breakpoints are file-specific, so when saving
// as a different file, clear the display of
// breakpoints from the old file name
docDisplay_.removeAllBreakpoints();
// update publish settings
syncPublishPath(saveItem.getPath());
}
fixupCodeBeforeSaving();
docUpdateSentinel_.save(saveItem.getPath(), fileType.getTypeId(), encoding, new SaveProgressIndicator(saveItem, fileType, executeOnSuccess));
events_.fireEvent(new SourceFileSavedEvent(getId(), saveItem.getPath()));
}
};
// to a non-R file type then confirm
if (fileType_.isR() && !fileType.isR()) {
globalDisplay_.showYesNoMessage(MessageDialog.WARNING, "Confirm Change File Type", "This file was created as an R script however " + "the file extension you specified will change " + "it into another file type that will no longer " + "open as an R script.\n\n" + "Are you sure you want to change the type of " + "the file so that it is no longer an R script?", new Operation() {
@Override
public void execute() {
saveCommand.execute();
}
}, false);
} else {
saveCommand.execute();
}
} catch (Exception e) {
indicator.onError(e.toString());
return;
}
indicator.onCompleted();
}
});
}
Aggregations