@Inject
  public GeneralPreferencesPane(
      RemoteFileSystemContext fsContext,
      FileDialogs fileDialogs,
      UIPrefs prefs,
      Session session,
      final GlobalDisplay globalDisplay,
      WorkbenchContext context) {
    fsContext_ = fsContext;
    fileDialogs_ = fileDialogs;
    prefs_ = prefs;
    session_ = session;

    RVersionsInfo versionsInfo = context.getRVersionsInfo();

    if (Desktop.isDesktop()) {
      if (Desktop.getFrame().canChooseRVersion()) {
        rVersion_ =
            new TextBoxWithButton(
                "R version:",
                "Change...",
                new ClickHandler() {
                  public void onClick(ClickEvent event) {
                    String ver = Desktop.getFrame().chooseRVersion();
                    if (!StringUtil.isNullOrEmpty(ver)) {
                      rVersion_.setText(ver);

                      globalDisplay.showMessage(
                          MessageDialog.INFO,
                          "Change R Version",
                          "You need to quit and re-open RStudio "
                              + "in order for this change to take effect.");
                    }
                  }
                });
        rVersion_.setWidth("100%");
        rVersion_.setText(Desktop.getFrame().getRVersion());
        spaced(rVersion_);
        add(rVersion_);
      }
    } else if (versionsInfo.isMultiVersion()) {
      rServerRVersion_ = new RVersionSelectWidget(versionsInfo.getAvailableRVersions());
      add(tight(rServerRVersion_));

      rememberRVersionForProjects_ = new CheckBox("Restore last used R version for projects");

      rememberRVersionForProjects_.setValue(true);
      Style style = rememberRVersionForProjects_.getElement().getStyle();
      style.setMarginTop(5, Unit.PX);
      style.setMarginBottom(12, Unit.PX);
      add(rememberRVersionForProjects_);
    }

    Label defaultLabel = new Label("Default working directory (when not in a project):");
    nudgeRight(defaultLabel);
    add(tight(defaultLabel));
    add(dirChooser_ = new DirectoryChooserTextBox(null, null, fileDialogs_, fsContext_));
    spaced(dirChooser_);
    nudgeRight(dirChooser_);
    textBoxWithChooser(dirChooser_);

    restoreLastProject_ = new CheckBox("Restore most recently opened project at startup");
    lessSpaced(restoreLastProject_);
    add(restoreLastProject_);

    add(
        checkboxPref(
            "Restore previously open source documents at startup",
            prefs_.restoreSourceDocuments()));

    add(loadRData_ = new CheckBox("Restore .RData into workspace at startup"));
    lessSpaced(loadRData_);

    saveWorkspace_ =
        new SelectWidget(
            "Save workspace to .RData on exit:", new String[] {"Always", "Never", "Ask"});
    spaced(saveWorkspace_);
    add(saveWorkspace_);

    alwaysSaveHistory_ = new CheckBox("Always save history (even when not saving .RData)");
    lessSpaced(alwaysSaveHistory_);
    add(alwaysSaveHistory_);

    removeHistoryDuplicates_ = new CheckBox("Remove duplicate entries in history");
    spaced(removeHistoryDuplicates_);
    add(removeHistoryDuplicates_);

    showLastDotValue_ = new CheckBox("Show .Last.value in environment listing");
    lessSpaced(showLastDotValue_);
    add(showLastDotValue_);

    rProfileOnResume_ = new CheckBox("Run Rprofile when resuming suspended session");
    spaced(rProfileOnResume_);
    if (!Desktop.isDesktop()) add(rProfileOnResume_);

    // The error handler features require source references; if this R
    // version doesn't support them, don't show these options.
    if (session_.getSessionInfo().getHaveSrcrefAttribute()) {
      add(
          checkboxPref(
              "Use debug error handler only when my code contains errors",
              prefs_.handleErrorsInUserCodeOnly()));
      CheckBox chkTracebacks =
          checkboxPref(
              "Automatically expand tracebacks in error inspector",
              prefs_.autoExpandErrorTracebacks());
      chkTracebacks.getElement().getStyle().setMarginBottom(15, Unit.PX);
      add(chkTracebacks);
    }

    // provide check for updates option in desktop mode when not
    // already globally disabled
    if (Desktop.isDesktop() && !session.getSessionInfo().getDisableCheckForUpdates()) {
      add(checkboxPref("Automatically notify me of updates to RStudio", prefs_.checkForUpdates()));
    }

    saveWorkspace_.setEnabled(false);
    loadRData_.setEnabled(false);
    dirChooser_.setEnabled(false);
    alwaysSaveHistory_.setEnabled(false);
    removeHistoryDuplicates_.setEnabled(false);
    rProfileOnResume_.setEnabled(false);
    showLastDotValue_.setEnabled(false);
    restoreLastProject_.setEnabled(false);
  }
示例#2
0
  public static void handleUnsavedChanges(
      final int saveAction,
      String caption,
      final SourceShim sourceShim,
      final WorkbenchContext workbenchContext,
      final UnsavedChangesTarget globalEnvTarget,
      final QuitContext quitContext) {
    // see what the unsaved changes situation is and prompt accordingly
    ArrayList<UnsavedChangesTarget> unsavedSourceDocs = sourceShim.getUnsavedChanges();

    // no unsaved changes at all
    if (saveAction != SaveAction.SAVEASK && unsavedSourceDocs.size() == 0) {
      // define quit operation
      final Operation quitOperation =
          new Operation() {
            public void execute() {
              quitContext.onReadyToQuit(saveAction == SaveAction.SAVE);
            }
          };

      // if this is a quit session then we always prompt
      if (isQuitSession()) {
        RStudioGinjector.INSTANCE
            .getGlobalDisplay()
            .showYesNoMessage(
                MessageDialog.QUESTION,
                caption,
                "Are you sure you want to quit the R session?",
                quitOperation,
                true);
      } else {
        quitOperation.execute();
      }

      return;
    }

    // just an unsaved environment
    if (unsavedSourceDocs.size() == 0 && workbenchContext != null) {
      // confirm quit and do it
      String prompt = "Save workspace image to " + workbenchContext.getREnvironmentPath() + "?";
      RStudioGinjector.INSTANCE
          .getGlobalDisplay()
          .showYesNoMessage(
              GlobalDisplay.MSG_QUESTION,
              caption,
              prompt,
              true,
              new Operation() {
                public void execute() {
                  quitContext.onReadyToQuit(true);
                }
              },
              new Operation() {
                public void execute() {
                  quitContext.onReadyToQuit(false);
                }
              },
              new Operation() {
                public void execute() {}
              },
              "Save",
              "Don't Save",
              true);
    }

    // a single unsaved document (can be any document in desktop mode, but
    // must be from the main window in web mode)
    else if (saveAction != SaveAction.SAVEASK
        && unsavedSourceDocs.size() == 1
        && (Desktop.isDesktop() || !(unsavedSourceDocs.get(0) instanceof UnsavedChangesItem))) {
      sourceShim.saveWithPrompt(
          unsavedSourceDocs.get(0),
          sourceShim.revertUnsavedChangesBeforeExitCommand(
              new Command() {
                @Override
                public void execute() {
                  quitContext.onReadyToQuit(saveAction == SaveAction.SAVE);
                }
              }),
          null);
    }

    // multiple save targets
    else {
      ArrayList<UnsavedChangesTarget> unsaved = new ArrayList<UnsavedChangesTarget>();
      if (saveAction == SaveAction.SAVEASK && globalEnvTarget != null) unsaved.add(globalEnvTarget);
      unsaved.addAll(unsavedSourceDocs);
      new UnsavedChangesDialog(
              caption,
              unsaved,
              new OperationWithInput<UnsavedChangesDialog.Result>() {

                @Override
                public void execute(Result result) {
                  ArrayList<UnsavedChangesTarget> saveTargets = result.getSaveTargets();

                  // remote global env target from list (if specified) and
                  // compute the saveChanges value
                  boolean saveGlobalEnv = saveAction == SaveAction.SAVE;
                  if (saveAction == SaveAction.SAVEASK && globalEnvTarget != null)
                    saveGlobalEnv = saveTargets.remove(globalEnvTarget);
                  final boolean saveChanges = saveGlobalEnv;

                  // save specified documents and then quit
                  sourceShim.handleUnsavedChangesBeforeExit(
                      saveTargets,
                      new Command() {
                        @Override
                        public void execute() {
                          quitContext.onReadyToQuit(saveChanges);
                        }
                      });
                }
              },

              // no cancel operation
              null)
          .showModal();
    }
  }