Esempio n. 1
0
 @Override
 public void onOpenProjectNewWindow(OpenProjectNewWindowEvent event) {
   // call the desktop to open the project (since it is
   // a conventional foreground gui application it has
   // less chance of running afowl of desktop app creation
   // & activation restrictions)
   FileSystemItem project = FileSystemItem.createFile(event.getProject());
   if (Desktop.isDesktop()) Desktop.getFrame().openProjectInNewWindow(project.getPath());
   else serverOpenProjectInNewWindow(project, null);
 }
Esempio n. 2
0
 public void showOpenProjectDialog(
     FileSystemContext fsContext,
     ProjectsServerOperations server,
     String defaultLocation,
     int defaultType,
     boolean showNewSession,
     final ProgressOperationWithInput<OpenProjectParams> onCompleted) {
   // 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)",
         new ProgressOperationWithInput<FileSystemItem>() {
           @Override
           public void execute(FileSystemItem input, ProgressIndicator indicator) {
             onCompleted.execute(new OpenProjectParams(input, null, false), indicator);
           }
         });
   } else {
     // in multi-session mode, we have a special dialog for opening projects
     WebFileDialogs webDialogs = (WebFileDialogs) dialogs;
     webDialogs.openProject(
         fsContext, FileSystemItem.createDir(defaultLocation), defaultType, onCompleted);
   }
 }
Esempio n. 3
0
 public FileType getTypeForFile(FileSystemItem file) {
   // last ditch default type -- see if this either a known text file type
   // or (for server mode) NOT a known binary type. the result of this is
   // that unknown files types are treated as text and opened in the editor
   // (we don't do this on desktop because  in that case users have the
   // recourse of using a local editor)
   String defaultType = Desktop.isDesktop() ? "application/octet-stream" : "text/plain";
   return getTypeForFile(file, defaultType);
 }
Esempio n. 4
0
  private String getDefaultPdfPreview() {
    if (Desktop.isDesktop()) {
      // if there is a desktop synctex viewer available then default to it
      if (Desktop.getFrame().getDesktopSynctexViewer().length() > 0) {
        return PDF_PREVIEW_DESKTOP_SYNCTEX;
      }

      // otherwise default to the system viewer on linux and the internal
      // viewer on mac (windows will always have a desktop synctex viewer)
      else {
        if (BrowseCap.isLinux()) {
          return PDF_PREVIEW_SYSTEM;
        } else {
          return PDF_PREVIEW_RSTUDIO;
        }
      }
    }

    // web mode -- always default to internal viewer
    else {
      return PDF_PREVIEW_RSTUDIO;
    }
  }
  private void onDeploy() {
    String appName = contents_.getSelectedApp();
    if (appName == null || appName == "Create New") appName = contents_.getNewAppName();

    String account = contents_.getSelectedAccount();

    if (isSatellite_) {
      // in a satellite window, call back to the main window to do a
      // deployment
      ShinyApps.deployFromSatellite(
          sourceDir_,
          sourceFile_,
          launchCheck_.getValue(),
          ShinyAppsDeploymentRecord.create(appName, account, ""));

      // we can't raise the main window if we aren't in desktop mode, so show
      // a dialog to guide the user there
      if (!Desktop.isDesktop()) {
        display_.showMessage(
            GlobalDisplay.MSG_INFO,
            "Deployment Started",
            "RStudio is deploying "
                + appName
                + " to ShinyApps. "
                + "Check the Deploy console tab in the main window for "
                + "status updates. ");
      }
    } else {
      // in the main window, initiate the deployment directly
      events_.fireEvent(
          new ShinyAppsDeployInitiatedEvent(
              sourceDir_,
              sourceFile_,
              launchCheck_.getValue(),
              ShinyAppsDeploymentRecord.create(appName, account, "")));
    }

    closeDialog();
  }
Esempio n. 6
0
  public FileType getTypeForFile(FileSystemItem file, boolean canUseDefault) {
    if (file != null) {
      String filename = file.getName().toLowerCase();
      FileType result = fileTypesByFilename_.get(filename);
      if (result != null) return result;

      String extension = FileSystemItem.getExtensionFromPath(filename);
      result = fileTypesByFileExtension_.get(extension);
      if (result != null) return result;

      // last ditch -- see if this either a known text file type
      // or (for server mode) NOT a known binary type. the result of
      // this is that unknown files types are treated as text and
      // opened in the editor (we don't do this on desktop because
      // in that case users have the recourse of using a local editor)
      String defaultType = Desktop.isDesktop() ? "application/octet-stream" : "text/plain";
      String mimeType = file.mimeType(defaultType);
      if (mimeType.startsWith("text/")) return TEXT;
    }

    if (canUseDefault) return defaultType_;
    else return null;
  }
Esempio n. 7
0
  public ToolbarButton getToolbarButton() {
    if (toolbarButton_ == null) {
      String buttonText =
          activeProjectFile_ != null
              ? mruList_.getQualifiedLabel(activeProjectFile_)
              : "Project: (None)";

      toolbarButton_ = new ToolbarButton(buttonText, RESOURCES.projectMenu(), this, true);

      if (activeProjectFile_ != null) {
        toolbarButton_.setTitle(activeProjectFile_);

        // also set the doc title so the browser tab carries the project
        if (!Desktop.isDesktop()) Document.get().setTitle("RStudio - " + buttonText);
      }

      if (activeProjectFile_ == null) {
        toolbarButton_.addStyleName(ThemeResources.INSTANCE.themeStyles().emptyProjectMenu());
      }
    }

    return toolbarButton_;
  }
Esempio n. 8
0
  @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);
  }
Esempio n. 9
0
  public ShellWidget(AceEditor editor) {
    styles_ = ConsoleResources.INSTANCE.consoleStyles();

    SelectInputClickHandler secondaryInputHandler = new SelectInputClickHandler();

    output_ = new PreWidget();
    output_.setStylePrimaryName(styles_.output());
    output_.addClickHandler(secondaryInputHandler);

    pendingInput_ = new PreWidget();
    pendingInput_.setStyleName(styles_.output());
    pendingInput_.addClickHandler(secondaryInputHandler);

    prompt_ = new HTML();
    prompt_.setStylePrimaryName(styles_.prompt());
    prompt_.addStyleName(KEYWORD_CLASS_NAME);

    input_ = editor;
    input_.setShowLineNumbers(false);
    input_.setShowPrintMargin(false);
    if (!Desktop.isDesktop()) input_.setNewLineMode(NewLineMode.Unix);
    input_.setUseWrapMode(true);
    input_.setPadding(0);
    input_.autoHeight();
    final Widget inputWidget = input_.asWidget();
    input_.addClickHandler(secondaryInputHandler);
    inputWidget.addStyleName(styles_.input());
    input_.addCursorChangedHandler(
        new CursorChangedHandler() {
          public void onCursorChanged(CursorChangedEvent event) {
            Scheduler.get()
                .scheduleDeferred(
                    new ScheduledCommand() {
                      @Override
                      public void execute() {
                        input_.scrollToCursor(scrollPanel_, 8, 60);
                      }
                    });
          }
        });
    input_.addCapturingKeyDownHandler(
        new KeyDownHandler() {
          @Override
          public void onKeyDown(KeyDownEvent event) {
            // If the user hits Page-Up from inside the console input, we need
            // to simulate pageup because focus is not contained in the scroll
            // panel (it's in the hidden textarea that Ace uses under the
            // covers).

            int keyCode = event.getNativeKeyCode();
            switch (keyCode) {
              case KeyCodes.KEY_PAGEUP:
                event.stopPropagation();
                event.preventDefault();

                // Can't scroll any further up. Return before we change focus.
                if (scrollPanel_.getVerticalScrollPosition() == 0) return;

                scrollPanel_.focus();
                int newScrollTop =
                    scrollPanel_.getVerticalScrollPosition() - scrollPanel_.getOffsetHeight() + 40;
                scrollPanel_.setVerticalScrollPosition(Math.max(0, newScrollTop));
                break;
            }
          }
        });

    inputLine_ = new DockPanel();
    inputLine_.setHorizontalAlignment(DockPanel.ALIGN_LEFT);
    inputLine_.setVerticalAlignment(DockPanel.ALIGN_TOP);
    inputLine_.add(prompt_, DockPanel.WEST);
    inputLine_.setCellWidth(prompt_, "1");
    inputLine_.add(input_.asWidget(), DockPanel.CENTER);
    inputLine_.setCellWidth(input_.asWidget(), "100%");
    inputLine_.setWidth("100%");

    verticalPanel_ = new VerticalPanel();
    verticalPanel_.setStylePrimaryName(styles_.console());
    verticalPanel_.addStyleName("ace_text-layer");
    verticalPanel_.addStyleName("ace_line");
    FontSizer.applyNormalFontSize(verticalPanel_);
    verticalPanel_.add(output_);
    verticalPanel_.add(pendingInput_);
    verticalPanel_.add(inputLine_);
    verticalPanel_.setWidth("100%");

    scrollPanel_ = new ClickableScrollPanel();
    scrollPanel_.setWidget(verticalPanel_);
    scrollPanel_.addStyleName("ace_editor");
    scrollPanel_.addStyleName("ace_scroller");
    scrollPanel_.addClickHandler(secondaryInputHandler);
    scrollPanel_.addKeyDownHandler(secondaryInputHandler);

    secondaryInputHandler.setInput(editor);

    scrollToBottomCommand_ =
        new TimeBufferedCommand(5) {
          @Override
          protected void performAction(boolean shouldSchedulePassive) {
            if (!DomUtils.selectionExists()) scrollPanel_.scrollToBottom();
          }
        };

    initWidget(scrollPanel_);

    addCopyHook(getElement());
  }