private void _rebuildButtons(@NotNull List<? extends AnAction> actions) {
    //
    // clear all items
    //
    softClear();

    //
    // fill items with actions
    //

    List<AnAction> principal = null;
    TBItemGroup principalGroup = null;
    if (myCustomizer != null) {
      myCustomizer.prepare(myActionGroup);

      // collect actions from principal group (NSTouchbarGroupItem must be created with fixed list of items)
      for (AnAction action: actions) {
        if (myCustomizer.isPrincipalGroupAction(action)) {
          if (principal == null) {
            principal = new ArrayList<>();
          }
          principal.add(action);
        }
      }

      // create group item for principal actions
      if (principal != null) {
        principalGroup = myGroupPool.remove(principal.size());
        if (principalGroup == null) {
          principalGroup = new TBItemGroup(myItems.toString(), myItemListener, principal);
        }
      }
    }

    int separatorCounter = 0;
    for (AnAction action: actions) {
      // 1. create separator
      // NOTE: we don't add separator into Main (or Principal) groups
      // just add separator into current list of actions
      if (action instanceof Separator sep) {
        int increment = 1;
        if (sep.getText() != null) {
          if (sep.getText().equals(ourSmallSeparatorText)) {
            addSpacing(false);
          }
          else if (sep.getText().equals(ourLargeSeparatorText)) {
            addSpacing(true);
          }
          else if (sep.getText().equals(ourFlexibleSeparatorText)) {
            addFlexibleSpacing();
          }
        }
        else {
          separatorCounter += increment;
        }

        continue;
      } // separator

      if (separatorCounter > 0) {
        if (separatorCounter == 1) {
          addSpacing(false);
        }
        else if (separatorCounter == 2) {
          addSpacing(true);
        }
        else {
          addFlexibleSpacing();
        }
        separatorCounter = 0;
      }

      // 2. find or create action button
      TBItemAnActionButton butt = null;

      // 2.1 check if current action from principal group
      if (principal != null) {
        int principalIndex = principal.indexOf(action);
        if (principalIndex >= 0) {
          if (principalIndex == 0) {
            addItem(principalGroup);
            setPrincipal(principalGroup);
          }
          butt = principalGroup.getItem(principalIndex);
          butt.setAnAction(action);
        }
      }

      // 2.2 create if wasn't found in principalGroup
      if (butt == null) {
        butt = createActionButton(action);
        addItem(butt);
      }

      // 3. update button with use of presentation
      final @NotNull Presentation presentation = myFactory.getPresentation(action);

      butt.myIsVisible = presentation.isVisible();

      if (!butt.myIsVisible)
        continue;

      final long startNs = butt.actionStats != null ? System.nanoTime() : 0;
      butt.setDisabled(!presentation.isEnabled());

      boolean isSelected = false;
      if (butt.getAnAction() instanceof Toggleable) {
        isSelected = Toggleable.isSelected(presentation);
        butt.updateOptions |= NSTLibrary.BUTTON_UPDATE_FLAGS; // permanent update of toggleable-buttons (do we really need this ??)
      }
      butt.setSelected(isSelected);

      // 5. customize if necessary
      if (myCustomizer == null || !myCustomizer.applyCustomizations(butt, presentation)) {
        // Customizations weren't found, so use default view style: only icon (if presented, otherwise text)
        butt.setIconFromPresentation(presentation);
        final boolean hideText = butt.originIcon != null;
        final String text = hideText ? null : presentation.getText();
        butt.setText(text);
      }

      if (butt.actionStats != null)
        butt.actionStats.updateViewNs += System.nanoTime() - startNs;

      // 6. All visual data (img/text/flags) is set now, schedule async update for native peers (and collect buttons with updates)
      butt.updateLater(false);
    } // foreach action

    //
    // update visible items of native peer
    //
    selectVisibleItemsToShow();
  }
private void _rebuildButtons(@NotNull List<? extends AnAction> actions)