From d2a2cd9c07d1643e332670a68d6caa08776a521f Mon Sep 17 00:00:00 2001 From: nik Date: Thu, 7 Nov 2013 15:51:40 +0400 Subject: [PATCH] don't hide run configuration type if there are only one irrelevant type (IDEA-116046) --- .../execution/impl/RunConfigurable.java | 45 +++++++++---------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurable.java b/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurable.java index ec9511b6a9b7..f8b51432e868 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurable.java +++ b/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurable.java @@ -1088,44 +1088,26 @@ class RunConfigurable extends BaseConfigurable { } private void showAddPopup(final boolean showApplicableTypesOnly) { - final JBPopupFactory popupFactory = JBPopupFactory.getInstance(); - final List configurationTypes; - int hiddenCount = 0; - if (showApplicableTypesOnly) { - List applicableTypes = new ArrayList(); - for (ConfigurationType type : getRunManager().getConfigurationFactories(false)) { - if (isApplicable(type)) { - applicableTypes.add(type); - } - else { - hiddenCount++; - } - } - configurationTypes = applicableTypes; - } - else { - configurationTypes = new ArrayList(Arrays.asList(getRunManager().getConfigurationFactories(false))); - } - + ConfigurationType[] allTypes = getRunManager().getConfigurationFactories(false); + final List configurationTypes = getTypesToShow(showApplicableTypesOnly, allTypes); Collections.sort(configurationTypes, new Comparator() { @Override public int compare(final ConfigurationType type1, final ConfigurationType type2) { return type1.getDisplayName().compareToIgnoreCase(type2.getDisplayName()); } }); + final int hiddenCount = allTypes.length - configurationTypes.size(); if (hiddenCount > 0) { configurationTypes.add(null); } - final int finalHiddenCount = hiddenCount; - final ListPopup popup = - popupFactory.createListPopup(new BaseListPopupStep( + final ListPopup popup = JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep( ExecutionBundle.message("add.new.run.configuration.acrtion.name"), configurationTypes) { @Override @NotNull public String getTextFor(final ConfigurationType type) { - return type != null ? type.getDisplayName() : "(" + finalHiddenCount + " more items)"; + return type != null ? type.getDisplayName() : "(" + hiddenCount + " more items)"; } @Override @@ -1197,7 +1179,6 @@ class RunConfigurable extends BaseConfigurable { createNewConfiguration(factory); return FINAL_CHOICE; } - }; } @@ -1205,12 +1186,26 @@ class RunConfigurable extends BaseConfigurable { public boolean hasSubstep(final ConfigurationType type) { return type != null && type.getConfigurationFactories().length > 1; } - }); //new TreeSpeedSearch(myTree); popup.showUnderneathOf(myToolbarDecorator.getActionsPanel()); } + private List getTypesToShow(boolean showApplicableTypesOnly, ConfigurationType[] allTypes) { + if (showApplicableTypesOnly) { + List applicableTypes = new ArrayList(); + for (ConfigurationType type : allTypes) { + if (isApplicable(type)) { + applicableTypes.add(type); + } + } + if (applicableTypes.size() < allTypes.length - 1) { + return applicableTypes; + } + } + return new ArrayList(Arrays.asList(allTypes)); + } + private boolean isApplicable(ConfigurationType type) { for (ConfigurationFactory factory : type.getConfigurationFactories()) { if (factory.isApplicable(myProject)) {