use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.
the class Plots method onSavePlotAsImage.
void onSavePlotAsImage() {
view_.bringToFront();
final ProgressIndicator indicator = globalDisplay_.getProgressIndicator("Error");
indicator.onProgress("Preparing to export plot...");
// get the default directory
FileSystemItem defaultDir = ExportPlotUtils.getDefaultSaveDirectory(workbenchContext_.getCurrentWorkingDir());
// get context
server_.getSavePlotContext(defaultDir.getPath(), new SimpleRequestCallback<SavePlotAsImageContext>() {
@Override
public void onResponseReceived(SavePlotAsImageContext context) {
indicator.onCompleted();
exportPlot_.savePlotAsImage(globalDisplay_, server_, context, ExportPlotOptions.adaptToSize(uiPrefs_.get().exportPlotOptions().getValue(), getPlotSize()), saveExportOptionsOperation_);
}
@Override
public void onError(ServerError error) {
indicator.onError(error.getUserMessage());
}
});
}
use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.
the class Files method onRenameFile.
@Handler
void onRenameFile() {
// get currently selected files
ArrayList<FileSystemItem> selectedFiles = view_.getSelectedFiles();
// validation: some selection exists
if (selectedFiles.size() == 0)
return;
// validation: no more than one file selected
if (selectedFiles.size() > 1) {
globalDisplay_.showErrorMessage("Invalid Selection", "Please select only one file to rename");
return;
}
// validation -- not prohibited move of public folder
if (!validateNotRestrictedFolder(selectedFiles, "renamed"))
return;
// prompt for new file name then execute the rename
final FileSystemItem file = selectedFiles.get(0);
globalDisplay_.promptForText("Rename File", "Please enter the new file name:", file.getName(), 0, file.getStem().length(), null, new ProgressOperationWithInput<String>() {
public void execute(String input, final ProgressIndicator progress) {
progress.onProgress("Renaming file...");
String path = file.getParentPath().completePath(input);
final FileSystemItem target = file.isDirectory() ? FileSystemItem.createDir(path) : FileSystemItem.createFile(path);
// clear selection
view_.selectNone();
// premptively rename in the UI then fallback to refreshing
// the view if there is an error
view_.renameFile(file, target);
// execute on the server
server_.renameFile(file, target, new VoidServerRequestCallback(progress) {
@Override
protected void onSuccess() {
// if we were successful, let editor know
if (!file.isDirectory()) {
eventBus_.fireEvent(new SourcePathChangedEvent(file.getPath(), target.getPath()));
}
}
@Override
protected void onFailure() {
onRefreshFiles();
}
});
}
});
}
use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.
the class FilesCopy method copyNextFile.
private void copyNextFile(final ArrayList<FileSystemItem> filesQueue, final FileSystemItem targetDirectory, final Command completedCommand) {
// terminate if there are no files left
if (filesQueue.size() == 0) {
if (completedCommand != null)
completedCommand.execute();
return;
}
// remove the first file from the list
final FileSystemItem sourceFile = filesQueue.remove(0);
// determine the default name and default selection
final String COPY_PREFIX = "CopyOf";
String defaultName = COPY_PREFIX + sourceFile.getName();
int defaultSelectionLength = COPY_PREFIX.length() + sourceFile.getStem().length();
// show prompt for new filename
final String objectName = sourceFile.isDirectory() ? "Folder" : "File";
globalDisplay_.promptForText("Copy " + objectName, "Enter a name for the copy of '" + sourceFile.getName() + "':", defaultName, 0, defaultSelectionLength, null, new ProgressOperationWithInput<String>() {
public void execute(String input, ProgressIndicator progress) {
progress.onProgress("Copying " + objectName.toLowerCase() + "...");
String targetFilePath = targetDirectory.completePath(input);
final FileSystemItem targetFile = FileSystemItem.createFile(targetFilePath);
server_.copyFile(sourceFile, targetFile, false, new VoidServerRequestCallback(progress) {
@Override
protected void onSuccess() {
// copy the next file in the queue
copyNextFile(filesQueue, targetDirectory, completedCommand);
}
});
}
});
}
use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.
the class FilesUpload method confirmFileUploadOverwriteMessage.
private String confirmFileUploadOverwriteMessage(PendingFileUpload pendingUpload) {
JsArray<FileSystemItem> overwrites = pendingUpload.getOverwrites();
FileSystemItem firstFile = overwrites.get(0);
boolean multiple = overwrites.length() > 1;
StringBuilder msg = new StringBuilder();
msg.append("The upload will overwrite ");
if (multiple)
msg.append("multiple files including ");
else
msg.append("the file ");
msg.append("\"" + firstFile.getPath() + "\". ");
msg.append("Are you sure you want to overwrite ");
if (multiple)
msg.append("these files?");
else
msg.append("this file?");
return msg.toString();
}
use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.
the class FilesList method addSelectionColumn.
private Column<FileSystemItem, Boolean> addSelectionColumn() {
Column<FileSystemItem, Boolean> checkColumn = new Column<FileSystemItem, Boolean>(new CheckboxCell(true, false) {
@Override
public void render(Context context, Boolean value, SafeHtmlBuilder sb) {
// don't render the check box if its for the parent path
if (parentPath_ == null || context.getIndex() > 0)
super.render(context, value, sb);
}
}) {
@Override
public Boolean getValue(FileSystemItem item) {
return selectionModel_.isSelected(item);
}
};
checkColumn.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
filesDataGrid_.addColumn(checkColumn);
filesDataGrid_.setColumnWidth(checkColumn, CHECK_COLUMN_WIDTH_PIXELS, Unit.PX);
return checkColumn;
}
Aggregations