Search in sources :

Example 1 with HistoryPrefs

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

the class GeneralPreferencesPane method initialize.

@Override
protected void initialize(RPrefs rPrefs) {
    // general prefs
    final GeneralPrefs generalPrefs = rPrefs.getGeneralPrefs();
    showServerHomePage_.setEnabled(true);
    reuseSessionsForProjectLinks_.setEnabled(true);
    saveWorkspace_.setEnabled(true);
    loadRData_.setEnabled(true);
    dirChooser_.setEnabled(true);
    showServerHomePage_.setValue(generalPrefs.getShowUserHomePage());
    reuseSessionsForProjectLinks_.setValue(generalPrefs.getReuseSessionsForProjectLinks());
    int saveWorkspaceIndex;
    switch(generalPrefs.getSaveAction()) {
        case SaveAction.NOSAVE:
            saveWorkspaceIndex = 1;
            break;
        case SaveAction.SAVE:
            saveWorkspaceIndex = 0;
            break;
        case SaveAction.SAVEASK:
        default:
            saveWorkspaceIndex = 2;
            break;
    }
    saveWorkspace_.getListBox().setSelectedIndex(saveWorkspaceIndex);
    Scheduler.get().scheduleDeferred(new ScheduledCommand() {

        @Override
        public void execute() {
            server_.getTerminalShells(new ServerRequestCallback<JsArray<TerminalShellInfo>>() {

                @Override
                public void onResponseReceived(JsArray<TerminalShellInfo> shells) {
                    int currentShell = generalPrefs.getDefaultTerminalShellValue();
                    int currentShellIndex = 0;
                    GeneralPreferencesPane.this.terminalShell_.getListBox().clear();
                    for (int i = 0; i < shells.length(); i++) {
                        TerminalShellInfo info = shells.get(i);
                        GeneralPreferencesPane.this.terminalShell_.addChoice(info.getShellName(), Integer.toString(info.getShellType()));
                        if (info.getShellType() == currentShell)
                            currentShellIndex = i;
                    }
                    if (GeneralPreferencesPane.this.terminalShell_.getListBox().getItemCount() > 0) {
                        GeneralPreferencesPane.this.terminalShell_.setEnabled((true));
                        GeneralPreferencesPane.this.terminalShell_.getListBox().setSelectedIndex(currentShellIndex);
                    }
                }

                @Override
                public void onError(ServerError error) {
                }
            });
        }
    });
    loadRData_.setValue(generalPrefs.getLoadRData());
    dirChooser_.setText(generalPrefs.getInitialWorkingDirectory());
    // history prefs
    HistoryPrefs historyPrefs = rPrefs.getHistoryPrefs();
    alwaysSaveHistory_.setEnabled(true);
    removeHistoryDuplicates_.setEnabled(true);
    alwaysSaveHistory_.setValue(historyPrefs.getAlwaysSave());
    removeHistoryDuplicates_.setValue(historyPrefs.getRemoveDuplicates());
    rProfileOnResume_.setValue(generalPrefs.getRprofileOnResume());
    rProfileOnResume_.setEnabled(true);
    showLastDotValue_.setValue(generalPrefs.getShowLastDotValue());
    showLastDotValue_.setEnabled(true);
    if (rServerRVersion_ != null)
        rServerRVersion_.setRVersion(generalPrefs.getDefaultRVersion());
    if (rememberRVersionForProjects_ != null) {
        rememberRVersionForProjects_.setValue(generalPrefs.getRestoreProjectRVersion());
    }
    // projects prefs
    ProjectsPrefs projectsPrefs = rPrefs.getProjectsPrefs();
    restoreLastProject_.setEnabled(true);
    restoreLastProject_.setValue(projectsPrefs.getRestoreLastProject());
}
Also used : GeneralPrefs(org.rstudio.studio.client.workbench.prefs.model.GeneralPrefs) TerminalShellInfo(org.rstudio.studio.client.workbench.views.terminal.TerminalShellInfo) JsArray(com.google.gwt.core.client.JsArray) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) ServerError(org.rstudio.studio.client.server.ServerError) ProjectsPrefs(org.rstudio.studio.client.workbench.prefs.model.ProjectsPrefs) ServerRequestCallback(org.rstudio.studio.client.server.ServerRequestCallback) HistoryPrefs(org.rstudio.studio.client.workbench.prefs.model.HistoryPrefs)

Example 2 with HistoryPrefs

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

the class GeneralPreferencesPane method onApply.

@Override
public boolean onApply(RPrefs rPrefs) {
    boolean restartRequired = super.onApply(rPrefs);
    if (saveWorkspace_.isEnabled()) {
        int saveAction;
        switch(saveWorkspace_.getListBox().getSelectedIndex()) {
            case 0:
                saveAction = SaveAction.SAVE;
                break;
            case 1:
                saveAction = SaveAction.NOSAVE;
                break;
            case 2:
            default:
                saveAction = SaveAction.SAVEASK;
                break;
        }
        int defaultShell = TerminalShellInfo.SHELL_DEFAULT;
        if (terminalShell_ != null && terminalShell_.isEnabled()) {
            int idx = terminalShell_.getListBox().getSelectedIndex();
            String valStr = terminalShell_.getListBox().getValue(idx);
            defaultShell = StringUtil.parseInt(valStr, TerminalShellInfo.SHELL_DEFAULT);
        }
        // set general prefs
        GeneralPrefs generalPrefs = GeneralPrefs.create(showServerHomePage_.getValue(), reuseSessionsForProjectLinks_.getValue(), saveAction, loadRData_.getValue(), rProfileOnResume_.getValue(), dirChooser_.getText(), getDefaultRVersion(), getRestoreProjectRVersion(), showLastDotValue_.getValue(), defaultShell);
        rPrefs.setGeneralPrefs(generalPrefs);
        // set history prefs
        HistoryPrefs historyPrefs = HistoryPrefs.create(alwaysSaveHistory_.getValue(), removeHistoryDuplicates_.getValue());
        rPrefs.setHistoryPrefs(historyPrefs);
        // set projects prefs
        ProjectsPrefs projectsPrefs = ProjectsPrefs.create(restoreLastProject_.getValue());
        rPrefs.setProjectsPrefs(projectsPrefs);
    }
    return restartRequired;
}
Also used : GeneralPrefs(org.rstudio.studio.client.workbench.prefs.model.GeneralPrefs) ProjectsPrefs(org.rstudio.studio.client.workbench.prefs.model.ProjectsPrefs) HistoryPrefs(org.rstudio.studio.client.workbench.prefs.model.HistoryPrefs)

Aggregations

GeneralPrefs (org.rstudio.studio.client.workbench.prefs.model.GeneralPrefs)2 HistoryPrefs (org.rstudio.studio.client.workbench.prefs.model.HistoryPrefs)2 ProjectsPrefs (org.rstudio.studio.client.workbench.prefs.model.ProjectsPrefs)2 JsArray (com.google.gwt.core.client.JsArray)1 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 ServerError (org.rstudio.studio.client.server.ServerError)1 ServerRequestCallback (org.rstudio.studio.client.server.ServerRequestCallback)1 TerminalShellInfo (org.rstudio.studio.client.workbench.views.terminal.TerminalShellInfo)1