use of com.google.gwt.user.client.ui.MenuItem in project rstudio by rstudio.
the class DocsMenu method setDocs.
public void setDocs(ImageResource[] icons, String[] names, String[] paths) {
clearItems();
names_.clear();
menuItems_.clear();
// de-duplicate names
names = deduplicate(names, paths);
assert icons.length == names.length && names.length == paths.length;
if (icons.length == 0) {
addItem(new DisabledMenuItem("(No documents)"));
}
for (int i = 0; i < icons.length; i++) {
String label = AppCommand.formatMenuLabel(icons[i], names[i] + " ", null);
final int tabIndex = i;
MenuItem item = addItem(label, true, new Command() {
public void execute() {
if (panel_ != null)
panel_.hide(false);
events_.fireEvent(new SwitchToDocEvent(tabIndex));
}
});
item.setTitle(paths[i]);
names_.add(names[i]);
menuItems_.add(item);
}
}
use of com.google.gwt.user.client.ui.MenuItem in project rstudio by rstudio.
the class CppCompletionPopupMenu method setCompletions.
public void setCompletions(JsArray<CppCompletion> completions, CommandWithArg<CppCompletion> onSelected) {
// save completions and selectable state
completions_ = completions;
onSelected_ = onSelected;
// clear existing items
updatingMenu_ = true;
menuBar_.clearItems();
// add items (remember first item for programmatic selection)
MenuItem firstItem = null;
for (int i = 0; i < completions.length(); i++) {
final CppCompletion completion = completions.get(i);
SafeHtmlBuilder sb = new SafeHtmlBuilder();
SafeHtmlUtil.appendImage(sb, RES.styles().itemImage(), completion.getIcon());
SafeHtmlUtil.appendSpan(sb, RES.styles().itemName(), completion.getTypedText());
MenuItem menuItem = new MenuItem(sb.toSafeHtml(), new ScheduledCommand() {
@Override
public void execute() {
docDisplay_.setFocus(true);
if (isSelectable())
onSelected_.execute(completion);
}
});
menuItem.addStyleName(RES.styles().itemMenu());
FontSizer.applyNormalFontSize(menuItem);
addItem(menuItem);
if (i == 0)
firstItem = menuItem;
}
updatingMenu_ = false;
// select first item
if (isSelectable() && (firstItem != null))
selectItem(firstItem);
if (completions.length() > 0) {
showMenu();
} else {
setVisible(false);
if (toolTip_ != null)
toolTip_.setVisible(false);
}
}
use of com.google.gwt.user.client.ui.MenuItem in project rstudio by rstudio.
the class HistoryBranchToolbarButton method onBeforePopulateMenu.
@Override
protected void onBeforePopulateMenu(ToolbarPopupMenu rootMenu) {
String label = "(all branches)";
rootMenu.addItem(new MenuItem(label, new SwitchBranchCommand(label, "--all")));
}
use of com.google.gwt.user.client.ui.MenuItem in project rstudio by rstudio.
the class BranchToolbarButton method populateMenu.
private void populateMenu(final ToolbarPopupMenu menu, final Map<String, List<String>> branchMap) {
MapUtil.forEach(branchMap, new MapUtil.ForEachCommand<String, List<String>>() {
@Override
public void execute(final String caption, final List<String> branches) {
// place commonly-used branches at the top
Collections.sort(branches, new Comparator<String>() {
private final String[] specialBranches_ = new String[] { "master", "develop", "trunk" };
@Override
public int compare(String o1, String o2) {
for (String specialBranch : specialBranches_) {
if (o1.endsWith(specialBranch))
return -1;
else if (o2.endsWith(specialBranch))
return 1;
}
return o1.compareToIgnoreCase(o2);
}
});
menu.addSeparator(new CustomMenuItemSeparator() {
@Override
public Widget createMainWidget() {
String branchLabel = caption.equals(LOCAL_BRANCHES) ? LOCAL_BRANCHES : "(Remote: " + caption + ")";
Label label = new Label(branchLabel);
label.addStyleName(ThemeStyles.INSTANCE.menuSubheader());
label.getElement().getStyle().setPaddingLeft(2, Unit.PX);
return label;
}
});
menu.addSeparator();
for (String branch : branches) {
// skip detached branches
if (branch.contains("HEAD detached at"))
continue;
// skip HEAD branches
if (branch.contains("HEAD ->"))
continue;
// construct branch label without remotes prefix
final String branchLabel = branch.replaceAll("^remotes/" + caption + "/", "");
final String branchValue = branch.replaceAll("\\s+\\-\\>.*", "");
menu.addItem(new MenuItem(branchLabel, new SwitchBranchCommand(branchLabel, branchValue)));
}
}
});
}
use of com.google.gwt.user.client.ui.MenuItem in project rstudio by rstudio.
the class TerminalPopupMenu method getDynamicPopupMenu.
@Override
public void getDynamicPopupMenu(final DynamicPopupMenuCallback callback) {
// clean out existing entries
clearItems();
addItem(commands_.newTerminal().createMenuItem(false));
addSeparator();
if (terminals_.terminalCount() > 0) {
for (final String handle : terminals_) {
Scheduler.ScheduledCommand cmd = new Scheduler.ScheduledCommand() {
@Override
public void execute() {
eventBus_.fireEvent(new SwitchToTerminalEvent(handle));
}
};
String caption = trimCaption(terminals_.getCaption(handle));
if (caption == null) {
continue;
}
// visual indicator that terminal has processes running
caption = addBusyIndicator(caption, terminals_.getHasSubprocs(handle));
String menuHtml = AppCommand.formatMenuLabel(null, /*icon*/
caption, /*label*/
false, /*html*/
null, /*shortcut*/
null, /*rightImage*/
null);
/*rightImageDesc*/
addItem(new MenuItem(menuHtml, true, cmd));
}
addSeparator();
addItem(commands_.renameTerminal().createMenuItem(false));
addItem(commands_.clearTerminalScrollbackBuffer().createMenuItem(false));
addSeparator();
addItem(commands_.previousTerminal().createMenuItem(false));
addItem(commands_.nextTerminal().createMenuItem(false));
addSeparator();
addItem(commands_.closeTerminal().createMenuItem(false));
}
callback.onPopupMenu(this);
}
Aggregations