Search in sources :

Example 56 with FileSystemItem

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

the class ConsoleErrorFrame method showSourceForFrame.

private void showSourceForFrame(ErrorFrame frame) {
    FileSystemItem sourceFile = FileSystemItem.createFile(frame.getFileName());
    RStudioGinjector.INSTANCE.getEventBus().fireEvent(new OpenSourceFileEvent(sourceFile, FilePosition.create(frame.getLineNumber(), frame.getCharacterNumber()), FileTypeRegistry.R, NavigationMethods.HIGHLIGHT_LINE));
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) OpenSourceFileEvent(org.rstudio.studio.client.common.filetypes.events.OpenSourceFileEvent)

Example 57 with FileSystemItem

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

the class DebugCommander method highlightDebugPosition.

// Private methods ---------------------------------------------------------
private void highlightDebugPosition(LineData lineData, boolean finished) {
    FileSystemItem sourceFile = FileSystemItem.createFile(debugFile_);
    DebugFilePosition position = DebugFilePosition.create(lineData.getLineNumber(), lineData.getEndLineNumber(), lineData.getCharacterNumber(), lineData.getEndCharacterNumber());
    eventBus_.fireEvent(new OpenSourceFileEvent(sourceFile, (FilePosition) position.cast(), FileTypeRegistry.R, finished ? NavigationMethods.DEBUG_END : NavigationMethods.DEBUG_STEP));
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) OpenSourceFileEvent(org.rstudio.studio.client.common.filetypes.events.OpenSourceFileEvent) FilePosition(org.rstudio.core.client.FilePosition) DebugFilePosition(org.rstudio.core.client.DebugFilePosition) DebugFilePosition(org.rstudio.core.client.DebugFilePosition)

Example 58 with FileSystemItem

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

the class ProjectOpener method showOpenProjectDialog.

public void showOpenProjectDialog(FileSystemContext fsContext, ProjectsServerOperations server, String defaultLocation, int defaultType, boolean showNewSession, final ProgressOperationWithInput<OpenProjectParams> onCompleted) {
    initialize();
    // use the default dialog on desktop mode or single-session mode
    FileDialogs dialogs = RStudioGinjector.INSTANCE.getFileDialogs();
    if (Desktop.isDesktop() || !RStudioGinjector.INSTANCE.getSession().getSessionInfo().getMultiSession()) {
        dialogs.openFile("Open Project", fsContext, FileSystemItem.createDir(defaultLocation), "R Projects (*.Rproj)", true, new ProgressOperationWithInput<FileSystemItem>() {

            @Override
            public void execute(FileSystemItem input, final ProgressIndicator indicator) {
                final CommandWithArg<FileSystemItem> onProjectFileReady = new CommandWithArg<FileSystemItem>() {

                    @Override
                    public void execute(FileSystemItem item) {
                        onCompleted.execute(new OpenProjectParams(item, null, false), indicator);
                    }
                };
                // null return values here imply a cancellation
                if (input == null)
                    return;
                if (input.isDirectory()) {
                    final String rprojPath = input.completePath(input.getName() + ".Rproj");
                    final FileSystemItem rprojFile = FileSystemItem.createFile(rprojPath);
                    server_.createProjectFile(rprojFile.getPath(), new ServerRequestCallback<Boolean>() {

                        @Override
                        public void onResponseReceived(Boolean success) {
                            onProjectFileReady.execute(rprojFile);
                        }

                        @Override
                        public void onError(ServerError error) {
                            Debug.logError(error);
                            onProjectFileReady.execute(rprojFile);
                        }
                    });
                } else {
                    onProjectFileReady.execute(input);
                }
            }
        });
    } else {
        // in multi-session mode, we have a special dialog for opening projects
        WebFileDialogs webDialogs = (WebFileDialogs) dialogs;
        webDialogs.openProject(fsContext, FileSystemItem.createDir(defaultLocation), defaultType, showNewSession, onCompleted);
    }
}
Also used : OpenProjectParams(org.rstudio.studio.client.projects.model.OpenProjectParams) ServerError(org.rstudio.studio.client.server.ServerError) CommandWithArg(org.rstudio.core.client.CommandWithArg) WebFileDialogs(org.rstudio.studio.client.common.impl.WebFileDialogs) FileDialogs(org.rstudio.studio.client.common.FileDialogs) FileSystemItem(org.rstudio.core.client.files.FileSystemItem) WebFileDialogs(org.rstudio.studio.client.common.impl.WebFileDialogs) ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) ServerRequestCallback(org.rstudio.studio.client.server.ServerRequestCallback)

Example 59 with FileSystemItem

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

the class Projects method onOpenProjectFile.

@Override
public void onOpenProjectFile(final OpenProjectFileEvent event) {
    // project options for current project
    FileSystemItem projFile = event.getFile();
    if (projFile.getPath().equals(session_.getSessionInfo().getActiveProjectFile())) {
        onProjectOptions();
        return;
    }
    // prompt to confirm
    String projectPath = projFile.getParentPathString();
    globalDisplay_.showYesNoMessage(GlobalDisplay.MSG_QUESTION, "Confirm Open Project", "Do you want to open the project " + projectPath + "?", new Operation() {

        public void execute() {
            switchToProject(event.getFile().getPath());
        }
    }, true);
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) Operation(org.rstudio.core.client.widget.Operation)

Example 60 with FileSystemItem

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

the class NewPackagePage method validateAsync.

@Override
protected void validateAsync(final NewProjectResult input, final OperationWithInput<Boolean> onValidated) {
    // validate package name first
    String packageName = txtProjectName_.getText().trim();
    if (!isPackageNameValid(packageName)) {
        globalDisplay_.showMessage(MessageDialog.WARNING, "Error", "Invalid package name '" + packageName + "'. Package names " + "should start with a letter, and contain only letters and numbers.");
        onValidated.execute(false);
        return;
    }
    final FileSystemItem projFile = FileSystemItem.createFile(input.getProjectFile());
    final FileSystemItem projDir = projFile.getParentPath();
    server_.stat(projDir.getPath(), new ServerRequestCallback<FileSystemItem>() {

        @Override
        public void onResponseReceived(final FileSystemItem item) {
            // no file at this path -- safe for use
            if (!item.exists()) {
                onValidated.execute(true);
                return;
            }
            // if it was a file, bail
            if (!item.isDirectory()) {
                globalDisplay_.showMessage(MessageDialog.WARNING, "Error", "A file already exists at path '" + item.getPath() + "'");
                onValidated.execute(false);
                return;
            }
            // check if this directory is empty
            server_.listFiles(item, false, new ServerRequestCallback<DirectoryListing>() {

                @Override
                public void onResponseReceived(DirectoryListing listing) {
                    boolean ok = true;
                    JsArray<FileSystemItem> children = listing.getFiles();
                    for (FileSystemItem child : JsUtil.asIterable(children)) {
                        boolean canIgnore = child.getExtension().equals(".Rproj") || child.getName().startsWith(".");
                        if (canIgnore)
                            continue;
                        ok = false;
                        break;
                    }
                    if (!ok) {
                        globalDisplay_.showMessage(MessageDialog.WARNING, "Error", "Directory '" + item.getPath() + "' already exists and is not empty.");
                    }
                    onValidated.execute(ok);
                }

                @Override
                public void onError(ServerError error) {
                    Debug.logError(error);
                    onValidated.execute(true);
                }
            });
        }

        @Override
        public void onError(ServerError error) {
            Debug.logError(error);
            onValidated.execute(true);
        }
    });
}
Also used : DirectoryListing(org.rstudio.studio.client.workbench.views.files.model.DirectoryListing) FileSystemItem(org.rstudio.core.client.files.FileSystemItem) ServerError(org.rstudio.studio.client.server.ServerError) ServerRequestCallback(org.rstudio.studio.client.server.ServerRequestCallback)

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