diff --git a/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerConfigurableTab.java b/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerConfigurableTab.java index 8b76a36ac2a..4f7592b6054 100644 --- a/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerConfigurableTab.java +++ b/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerConfigurableTab.java @@ -27,6 +27,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.TextComponentAccessor; import com.intellij.openapi.ui.TextFieldWithBrowseButton; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.ui.ListCellRendererWrapper; import com.intellij.ui.RawCommandLineEditor; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; @@ -41,19 +42,11 @@ import org.jetbrains.kotlin.idea.PluginStartupComponent; import javax.swing.*; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; -import java.util.List; - -import static java.util.Arrays.asList; +import java.util.LinkedHashMap; +import java.util.Map; public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Configurable.NoScroll{ - private static final List moduleKindDescriptions = asList( - "Plain (put to global scope)", - "AMD", - "CommonJS/node.js", - "UMD (detect AMD or CommonJS if available, fallback to plain)" - ); - private static final List moduleKindIds = asList(K2JsArgumentConstants.MODULE_PLAIN, K2JsArgumentConstants.MODULE_AMD, - K2JsArgumentConstants.MODULE_COMMONJS, K2JsArgumentConstants.MODULE_UMD); + private static final Map moduleKindDescriptions = new LinkedHashMap(); private final CommonCompilerArguments commonCompilerArguments; private final K2JSCompilerArguments k2jsCompilerArguments; private final CompilerSettings compilerSettings; @@ -75,6 +68,13 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co private JCheckBox enablePreciseIncrementalCheckBox; private JComboBox moduleKindComboBox; + static { + moduleKindDescriptions.put(K2JsArgumentConstants.MODULE_PLAIN, "Plain (put to global scope)"); + moduleKindDescriptions.put(K2JsArgumentConstants.MODULE_AMD, "AMD"); + moduleKindDescriptions.put(K2JsArgumentConstants.MODULE_COMMONJS, "CommonJS"); + moduleKindDescriptions.put(K2JsArgumentConstants.MODULE_UMD, "UMD (detect AMD or CommonJS if available, fallback to plain)"); + } + public KotlinCompilerConfigurableTab(Project project) { this.commonCompilerArguments = KotlinCommonCompilerArgumentsHolder.getInstance(project).getSettings(); this.k2jsCompilerArguments = Kotlin2JsCompilerArgumentsHolder.getInstance(project).getSettings(); @@ -103,10 +103,22 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co @SuppressWarnings("unchecked") private void fillModuleKindList() { - for (String description : moduleKindDescriptions) { - // TODO: not sure if it's a right way to add items to a combo box - moduleKindComboBox.addItem(description); + for (String moduleKind : moduleKindDescriptions.keySet()) { + moduleKindComboBox.addItem(moduleKind); } + moduleKindComboBox.setRenderer(new ListCellRendererWrapper() { + @Override + public void customize(JList list, String value, int index, boolean selected, boolean hasFocus) { + setText(getModuleKindDescription(value)); + } + }); + } + + @NotNull + private static String getModuleKindDescription(@NotNull String moduleKind) { + String result = moduleKindDescriptions.get(moduleKind); + assert result != null : "Module kind " + moduleKind + " was not added to combobox, therefore it should not be here"; + return result; } @NotNull @@ -144,7 +156,7 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co } private String getSelectedModuleKind() { - return moduleKindIds.get(moduleKindComboBox.getSelectedIndex()); + return (String) moduleKindComboBox.getSelectedItem(); } @Override @@ -184,12 +196,7 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co outputPrefixFile.setText(k2jsCompilerArguments.outputPrefix); outputPostfixFile.setText(k2jsCompilerArguments.outputPostfix); - String moduleKind = k2jsCompilerArguments.moduleKind; - int index = moduleKind != null ? moduleKindIds.indexOf(moduleKind) : 0; - if (index < 0) { - index = 0; - } - moduleKindComboBox.setSelectedIndex(index); + moduleKindComboBox.setSelectedItem(k2jsCompilerArguments.moduleKind); } @Override