List<AnAction> (@NotNull List<? extends AnAction> visibleChildren, @NotNull UpdateSession updateSession) { LinkedHashSet<AnAction> heaviest = null; double maxWeight = Presentation.DEFAULT_WEIGHT; for (AnAction action : visibleChildren) { Presentation presentation = updateSession.presentation(action); if (presentation.isEnabled() && presentation.isVisible()) { if (presentation.getWeight() > maxWeight) { maxWeight = presentation.getWeight(); heaviest = new LinkedHashSet<>(); } if (presentation.getWeight() == maxWeight && heaviest != null) { heaviest.add(action); } } } if (heaviest == null) { return new ArrayList<>(visibleChildren); } ArrayList<AnAction> chosen = new ArrayList<>(); boolean prevSeparator = true; for (AnAction action : visibleChildren) { final boolean separator = action instanceof Separator; if (separator && !prevSeparator) { chosen.add(action); } prevSeparator = separator; if (shouldBeChosenAnyway(action)) { heaviest.add(action); } if (heaviest.contains(action)) { chosen.add(action); } } ActionGroup other = new ExcludingActionGroup(getDelegate(), heaviest); other.setPopup(true); updateSession.presentation(other).setText(IdeBundle.messagePointer("action.presentation.WeighingActionGroup.text")); return JBIterable.from(chosen).append(new Separator()).append(other).toList(); }