use of org.rstudio.core.client.widget.CustomMenuItemSeparator 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)));
}
}
});
}
Aggregations