Search in sources :

Example 1 with KeyboardShortcut

use of org.rstudio.core.client.command.KeyboardShortcut in project rstudio by rstudio.

the class ShowPublicKeyDialog method createMainWidget.

@Override
protected Widget createMainWidget() {
    VerticalPanel panel = new VerticalPanel();
    int mod = BrowseCap.hasMetaKey() ? KeyboardShortcut.META : KeyboardShortcut.CTRL;
    String cmdText = new KeyboardShortcut(mod, 'C').toString(true);
    HTML label = new HTML("Press " + cmdText + " to copy the key to the clipboard");
    label.addStyleName(RES.styles().viewPublicKeyLabel());
    panel.add(label);
    textArea_ = new TextArea();
    textArea_.setReadOnly(true);
    textArea_.setText(publicKey_);
    textArea_.addStyleName(RES.styles().viewPublicKeyContent());
    textArea_.setSize("400px", "250px");
    textArea_.getElement().setAttribute("spellcheck", "false");
    FontSizer.applyNormalFontSize(textArea_.getElement());
    panel.add(textArea_);
    return panel;
}
Also used : VerticalPanel(com.google.gwt.user.client.ui.VerticalPanel) KeyboardShortcut(org.rstudio.core.client.command.KeyboardShortcut) TextArea(com.google.gwt.user.client.ui.TextArea) HTML(com.google.gwt.user.client.ui.HTML)

Example 2 with KeyboardShortcut

use of org.rstudio.core.client.command.KeyboardShortcut in project rstudio by rstudio.

the class AddinsMRUList method manageCommand.

private void manageCommand(AppCommand command, List<RAddin> addinsList, KeyMap keyMap, int index) {
    if (index >= addinsList.size()) {
        command.setEnabled(false);
        command.setVisible(false);
        return;
    }
    RAddin addin = addinsList.get(index);
    command.setEnabled(true);
    command.setVisible(true);
    String description = addin.getDescription() + " [" + addin.getId() + "]";
    command.setDesc(description);
    String name = StringUtil.truncate(addin.getName(), 25, "...");
    command.setLabel(name);
    List<KeySequence> keys = keyMap.getBindings(addin.getId());
    if (keys != null && !keys.isEmpty())
        command.setShortcut(new KeyboardShortcut(keys.get(0)));
    else
        command.setShortcut(null);
}
Also used : RAddin(org.rstudio.studio.client.workbench.addins.Addins.RAddin) KeyboardShortcut(org.rstudio.core.client.command.KeyboardShortcut) KeySequence(org.rstudio.core.client.command.KeyboardShortcut.KeySequence)

Example 3 with KeyboardShortcut

use of org.rstudio.core.client.command.KeyboardShortcut in project rstudio by rstudio.

the class TextEditingTargetWidget method createToolbar.

private Toolbar createToolbar(TextFileType fileType) {
    Toolbar toolbar = new EditingTargetToolbar(commands_, true);
    toolbar.addLeftWidget(commands_.saveSourceDoc().createToolbarButton());
    sourceOnSave_.getElement().getStyle().setMarginRight(0, Unit.PX);
    toolbar.addLeftWidget(sourceOnSave_);
    srcOnSaveLabel_.getElement().getStyle().setMarginRight(9, Unit.PX);
    toolbar.addLeftWidget(srcOnSaveLabel_);
    toolbar.addLeftSeparator();
    toolbar.addLeftWidget(commands_.checkSpelling().createToolbarButton());
    toolbar.addLeftWidget(findReplace_.createFindReplaceButton());
    toolbar.addLeftWidget(createCodeTransformMenuButton());
    notebookSeparatorWidget_ = toolbar.addLeftSeparator();
    toolbar.addLeftWidget(notebookToolbarButton_ = commands_.compileNotebook().createToolbarButton());
    int mod = BrowseCap.hasMetaKey() ? KeyboardShortcut.META : KeyboardShortcut.CTRL;
    String cmdText = new KeyboardShortcut(mod + KeyboardShortcut.SHIFT, 'K').toString(true);
    cmdText = DomUtils.htmlToText(cmdText);
    notebookToolbarButton_.setTitle("Compile Report (" + cmdText + ")");
    texSeparatorWidget_ = toolbar.addLeftSeparator();
    toolbar.addLeftWidget(texToolbarButton_ = createLatexFormatButton());
    toolbar.addLeftSeparator();
    toolbar.addLeftWidget(previewHTMLButton_ = commands_.previewHTML().createToolbarButton());
    knitDocumentButton_ = commands_.knitDocument().createToolbarButton(false);
    knitDocumentButton_.getElement().getStyle().setMarginRight(0, Unit.PX);
    toolbar.addLeftWidget(knitDocumentButton_);
    toolbar.addLeftWidget(compilePdfButton_ = commands_.compilePDF().createToolbarButton());
    rmdFormatButton_ = new ToolbarPopupMenuButton(false, true);
    rmdFormatButton_.getMenu().setAutoOpen(true);
    toolbar.addLeftWidget(rmdFormatButton_);
    runDocumentMenuButton_ = new ToolbarPopupMenuButton(false, true);
    addClearKnitrCacheMenu(runDocumentMenuButton_);
    runDocumentMenuButton_.addSeparator();
    runDocumentMenuButton_.addMenuItem(commands_.clearPrerenderedOutput().createMenuItem(false), "");
    toolbar.addLeftWidget(runDocumentMenuButton_);
    runDocumentMenuButton_.setVisible(false);
    ToolbarPopupMenu rmdOptionsMenu = new ToolbarPopupMenu();
    rmdOptionsMenu.addItem(commands_.editRmdFormatOptions().createMenuItem(false));
    rmdOptionsButton_ = new ToolbarButton(null, new ImageResource2x(StandardIcons.INSTANCE.options2x()), rmdOptionsMenu, false);
    toolbar.addLeftWidget(rmdOptionsButton_);
    toolbar.addLeftSeparator();
    toolbar.addLeftWidget(commands_.synctexSearch().createToolbarButton());
    // create menu of chunk skeletons based on common engine types
    ToolbarPopupMenu insertChunksMenu = new ToolbarPopupMenu();
    insertChunksMenu.addItem(commands_.insertChunkR().createMenuItem(false));
    insertChunksMenu.addSeparator();
    if (!BrowseCap.isWindowsDesktop()) {
        insertChunksMenu.addItem(commands_.insertChunkBash().createMenuItem(false));
    }
    insertChunksMenu.addItem(commands_.insertChunkPython().createMenuItem(false));
    insertChunksMenu.addItem(commands_.insertChunkRCPP().createMenuItem(false));
    insertChunksMenu.addItem(commands_.insertChunkSQL().createMenuItem(false));
    insertChunksMenu.addItem(commands_.insertChunkStan().createMenuItem(false));
    insertChunkMenu_ = new ToolbarButton("Insert", commands_.insertChunk().getImageResource(), insertChunksMenu, true);
    toolbar.addRightWidget(insertChunkMenu_);
    // create button that just runs default chunk insertion
    insertChunkButton_ = commands_.insertChunk().createToolbarButton(false);
    toolbar.addRightWidget(insertChunkButton_);
    toolbar.addRightWidget(runButton_ = commands_.executeCode().createToolbarButton(false));
    toolbar.addRightSeparator();
    toolbar.addRightWidget(runLastButton_ = commands_.executeLastCode().createToolbarButton(false));
    toolbar.addRightWidget(goToPrevButton_ = commands_.goToPrevSection().createToolbarButton(false));
    toolbar.addRightWidget(goToNextButton_ = commands_.goToNextSection().createToolbarButton(false));
    toolbar.addRightSeparator();
    final String SOURCE_BUTTON_TITLE = "Source the active document";
    sourceButton_ = new ToolbarButton("Source", commands_.sourceActiveDocument().getImageResource(), new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            if (uiPrefs_.sourceWithEcho().getValue())
                commands_.sourceActiveDocumentWithEcho().execute();
            else
                commands_.sourceActiveDocument().execute();
        }
    });
    sourceButton_.setTitle(SOURCE_BUTTON_TITLE);
    toolbar.addRightWidget(sourceButton_);
    uiPrefs_.sourceWithEcho().addValueChangeHandler(new ValueChangeHandler<Boolean>() {

        @Override
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            if (event.getValue())
                sourceButton_.setTitle(SOURCE_BUTTON_TITLE + " (with echo)");
            else
                sourceButton_.setTitle(SOURCE_BUTTON_TITLE);
        }
    });
    ToolbarPopupMenu sourceMenu = new ToolbarPopupMenu();
    sourceMenu.addItem(commands_.sourceActiveDocument().createMenuItem(false));
    sourceMenu.addItem(commands_.sourceActiveDocumentWithEcho().createMenuItem(false));
    sourceMenuButton_ = new ToolbarButton(sourceMenu, true);
    toolbar.addRightWidget(sourceMenuButton_);
    //toolbar.addRightSeparator();
    ToolbarPopupMenu chunksMenu = new ToolbarPopupMenu();
    chunksMenu.addItem(commands_.executeCode().createMenuItem(false));
    chunksMenu.addSeparator();
    chunksMenu.addItem(commands_.executeCurrentChunk().createMenuItem(false));
    chunksMenu.addItem(commands_.executeNextChunk().createMenuItem(false));
    chunksMenu.addSeparator();
    chunksMenu.addItem(commands_.executeSetupChunk().createMenuItem(false));
    chunksMenu.addItem(runSetupChunkOptionMenu_ = new UIPrefMenuItem<Boolean>(uiPrefs_.autoRunSetupChunk(), true, "Run Setup Chunk Automatically", uiPrefs_));
    chunksMenu.addSeparator();
    chunksMenu.addItem(commands_.executePreviousChunks().createMenuItem(false));
    chunksMenu.addItem(commands_.executeSubsequentChunks().createMenuItem(false));
    if (uiPrefs_.showRmdChunkOutputInline().getValue()) {
        chunksMenu.addSeparator();
        chunksMenu.addItem(commands_.restartRRunAllChunks().createMenuItem(false));
        chunksMenu.addItem(commands_.restartRClearOutput().createMenuItem(false));
    }
    chunksMenu.addSeparator();
    chunksMenu.addItem(commands_.executeAllCode().createMenuItem(false));
    chunksButton_ = new ToolbarButton("Run", commands_.executeCode().getImageResource(), chunksMenu, true);
    toolbar.addRightWidget(chunksButton_);
    ToolbarPopupMenu shinyLaunchMenu = shinyViewerMenu_;
    shinyLaunchButton_ = new ToolbarButton(shinyLaunchMenu, true);
    shinyLaunchButton_.setVisible(false);
    toolbar.addRightWidget(shinyLaunchButton_);
    if (SessionUtils.showPublishUi(session_, uiPrefs_)) {
        toolbar.addRightSeparator();
        publishButton_ = new RSConnectPublishButton(RSConnect.CONTENT_TYPE_APP, false, null);
        toolbar.addRightWidget(publishButton_);
    }
    toggleDocOutlineButton_ = new LatchingToolbarButton("", new ImageResource2x(StandardIcons.INSTANCE.outline2x()), new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            final double initialSize = editorPanel_.getWidgetSize(docOutlineWidget_);
            // Clicking the icon toggles the outline widget's visibility. The
            // 'destination' below is the width we would like to set -- we
            // animate to that position for a slightly nicer visual treatment.
            final double destination = docOutlineWidget_.getOffsetWidth() > 5 ? 0 : Math.min(editorPanel_.getOffsetWidth(), target_.getPreferredOutlineWidgetSize());
            // Update tooltip ('Show'/'Hide' depending on current visibility)
            String title = toggleDocOutlineButton_.getTitle();
            if (destination != 0)
                title = title.replace("Show ", "Hide ");
            else
                title = title.replace("Hide ", "Show ");
            toggleDocOutlineButton_.setTitle(title);
            toggleDocOutlineButton_.setLatched(destination != 0);
            new Animation() {

                @Override
                protected void onUpdate(double progress) {
                    double size = destination * progress + initialSize * (1 - progress);
                    editorPanel_.setWidgetSize(docOutlineWidget_, size);
                    editor_.onResize();
                }

                @Override
                protected void onComplete() {
                    target_.setPreferredOutlineWidgetVisibility(destination != 0);
                }
            }.run(500);
        }
    });
    // Time-out setting the latch just to ensure the document outline
    // has actually been appropriately rendered.
    new Timer() {

        @Override
        public void run() {
            String title = commands_.toggleDocumentOutline().getTooltip();
            title = editorPanel_.getWidgetSize(docOutlineWidget_) > 0 ? title.replace("Show ", "Hide ") : title.replace("Hide ", "Show ");
            toggleDocOutlineButton_.setTitle(title);
            toggleDocOutlineButton_.setLatched(docOutlineWidget_.getOffsetWidth() > 0);
        }
    }.schedule(100);
    toolbar.addRightSeparator();
    toolbar.addRightWidget(toggleDocOutlineButton_);
    return toolbar;
}
Also used : EditingTargetToolbar(org.rstudio.studio.client.workbench.views.source.editors.EditingTargetToolbar) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) Timer(com.google.gwt.user.client.Timer) KeyboardShortcut(org.rstudio.core.client.command.KeyboardShortcut) RSConnectPublishButton(org.rstudio.studio.client.rsconnect.ui.RSConnectPublishButton) ImageResource2x(org.rstudio.core.client.resources.ImageResource2x) Animation(com.google.gwt.animation.client.Animation) EditingTargetToolbar(org.rstudio.studio.client.workbench.views.source.editors.EditingTargetToolbar)

Aggregations

KeyboardShortcut (org.rstudio.core.client.command.KeyboardShortcut)3 Animation (com.google.gwt.animation.client.Animation)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 Timer (com.google.gwt.user.client.Timer)1 HTML (com.google.gwt.user.client.ui.HTML)1 TextArea (com.google.gwt.user.client.ui.TextArea)1 VerticalPanel (com.google.gwt.user.client.ui.VerticalPanel)1 KeySequence (org.rstudio.core.client.command.KeyboardShortcut.KeySequence)1 ImageResource2x (org.rstudio.core.client.resources.ImageResource2x)1 RSConnectPublishButton (org.rstudio.studio.client.rsconnect.ui.RSConnectPublishButton)1 RAddin (org.rstudio.studio.client.workbench.addins.Addins.RAddin)1 EditingTargetToolbar (org.rstudio.studio.client.workbench.views.source.editors.EditingTargetToolbar)1