public static @NotNull JBPopup createAddPopup(@NotNull Project project,
                                                final @NotNull List<? extends ConfigurationType> typesToShow,
                                                final @NotNull @Nls String defaultText,
                                                final @NotNull Consumer<? super ConfigurationFactory> creator,
                                                final @Nullable ConfigurationType selectedConfigurationType,
                                                final @Nullable Runnable finalStep, boolean showTitle) {
    if (Registry.is("run.configuration.use.tree.popup.to.add.new", false)) {
      return createAddTreePopup(project, creator, selectedConfigurationType, showTitle);
    }

    BaseListPopupStep<ConfigurationType> step = new BaseListPopupStep<>(
      showTitle ? ExecutionBundle.message("add.new.run.configuration.action2.name") : null, typesToShow) {

      @Override
      public @NotNull String getTextFor(final ConfigurationType type) {
        return type != HIDDEN_ITEMS_STUB ? type.getDisplayName() : defaultText;
      }

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

      @Override
      public Icon getIconFor(final ConfigurationType type) {
        return type.getIcon();
      }

      @Override
      public PopupStep<?> onChosen(final ConfigurationType type, final boolean finalChoice) {
        if (hasSubstep(type)) {
          return getSupStep(type);
        }
        if (type == HIDDEN_ITEMS_STUB) {
          return doFinalStep(finalStep);
        }

        final ConfigurationFactory[] factories = type.getConfigurationFactories();
        if (factories.length > 0) {
          creator.consume(factories[0]);
        }
        return FINAL_CHOICE;
      }

      @Override
      public int getDefaultOptionIndex() {
        return selectedConfigurationType != HIDDEN_ITEMS_STUB
               ? typesToShow.indexOf(selectedConfigurationType)
               : super.getDefaultOptionIndex();
      }

      private ListPopupStep<?> getSupStep(final ConfigurationType type) {
        final ConfigurationFactory[] factories = type.getConfigurationFactories();
        Arrays.sort(factories, (factory1, factory2) -> factory1.getName().compareToIgnoreCase(factory2.getName()));
        return new BaseListPopupStep<>(
          ExecutionBundle.message("add.new.run.configuration.action.name", type.getDisplayName()), factories) {

          @Override
          public @NotNull String getTextFor(final ConfigurationFactory value) {
            return value.getName();
          }

          @Override
          public Icon getIconFor(final ConfigurationFactory factory) {
            return factory.getIcon();
          }

          @Override
          public PopupStep<?> onChosen(final ConfigurationFactory factory, final boolean finalChoice) {
            creator.consume(factory);
            return FINAL_CHOICE;
          }
        };
      }

      @Override
      public boolean hasSubstep(final ConfigurationType type) {
        return type.getConfigurationFactories().length > 1;
      }
    };

    return new ListPopupImpl(project, step) {
      @Override
      protected void onSpeedSearchPatternChanged() {
        List<ConfigurationType> values = step.getValues();
        values.clear();
        values.addAll(RunConfigurable.Companion.configurationTypeSorted(project,
                                                                        false,
                                                                        ConfigurationType.CONFIGURATION_TYPE_EP.getExtensionList(),
                                                                        true));

        getListModel().updateOriginalList();
        super.onSpeedSearchPatternChanged();
      }
    };
  }
public static @NotNull JBPopup createAddPopup(@NotNull Project project,
                                                final @NotNull List<? extends ConfigurationType> typesToShow,
                                                final @NotNull @Nls String defaultText,
                                                final @NotNull Consumer<? super ConfigurationFactory> creator,
                                                final @Nullable ConfigurationType selectedConfigurationType,
                                                final @Nullable Runnable finalStep, boolean showTitle)