use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.
the class TextEditingTarget method getSaveFileDefaultDir.
private FileSystemItem getSaveFileDefaultDir() {
FileSystemItem fsi = null;
SessionInfo si = session_.getSessionInfo();
if (si.getBuildToolsType() == SessionInfo.BUILD_TOOLS_PACKAGE) {
FileSystemItem pkg = FileSystemItem.createDir(si.getBuildTargetDir());
if (fileType_.isR()) {
fsi = FileSystemItem.createDir(pkg.completePath("R"));
} else if (fileType_.isC() && si.getHasPackageSrcDir()) {
fsi = FileSystemItem.createDir(pkg.completePath("src"));
} else if (fileType_.isRd()) {
fsi = FileSystemItem.createDir(pkg.completePath("man"));
} else if ((fileType_.isRnw() || fileType_.isRmd()) && si.getHasPackageVignetteDir()) {
fsi = FileSystemItem.createDir(pkg.completePath("vignettes"));
}
}
if (fsi == null)
fsi = workbenchContext_.getDefaultFileDialogDir();
return fsi;
}
use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.
the class FileExport method export.
public void export(String caption, String description, final FileSystemItem parentDir, final ArrayList<FileSystemItem> files) {
// validation: some files provided
if (files.size() == 0)
return;
// case: single file which is not a folder
if ((files.size()) == 1 && !files.get(0).isDirectory()) {
final FileSystemItem file = files.get(0);
showFileExport(caption, description, file.getStem(), file.getExtension(), new ProgressOperationWithInput<String>() {
public void execute(String name, ProgressIndicator progress) {
// progress complete
progress.onCompleted();
// execute the download (open in a new window)
globalDisplay_.openWindow(server_.getFileExportUrl(name, file));
}
});
} else // case: folder or multiple files
{
// determine the default zip file name based on the selection
String defaultArchiveName;
if (files.size() == 1)
defaultArchiveName = files.get(0).getStem();
else
defaultArchiveName = "rstudio-export";
// prompt user
final String ZIP = ".zip";
showFileExport(caption, description, defaultArchiveName, ZIP, new ProgressOperationWithInput<String>() {
public void execute(String archiveName, ProgressIndicator progress) {
// progress complete
progress.onCompleted();
// force zip extension in case the user deleted it
if (!archiveName.endsWith(ZIP))
archiveName += ZIP;
// build list of filenames
ArrayList<String> filenames = new ArrayList<String>();
for (FileSystemItem file : files) filenames.add(file.getName());
// execute the download (open in a new window)
globalDisplay_.openWindow(server_.getFileExportUrl(archiveName, parentDir, filenames));
}
});
}
}
use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.
the class FileTypeRegistry method satelliteEditFile.
private void satelliteEditFile(JavaScriptObject file, JavaScriptObject position, boolean highlightLine) {
FileSystemItem fsi = file.cast();
FilePosition pos = position.cast();
editFile(fsi, pos);
}
use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.
the class Files method initSession.
private void initSession() {
final SessionInfo sessionInfo = session_.getSessionInfo();
ClientInitState state = sessionInfo.getClientState();
// make the column sort order persistent
new JSObjectStateValue(MODULE_FILES, KEY_SORT_ORDER, ClientState.PROJECT_PERSISTENT, state, false) {
@Override
protected void onInit(JsObject value) {
if (value != null)
columnSortOrder_ = value.cast();
else
columnSortOrder_ = null;
lastKnownState_ = columnSortOrder_;
view_.setColumnSortOrder(columnSortOrder_);
}
@Override
protected JsObject getValue() {
if (columnSortOrder_ != null)
return columnSortOrder_.cast();
else
return null;
}
@Override
protected boolean hasChanged() {
if (lastKnownState_ != columnSortOrder_) {
lastKnownState_ = columnSortOrder_;
return true;
} else {
return false;
}
}
private JsArray<ColumnSortInfo> lastKnownState_ = null;
};
// navigate to previous directory (works for resumed case)
new StringStateValue(MODULE_FILES, KEY_PATH, ClientState.PROJECT_PERSISTENT, state) {
@Override
protected void onInit(final String value) {
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
public void execute() {
// we don't need to initialize from client state
if (hasNavigatedToDirectory_)
return;
// compute start dir
String path = transformPathStateValue(value);
FileSystemItem start = path != null ? FileSystemItem.createDir(path) : FileSystemItem.createDir(sessionInfo.getInitialWorkingDir());
navigateToDirectory(start);
}
});
}
@Override
protected String getValue() {
return currentPath_.getPath();
}
private String transformPathStateValue(String value) {
// if the value is null then return null
if (value == null)
return null;
// only respect the value for projects
String projectFile = session_.getSessionInfo().getActiveProjectFile();
if (projectFile == null)
return null;
// ensure that the value is within the project dir (it wouldn't
// be if the project directory has been moved or renamed)
String projectDirPath = FileSystemItem.createFile(projectFile).getParentPathString();
if (value.startsWith(projectDirPath))
return value;
else
return null;
}
};
}
use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.
the class SavePlotAsPdfDialog method createMainWidget.
@Override
protected Widget createMainWidget() {
ExportPlotResources.Styles styles = ExportPlotResources.INSTANCE.styles();
Grid grid = new Grid(7, 2);
grid.setStylePrimaryName(styles.savePdfMainWidget());
// paper size
grid.setWidget(0, 0, new Label("PDF Size:"));
// paper size label
paperSizeEditor_ = new PaperSizeEditor();
grid.setWidget(0, 1, paperSizeEditor_);
// orientation
grid.setWidget(1, 0, new Label("Orientation:"));
HorizontalPanel orientationPanel = new HorizontalPanel();
orientationPanel.setSpacing(kComponentSpacing);
VerticalPanel orientationGroupPanel = new VerticalPanel();
final String kOrientationGroup = new String("Orientation");
portraitRadioButton_ = new RadioButton(kOrientationGroup, "Portrait");
orientationGroupPanel.add(portraitRadioButton_);
landscapeRadioButton_ = new RadioButton(kOrientationGroup, "Landscape");
orientationGroupPanel.add(landscapeRadioButton_);
orientationPanel.add(orientationGroupPanel);
grid.setWidget(1, 1, orientationPanel);
boolean haveCairoPdf = sessionInfo_.isCairoPdfAvailable();
if (haveCairoPdf)
grid.setWidget(2, 0, new Label("Options:"));
HorizontalPanel cairoPdfPanel = new HorizontalPanel();
String label = "Use cairo_pdf device";
if (BrowseCap.isMacintoshDesktop())
label = label + " (requires X11)";
chkCairoPdf_ = new CheckBox(label);
chkCairoPdf_.getElement().getStyle().setMarginLeft(kComponentSpacing, Unit.PX);
cairoPdfPanel.add(chkCairoPdf_);
chkCairoPdf_.setValue(haveCairoPdf && options_.getCairoPdf());
if (haveCairoPdf)
grid.setWidget(2, 1, cairoPdfPanel);
grid.setWidget(3, 0, new HTML(" "));
ThemedButton directoryButton = new ThemedButton("Directory...");
directoryButton.setStylePrimaryName(styles.directoryButton());
directoryButton.getElement().getStyle().setMarginLeft(-2, Unit.PX);
grid.setWidget(4, 0, directoryButton);
directoryButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
fileDialogs_.chooseFolder("Choose Directory", fileSystemContext_, FileSystemItem.createDir(directoryLabel_.getTitle().trim()), new ProgressOperationWithInput<FileSystemItem>() {
public void execute(FileSystemItem input, ProgressIndicator indicator) {
if (input == null)
return;
indicator.onCompleted();
// update default
ExportPlotUtils.setDefaultSaveDirectory(input);
// set display
setDirectory(input);
}
});
}
});
directoryLabel_ = new Label();
setDirectory(defaultDirectory_);
directoryLabel_.setStylePrimaryName(styles.savePdfDirectoryLabel());
grid.setWidget(4, 1, directoryLabel_);
Label fileNameLabel = new Label("File name:");
fileNameLabel.setStylePrimaryName(styles.savePdfFileNameLabel());
grid.setWidget(5, 0, fileNameLabel);
fileNameTextBox_ = new TextBox();
fileNameTextBox_.setText(defaultPlotName_);
fileNameTextBox_.setStylePrimaryName(styles.savePdfFileNameTextBox());
grid.setWidget(5, 1, fileNameTextBox_);
// view after size
viewAfterSaveCheckBox_ = new CheckBox("View plot after saving");
viewAfterSaveCheckBox_.setStylePrimaryName(styles.savePdfViewAfterCheckbox());
viewAfterSaveCheckBox_.setValue(options_.getViewAfterSave());
grid.setWidget(6, 1, viewAfterSaveCheckBox_);
// set default value
if (options_.getPortrait())
portraitRadioButton_.setValue(true);
else
landscapeRadioButton_.setValue(true);
// return the widget
return grid;
}
Aggregations