Search in sources :

Example 41 with FileSystemItem

use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.

the class SavePlotAsPdfDialog method attemptSavePdf.

private void attemptSavePdf(boolean overwrite, final Operation onCompleted) {
    // validate file name
    FileSystemItem targetPath = getTargetPath();
    if (targetPath == null) {
        globalDisplay_.showErrorMessage("File Name Required", "You must provide a file name for the plot pdf.", fileNameTextBox_);
        return;
    }
    // invoke handler
    SavePlotAsHandler handler = createSavePlotAsHandler();
    handler.attemptSave(targetPath, overwrite, viewAfterSaveCheckBox_.getValue(), onCompleted);
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem)

Example 42 with FileSystemItem

use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.

the class FilesPane method onBeforeSelected.

@Override
public void onBeforeSelected() {
    if (needsInit) {
        needsInit = false;
        FileSystemItem home = FileSystemItem.home();
        observer_.onFileNavigation(home);
    } else {
        Scheduler.get().scheduleDeferred(new ScheduledCommand() {

            @Override
            public void execute() {
                filesList_.redraw();
            }
        });
    }
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand)

Example 43 with FileSystemItem

use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.

the class FilesList method updateWithAction.

public void updateWithAction(FileChange viewAction) {
    final FileSystemItem file = viewAction.getFile();
    final List<FileSystemItem> files = getFiles();
    switch(viewAction.getType()) {
        case FileChange.ADD:
            if (file.getParentPath().equalTo(containingPath_)) {
                int row = rowForFile(file);
                if (row == -1) {
                    files.add(file);
                    filesDataGrid_.setPageSize(files.size() + 1);
                } else {
                    // since we eagerly perform renames at the client UI
                    // layer then sometimes an "added" file is really just
                    // a rename. in this case the file already exists due
                    // to the eager rename in the client but still needs its
                    // metadata updated
                    files.set(row, file);
                }
            }
            break;
        case FileChange.MODIFIED:
            {
                int row = rowForFile(file);
                if (row != -1)
                    files.set(row, file);
            }
            break;
        case FileChange.DELETE:
            {
                int row = rowForFile(file);
                if (row != -1) {
                    files.remove(row);
                    // if a file is deleted and then re-added within the same
                    // event loop (as occurs when gedit saves a text file) the
                    // table doesn't always update correctly (it has a duplicate
                    // of the item deleted / re-added). the call to flush overcomes
                    // this issue
                    dataProvider_.flush();
                }
            }
            break;
        default:
            Debug.log("Unexpected file change type: " + viewAction.getType());
            break;
    }
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem)

Example 44 with FileSystemItem

use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.

the class HelpPane method getDocTitle.

private String getDocTitle(Document doc) {
    String docUrl = StringUtil.notNull(doc.getURL());
    String docTitle = doc.getTitle();
    String previewPrefix = new String("/help/preview?file=");
    int previewLoc = docUrl.indexOf(previewPrefix);
    if (previewLoc != -1) {
        String file = docUrl.substring(previewLoc + previewPrefix.length());
        file = URL.decodeQueryString(file);
        FileSystemItem fsi = FileSystemItem.createFile(file);
        docTitle = fsi.getName();
    } else if (StringUtil.isNullOrEmpty(docTitle)) {
        String url = new String(docUrl);
        url = url.split("\\?")[0];
        url = url.split("#")[0];
        String[] chunks = url.split("/");
        docTitle = chunks[chunks.length - 1];
    }
    return docTitle;
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem)

Example 45 with FileSystemItem

use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.

the class RSConnectDeploy method populateDeploymentFiles.

private void populateDeploymentFiles(final ProgressIndicator indicator) {
    if (source_ == null)
        return;
    // dependencies; just inject it directly into the list.
    if (source_.isSelfContained() && source_.isStatic() && !source_.isWebsiteRmd()) {
        ArrayList<String> files = new ArrayList<String>();
        FileSystemItem selfContained = FileSystemItem.createFile(source_.getDeployFile());
        files.add(selfContained.getName());
        setFileList(files, null, null);
        setPrimaryFile(selfContained.getName());
        return;
    }
    // ternery operator maps to appropriate files to list for deployment:
    // website code    - website code directory 
    // static website  - website build directory
    // document        - R Markdown document
    // non-document    - Shiny app directory
    final String fileSource = source_.isDocument() ? source_.isWebsiteRmd() ? source_.isStatic() ? source_.getDeployDir() : source_.getWebsiteDir() : source_.getDeployFile() : source_.getDeployDir();
    indicator.onProgress("Collecting files...");
    server_.getDeploymentFiles(fileSource, asMultipleRmd_, new ServerRequestCallback<RSConnectDeploymentFiles>() {

        @Override
        public void onResponseReceived(RSConnectDeploymentFiles files) {
            if (files.getDirSize() > files.getMaxSize()) {
                indicator.onError("The item to be deployed (" + fileSource + ") " + "exceeds the maximum deployment size, which is " + StringUtil.formatFileSize(files.getMaxSize()) + "." + " Consider creating a new directory containing " + "only the content you wish to deploy.");
            } else {
                if (files.getDirList() == null || files.getDirList().length() == 0) {
                    indicator.onError("Could not determine the list of " + "files to deploy.");
                    indicator.onCompleted();
                }
                setFileList(JsArrayUtil.fromJsArrayString(files.getDirList()), fromPrevious_ != null ? fromPrevious_.getAdditionalFiles() : null, fromPrevious_ != null ? fromPrevious_.getIgnoredFiles() : null);
                if (!source_.isWebsiteRmd())
                    setPrimaryFile(FileSystemItem.createFile(source_.getDeployFile()).getName());
            }
            Scheduler.get().scheduleDeferred(new ScheduledCommand() {

                @Override
                public void execute() {
                    indicator.clearProgress();
                }
            });
        }

        @Override
        public void onError(ServerError error) {
            // we need to have a list of files to deploy to proceed
            indicator.onError("Could not find files to deploy: \n\n" + error.getMessage());
            indicator.onCompleted();
        }
    });
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) ServerError(org.rstudio.studio.client.server.ServerError) ArrayList(java.util.ArrayList) RSConnectDeploymentFiles(org.rstudio.studio.client.rsconnect.model.RSConnectDeploymentFiles)

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