Example #1
0
  @Override
  protected Widget createMainWidget() {
    VerticalPanel panel = new VerticalPanel();
    panel.setStyleName(ThemeStyles.INSTANCE.fileUploadPanel());

    // directory panel
    HorizontalPanel directoryPanel = new HorizontalPanel();
    directoryPanel.setWidth("100%");
    directoryPanel.setStyleName(ThemeStyles.INSTANCE.fileUploadField());

    // directory name (informational field)
    panel.add(new Label("Target directory:"));
    directoryNameWidget_ = new DirectoryNameWidget();
    directoryNameWidget_.setDirectory(targetDirectory_);
    directoryPanel.add(directoryNameWidget_);

    // browse directory button
    // JJA: removed browse button (was causing confusion for users who
    // thought it was what they should press to browse local files)
    /*
    Button browseButton = new Button("Browse...",
                                     new BrowseDirectoryClickHandler());
    browseButton.getElement().getStyle().setMarginRight(5, Unit.PX);
    directoryPanel.add(browseButton);
    directoryPanel.setCellHorizontalAlignment(
                                        browseButton,
                                        HasHorizontalAlignment.ALIGN_RIGHT);
    */
    panel.add(directoryPanel);

    // filename field
    panel.add(new Label("File to upload:"));
    fileUpload_ = new FileUpload();
    fileUpload_.setStyleName(ThemeStyles.INSTANCE.fileUploadField());
    fileUpload_.setName("file");
    panel.add(fileUpload_);

    // zip file tip field
    HTML tip =
        new HTML(
            "<b>TIP</b>: To upload multiple files or a "
                + "directory, create a zip file. The zip file will "
                + "be automatically expanded after upload.");
    tip.addStyleName(ThemeStyles.INSTANCE.fileUploadField());
    tip.addStyleName(ThemeStyles.INSTANCE.fileUploadTipLabel());
    panel.add(tip);

    // target directory hidden field
    targetDirectoryHidden_ = new Hidden("targetDirectory", targetDirectory_.getPath());
    panel.add(targetDirectoryHidden_);

    return panel;
  }
Example #2
0
  private void manageChunkIcons(AceEditorNative editor) {
    Element container = editor.getContainer();
    if (container == null) return;

    Element[] icons =
        DomUtils.getElementsByClassName(container, ThemeStyles.INSTANCE.inlineChunkToolbar());

    for (Element icon : icons) icon.removeFromParent();

    if (!uiPrefs_.showInlineToolbarForRCodeChunks().getValue()) return;

    if (!shouldDisplayIcons(editor)) return;

    Element[] chunkStarts = DomUtils.getElementsByClassName("rstudio_chunk_start ace_start");

    for (int i = 0; i < chunkStarts.length; i++) {
      Element el = chunkStarts[i];

      if (isPseudoMarker(el)) continue;

      if (!isRunnableChunk(el, editor)) continue;

      if (!DomUtils.isVisibleVert(container, el)) continue;

      if (el.getChildCount() > 0) el.removeAllChildren();

      addToolbar(el, isSetupChunk(el, editor), editor);
    }
  }
Example #3
0
 private Image createRunIcon() {
   Image icon = new Image(ThemeResources.INSTANCE.runChunk());
   icon.addStyleName(ThemeStyles.INSTANCE.highlightIcon());
   icon.setTitle(commands_.executeCurrentChunk().getTooltip());
   bindNativeClickToExecuteChunk(this, icon.getElement());
   return icon;
 }
Example #4
0
  private void addToolbar(Element el, boolean isSetupChunk, AceEditorNative editor) {
    FlowPanel toolbarPanel = new FlowPanel();
    toolbarPanel.addStyleName(ThemeStyles.INSTANCE.inlineChunkToolbar());

    boolean isDark = themes_.isDark(themes_.getEffectiveThemeName(uiPrefs_.theme().getValue()));

    if (isSetupChunk) {
      Image optionsIcon = createOptionsIcon(isDark, true);
      toolbarPanel.add(optionsIcon);
    } else {
      Image optionsIcon = createOptionsIcon(isDark, false);
      optionsIcon.getElement().getStyle().setMarginRight(9, Unit.PX);
      toolbarPanel.add(optionsIcon);

      // Note that 'run current chunk' currently only operates within Rmd
      if (editor.getSession().getMode().getId().equals("mode/rmarkdown")) {
        Image runPreviousIcon = createRunPreviousIcon(isDark);
        runPreviousIcon.getElement().getStyle().setMarginRight(8, Unit.PX);
        toolbarPanel.add(runPreviousIcon);

        Image runIcon = createRunIcon();
        toolbarPanel.add(runIcon);
      }
    }

    display(toolbarPanel, el);
  }
Example #5
0
  private Image createRunPreviousIcon(boolean dark) {
    Image icon =
        new Image(
            dark
                ? ThemeResources.INSTANCE.runPreviousChunksDark()
                : ThemeResources.INSTANCE.runPreviousChunksLight());
    icon.addStyleName(ThemeStyles.INSTANCE.highlightIcon());

    icon.setTitle(commands_.executePreviousChunks().getTooltip());
    bindNativeClickToExecutePreviousChunks(this, icon.getElement());
    return icon;
  }
 @Override
 public void onBrowserEvent(Event event) {
   Element element = DOM.eventGetTarget(event);
   switch (DOM.eventGetType(event)) {
     case Event.ONCLICK:
       {
         if (element.getClassName().equals(ThemeStyles.INSTANCE.menuRightImage()))
           ProjectMRUList.setOpenInNewWindow(true);
       }
   }
   super.onBrowserEvent(event);
 }
Example #7
0
  public ChunkOutputUi(
      String docId,
      DocDisplay display,
      ChunkDefinition def,
      PinnedLineWidget.Host lineWidgetHost,
      ChunkOutputWidget widget) {
    display_ = display;
    chunkId_ = def.getChunkId();
    docId_ = docId;
    def_ = def;
    boolean hasOutput = widget != null;
    if (widget == null) {
      widget =
          new ChunkOutputWidget(def.getChunkId(), def.getOptions(), def.getExpansionState(), this);
    } else {
      widget.setHost(this);
    }

    outputWidget_ = widget;

    // sync the widget's expanded/collapsed state to the underlying chunk
    // definition (which is persisted)
    outputWidget_.addExpansionStateChangeHandler(
        new ValueChangeHandler<Integer>() {
          @Override
          public void onValueChange(ValueChangeEvent<Integer> event) {
            def_.setExpansionState(event.getValue());
          }
        });

    Element ele = outputWidget_.getElement();
    ele.addClassName(ThemeStyles.INSTANCE.selectableText());

    // if we didn't start with output, make the widget initially invisible
    // (until it gets some output)
    if (!hasOutput) {
      ele.getStyle().setHeight(0, Unit.PX);
      outputWidget_.setVisible(false);
    }

    lineWidget_ =
        new PinnedLineWidget(
            ChunkDefinition.LINE_WIDGET_TYPE,
            display_,
            outputWidget_,
            def.getRow(),
            def,
            lineWidgetHost);

    attached_ = true;
  }
Example #8
0
  private Image createOptionsIcon(boolean dark, boolean setupChunk) {
    Image icon =
        new Image(
            dark
                ? ThemeResources.INSTANCE.chunkOptionsDark()
                : ThemeResources.INSTANCE.chunkOptionsLight());
    icon.addStyleName(ThemeStyles.INSTANCE.highlightIcon());

    if (setupChunk) icon.addStyleName(RES.styles().setupChunk());

    icon.setTitle("Modify chunk options");
    bindNativeClickToOpenOptions(this, icon.getElement());
    return icon;
  }
Example #9
0
  protected ModalDialogBase(SimplePanel containerPanel) {
    // core initialization. passing false for modal works around
    // modal PopupPanel supressing global keyboard accelerators (like
    // Ctrl-N or Ctrl-T). modality is achieved via setGlassEnabled(true)
    super(false, false);
    setGlassEnabled(true);
    addStyleDependentName("ModalDialog");

    // main panel used to host UI
    mainPanel_ = new VerticalPanel();
    bottomPanel_ = new HorizontalPanel();
    bottomPanel_.setStyleName(ThemeStyles.INSTANCE.dialogBottomPanel());
    bottomPanel_.setWidth("100%");
    buttonPanel_ = new HorizontalPanel();
    leftButtonPanel_ = new HorizontalPanel();
    bottomPanel_.add(leftButtonPanel_);
    bottomPanel_.add(buttonPanel_);
    setButtonAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
    mainPanel_.add(bottomPanel_);

    // embed main panel in a custom container if specified
    containerPanel_ = containerPanel;
    if (containerPanel_ != null) {
      containerPanel_.setWidget(mainPanel_);
      setWidget(containerPanel_);
    } else {
      setWidget(mainPanel_);
    }

    addDomHandler(
        new KeyDownHandler() {
          public void onKeyDown(KeyDownEvent event) {
            // Is this too aggressive? Alternatively we could only filter out
            // keycodes that are known to be problematic (pgup/pgdown)
            event.stopPropagation();
          }
        },
        KeyDownEvent.getType());
  }
Example #10
0
    private DocTab(
        ImageResource icon,
        String docId,
        String title,
        String tooltip,
        TabCloseObserver closeHandler) {
      docId_ = docId;

      final HorizontalPanel layoutPanel = new HorizontalPanel();
      layoutPanel.setStylePrimaryName(styles_.tabLayout());
      layoutPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_BOTTOM);
      layoutPanel.getElement().setDraggable("true");
      layoutPanel.addDomHandler(
          new DragStartHandler() {
            @Override
            public void onDragStart(DragStartEvent evt) {
              evt.getDataTransfer()
                  .setData(
                      getDataTransferFormat(),
                      docId_ + "|" + SourceWindowManager.getSourceWindowId());
              JsObject dt = evt.getDataTransfer().cast();
              dt.setString("effectAllowed", "move");

              // figure out where the cursor is inside the element; because the
              // drag shows an image of the tab, knowing where the cursor is
              // inside that image is necessary for us to know the screen
              // location of the dragged image
              int evtX = evt.getNativeEvent().getClientX();
              ElementEx ele = getElement().cast();
              events_.fireEvent(
                  new DocTabDragInitiatedEvent(
                      docId_,
                      getElement().getClientWidth(),
                      evtX - ele.getBoundingClientRect().getLeft()));
            }
          },
          DragStartEvent.getType());

      HTML left = new HTML();
      left.setStylePrimaryName(styles_.tabLayoutLeft());
      layoutPanel.add(left);

      contentPanel_ = new HorizontalPanel();
      contentPanel_.setTitle(tooltip);
      contentPanel_.setStylePrimaryName(styles_.tabLayoutCenter());
      contentPanel_.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);

      if (icon != null) contentPanel_.add(imageForIcon(icon));

      label_ = new Label(title, false);
      label_.addStyleName(styles_.docTabLabel());
      contentPanel_.add(label_);

      appendDirtyMarker();

      Image img = new Image(ThemeResources.INSTANCE.closeTab());
      img.setStylePrimaryName(styles_.closeTabButton());
      img.addStyleName(ThemeStyles.INSTANCE.handCursor());
      contentPanel_.add(img);

      layoutPanel.add(contentPanel_);

      HTML right = new HTML();
      right.setStylePrimaryName(styles_.tabLayoutRight());
      layoutPanel.add(right);

      initWidget(layoutPanel);

      this.sinkEvents(Event.ONCLICK);
      closeHandler_ = closeHandler;
      closeElement_ = img.getElement();
    }