Search in sources :

Example 76 with FileSystemItem

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

the class FilesList method addIconColumn.

private Column<FileSystemItem, ImageResource> addIconColumn(final FileTypeRegistry fileTypeRegistry) {
    Column<FileSystemItem, ImageResource> iconColumn = new Column<FileSystemItem, ImageResource>(new ImageResourceCell()) {

        @Override
        public ImageResource getValue(FileSystemItem object) {
            if (object == parentPath_)
                return new ImageResource2x(FileIconResources.INSTANCE.iconUpFolder2x());
            else
                return fileTypeRegistry.getIconForFile(object);
        }
    };
    iconColumn.setSortable(true);
    filesDataGrid_.addColumn(iconColumn, SafeHtmlUtils.fromSafeConstant("<br/>"));
    filesDataGrid_.setColumnWidth(iconColumn, ICON_COLUMN_WIDTH_PIXELS, Unit.PX);
    sortHandler_.setComparator(iconColumn, new FilesListComparator() {

        @Override
        public int doCompare(FileSystemItem arg0, FileSystemItem arg1) {
            if (arg0.isDirectory() && !arg1.isDirectory())
                return 1;
            else if (arg1.isDirectory() && !arg0.isDirectory())
                return -1;
            else
                return arg0.getExtension().compareTo(arg1.getExtension());
        }
    });
    return iconColumn;
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) ImageResource(com.google.gwt.resources.client.ImageResource) LinkColumn(org.rstudio.core.client.cellview.LinkColumn) TextColumn(com.google.gwt.user.cellview.client.TextColumn) Column(com.google.gwt.user.cellview.client.Column) ImageResource2x(org.rstudio.core.client.resources.ImageResource2x) ImageResourceCell(com.google.gwt.cell.client.ImageResourceCell)

Example 77 with FileSystemItem

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

the class DocsMenu method deduplicate.

private String[] deduplicate(String[] names, String[] paths) {
    Map<String, Integer> counts = new HashMap<String, Integer>();
    // initialize map with zeroes
    int n = names.length;
    for (int i = 0; i < n; i++) counts.put(names[i], 0);
    // generate counts
    for (int i = 0; i < n; i++) counts.put(names[i], counts.get(names[i]) + 1);
    // de-duplicate names based on path components
    String[] deduped = new String[names.length];
    for (int i = 0; i < n; i++) {
        if (counts.get(names[i]) >= 2) {
            FileSystemItem item = FileSystemItem.createFile(paths[i]);
            deduped[i] = names[i] + " — " + item.getParentPath().getName();
        } else {
            deduped[i] = names[i];
        }
    }
    // count duplicates once more
    counts.clear();
    for (int i = 0; i < n; i++) counts.put(deduped[i], 0);
    for (int i = 0; i < n; i++) counts.put(deduped[i], counts.get(deduped[i]) + 1);
    // for items that are still duplicated, just print the full parent path
    for (int i = 0; i < n; i++) {
        if (counts.get(deduped[i]) >= 2) {
            FileSystemItem item = FileSystemItem.createFile(paths[i]);
            deduped[i] = names[i] + " — " + item.getParentPath().getPath();
        }
    }
    return deduped;
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) HashMap(java.util.HashMap)

Example 78 with FileSystemItem

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

the class Plots method onSavePlotAsPdf.

void onSavePlotAsPdf() {
    view_.bringToFront();
    final ProgressIndicator indicator = globalDisplay_.getProgressIndicator("Error");
    indicator.onProgress("Preparing to export plot...");
    // get the default directory
    final FileSystemItem defaultDir = ExportPlotUtils.getDefaultSaveDirectory(workbenchContext_.getCurrentWorkingDir());
    // get context
    server_.getUniqueSavePlotStem(defaultDir.getPath(), new SimpleRequestCallback<String>() {

        @Override
        public void onResponseReceived(String stem) {
            indicator.onCompleted();
            Size size = getPlotSize();
            final SavePlotAsPdfOptions currentOptions = uiPrefs_.get().savePlotAsPdfOptions().getValue();
            exportPlot_.savePlotAsPdf(globalDisplay_, server_, session_.getSessionInfo(), defaultDir, stem, currentOptions, pixelsToInches(size.width), pixelsToInches(size.height), new OperationWithInput<SavePlotAsPdfOptions>() {

                @Override
                public void execute(SavePlotAsPdfOptions options) {
                    if (!SavePlotAsPdfOptions.areEqual(options, currentOptions)) {
                        UIPrefs prefs = uiPrefs_.get();
                        prefs.savePlotAsPdfOptions().setGlobalValue(options);
                        prefs.writeUIPrefs();
                    }
                }
            });
        }

        @Override
        public void onError(ServerError error) {
            indicator.onError(error.getUserMessage());
        }
    });
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) Size(org.rstudio.core.client.Size) ServerError(org.rstudio.studio.client.server.ServerError) OperationWithInput(org.rstudio.core.client.widget.OperationWithInput) SavePlotAsPdfOptions(org.rstudio.studio.client.workbench.views.plots.model.SavePlotAsPdfOptions) UIPrefs(org.rstudio.studio.client.workbench.prefs.model.UIPrefs)

Example 79 with FileSystemItem

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

the class Source method openNotebook.

private void openNotebook(final FileSystemItem rnbFile, final TextFileType fileType, final ResultCallback<EditingTarget, ServerError> resultCallback) {
    // construct path to .Rmd
    final String rnbPath = rnbFile.getPath();
    final String rmdPath = FilePathUtils.filePathSansExtension(rnbPath) + ".Rmd";
    final FileSystemItem rmdFile = FileSystemItem.createFile(rmdPath);
    // TODO: should we perform conflict resolution here as well?
    if (openFileAlreadyOpen(rmdFile, resultCallback))
        return;
    // ask the server to extract the .Rmd, then open that
    Command extractRmdCommand = new Command() {

        @Override
        public void execute() {
            server_.extractRmdFromNotebook(rnbPath, new ServerRequestCallback<SourceDocumentResult>() {

                @Override
                public void onResponseReceived(SourceDocumentResult doc) {
                    openNotebook(rmdFile, doc, resultCallback);
                }

                @Override
                public void onError(ServerError error) {
                    globalDisplay_.showErrorMessage("Notebook Open Failed", "This notebook could not be opened. \n\n" + error.getMessage());
                    resultCallback.onFailure(error);
                }
            });
        }
    };
    dependencyManager_.withRMarkdown("R Notebook", "Using R Notebooks", extractRmdCommand);
}
Also used : SourceDocumentResult(org.rstudio.studio.client.workbench.views.source.model.SourceDocumentResult) FileSystemItem(org.rstudio.core.client.files.FileSystemItem) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) Command(com.google.gwt.user.client.Command) AppCommand(org.rstudio.core.client.command.AppCommand) ServerError(org.rstudio.studio.client.server.ServerError) JSONString(com.google.gwt.json.client.JSONString) JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 80 with FileSystemItem

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

the class TextEditingTarget method onSetWorkingDirToActiveDoc.

@Handler
public void onSetWorkingDirToActiveDoc() {
    // get path
    String activeDocPath = docUpdateSentinel_.getPath();
    if (activeDocPath != null) {
        FileSystemItem wdPath = FileSystemItem.createFile(activeDocPath).getParentPath();
        consoleDispatcher_.executeSetWd(wdPath, true);
    } else {
        globalDisplay_.showMessage(MessageDialog.WARNING, "Source File Not Saved", "The currently active source file is not saved so doesn't " + "have a directory to change into.");
        return;
    }
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) JsArrayString(com.google.gwt.core.client.JsArrayString) Handler(org.rstudio.core.client.command.Handler) ChangeFontSizeHandler(org.rstudio.studio.client.application.events.ChangeFontSizeHandler) RecordNavigationPositionHandler(org.rstudio.studio.client.workbench.views.source.events.RecordNavigationPositionHandler) EnsureHeightHandler(org.rstudio.core.client.events.EnsureHeightHandler) EnsureVisibleHandler(org.rstudio.core.client.events.EnsureVisibleHandler) HideMessageHandler(org.rstudio.studio.client.workbench.views.source.editors.text.status.StatusBar.HideMessageHandler) FileChangeHandler(org.rstudio.studio.client.workbench.views.files.events.FileChangeHandler)

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