use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.
the class FilesList method addIconColumn.
private Column<FileSystemItem, ImageResource> addIconColumn(final FileTypeRegistry fileTypeRegistry) {
Column<FileSystemItem, ImageResource> iconColumn = new Column<FileSystemItem, ImageResource>(new ImageResourceCell()) {
@Override
public ImageResource getValue(FileSystemItem object) {
if (object == parentPath_)
return new ImageResource2x(FileIconResources.INSTANCE.iconUpFolder2x());
else
return fileTypeRegistry.getIconForFile(object);
}
};
iconColumn.setSortable(true);
filesDataGrid_.addColumn(iconColumn, SafeHtmlUtils.fromSafeConstant("<br/>"));
filesDataGrid_.setColumnWidth(iconColumn, ICON_COLUMN_WIDTH_PIXELS, Unit.PX);
sortHandler_.setComparator(iconColumn, new FilesListComparator() {
@Override
public int doCompare(FileSystemItem arg0, FileSystemItem arg1) {
if (arg0.isDirectory() && !arg1.isDirectory())
return 1;
else if (arg1.isDirectory() && !arg0.isDirectory())
return -1;
else
return arg0.getExtension().compareTo(arg1.getExtension());
}
});
return iconColumn;
}
use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.
the class DocsMenu method deduplicate.
private String[] deduplicate(String[] names, String[] paths) {
Map<String, Integer> counts = new HashMap<String, Integer>();
// initialize map with zeroes
int n = names.length;
for (int i = 0; i < n; i++) counts.put(names[i], 0);
// generate counts
for (int i = 0; i < n; i++) counts.put(names[i], counts.get(names[i]) + 1);
// de-duplicate names based on path components
String[] deduped = new String[names.length];
for (int i = 0; i < n; i++) {
if (counts.get(names[i]) >= 2) {
FileSystemItem item = FileSystemItem.createFile(paths[i]);
deduped[i] = names[i] + " — " + item.getParentPath().getName();
} else {
deduped[i] = names[i];
}
}
// count duplicates once more
counts.clear();
for (int i = 0; i < n; i++) counts.put(deduped[i], 0);
for (int i = 0; i < n; i++) counts.put(deduped[i], counts.get(deduped[i]) + 1);
// for items that are still duplicated, just print the full parent path
for (int i = 0; i < n; i++) {
if (counts.get(deduped[i]) >= 2) {
FileSystemItem item = FileSystemItem.createFile(paths[i]);
deduped[i] = names[i] + " — " + item.getParentPath().getPath();
}
}
return deduped;
}
use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.
the class Plots method onSavePlotAsPdf.
void onSavePlotAsPdf() {
view_.bringToFront();
final ProgressIndicator indicator = globalDisplay_.getProgressIndicator("Error");
indicator.onProgress("Preparing to export plot...");
// get the default directory
final FileSystemItem defaultDir = ExportPlotUtils.getDefaultSaveDirectory(workbenchContext_.getCurrentWorkingDir());
// get context
server_.getUniqueSavePlotStem(defaultDir.getPath(), new SimpleRequestCallback<String>() {
@Override
public void onResponseReceived(String stem) {
indicator.onCompleted();
Size size = getPlotSize();
final SavePlotAsPdfOptions currentOptions = uiPrefs_.get().savePlotAsPdfOptions().getValue();
exportPlot_.savePlotAsPdf(globalDisplay_, server_, session_.getSessionInfo(), defaultDir, stem, currentOptions, pixelsToInches(size.width), pixelsToInches(size.height), new OperationWithInput<SavePlotAsPdfOptions>() {
@Override
public void execute(SavePlotAsPdfOptions options) {
if (!SavePlotAsPdfOptions.areEqual(options, currentOptions)) {
UIPrefs prefs = uiPrefs_.get();
prefs.savePlotAsPdfOptions().setGlobalValue(options);
prefs.writeUIPrefs();
}
}
});
}
@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 Source method openNotebook.
private void openNotebook(final FileSystemItem rnbFile, final TextFileType fileType, final ResultCallback<EditingTarget, ServerError> resultCallback) {
// construct path to .Rmd
final String rnbPath = rnbFile.getPath();
final String rmdPath = FilePathUtils.filePathSansExtension(rnbPath) + ".Rmd";
final FileSystemItem rmdFile = FileSystemItem.createFile(rmdPath);
// TODO: should we perform conflict resolution here as well?
if (openFileAlreadyOpen(rmdFile, resultCallback))
return;
// ask the server to extract the .Rmd, then open that
Command extractRmdCommand = new Command() {
@Override
public void execute() {
server_.extractRmdFromNotebook(rnbPath, new ServerRequestCallback<SourceDocumentResult>() {
@Override
public void onResponseReceived(SourceDocumentResult doc) {
openNotebook(rmdFile, doc, resultCallback);
}
@Override
public void onError(ServerError error) {
globalDisplay_.showErrorMessage("Notebook Open Failed", "This notebook could not be opened. \n\n" + error.getMessage());
resultCallback.onFailure(error);
}
});
}
};
dependencyManager_.withRMarkdown("R Notebook", "Using R Notebooks", extractRmdCommand);
}
use of org.rstudio.core.client.files.FileSystemItem 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