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;
}
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();
}
}
}
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_)";
}
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;
}
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));
}
Aggregations