use of com.google.gwt.user.client.ui.MenuItem 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 com.google.gwt.user.client.ui.MenuItem in project rstudio by rstudio.
the class TextEditingTargetPresentationHelper method buildSlideMenu.
public void buildSlideMenu(final String path, boolean isDirty, final EditingTarget editor, final CommandWithArg<StatusBarPopupRequest> onCompleted) {
// rpc response handler
SimpleRequestCallback<SlideNavigation> requestCallback = new SimpleRequestCallback<SlideNavigation>() {
@Override
public void onResponseReceived(SlideNavigation slideNavigation) {
// create the menu and make sure we have some slides to return
StatusBarPopupMenu menu = new StatusBarPopupMenu();
if (slideNavigation.getTotalSlides() == 0) {
onCompleted.execute(new StatusBarPopupRequest(menu, null));
return;
}
MenuItem defaultMenuItem = null;
int length = slideNavigation.getItems().length();
for (int i = 0; i < length; i++) {
SlideNavigationItem item = slideNavigation.getItems().get(i);
String title = item.getTitle();
if (StringUtil.isNullOrEmpty(title))
title = "(Untitled Slide)";
StringBuilder indentBuilder = new StringBuilder();
for (int level = 0; level < item.getIndent(); level++) indentBuilder.append(" ");
SafeHtmlBuilder labelBuilder = new SafeHtmlBuilder();
labelBuilder.appendHtmlConstant(indentBuilder.toString());
labelBuilder.appendEscaped(title);
final int targetSlide = i;
final MenuItem menuItem = new MenuItem(labelBuilder.toSafeHtml(), new Command() {
public void execute() {
navigateToSlide(editor, targetSlide);
}
});
menu.addItem(menuItem);
// see if this is the default menu item
if (defaultMenuItem == null && item.getLine() >= (docDisplay_.getSelectionStart().getRow())) {
defaultMenuItem = menuItem;
}
}
StatusBarPopupRequest request = new StatusBarPopupRequest(menu, defaultMenuItem);
onCompleted.execute(request);
}
};
// send code over the wire if we are dirty
if (isDirty) {
server_.getSlideNavigationForCode(docDisplay_.getCode(), FileSystemItem.createFile(path).getParentPathString(), requestCallback);
} else {
server_.getSlideNavigationForFile(path, requestCallback);
}
}
use of com.google.gwt.user.client.ui.MenuItem in project rstudio by rstudio.
the class TextEditingTarget method addFunctionsToMenu.
private MenuItem addFunctionsToMenu(StatusBarPopupMenu menu, final JsArray<Scope> funcs, String indent, Scope defaultFunction, boolean includeNoFunctionsMessage) {
MenuItem defaultMenuItem = null;
if (funcs.length() == 0 && includeNoFunctionsMessage) {
String type = fileType_.canExecuteChunks() ? "chunks" : "functions";
MenuItem noFunctions = new MenuItem("(No " + type + " defined)", false, (Command) null);
noFunctions.setEnabled(false);
noFunctions.getElement().addClassName("disabled");
menu.addItem(noFunctions);
}
for (int i = 0; i < funcs.length(); i++) {
final Scope func = funcs.get(i);
String childIndent = indent;
if (!StringUtil.isNullOrEmpty(func.getLabel())) {
SafeHtmlBuilder labelBuilder = new SafeHtmlBuilder();
labelBuilder.appendHtmlConstant(indent);
labelBuilder.appendEscaped(func.getLabel());
final MenuItem menuItem = new MenuItem(labelBuilder.toSafeHtml(), new Command() {
public void execute() {
docDisplay_.navigateToPosition(toSourcePosition(func), true);
}
});
addScopeStyle(menuItem, func);
menu.addItem(menuItem);
childIndent = indent + " ";
if (defaultFunction != null && defaultMenuItem == null && func.getLabel().equals(defaultFunction.getLabel()) && func.getPreamble().getRow() == defaultFunction.getPreamble().getRow() && func.getPreamble().getColumn() == defaultFunction.getPreamble().getColumn()) {
defaultMenuItem = menuItem;
}
}
MenuItem childDefaultMenuItem = addFunctionsToMenu(menu, func.getChildren(), childIndent, defaultMenuItem == null ? defaultFunction : null, false);
if (childDefaultMenuItem != null)
defaultMenuItem = childDefaultMenuItem;
}
return defaultMenuItem;
}
use of com.google.gwt.user.client.ui.MenuItem in project rstudio by rstudio.
the class TextEditingTarget method createMenuItemForType.
private MenuItem createMenuItemForType(final TextFileType type) {
SafeHtmlBuilder labelBuilder = new SafeHtmlBuilder();
labelBuilder.appendEscaped(type.getLabel());
MenuItem menuItem = new MenuItem(labelBuilder.toSafeHtml(), new Command() {
public void execute() {
docUpdateSentinel_.changeFileType(type.getTypeId(), new SaveProgressIndicator(null, type, null));
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
focus();
}
});
}
});
return menuItem;
}
Aggregations