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);
   }
 }
  public CompileNotebookOptionsDialog(
      String docId,
      String defaultTitle,
      String defaultAuthor,
      String defaultType,
      final OperationWithInput<CompileNotebookOptions> operation) {
    super("Compile Notebook from R Script", operation);
    docId_ = docId;
    RStudioGinjector.INSTANCE.injectMembers(this);

    widget_ = GWT.<Binder>create(Binder.class).createAndBindUi(this);
    txtTitle_.setText(defaultTitle);
    txtAuthor_.setText(defaultAuthor);

    if (showTypes_) {
      setType(defaultType);

      typeLabelPanel_.setCellVerticalAlignment(lblType_, HasVerticalAlignment.ALIGN_MIDDLE);

      HelpButton helpButton = HelpButton.createHelpButton("notebook_types");
      typeLabelPanel_.add(helpButton);
      typeLabelPanel_.setCellVerticalAlignment(helpButton, HasVerticalAlignment.ALIGN_MIDDLE);

      divTypeSelector_.getStyle().setPaddingBottom(10, Unit.PX);
    } else {
      setType(CompileNotebookOptions.TYPE_DEFAULT);
      divTypeSelector_.getStyle().setDisplay(Style.Display.NONE);
    }

    setOkButtonCaption("Compile");
  }
  public LocalRepositoriesWidget() {
    RStudioGinjector.INSTANCE.injectMembers(this);

    VerticalPanel panel = new VerticalPanel();
    panel.add(new LabelWithHelp("Local repositories:", "packrat_local_repos"));

    HorizontalPanel hp = new HorizontalPanel();
    listBox_ = new ListBox(true);
    listBox_.addStyleName(RES.styles().listBox());
    listBox_.getElement().<SelectElement>cast().setSize(3);
    hp.add(listBox_);

    VerticalPanel buttonPanel = new VerticalPanel();
    SmallButton buttonAdd = createButton("Add...");
    buttonAdd.addClickHandler(addButtonClicked_);
    buttonPanel.add(buttonAdd);
    SmallButton buttonRemove = createButton("Remove");
    buttonRemove.addClickHandler(removeButtonClicked_);
    buttonPanel.add(buttonRemove);
    hp.add(buttonPanel);

    panel.add(hp);

    initWidget(panel);
  }
  public DocTabLayoutPanel(boolean closeableTabs, int padding, int rightMargin) {
    super(BAR_HEIGHT, Style.Unit.PX);
    closeableTabs_ = closeableTabs;
    padding_ = padding;
    rightMargin_ = rightMargin;
    styles_ = ThemeResources.INSTANCE.themeStyles();
    addStyleName(styles_.docTabPanel());
    addStyleName(styles_.moduleTabPanel());
    dragManager_ = new DragManager();

    // listen for global drag events (these are broadcasted from other windows
    // to notify us of incoming drags)
    events_ = RStudioGinjector.INSTANCE.getEventBus();
    events_.addHandler(DocTabDragStartedEvent.TYPE, dragManager_);

    // sink drag-related events on the tab bar element; unfortunately
    // GWT does not provide bits for the drag-related events, and
    Scheduler.get()
        .scheduleDeferred(
            new ScheduledCommand() {
              @Override
              public void execute() {
                Element tabBar = getTabBarElement();
                DOM.sinkBitlessEvent(tabBar, "dragenter");
                DOM.sinkBitlessEvent(tabBar, "dragover");
                DOM.sinkBitlessEvent(tabBar, "dragend");
                DOM.sinkBitlessEvent(tabBar, "dragleave");
                DOM.sinkBitlessEvent(tabBar, "drop");
                Event.setEventListener(tabBar, dragManager_);
              }
            });
  }
  @Override
  protected void doSaveChanges(
      final RPrefs rPrefs,
      final Operation onCompleted,
      final ProgressIndicator progressIndicator,
      final boolean reload) {
    // save changes
    server_.setPrefs(
        rPrefs,
        session_.getSessionInfo().getUiPrefs(),
        new SimpleRequestCallback<Void>() {

          @Override
          public void onResponseReceived(Void response) {
            progressIndicator.onCompleted();
            if (onCompleted != null) onCompleted.execute();
            if (reload) reload();
          }

          @Override
          public void onError(ServerError error) {
            progressIndicator.onError(error.getUserMessage());
          }
        });

    // broadcast UI pref changes to satellites
    RStudioGinjector.INSTANCE
        .getSatelliteManager()
        .dispatchCrossWindowEvent(
            new UiPrefsChangedEvent(
                UiPrefsChangedEvent.Data.create(
                    UiPrefsChangedEvent.GLOBAL_TYPE, session_.getSessionInfo().getUiPrefs())));
  }
  public ProjectPopupMenu(SessionInfo sessionInfo, Commands commands) {
    RStudioGinjector.INSTANCE.injectMembers(this);

    commands_ = commands;

    addItem(commands.newProject().createMenuItem(false));
    addSeparator();
    addItem(commands.openProject().createMenuItem(false));
    addItem(commands.openProjectInNewWindow().createMenuItem(false));
    addItem(commands.shareProject().createMenuItem(false));
    addItem(commands.closeProject().createMenuItem(false));
    addSeparator();
    addItem(commands.projectMru0().createMenuItem(false));
    addItem(commands.projectMru1().createMenuItem(false));
    addItem(commands.projectMru2().createMenuItem(false));
    addItem(commands.projectMru3().createMenuItem(false));
    addItem(commands.projectMru4().createMenuItem(false));
    addItem(commands.projectMru5().createMenuItem(false));
    addItem(commands.projectMru6().createMenuItem(false));
    addItem(commands.projectMru7().createMenuItem(false));
    addItem(commands.projectMru8().createMenuItem(false));
    addItem(commands.projectMru9().createMenuItem(false));
    addItem(commands.projectMru10().createMenuItem(false));
    addItem(commands.projectMru11().createMenuItem(false));
    addItem(commands.projectMru12().createMenuItem(false));
    addItem(commands.projectMru13().createMenuItem(false));
    addItem(commands.projectMru14().createMenuItem(false));
    addSeparator();
    addItem(commands.clearRecentProjects().createMenuItem(false));
    addSeparator();
    addItem(commands.projectOptions().createMenuItem(false));

    activeProjectFile_ = sessionInfo.getActiveProjectFile();
  }
Beispiel #7
0
  public ChunkIconsManager() {
    RStudioGinjector.INSTANCE.injectMembers(this);
    events_.addHandler(
        AfterAceRenderEvent.TYPE,
        new AfterAceRenderEvent.Handler() {

          @Override
          public void onAfterAceRender(AfterAceRenderEvent event) {
            manageChunkIcons(event.getEditor());
          }
        });
  }
  public RSConnectPublishButton(int contentType, boolean showCaption, AppCommand boundCommand) {
    contentType_ = contentType;
    showCaption_ = showCaption;
    boundCommand_ = boundCommand;

    // create root widget
    HorizontalPanel panel = new HorizontalPanel();

    // create publish button itself
    publishButton_ =
        new ToolbarButton(
            RStudioGinjector.INSTANCE.getCommands().rsconnectDeploy().getImageResource(),
            new ClickHandler() {
              @Override
              public void onClick(ClickEvent arg0) {
                onPublishButtonClick();
              }
            });

    panel.add(publishButton_);

    // create drop menu of previous deployments/other commands
    publishMenu_ = new DeploymentPopupMenu();
    publishMenuButton_ = new ToolbarButton(publishMenu_, true);
    panel.add(publishMenuButton_);

    // initialize composite widget
    initWidget(panel);

    // initialize injected members
    RStudioGinjector.INSTANCE.injectMembers(this);

    // compute initial visible state
    applyVisiblity();
    applyCaption("Publish");
    setPreviousDeployments(null);

    // give ourselves some breathing room on the right
    getElement().getStyle().setMarginRight(4, Unit.PX);
  }
Beispiel #9
0
  private void indentPastedRange(Range range) {
    if (fileType_ == null
        || !fileType_.canAutoIndent()
        || !RStudioGinjector.INSTANCE.getUIPrefs().reindentOnPaste().getValue()) {
      return;
    }

    String firstLinePrefix =
        getSession()
            .getTextRange(
                Range.fromPoints(Position.create(range.getStart().getRow(), 0), range.getStart()));

    if (firstLinePrefix.trim().length() != 0) {
      Position newStart = Position.create(range.getStart().getRow() + 1, 0);
      if (newStart.compareTo(range.getEnd()) >= 0) return;

      range = Range.fromPoints(newStart, range.getEnd());
    }

    getSession().reindent(range);
  }
Beispiel #10
0
 @Override
 public void onOutputRemoved() {
   RStudioGinjector.INSTANCE
       .getEventBus()
       .fireEvent(new ChunkChangeEvent(docId_, chunkId_, 0, ChunkChangeEvent.CHANGE_REMOVE));
 }
Beispiel #11
0
 public void print() {
   PrintIFrame printIFrame =
       new PrintIFrame(getCode(), RStudioGinjector.INSTANCE.getUIPrefs().fontSize().getValue());
   RootPanel.get().add(printIFrame);
 }
Beispiel #12
0
  @Inject
  public AceEditor() {
    widget_ = new AceEditorWidget();
    completionManager_ = new NullCompletionManager();
    RStudioGinjector.INSTANCE.injectMembers(this);

    widget_.addValueChangeHandler(
        new ValueChangeHandler<Void>() {
          public void onValueChange(ValueChangeEvent<Void> evt) {
            ValueChangeEvent.fire(AceEditor.this, null);
          }
        });
    widget_.addFoldChangeHandler(
        new FoldChangeEvent.Handler() {
          @Override
          public void onFoldChange(FoldChangeEvent event) {
            AceEditor.this.fireEvent(new FoldChangeEvent());
          }
        });

    addCapturingKeyDownHandler(
        new KeyDownHandler() {
          @Override
          public void onKeyDown(KeyDownEvent event) {
            if (useVimMode_) return;

            int mod = KeyboardShortcut.getModifierValue(event.getNativeEvent());
            if (mod == KeyboardShortcut.CTRL) {
              switch (event.getNativeKeyCode()) {
                case 'U':
                  event.preventDefault();
                  InputEditorUtil.yankBeforeCursor(AceEditor.this, true);
                  break;
                case 'K':
                  event.preventDefault();
                  InputEditorUtil.yankAfterCursor(AceEditor.this, true);
                  break;
                case 'Y':
                  event.preventDefault();
                  Position start = getSelectionStart();
                  InputEditorUtil.pasteYanked(AceEditor.this);
                  indentPastedRange(Range.fromPoints(start, getSelectionEnd()));
                  break;
              }
            }
          }
        });

    addPasteHandler(
        new PasteEvent.Handler() {
          @Override
          public void onPaste(PasteEvent event) {
            final Position start = getSelectionStart();

            Scheduler.get()
                .scheduleDeferred(
                    new ScheduledCommand() {
                      @Override
                      public void execute() {
                        Range range = Range.fromPoints(start, getSelectionEnd());
                        indentPastedRange(range);
                      }
                    });
          }
        });

    // handle click events
    addAceClickHandler(
        new AceClickEvent.Handler() {
          @Override
          public void onClick(AceClickEvent event) {
            fixVerticalOffsetBug();
            if (DomUtils.isCommandClick(event.getNativeEvent())) {
              // eat the event so ace doesn't do anything with it
              event.preventDefault();
              event.stopPropagation();

              // set the cursor position
              setCursorPosition(event.getDocumentPosition());

              // go to function definition
              fireEvent(new CommandClickEvent());
            } else {
              // if the focus in the Help pane or another iframe
              // we need to make sure to get it back
              WindowEx.get().focus();
            }
          }
        });

    addCursorChangedHandler(
        new CursorChangedHandler() {
          @Override
          public void onCursorChanged(CursorChangedEvent event) {
            fixVerticalOffsetBug();
            clearLineHighlight();
          }
        });

    addValueChangeHandler(
        new ValueChangeHandler<Void>() {
          @Override
          public void onValueChange(ValueChangeEvent<Void> event) {
            clearDebugLineHighlight();
          }
        });
  }
 public TextEditingTargetRMarkdownHelper() {
   RStudioGinjector.INSTANCE.injectMembers(this);
 }
    public void endDrag(final Event evt, int action) {
      if (curState_ == STATE_NONE) return;

      // remove the properties used to position for dragging
      if (dragElement_ != null) {
        dragElement_.getStyle().clearLeft();
        dragElement_.getStyle().clearPosition();
        dragElement_.getStyle().clearZIndex();
        dragElement_.getStyle().clearDisplay();
        dragElement_.getStyle().clearOpacity();

        // insert this tab where the placeholder landed if we're not
        // cancelling
        if (action == ACTION_COMMIT) {
          dragTabsHost_.removeChild(dragElement_);
          dragTabsHost_.insertAfter(dragElement_, dragPlaceholder_);
        }
      }

      // remove the placeholder
      if (dragPlaceholder_ != null) {
        dragTabsHost_.removeChild(dragPlaceholder_);
        dragPlaceholder_ = null;
      }

      if (dragElement_ != null && action == ACTION_EXTERNAL) {
        // if we own the dragged tab, change to external drag state
        dragElement_.getStyle().setOpacity(0.4);
        curState_ = STATE_EXTERNAL;
      } else {
        // otherwise, we're back to pristine
        curState_ = STATE_NONE;
        events_.fireEvent(new DocTabDragStateChangedEvent(DocTabDragStateChangedEvent.STATE_NONE));
      }

      if (dragElement_ != null && action == ACTION_COMMIT) {
        // let observer know we moved; adjust the destination position one to
        // the left if we're right of the start position to account for the
        // position of the tab prior to movement
        if (startPos_ != null && startPos_ != destPos_) {
          TabReorderEvent event = new TabReorderEvent(startPos_, destPos_);
          fireEvent(event);
        }
      }

      // this is the case when we adopt someone else's doc
      if (dragElement_ == null && evt != null && action == ACTION_COMMIT) {
        // pull the document ID and source window out
        String data = evt.getDataTransfer().getData(getDataTransferFormat());
        if (StringUtil.isNullOrEmpty(data)) return;

        // the data format is docID|windowID; windowID can be omitted if
        // the main window is the origin
        String pieces[] = data.split("\\|");
        if (pieces.length < 1) return;

        events_.fireEvent(
            new DocWindowChangedEvent(
                pieces[0], pieces.length > 1 ? pieces[1] : "", initDragParams_, destPos_));
      }

      // this is the case when our own drag ends; if it ended outside our
      // window and outside all satellites, treat it as a tab tear-off
      if (dragElement_ != null && evt != null && action == ACTION_CANCEL) {
        // if this is the last tab in satellite, we don't want to tear
        // it out
        boolean isLastSatelliteTab = docTabs_.size() == 1 && Satellite.isCurrentWindowSatellite();

        // did the user drag the tab outside this doc?
        if (!isLastSatelliteTab
            && DomUtils.elementFromPoint(evt.getClientX(), evt.getClientY()) == null) {
          // did it end in any RStudio satellite window?
          String targetWindowName;
          Satellite satellite = RStudioGinjector.INSTANCE.getSatellite();
          if (Satellite.isCurrentWindowSatellite()) {
            // this is a satellite, ask the main window
            targetWindowName = satellite.getWindowAtPoint(evt.getScreenX(), evt.getScreenY());
          } else {
            // this is the main window, query our own satellites
            targetWindowName =
                RStudioGinjector.INSTANCE
                    .getSatelliteManager()
                    .getWindowAtPoint(evt.getScreenX(), evt.getScreenY());
          }
          if (targetWindowName == null) {
            // it was dragged over nothing RStudio owns--pop it out
            events_.fireEvent(
                new PopoutDocInitiatedEvent(
                    initDragParams_.getDocId(), new Point(evt.getScreenX(), evt.getScreenY())));
          }
        }
      }

      if (curState_ != STATE_EXTERNAL) {
        // if we're in an end state, clear the drag element
        dragElement_ = null;
      }
    }
Beispiel #15
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();
    }
  }
 @Override
 public void onError(String message) {
   RStudioGinjector.INSTANCE.getGlobalDisplay().showErrorMessage("Error", message);
 }
 private String getErrorClass() {
   return styles_.output() + " " + RStudioGinjector.INSTANCE.getUIPrefs().getThemeErrorClass();
 }
  public BrowseAddinsDialog(OperationWithInput<Command> operation) {
    super("Addins", operation);
    RStudioGinjector.INSTANCE.injectMembers(this);

    setOkButtonCaption("Execute");

    filterWidget_ =
        new FilterWidget() {
          @Override
          public void filter(String query) {
            BrowseAddinsDialog.this.filter(query);
          }
        };
    filterWidget_.getElement().getStyle().setFloat(Style.Float.LEFT);

    helpLink_ = new HelpLink("Using RStudio Addins", "rstudio_addins", false);
    helpLink_.getElement().getStyle().setFloat(Style.Float.RIGHT);

    keyProvider_ =
        new ProvidesKey<RAddin>() {
          @Override
          public Object getKey(RAddin addin) {
            return addin.hashCode();
          }
        };

    table_ = new DataGrid<RAddin>(1000, RES, keyProvider_);
    table_.setWidth("500px");
    table_.setHeight("400px");

    selectionModel_ = new SingleSelectionModel<RAddin>();
    selectionModel_.addSelectionChangeHandler(
        new SelectionChangeEvent.Handler() {
          @Override
          public void onSelectionChange(SelectionChangeEvent event) {
            selection_ = selectionModel_.getSelectedObject();
          }
        });

    table_.setSelectionModel(selectionModel_);
    table_.setEmptyTableWidget(emptyTableLabel("Loading addins..."));

    addColumns();

    dataProvider_ = new ListDataProvider<RAddin>();
    dataProvider_.addDataDisplay(table_);

    originalData_ = new ArrayList<RAddin>();

    // sync to current addins
    addins_ = addinsCommandManager_.getRAddins();
    List<RAddin> data = new ArrayList<RAddin>();
    for (String key : JsUtil.asIterable(addins_.keys())) data.add(addins_.get(key));
    dataProvider_.setList(data);
    originalData_ = data;
    table_.setEmptyTableWidget(emptyTableLabel("No addins available"));

    addLeftWidget(
        new ThemedButton(
            "Keyboard Shortcuts...",
            new ClickHandler() {
              @Override
              public void onClick(ClickEvent event) {
                ModifyKeyboardShortcutsWidget widget = new ModifyKeyboardShortcutsWidget("addin");
                widget.showModal();
              }
            }));

    FlowPanel headerPanel = new FlowPanel();
    headerPanel.add(filterWidget_);
    headerPanel.add(helpLink_);

    container_ = new VerticalPanel();
    container_.add(headerPanel);
    container_.add(new VerticalSeparator("4px"));
    container_.add(table_);
  }