Search in sources :

Example 71 with FileSystemItem

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());
        }
    });
}
Also used : SavePlotAsImageContext(org.rstudio.studio.client.workbench.exportplot.model.SavePlotAsImageContext) FileSystemItem(org.rstudio.core.client.files.FileSystemItem) ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) ServerError(org.rstudio.studio.client.server.ServerError)

Example 72 with FileSystemItem

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();
                }
            });
        }
    });
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) SourcePathChangedEvent(org.rstudio.studio.client.workbench.views.source.events.SourcePathChangedEvent) OpenFileInBrowserHandler(org.rstudio.studio.client.common.filetypes.events.OpenFileInBrowserHandler) Handler(org.rstudio.core.client.command.Handler)

Example 73 with FileSystemItem

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);
                }
            });
        }
    });
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) VoidServerRequestCallback(org.rstudio.studio.client.server.VoidServerRequestCallback)

Example 74 with FileSystemItem

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();
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem)

Example 75 with FileSystemItem

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;
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) LinkColumn(org.rstudio.core.client.cellview.LinkColumn) TextColumn(com.google.gwt.user.cellview.client.TextColumn) Column(com.google.gwt.user.cellview.client.Column) CheckboxCell(com.google.gwt.cell.client.CheckboxCell) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder)

Aggregations

FileSystemItem (org.rstudio.core.client.files.FileSystemItem)89 ServerError (org.rstudio.studio.client.server.ServerError)18 ProgressIndicator (org.rstudio.core.client.widget.ProgressIndicator)16 JsArrayString (com.google.gwt.core.client.JsArrayString)14 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)10 Handler (org.rstudio.core.client.command.Handler)10 Command (com.google.gwt.user.client.Command)9 ArrayList (java.util.ArrayList)7 AppCommand (org.rstudio.core.client.command.AppCommand)7 VoidServerRequestCallback (org.rstudio.studio.client.server.VoidServerRequestCallback)6 TextFileType (org.rstudio.studio.client.common.filetypes.TextFileType)5 JsArray (com.google.gwt.core.client.JsArray)4 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)4 JSONString (com.google.gwt.json.client.JSONString)4 FilePosition (org.rstudio.core.client.FilePosition)4 ServerRequestCallback (org.rstudio.studio.client.server.ServerRequestCallback)4 EditingTarget (org.rstudio.studio.client.workbench.views.source.editors.EditingTarget)4 CodeBrowserEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.codebrowser.CodeBrowserEditingTarget)4 DataEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.data.DataEditingTarget)4 TextEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget)4