Search in sources :

Example 66 with FileSystemItem

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

the class ExportPlotUtils method composeTargetPath.

public static FileSystemItem composeTargetPath(String ext, TextBox fileNameTextBox, FileSystemItem directory) {
    // get the filename
    String filename = fileNameTextBox.getText().trim();
    if (filename.length() == 0)
        return null;
    // compute the target path
    FileSystemItem targetPath = FileSystemItem.createFile(directory.completePath(filename));
    // if the extension isn't already correct then append it
    if (!targetPath.getExtension().equalsIgnoreCase(ext))
        targetPath = FileSystemItem.createFile(targetPath.getPath() + ext);
    // return the path
    return targetPath;
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem)

Example 67 with FileSystemItem

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

the class SavePlotAsImageDialog method attemptSavePlot.

private void attemptSavePlot(boolean overwrite, final Operation onCompleted) {
    // get plot format 
    final String format = saveAsTarget_.getFormat();
    // validate path
    FileSystemItem targetPath = saveAsTarget_.getTargetPath();
    if (targetPath == null) {
        globalDisplay_.showErrorMessage("File Name Required", "You must provide a file name for the plot image.", saveAsTarget_);
        return;
    }
    saveOperation_.attemptSave(progressIndicator_, targetPath, format, getSizeEditor(), overwrite, viewAfterSaveCheckBox_.getValue(), onCompleted);
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem)

Example 68 with FileSystemItem

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

the class RemoteFileSystemContext method cd.

public void cd(String relativeOrAbsolutePath) {
    final String newPath = combine(workingDir_, relativeOrAbsolutePath);
    final FileSystemItem newPathEntry = FileSystemItem.createDir(newPath);
    final ArrayList<FileSystemItem> fsi = new ArrayList<FileSystemItem>();
    server_.listFiles(newPathEntry, // since this is used for the file dialog don't 
    false, // cause the call to reset the server monitoring state
    new ServerRequestCallback<DirectoryListing>() {

        @Override
        public void onError(ServerError error) {
            if (callbacks_ != null)
                callbacks_.onError(error.getUserMessage());
        }

        @Override
        public void onResponseReceived(final DirectoryListing response) {
            final JsArray<FileSystemItem> files = response.getFiles();
            for (int i = 0; i < files.length(); i++) fsi.add(files.get(i));
            workingDir_ = newPath;
            contents_ = fsi.toArray(new FileSystemItem[0]);
            if (callbacks_ != null)
                callbacks_.onNavigated();
        }
    });
}
Also used : DirectoryListing(org.rstudio.studio.client.workbench.views.files.model.DirectoryListing) FileSystemItem(org.rstudio.core.client.files.FileSystemItem) JsArray(com.google.gwt.core.client.JsArray) ServerError(org.rstudio.studio.client.server.ServerError) ArrayList(java.util.ArrayList)

Example 69 with FileSystemItem

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

the class RemoteFileSystemContext method mkdir.

public void mkdir(final String directoryName, final ProgressIndicator progress) {
    String error;
    if (null != (error = validatePathElement(directoryName, true))) {
        progress.onError(error);
        return;
    }
    final String baseDir = workingDir_;
    String newPath = combine(baseDir, directoryName);
    final FileSystemItem newFolder = FileSystemItem.createDir(newPath);
    server_.createFolder(newFolder, new ServerRequestCallback<org.rstudio.studio.client.server.Void>() {

        @Override
        public void onError(ServerError error) {
            progress.onError(error.getUserMessage());
        }

        @Override
        public void onResponseReceived(Void response) {
            if (baseDir.equals(workingDir_)) {
                progress.onCompleted();
                if (callbacks_ != null)
                    callbacks_.onDirectoryCreated(newFolder);
            }
        }
    });
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) ServerError(org.rstudio.studio.client.server.ServerError) Void(org.rstudio.studio.client.server.Void)

Example 70 with FileSystemItem

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

the class PackageLibraryUtils method typeOfLibrary.

public static PackageLibraryType typeOfLibrary(Session session, String library) {
    FileSystemItem projectDir = null;
    SessionInfo sessionInfo = session.getSessionInfo();
    if (sessionInfo != null)
        projectDir = sessionInfo.getActiveProjectDir();
    // belongs in the project library
    if (StringUtil.isNullOrEmpty(library) || (projectDir != null && library.startsWith(projectDir.getPath()))) {
        return PackageLibraryType.Project;
    } else if (library.startsWith(FileSystemItem.HOME_PATH)) {
        return PackageLibraryType.User;
    } else {
        return PackageLibraryType.System;
    }
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) SessionInfo(org.rstudio.studio.client.workbench.model.SessionInfo)

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