Search in sources :

Example 36 with FileSystemItem

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

Example 37 with FileSystemItem

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

Example 38 with FileSystemItem

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

Example 39 with FileSystemItem

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;
        }
    };
}
Also used : JsObject(org.rstudio.core.client.js.JsObject) JsArray(com.google.gwt.core.client.JsArray) FileSystemItem(org.rstudio.core.client.files.FileSystemItem) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) SessionInfo(org.rstudio.studio.client.workbench.model.SessionInfo) StringStateValue(org.rstudio.studio.client.workbench.model.helper.StringStateValue) ClientInitState(org.rstudio.studio.client.workbench.model.ClientInitState) JSObjectStateValue(org.rstudio.studio.client.workbench.model.helper.JSObjectStateValue)

Example 40 with FileSystemItem

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("&nbsp;"));
    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;
}
Also used : Grid(com.google.gwt.user.client.ui.Grid) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) Label(com.google.gwt.user.client.ui.Label) HTML(com.google.gwt.user.client.ui.HTML) RadioButton(com.google.gwt.user.client.ui.RadioButton) TextBox(com.google.gwt.user.client.ui.TextBox) ProgressOperationWithInput(org.rstudio.core.client.widget.ProgressOperationWithInput) ThemedButton(org.rstudio.core.client.widget.ThemedButton) VerticalPanel(com.google.gwt.user.client.ui.VerticalPanel) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) FileSystemItem(org.rstudio.core.client.files.FileSystemItem) ExportPlotResources(org.rstudio.studio.client.workbench.exportplot.ExportPlotResources) CheckBox(com.google.gwt.user.client.ui.CheckBox) ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) HorizontalPanel(com.google.gwt.user.client.ui.HorizontalPanel)

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