Search in sources :

Example 1 with UIPrefs

use of org.rstudio.studio.client.workbench.prefs.model.UIPrefs in project rstudio by rstudio.

the class Projects method createNewProject.

private void createNewProject(final NewProjectResult newProject, final boolean saveChanges) {
    // This gets a little crazy. We have several pieces of asynchronous logic
    // that each may or may not need to be executed, depending on the type
    // of project being created and on whether the previous pieces of logic
    // succeed. Plus we have this ProgressIndicator that needs to be fed
    // properly.
    final ProgressIndicator indicator = globalDisplay_.getProgressIndicator("Error Creating Project");
    // Here's the command queue that will hold the various operations.
    final SerializedCommandQueue createProjectCmds = new SerializedCommandQueue();
    // WARNING: When calling addCommand, BE SURE TO PASS FALSE as the second
    // argument, to delay running of the commands until they are all
    // scheduled.
    // First, attempt to update the default project location pref
    createProjectCmds.addCommand(new SerializedCommand() {

        @Override
        public void onExecute(final Command continuation) {
            UIPrefs uiPrefs = pUIPrefs_.get();
            // update default project location pref if necessary
            if ((newProject.getNewDefaultProjectLocation() != null) || (newProject.getCreateGitRepo() != uiPrefs.newProjGitInit().getValue())) {
                indicator.onProgress("Saving defaults...");
                if (newProject.getNewDefaultProjectLocation() != null) {
                    uiPrefs.defaultProjectLocation().setGlobalValue(newProject.getNewDefaultProjectLocation());
                }
                if (newProject.getCreateGitRepo() != uiPrefs.newProjGitInit().getValue()) {
                    uiPrefs.newProjGitInit().setGlobalValue(newProject.getCreateGitRepo());
                }
                if (newProject.getUsePackrat() != uiPrefs.newProjUsePackrat().getValue()) {
                    uiPrefs.newProjUsePackrat().setGlobalValue(newProject.getUsePackrat());
                }
                // call the server -- in all cases continue on with
                // creating the project (swallow errors updating the pref)
                projServer_.setUiPrefs(session_.getSessionInfo().getUiPrefs(), new VoidServerRequestCallback(indicator) {

                    @Override
                    public void onResponseReceived(Void response) {
                        continuation.execute();
                    }

                    @Override
                    public void onError(ServerError error) {
                        super.onError(error);
                        continuation.execute();
                    }
                });
            } else {
                continuation.execute();
            }
        }
    }, false);
    // Next, if necessary, clone a repo
    if (newProject.getVcsCloneOptions() != null) {
        createProjectCmds.addCommand(new SerializedCommand() {

            @Override
            public void onExecute(final Command continuation) {
                VcsCloneOptions cloneOptions = newProject.getVcsCloneOptions();
                if (cloneOptions.getVcsName().equals((VCSConstants.GIT_ID)))
                    indicator.onProgress("Cloning Git repository...");
                else
                    indicator.onProgress("Checking out SVN repository...");
                gitServer_.vcsClone(cloneOptions, new ServerRequestCallback<ConsoleProcess>() {

                    @Override
                    public void onResponseReceived(ConsoleProcess proc) {
                        final ConsoleProgressDialog consoleProgressDialog = new ConsoleProgressDialog(proc, gitServer_);
                        consoleProgressDialog.showModal();
                        proc.addProcessExitHandler(new ProcessExitEvent.Handler() {

                            @Override
                            public void onProcessExit(ProcessExitEvent event) {
                                if (event.getExitCode() == 0) {
                                    consoleProgressDialog.hide();
                                    continuation.execute();
                                } else {
                                    indicator.onCompleted();
                                }
                            }
                        });
                    }

                    @Override
                    public void onError(ServerError error) {
                        Debug.logError(error);
                        indicator.onError(error.getUserMessage());
                    }
                });
            }
        }, false);
    }
    // Next, create the project itself -- depending on the type, this
    // could involve creating an R package, or Shiny application, and so on.
    createProjectCmds.addCommand(new SerializedCommand() {

        @Override
        public void onExecute(final Command continuation) {
            // Validate the package name if we're creating a package
            if (newProject.getNewPackageOptions() != null) {
                final String packageName = newProject.getNewPackageOptions().getPackageName();
                if (!PACKAGE_NAME_PATTERN.test(packageName)) {
                    indicator.onError("Invalid package name '" + packageName + "': " + "package names must start with a letter, and contain " + "only letters and numbers.");
                    return;
                }
            }
            indicator.onProgress("Creating project...");
            if (newProject.getNewPackageOptions() == null) {
                projServer_.createProject(newProject.getProjectFile(), newProject.getNewPackageOptions(), newProject.getNewShinyAppOptions(), newProject.getProjectTemplateOptions(), new VoidServerRequestCallback(indicator) {

                    @Override
                    public void onSuccess() {
                        continuation.execute();
                    }
                });
            } else {
                String projectFile = newProject.getProjectFile();
                String packageDirectory = projectFile.substring(0, projectFile.lastIndexOf('/'));
                projServer_.packageSkeleton(newProject.getNewPackageOptions().getPackageName(), packageDirectory, newProject.getNewPackageOptions().getCodeFiles(), newProject.getNewPackageOptions().getUsingRcpp(), new ServerRequestCallback<RResult<Void>>() {

                    @Override
                    public void onResponseReceived(RResult<Void> response) {
                        if (response.failed())
                            indicator.onError(response.errorMessage());
                        else
                            continuation.execute();
                    }

                    @Override
                    public void onError(ServerError error) {
                        Debug.logError(error);
                        indicator.onError(error.getUserMessage());
                    }
                });
            }
        }
    }, false);
    // Next, initialize a git repo if requested
    if (newProject.getCreateGitRepo()) {
        createProjectCmds.addCommand(new SerializedCommand() {

            @Override
            public void onExecute(final Command continuation) {
                indicator.onProgress("Initializing git repository...");
                String projDir = FileSystemItem.createFile(newProject.getProjectFile()).getParentPathString();
                gitServer_.gitInitRepo(projDir, new VoidServerRequestCallback(indicator) {

                    @Override
                    public void onSuccess() {
                        continuation.execute();
                    }

                    @Override
                    public void onFailure() {
                        continuation.execute();
                    }
                });
            }
        }, false);
    }
    // Generate a new packrat project
    if (newProject.getUsePackrat()) {
        createProjectCmds.addCommand(new SerializedCommand() {

            @Override
            public void onExecute(final Command continuation) {
                indicator.onProgress("Initializing packrat project...");
                String projDir = FileSystemItem.createFile(newProject.getProjectFile()).getParentPathString();
                packratServer_.packratBootstrap(projDir, false, new VoidServerRequestCallback(indicator) {

                    @Override
                    public void onSuccess() {
                        continuation.execute();
                    }
                });
            }
        }, false);
    }
    if (newProject.getOpenInNewWindow()) {
        createProjectCmds.addCommand(new SerializedCommand() {

            @Override
            public void onExecute(final Command continuation) {
                FileSystemItem project = FileSystemItem.createFile(newProject.getProjectFile());
                if (Desktop.isDesktop()) {
                    Desktop.getFrame().openProjectInNewWindow(project.getPath());
                    continuation.execute();
                } else {
                    indicator.onProgress("Preparing to open project...");
                    serverOpenProjectInNewWindow(project, newProject.getRVersion(), continuation);
                }
            }
        }, false);
    }
    // If we get here, dismiss the progress indicator
    createProjectCmds.addCommand(new SerializedCommand() {

        @Override
        public void onExecute(Command continuation) {
            indicator.onCompleted();
            if (!newProject.getOpenInNewWindow()) {
                applicationQuit_.performQuit(saveChanges, newProject.getProjectFile(), newProject.getRVersion());
            }
            continuation.execute();
        }
    }, false);
    // Now set it all in motion!
    createProjectCmds.run();
}
Also used : ConsoleProgressDialog(org.rstudio.studio.client.workbench.views.vcs.common.ConsoleProgressDialog) VcsCloneOptions(org.rstudio.studio.client.common.vcs.VcsCloneOptions) SerializedCommand(org.rstudio.core.client.SerializedCommand) SerializedCommandQueue(org.rstudio.core.client.SerializedCommandQueue) ServerError(org.rstudio.studio.client.server.ServerError) FileSystemItem(org.rstudio.core.client.files.FileSystemItem) Command(com.google.gwt.user.client.Command) SerializedCommand(org.rstudio.core.client.SerializedCommand) ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) ConsoleProcess(org.rstudio.studio.client.common.console.ConsoleProcess) VoidServerRequestCallback(org.rstudio.studio.client.server.VoidServerRequestCallback) VoidServerRequestCallback(org.rstudio.studio.client.server.VoidServerRequestCallback) ServerRequestCallback(org.rstudio.studio.client.server.ServerRequestCallback) UIPrefs(org.rstudio.studio.client.workbench.prefs.model.UIPrefs) Void(org.rstudio.studio.client.server.Void) ProcessExitEvent(org.rstudio.studio.client.common.console.ProcessExitEvent) RResult(org.rstudio.studio.client.server.remote.RResult)

Example 2 with UIPrefs

use of org.rstudio.studio.client.workbench.prefs.model.UIPrefs in project rstudio by rstudio.

the class NewDirectoryPage method onAddWidgets.

@Override
protected void onAddWidgets() {
    NewProjectResources.Styles styles = NewProjectResources.INSTANCE.styles();
    HorizontalPanel panel = new HorizontalPanel();
    panel.addStyleName(styles.wizardMainColumn());
    // create the dir name label
    dirNameLabel_ = new Label("Directory name:");
    dirNameLabel_.addStyleName(styles.wizardTextEntryLabel());
    // top panel widgets
    onAddTopPanelWidgets(panel);
    // dir name
    VerticalPanel namePanel = new VerticalPanel();
    namePanel.addStyleName(styles.newProjectDirectoryName());
    namePanel.add(dirNameLabel_);
    txtProjectName_ = new TextBox();
    txtProjectName_.setWidth("100%");
    txtProjectName_.getElement().setAttribute("spellcheck", "false");
    namePanel.add(txtProjectName_);
    panel.add(namePanel);
    addWidget(panel);
    onAddBodyWidgets();
    addSpacer();
    // project dir
    newProjectParent_ = new DirectoryChooserTextBox("Create project as subdirectory of:", txtProjectName_);
    addWidget(newProjectParent_);
    // if git is available then add git init
    UIPrefs uiPrefs = RStudioGinjector.INSTANCE.getUIPrefs();
    SessionInfo sessionInfo = RStudioGinjector.INSTANCE.getSession().getSessionInfo();
    HorizontalPanel optionsPanel = null;
    if (getOptionsSideBySide())
        optionsPanel = new HorizontalPanel();
    chkGitInit_ = new CheckBox("Create a git repository");
    chkGitInit_.addStyleName(styles.wizardCheckbox());
    if (sessionInfo.isVcsAvailable(VCSConstants.GIT_ID)) {
        chkGitInit_.setValue(uiPrefs.newProjGitInit().getValue());
        chkGitInit_.getElement().getStyle().setMarginRight(7, Unit.PX);
        if (optionsPanel != null) {
            optionsPanel.add(chkGitInit_);
        } else {
            addSpacer();
            addWidget(chkGitInit_);
        }
    }
    // Initialize project with packrat
    chkPackratInit_ = new CheckBox("Use packrat with this project");
    chkPackratInit_.setValue(uiPrefs.newProjUsePackrat().getValue());
    if (!sessionInfo.getPackratAvailable()) {
        chkPackratInit_.setValue(false);
        chkPackratInit_.setVisible(false);
    }
    if (optionsPanel != null) {
        optionsPanel.add(chkPackratInit_);
    } else {
        addSpacer();
        addWidget(chkPackratInit_);
    }
    if (optionsPanel != null) {
        addSpacer();
        addWidget(optionsPanel);
    }
}
Also used : VerticalPanel(com.google.gwt.user.client.ui.VerticalPanel) CheckBox(com.google.gwt.user.client.ui.CheckBox) HorizontalPanel(com.google.gwt.user.client.ui.HorizontalPanel) Label(com.google.gwt.user.client.ui.Label) SessionInfo(org.rstudio.studio.client.workbench.model.SessionInfo) TextBox(com.google.gwt.user.client.ui.TextBox) DirectoryChooserTextBox(org.rstudio.core.client.widget.DirectoryChooserTextBox) DirectoryChooserTextBox(org.rstudio.core.client.widget.DirectoryChooserTextBox) UIPrefs(org.rstudio.studio.client.workbench.prefs.model.UIPrefs)

Example 3 with UIPrefs

use of org.rstudio.studio.client.workbench.prefs.model.UIPrefs in project rstudio by rstudio.

the class ShinyApplication method setShinyViewerType.

private void setShinyViewerType(int viewerType) {
    UIPrefs prefs = pPrefs_.get();
    prefs.shinyViewerType().setGlobalValue(viewerType);
    prefs.writeUIPrefs();
    // snap the app into the new location
    if (currentViewType_ != viewerType && params_ != null) {
        // the old instance
        if (currentViewType_ == ShinyViewerType.SHINY_VIEWER_PANE || currentViewType_ == ShinyViewerType.SHINY_VIEWER_WINDOW) {
            if (currentViewType_ == ShinyViewerType.SHINY_VIEWER_WINDOW) {
                stopOnNextClose_ = false;
                satelliteManager_.closeSatelliteWindow(ShinyApplicationSatellite.NAME);
            } else {
                eventBus_.fireEvent(new ViewerClearedEvent(false));
            }
        }
        // assign new viewer type
        currentViewType_ = viewerType;
        params_.setViewerType(viewerType);
        if (currentViewType_ == ShinyViewerType.SHINY_VIEWER_PANE || currentViewType_ == ShinyViewerType.SHINY_VIEWER_WINDOW || currentViewType_ == ShinyViewerType.SHINY_VIEWER_BROWSER) {
            eventBus_.fireEvent(new ShinyApplicationStatusEvent(params_));
        }
    }
}
Also used : ViewerClearedEvent(org.rstudio.studio.client.workbench.views.viewer.events.ViewerClearedEvent) ShinyApplicationStatusEvent(org.rstudio.studio.client.shiny.events.ShinyApplicationStatusEvent) UIPrefs(org.rstudio.studio.client.workbench.prefs.model.UIPrefs)

Example 4 with UIPrefs

use of org.rstudio.studio.client.workbench.prefs.model.UIPrefs 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 5 with UIPrefs

use of org.rstudio.studio.client.workbench.prefs.model.UIPrefs in project rstudio by rstudio.

the class ChunkOutputStream method showErrorOutput.

@Override
public void showErrorOutput(UnhandledError err) {
    hasErrors_ = true;
    // error UX
    if (err.getErrorFrames() != null && err.getErrorFrames().length() < 2) {
        flushQueuedErrors();
        return;
    }
    int idx = queuedError_.indexOf(err.getErrorMessage());
    if (idx >= 0) {
        // emit any messages queued prior to the error
        if (idx > 0) {
            renderConsoleOutput(queuedError_.substring(0, idx), classOfOutput(ChunkConsolePage.CONSOLE_ERROR));
            initializeOutput(RmdChunkOutputUnit.TYPE_ERROR);
        }
        // leave messages following the error in the queue
        queuedError_ = queuedError_.substring(idx + err.getErrorMessage().length());
    } else {
        // flush any irrelevant messages from the stream
        flushQueuedErrors();
    }
    UIPrefs prefs = RStudioGinjector.INSTANCE.getUIPrefs();
    ConsoleError error = new ConsoleError(err, prefs.getThemeErrorClass(), this, null);
    error.setTracebackVisible(prefs.autoExpandErrorTracebacks().getValue());
    add(error);
    flushQueuedErrors();
    onHeightChanged();
}
Also used : ConsoleError(org.rstudio.studio.client.common.debugging.ui.ConsoleError) UIPrefs(org.rstudio.studio.client.workbench.prefs.model.UIPrefs)

Aggregations

UIPrefs (org.rstudio.studio.client.workbench.prefs.model.UIPrefs)5 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)2 ProgressIndicator (org.rstudio.core.client.widget.ProgressIndicator)2 ServerError (org.rstudio.studio.client.server.ServerError)2 Command (com.google.gwt.user.client.Command)1 CheckBox (com.google.gwt.user.client.ui.CheckBox)1 HorizontalPanel (com.google.gwt.user.client.ui.HorizontalPanel)1 Label (com.google.gwt.user.client.ui.Label)1 TextBox (com.google.gwt.user.client.ui.TextBox)1 VerticalPanel (com.google.gwt.user.client.ui.VerticalPanel)1 SerializedCommand (org.rstudio.core.client.SerializedCommand)1 SerializedCommandQueue (org.rstudio.core.client.SerializedCommandQueue)1 Size (org.rstudio.core.client.Size)1 DirectoryChooserTextBox (org.rstudio.core.client.widget.DirectoryChooserTextBox)1 OperationWithInput (org.rstudio.core.client.widget.OperationWithInput)1 ConsoleProcess (org.rstudio.studio.client.common.console.ConsoleProcess)1 ProcessExitEvent (org.rstudio.studio.client.common.console.ProcessExitEvent)1 ConsoleError (org.rstudio.studio.client.common.debugging.ui.ConsoleError)1 VcsCloneOptions (org.rstudio.studio.client.common.vcs.VcsCloneOptions)1 ServerRequestCallback (org.rstudio.studio.client.server.ServerRequestCallback)1