@Override
  public void actionPerformed(@NotNull AnActionEvent e) {
    JComponent button = e.getPresentation().getClientProperty(CustomComponentAction.COMPONENT_KEY);
    if (button == null || !button.isValid()) return;
    List<ScopeDescriptor> items = new ArrayList<>();
    HashMap<ScopeDescriptor, ScopeSeparator> separators = new HashMap<>();
    final ScopeSeparator[] nextSeparator = {null};
    processScopes(o -> {
      if (o instanceof ScopeSeparator separator && !items.isEmpty()) {
        nextSeparator[0] = separator;
      } else if (!o.scopeEquals(null) && o.getScope() instanceof GlobalSearchScope) {
        if (nextSeparator[0] != null) {
          separators.put(items.get(items.size() - 1), nextSeparator[0]);
          nextSeparator[0] = null;
        }
        items.add(o);
      }
      return true;
    });
    BaseListPopupStep<ScopeDescriptor> step = new BaseListPopupStep<>("", items) {
      @Nullable
      @Override
      public PopupStep<?> onChosen(ScopeDescriptor selectedValue, boolean finalChoice) {
        onScopeSelected(selectedValue);
        ActionToolbar toolbar = ActionToolbar.findToolbarBy(button);
        if (toolbar != null) toolbar.updateActionsImmediately();
        return FINAL_CHOICE;
      }

      @Override
      public boolean isSpeedSearchEnabled() {
        return true;
      }

      @NotNull
      @Override
      public String getTextFor(ScopeDescriptor value) {
        return StringUtil.notNullize(value.getDisplayName());
      }

      @Override
      public @Nullable ListSeparator getSeparatorAbove(ScopeDescriptor value) {
        var separator = separators.get(value);
        if (separator != null) {
          return new ListSeparator(separator.getDisplayName());
        }
        return null;
      }

      @Override
      public Icon getIconFor(ScopeDescriptor value) {
        return value.getIcon();
      }

      @Override
      public boolean isSelectable(ScopeDescriptor value) {
        return value.getScope() instanceof GlobalSearchScope;
      }
    };
    ScopeDescriptor selection = getSelectedScope();
    step.setDefaultOptionIndex(ContainerUtil.indexOf(items, o -> Objects.equals(o.getDisplayName(), selection.getDisplayName())));
    ListPopupImpl popup = new ListPopupImpl(e.getProject(), step);
    popup.setMaxRowCount(10);
    popup.showUnderneathOf(button);
  }
@Override
  public void actionPerformed(@NotNull AnActionEvent e)