Search in sources :

Example 6 with AppCommand

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

the class TextEditingTargetWidget method setFormatOptions.

@Override
public void setFormatOptions(TextFileType fileType, boolean showRmdFormatMenu, boolean canEditFormatOptions, List<String> options, List<String> values, List<String> extensions, String selectedOption) {
    if (!canEditFormatOptions) {
        setFormatText("");
    }
    setRmdFormatButtonVisible(showRmdFormatMenu);
    rmdFormatButton_.setEnabled(showRmdFormatMenu);
    rmdFormatButton_.clearMenu();
    int parenPos = selectedOption.indexOf('(');
    if (parenPos != -1)
        selectedOption = selectedOption.substring(0, parenPos).trim();
    // don't show format text (but leave the code in for now in case
    // we change our mind)
    // setFormatText(selectedOption);
    setFormatText("");
    String prefix = fileType.isPlainMarkdown() ? "Preview " : "Knit to ";
    for (int i = 0; i < Math.min(options.size(), values.size()); i++) {
        String ext = extensions.get(i);
        ImageResource img = ext != null ? fileTypeRegistry_.getIconForFilename("output." + ext) : fileTypeRegistry_.getIconForFilename("Makefile");
        final String valueName = values.get(i);
        ScheduledCommand cmd = new ScheduledCommand() {

            @Override
            public void execute() {
                handlerManager_.fireEvent(new RmdOutputFormatChangedEvent(valueName));
            }
        };
        String text = ext == ".nb.html" ? "Preview Notebook" : prefix + options.get(i);
        MenuItem item = ImageMenuItem.create(img, text, cmd, 2);
        rmdFormatButton_.addMenuItem(item, values.get(i));
    }
    if (session_.getSessionInfo().getKnitParamsAvailable()) {
        final AppCommand knitWithParams = commands_.knitWithParameters();
        rmdFormatButton_.addSeparator();
        ScheduledCommand cmd = new ScheduledCommand() {

            @Override
            public void execute() {
                knitWithParams.execute();
            }
        };
        MenuItem item = new MenuItem(knitWithParams.getMenuHTML(false), true, cmd);
        rmdFormatButton_.addMenuItem(item, knitWithParams.getMenuLabel(false));
    }
    if (session_.getSessionInfo().getKnitWorkingDirAvailable()) {
        MenuBar knitDirMenu = new MenuBar(true);
        DocPropMenuItem knitInDocDir = new DocShadowPropMenuItem("Document Directory", docUpdateSentinel_, uiPrefs_.knitWorkingDir(), RenderRmdEvent.WORKING_DIR_PROP, UIPrefsAccessor.KNIT_DIR_DEFAULT);
        knitDirMenu.addItem(knitInDocDir);
        DocPropMenuItem knitInProjectDir = new DocShadowPropMenuItem("Project Directory", docUpdateSentinel_, uiPrefs_.knitWorkingDir(), RenderRmdEvent.WORKING_DIR_PROP, UIPrefsAccessor.KNIT_DIR_PROJECT);
        knitDirMenu.addItem(knitInProjectDir);
        DocPropMenuItem knitInCurrentDir = new DocShadowPropMenuItem("Current Working Directory", docUpdateSentinel_, uiPrefs_.knitWorkingDir(), RenderRmdEvent.WORKING_DIR_PROP, UIPrefsAccessor.KNIT_DIR_CURRENT);
        knitDirMenu.addItem(knitInCurrentDir);
        rmdFormatButton_.addSeparator();
        rmdFormatButton_.addMenuItem(knitDirMenu, "Knit Directory");
    }
    addClearKnitrCacheMenu(rmdFormatButton_);
    showRmdViewerMenuItems(true, canEditFormatOptions, fileType.isRmd(), RmdOutput.TYPE_STATIC);
    if (publishButton_ != null)
        publishButton_.setIsStatic(true);
    isShiny_ = false;
}
Also used : AppCommand(org.rstudio.core.client.command.AppCommand) ImageResource(com.google.gwt.resources.client.ImageResource) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) RmdOutputFormatChangedEvent(org.rstudio.studio.client.rmarkdown.events.RmdOutputFormatChangedEvent) ImageMenuItem(org.rstudio.studio.client.common.ImageMenuItem)

Example 7 with AppCommand

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

the class Shell method onExecutePendingInput.

@Override
public void onExecutePendingInput(ConsoleExecutePendingInputEvent event) {
    // take it if we are focused and we have a command to enter
    if (view_.getInputEditorDisplay().isFocused() && (view_.getInputEditorDisplay().getText().length() > 0)) {
        processCommandEntry();
    } else // otherwise delegate back to the source view. we do this via
    // executing a command which is a bit of hack but it's a clean
    // way to call code within the "current editor" (an event would
    // go to all editors). another alternative would be to 
    // call a method on the SourceShim
    {
        AppCommand command = commands_.getCommandById(event.getCommandId());
        // the current editor may be in another window; if one of our source
        // windows was last focused, use that one instead
        SourceWindowManager manager = RStudioGinjector.INSTANCE.getSourceWindowManager();
        if (!StringUtil.isNullOrEmpty(manager.getLastFocusedSourceWindowId())) {
            RStudioGinjector.INSTANCE.getSatelliteManager().dispatchCommand(command, SourceSatellite.NAME_PREFIX + manager.getLastFocusedSourceWindowId());
        } else {
            command.execute();
        }
    }
}
Also used : SourceWindowManager(org.rstudio.studio.client.workbench.views.source.SourceWindowManager) AppCommand(org.rstudio.core.client.command.AppCommand)

Example 8 with AppCommand

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

the class Source method manageCommands.

private void manageCommands() {
    boolean hasDocs = editors_.size() > 0;
    commands_.closeSourceDoc().setEnabled(hasDocs);
    commands_.closeAllSourceDocs().setEnabled(hasDocs);
    commands_.nextTab().setEnabled(hasDocs);
    commands_.previousTab().setEnabled(hasDocs);
    commands_.firstTab().setEnabled(hasDocs);
    commands_.lastTab().setEnabled(hasDocs);
    commands_.switchToTab().setEnabled(hasDocs);
    commands_.setWorkingDirToActiveDoc().setEnabled(hasDocs);
    HashSet<AppCommand> newCommands = activeEditor_ != null ? activeEditor_.getSupportedCommands() : new HashSet<AppCommand>();
    HashSet<AppCommand> commandsToEnable = new HashSet<AppCommand>(newCommands);
    commandsToEnable.removeAll(activeCommands_);
    HashSet<AppCommand> commandsToDisable = new HashSet<AppCommand>(activeCommands_);
    commandsToDisable.removeAll(newCommands);
    for (AppCommand command : commandsToEnable) {
        command.setEnabled(true);
        command.setVisible(true);
    }
    for (AppCommand command : commandsToDisable) {
        command.setEnabled(false);
        command.setVisible(false);
    }
    // commands which should always be visible even when disabled
    commands_.saveSourceDoc().setVisible(true);
    commands_.saveSourceDocAs().setVisible(true);
    commands_.printSourceDoc().setVisible(true);
    commands_.setWorkingDirToActiveDoc().setVisible(true);
    commands_.debugBreakpoint().setVisible(true);
    // manage synctex commands
    manageSynctexCommands();
    // manage vcs commands
    manageVcsCommands();
    // manage save and save all
    manageSaveCommands();
    // manage source navigation
    manageSourceNavigationCommands();
    // manage RSConnect commands
    manageRSConnectCommands();
    // manage R Markdown commands
    manageRMarkdownCommands();
    // manage multi-tab commands
    manageMultiTabCommands();
    activeCommands_ = newCommands;
    // give the active editor a chance to manage commands
    if (activeEditor_ != null)
        activeEditor_.manageCommands();
    assert verifyNoUnsupportedCommands(newCommands) : "Unsupported commands detected (please add to Source.dynamicCommands_)";
}
Also used : AppCommand(org.rstudio.core.client.command.AppCommand) HashSet(java.util.HashSet)

Example 9 with AppCommand

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

the class ChunkContextToolbar method createMenuItemForType.

private MenuItem createMenuItemForType(final AppCommand command, final String chunkType) {
    SafeHtml menuHTML = new SafeHtmlBuilder().appendHtmlConstant(command.getMenuHTML(false)).toSafeHtml();
    MenuItem menuItem = new MenuItem(menuHTML, new Command() {

        public void execute() {
            host_.switchChunk(chunkType);
        }
    });
    return menuItem;
}
Also used : AppCommand(org.rstudio.core.client.command.AppCommand) Command(com.google.gwt.user.client.Command) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) MenuItem(com.google.gwt.user.client.ui.MenuItem) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder)

Example 10 with AppCommand

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

the class TextEditingTargetWidget method addClearKnitrCacheMenu.

private void addClearKnitrCacheMenu(ToolbarPopupMenuButton menuButton) {
    final AppCommand clearKnitrCache = commands_.clearKnitrCache();
    menuButton.addSeparator();
    ScheduledCommand cmd = new ScheduledCommand() {

        @Override
        public void execute() {
            clearKnitrCache.execute();
        }
    };
    MenuItem item = new MenuItem(clearKnitrCache.getMenuHTML(false), true, cmd);
    menuButton.addMenuItem(item, clearKnitrCache.getMenuLabel(false));
}
Also used : AppCommand(org.rstudio.core.client.command.AppCommand) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) ImageMenuItem(org.rstudio.studio.client.common.ImageMenuItem)

Aggregations

AppCommand (org.rstudio.core.client.command.AppCommand)10 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)2 MenuItem (com.google.gwt.user.client.ui.MenuItem)2 VisibleChangedHandler (org.rstudio.core.client.command.VisibleChangedHandler)2 ImageMenuItem (org.rstudio.studio.client.common.ImageMenuItem)2 RunAsyncCallback (com.google.gwt.core.client.RunAsyncCallback)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 AnimationCallback (com.google.gwt.layout.client.Layout.AnimationCallback)1 ImageResource (com.google.gwt.resources.client.ImageResource)1 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)1 SafeHtmlBuilder (com.google.gwt.safehtml.shared.SafeHtmlBuilder)1 Command (com.google.gwt.user.client.Command)1 RootLayoutPanel (com.google.gwt.user.client.ui.RootLayoutPanel)1 SuggestOracle (com.google.gwt.user.client.ui.SuggestOracle)1 Inject (com.google.inject.Inject)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 CommandHandler (org.rstudio.core.client.command.CommandHandler)1 EnabledChangedHandler (org.rstudio.core.client.command.EnabledChangedHandler)1 SearchWidget (org.rstudio.core.client.widget.SearchWidget)1