Search in sources :

Example 46 with FileSystemItem

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

the class RSConnectDeploy method onAddFileClick.

private void onAddFileClick() {
    FileDialogs dialogs = RStudioGinjector.INSTANCE.getFileDialogs();
    final FileSystemItem sourceDir = FileSystemItem.createDir(source_.getDeployDir());
    dialogs.openFile("Select File", RStudioGinjector.INSTANCE.getRemoteFileSystemContext(), sourceDir, new ProgressOperationWithInput<FileSystemItem>() {

        @Override
        public void execute(FileSystemItem input, ProgressIndicator indicator) {
            if (input != null) {
                String path = input.getPathRelativeTo(sourceDir);
                if (path == null) {
                    display_.showMessage(GlobalDisplay.MSG_INFO, "Cannot Add File", "Only files in the same folder as the " + "document (" + sourceDir + ") or one of its " + "sub-folders may be added.");
                    return;
                } else {
                    // see if the file is already in the list (we don't 
                    // want to duplicate an existing entry)
                    ArrayList<String> files = getFileList();
                    for (String file : files) {
                        if (file.equals(path)) {
                            indicator.onCompleted();
                            return;
                        }
                    }
                    addFileToList(path);
                    filesAddedManually_.add(path);
                }
            }
            indicator.onCompleted();
        }
    });
}
Also used : FileDialogs(org.rstudio.studio.client.common.FileDialogs) FileSystemItem(org.rstudio.core.client.files.FileSystemItem) ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) ArrayList(java.util.ArrayList)

Example 47 with FileSystemItem

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

the class RSConnectPublishButton method rebuildPopupMenu.

// rebuilds the popup menu--this can happen when the menu is invoked; it can
// also happen when the button is created if we're aggressively checking
// publish status
private void rebuildPopupMenu(final ToolbarPopupMenu.DynamicPopupMenuCallback callback) {
    final ToolbarPopupMenu menu = publishMenu_;
    // prevent reentrancy
    if (populating_) {
        if (callback != null)
            callback.onPopupMenu(menu);
        return;
    }
    // handle case where we don't have a content path (i.e. plots)
    if (contentPath_ == null) {
        setPreviousDeployments(null);
        if (callback != null)
            callback.onPopupMenu(menu);
        return;
    }
    // (unless we're forcefully repopulating)
    if (populatedPath_ != null && populatedPath_.equals(contentPath_)) {
        if (callback != null)
            callback.onPopupMenu(menu);
        return;
    }
    String contentPath = contentPath_;
    boolean parent = false;
    // CONTENT_TYPE_APP_SINGLE and their own deployment records)
    if (contentType_ == RSConnect.CONTENT_TYPE_APP && StringUtil.getExtension(contentPath_).equalsIgnoreCase("r"))
        parent = true;
    // if this is a document in a website, use the parent path
    if (contentType_ == RSConnect.CONTENT_TYPE_WEBSITE)
        parent = true;
    // apply parent path if needed
    if (parent) {
        FileSystemItem fsiContent = FileSystemItem.createFile(contentPath_);
        contentPath = fsiContent.getParentPathString();
    }
    populating_ = true;
    server_.getRSConnectDeployments(contentPath, outputPath_ == null ? "" : outputPath_, new ServerRequestCallback<JsArray<RSConnectDeploymentRecord>>() {

        @Override
        public void onResponseReceived(JsArray<RSConnectDeploymentRecord> recs) {
            populatedPath_ = contentPath_;
            populating_ = false;
            // that are static (as we can't update them)
            if (contentType_ == RSConnect.CONTENT_TYPE_WEBSITE && (docPreview_ == null || StringUtil.isNullOrEmpty(docPreview_.getOutputFile()))) {
                JsArray<RSConnectDeploymentRecord> codeRecs = JsArray.createArray().cast();
                for (int i = 0; i < recs.length(); i++) {
                    if (!recs.get(i).getAsStatic())
                        codeRecs.push(recs.get(i));
                }
                recs = codeRecs;
            }
            setPreviousDeployments(recs);
            if (callback != null)
                callback.onPopupMenu(menu);
        }

        @Override
        public void onError(ServerError error) {
            populating_ = false;
            if (callback != null)
                callback.onPopupMenu(menu);
        }
    });
}
Also used : ToolbarPopupMenu(org.rstudio.core.client.widget.ToolbarPopupMenu) FileSystemItem(org.rstudio.core.client.files.FileSystemItem) JsArray(com.google.gwt.core.client.JsArray) ServerError(org.rstudio.studio.client.server.ServerError) RSConnectDeploymentRecord(org.rstudio.studio.client.rsconnect.model.RSConnectDeploymentRecord)

Example 48 with FileSystemItem

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

the class EnvironmentPresenter method openOrUpdateFileBrowsePoint.

private void openOrUpdateFileBrowsePoint(boolean debugging, boolean sourceChanged) {
    String file = currentBrowseFile_;
    // if we have no file and no source code, we can do no navigation 
    if (!CallFrame.isNavigableFilename(file) && !useCurrentBrowseSource_) {
        return;
    }
    // file itself
    if (currentBrowsePosition_ != null && !useCurrentBrowseSource_) {
        FileSystemItem sourceFile = FileSystemItem.createFile(file);
        eventBus_.fireEvent(new OpenSourceFileEvent(sourceFile, (FilePosition) currentBrowsePosition_.cast(), FileTypeRegistry.R, debugging ? NavigationMethods.DEBUG_STEP : NavigationMethods.DEBUG_END));
    } else // the copy from the server into the code browser window
    if (useCurrentBrowseSource_ && currentBrowseSource_.length() > 0) {
        if (debugging) {
            // create the function name for the code browser by removing the
            // () indicator supplied by the server
            String functionName = environmentName_;
            int idx = functionName.indexOf('(');
            if (idx > 0) {
                functionName = functionName.substring(0, idx);
            }
            // omit qualifiers
            idx = functionName.indexOf("::");
            if (idx > 0) {
                functionName = functionName.substring(idx + 1);
                // :::, too
                if (functionName.startsWith(":"))
                    functionName = functionName.substring(1);
            }
            // create the function definition
            searchFunction_ = SearchPathFunctionDefinition.create(functionName, StringUtil.isNullOrEmpty(functionEnvName_) ? "debugging" : functionEnvName_, currentBrowseSource_, true);
            if (sourceChanged) {
                // if this is a different source file than we already have open,
                // open it 
                eventBus_.fireEvent(new CodeBrowserNavigationEvent(searchFunction_, currentBrowsePosition_.functionRelativePosition(currentFunctionLineNumber_), contextDepth_ == 1, false));
            } else if (currentBrowsePosition_.getLine() > 0) {
                // if this is the same one currently open, just move the 
                // highlight
                eventBus_.fireEvent(new CodeBrowserHighlightEvent(searchFunction_, currentBrowsePosition_.functionRelativePosition(currentFunctionLineNumber_)));
            }
        } else {
            eventBus_.fireEvent(new CodeBrowserFinishedEvent(searchFunction_));
        }
    }
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) CodeBrowserNavigationEvent(org.rstudio.studio.client.workbench.views.source.events.CodeBrowserNavigationEvent) OpenSourceFileEvent(org.rstudio.studio.client.common.filetypes.events.OpenSourceFileEvent) CodeBrowserHighlightEvent(org.rstudio.studio.client.workbench.views.source.events.CodeBrowserHighlightEvent) CodeBrowserFinishedEvent(org.rstudio.studio.client.workbench.views.source.events.CodeBrowserFinishedEvent) JsArrayString(com.google.gwt.core.client.JsArrayString) DebugFilePosition(org.rstudio.core.client.DebugFilePosition) FilePosition(org.rstudio.core.client.FilePosition)

Example 49 with FileSystemItem

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

the class RCompletionManager method goToFunctionDefinition.

public void goToFunctionDefinition() {
    // check for a file-local definition (intra-file navigation -- using
    // the active scope tree)
    AceEditor editor = (AceEditor) docDisplay_;
    if (editor != null) {
        TokenCursor cursor = editor.getSession().getMode().getRCodeModel().getTokenCursor();
        if (cursor.moveToPosition(editor.getCursorPosition(), true)) {
            // token (obstensibly a funciton name)
            if (cursor.isLeftBracket())
                cursor.moveToPreviousToken();
            // navigate (as this isn't the 'full' function name)
            if (cursor.moveToPreviousToken()) {
                if (cursor.isExtractionOperator())
                    return;
                cursor.moveToNextToken();
            }
            // if this is a string, try resolving that string as a file name
            if (cursor.hasType("string")) {
                String tokenValue = cursor.currentValue();
                String path = tokenValue.substring(1, tokenValue.length() - 1);
                FileSystemItem filePath = FileSystemItem.createFile(path);
                // This will show a dialog error if no such file exists; this
                // seems the most appropriate action in such a case.
                fileTypeRegistry_.editFile(filePath);
            }
            String functionName = cursor.currentValue();
            JsArray<ScopeFunction> scopes = editor.getAllFunctionScopes();
            for (int i = 0; i < scopes.length(); i++) {
                ScopeFunction scope = scopes.get(i);
                if (scope.getFunctionName().equals(functionName)) {
                    navigableSourceEditor_.navigateToPosition(SourcePosition.create(scope.getPreamble().getRow(), scope.getPreamble().getColumn()), true);
                    return;
                }
            }
        }
    }
    // intra-file navigation failed -- hit the server and find a definition
    // in the project index
    // determine current line and cursor position
    InputEditorLineWithCursorPosition lineWithPos = InputEditorUtil.getLineWithCursorPosition(input_);
    // delayed progress indicator
    final GlobalProgressDelayer progress = new GlobalProgressDelayer(globalDisplay_, 1000, "Searching for function definition...");
    server_.getObjectDefinition(lineWithPos.getLine(), lineWithPos.getPosition(), new ServerRequestCallback<ObjectDefinition>() {

        @Override
        public void onResponseReceived(ObjectDefinition def) {
            // dismiss progress
            progress.dismiss();
            // if we got a hit
            if (def.getObjectName() != null) {
                // search locally if a function navigator was provided
                if (navigableSourceEditor_ != null) {
                    // try to search for the function locally
                    SourcePosition position = navigableSourceEditor_.findFunctionPositionFromCursor(def.getObjectName());
                    if (position != null) {
                        navigableSourceEditor_.navigateToPosition(position, true);
                        // we're done
                        return;
                    }
                }
                // navigate to the file/loc
                if (def.getObjectType() == FileFunctionDefinition.OBJECT_TYPE) {
                    FileFunctionDefinition fileDef = def.getObjectData().cast();
                    fileTypeRegistry_.editFile(fileDef.getFile(), fileDef.getPosition());
                } else // search path definition
                if (def.getObjectType() == SearchPathFunctionDefinition.OBJECT_TYPE) {
                    SearchPathFunctionDefinition searchDef = def.getObjectData().cast();
                    eventBus_.fireEvent(new CodeBrowserNavigationEvent(searchDef));
                } else // finally, check to see if it's a data frame
                if (def.getObjectType() == DataDefinition.OBJECT_TYPE) {
                    eventBus_.fireEvent(new SendToConsoleEvent("View(" + def.getObjectName() + ")", true, false));
                }
            }
        }

        @Override
        public void onError(ServerError error) {
            progress.dismiss();
            globalDisplay_.showErrorMessage("Error Searching for Function", error.getUserMessage());
        }
    });
}
Also used : SearchPathFunctionDefinition(org.rstudio.studio.client.workbench.codesearch.model.SearchPathFunctionDefinition) InputEditorLineWithCursorPosition(org.rstudio.studio.client.workbench.views.console.shell.editor.InputEditorLineWithCursorPosition) ServerError(org.rstudio.studio.client.server.ServerError) GlobalProgressDelayer(org.rstudio.studio.client.common.GlobalProgressDelayer) AceEditor(org.rstudio.studio.client.workbench.views.source.editors.text.AceEditor) ObjectDefinition(org.rstudio.studio.client.workbench.codesearch.model.ObjectDefinition) ScopeFunction(org.rstudio.studio.client.workbench.views.source.editors.text.ScopeFunction) TokenCursor(org.rstudio.studio.client.workbench.views.source.editors.text.ace.TokenCursor) FileSystemItem(org.rstudio.core.client.files.FileSystemItem) CodeBrowserNavigationEvent(org.rstudio.studio.client.workbench.views.source.events.CodeBrowserNavigationEvent) SourcePosition(org.rstudio.studio.client.workbench.views.source.model.SourcePosition) SendToConsoleEvent(org.rstudio.studio.client.workbench.views.console.events.SendToConsoleEvent) FileFunctionDefinition(org.rstudio.studio.client.workbench.codesearch.model.FileFunctionDefinition)

Example 50 with FileSystemItem

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

the class FileDialog method shouldAccept.

/**
    * Validate the current state of the dialog. Subclasses can override
    * this but super.shouldAccept() MUST be the last validation that occurs.
    * @return true if the dialog is in a valid state for acceptance
    */
protected boolean shouldAccept() {
    browser_.setFilename(browser_.getFilename().trim());
    String filename = browser_.getFilename();
    if (filename.length() == 0)
        return false;
    int lastIndex = filename.lastIndexOf('/');
    if (lastIndex >= 0) {
        String dir = filename.substring(0, lastIndex);
        if (dir.length() == 0)
            dir = "/";
        String file = filename.substring(lastIndex + 1);
        // doesn't have list permissions.
        if (dir.equals("/shared")) {
            cd(filename);
            return false;
        }
        browser_.setFilename(file);
        browser_.setFilenameEnabled(false);
        attemptAcceptOnNextNavigate_ = true;
        cd(dir);
        return false;
    }
    String filenameValidationError = context_.validatePathElement(filename, true);
    if (filenameValidationError != null) {
        browser_.selectFilename();
        showError(filenameValidationError);
        return false;
    }
    if (navigateIfDirectory())
        return false;
    boolean useExactFilename = browser_.getSelectedValue() != null && browser_.getSelectedValue().equals(filename);
    if (!useExactFilename || getAlwaysMungeFilename()) {
        browser_.setFilename(mungeFilename(filename));
    }
    if (navigateIfDirectory())
        return false;
    FileSystemItem item = context_.itemForName(filename, true, false);
    if (item == null) {
        if (!allowNonexistentFile_) {
            showError("File does not exist");
            return false;
        }
    } else {
        if (item.isDirectory()) {
            assert false : "This case should be covered by navigateIfDirectory";
            return false;
        } else if (promptOnOverwrite_) {
            /* WARNING. showOverwritePrompt() MAY CAUSE accept() TO BE CALLED
                DIRECTLY. ALL OTHER VALIDATION *MUST* BE COMPLETE BEFORE
                CALLING showOverwritePrompt()!!! */
            showOverwritePrompt();
            return false;
        }
    }
    return true;
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem)

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