Search in sources :

Example 1 with CustomMenuItemSeparator

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)));
            }
        }
    });
}
Also used : CustomMenuItemSeparator(org.rstudio.core.client.widget.CustomMenuItemSeparator) MapUtil(org.rstudio.core.client.MapUtil) Label(com.google.gwt.user.client.ui.Label) ArrayList(java.util.ArrayList) List(java.util.List) MenuItem(com.google.gwt.user.client.ui.MenuItem) JsArrayString(com.google.gwt.core.client.JsArrayString) Comparator(java.util.Comparator)

Aggregations

JsArrayString (com.google.gwt.core.client.JsArrayString)1 Label (com.google.gwt.user.client.ui.Label)1 MenuItem (com.google.gwt.user.client.ui.MenuItem)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 List (java.util.List)1 MapUtil (org.rstudio.core.client.MapUtil)1 CustomMenuItemSeparator (org.rstudio.core.client.widget.CustomMenuItemSeparator)1