use of org.rstudio.studio.client.workbench.prefs.model.GeneralPrefs 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());
}
use of org.rstudio.studio.client.workbench.prefs.model.GeneralPrefs 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;
}
Aggregations