Disposable (@NotNull Component contentPane) { DefaultActionGroup actions = new DefaultActionGroup(); // // Collect touchbar actions from component hierarchy. // List<AnAction> actionList = findAllTouchbarActions(contentPane); if (actionList != null) { actions.addAll(actionList); } if (LOG.isDebugEnabled()) { if (actionList == null || actionList.isEmpty()) { LOG.debug("window '%s' hasn't any touchbar actions", contentPane); } else { List<AnAction> leaves = new ArrayList<>(); Helpers.collectLeafActions(actions, leaves); LOG.debug("show actions of window '%s' (count=%d):", contentPane, leaves.size()); for (AnAction act : leaves) { LOG.debug("\t'%s' | id=%s | %s", act.getTemplateText(), Helpers.getActionId(act), act); } } } // // Process customizations // final ModalityState ms = LaterInvocator.getCurrentModalityState(); final TBPanel.CrossEscInfo crossEscInfo = isCrossEscGroup(actions) ? new TBPanel.CrossEscInfo(true, false) : null; final Customizer customizer = new Customizer(crossEscInfo, null/*dialog actions mustn't be closed because of auto-close*/) { private final @NotNull WeakReference<Component> myRoot = new WeakReference<>(contentPane); @Override void onBeforeActionsExpand(@NotNull ActionGroup actionGroup) { // NOTE: possible optimization - listen for component hierarchy changes and do traverse only when it was changed List<AnAction> allActs = findAllTouchbarActions(myRoot.get()); actions.removeAll(); if (allActs != null) { actions.addAll(allActs); } } }; customizer.addBaseCustomizations((pc, button, presentation) -> { // set common properties button.setModality(ms); // process per-action data from TouchbarActionCustomizations boolean isDefault = false; final TouchbarActionCustomizations actionCustomizations = TouchbarActionCustomizations.getCustomizations(button.getAnAction()); if (actionCustomizations != null) { isDefault = actionCustomizations.isDefault(); if (!isDefault && actionCustomizations.getComponent() instanceof JButton jb) { // also check properties of JButton isDefault = jb.getAction() != null ? jb.getAction().getValue(DialogWrapper.DEFAULT_ACTION) != null : jb.isDefaultButton(); } button.setComponent(actionCustomizations.getComponent()); button.setText(actionCustomizations.isShowText() ? presentation.getText() : null); button.setIcon(actionCustomizations.isShowImage() ? presentation.getIcon() : null); // small customization for south-panel dialog buttons if (actionCustomizations.getComponent() instanceof JButton) { button.setLayout(BUTTON_MIN_WIDTH_DLG, NSTLibrary.LAYOUT_FLAG_MIN_WIDTH, BUTTON_IMAGE_MARGIN, BUTTON_BORDER); } } else { TouchbarActionCustomizations parentAc = pc == null ? null : pc.getCustomizations(); button.setIconAndTextFromPresentation(presentation, parentAc); button.setComponent(parentAc == null ? null : parentAc.getComponent()); } if (isDefault) { button.setColored(); } }); TouchBarsManager.registerAndShow(contentPane, actions, customizer); return () -> { LOG.debug("hide actions of window '%s'", contentPane); TouchBarsManager.unregister(contentPane); }; }