KT-3008 Add UI that allows to change module kind in IDEA Kotlin configurator

This commit is contained in:
Alexey Andreev
2016-04-22 14:06:16 +03:00
parent 496539d101
commit b090b79d92
6 changed files with 71 additions and 14 deletions
@@ -3,7 +3,7 @@
<grid id="27dc6" binding="contentPane" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="594" height="357"/>
<xy x="20" y="20" width="828" height="622"/>
</constraints>
<properties/>
<border type="none"/>
@@ -81,7 +81,7 @@
</component>
</children>
</grid>
<grid id="98e8a" layout-manager="GridLayoutManager" row-count="5" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="98e8a" layout-manager="GridLayoutManager" row-count="6" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
@@ -160,6 +160,23 @@
<text resource-bundle="org/jetbrains/kotlin/idea/KotlinBundle" key="kotlin.compiler.js.option.output.copy.files"/>
</properties>
</component>
<component id="915d" class="javax.swing.JLabel">
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="ca29c"/>
<text value="Module &amp;kind:"/>
</properties>
</component>
<component id="ca29c" class="javax.swing.JComboBox" binding="moduleKindComboBox">
<constraints>
<grid row="5" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<model/>
</properties>
</component>
</children>
</grid>
</children>
@@ -40,8 +40,18 @@ 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;
public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Configurable.NoScroll{
private static final List<String> 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<String> moduleKindIds = asList("plain", "amd", "commonjs", "umd");
private final CommonCompilerArguments commonCompilerArguments;
private final K2JSCompilerArguments k2jsCompilerArguments;
private final CompilerSettings compilerSettings;
@@ -61,6 +71,7 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co
private JCheckBox copyRuntimeFilesCheckBox;
private JCheckBox keepAliveCheckBox;
private JCheckBox enablePreciseIncrementalCheckBox;
private JComboBox moduleKindComboBox;
public KotlinCompilerConfigurableTab(Project project) {
this.commonCompilerArguments = KotlinCommonCompilerArgumentsHolder.getInstance(project).getSettings();
@@ -84,6 +95,16 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co
labelForOutputDirectory.setEnabled(copyRuntimeFilesCheckBox.isSelected());
}
});
fillModuleKindList();
}
@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);
}
}
@NotNull
@@ -116,7 +137,12 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co
ComparingUtils.isModified(generateSourceMapsCheckBox, k2jsCompilerArguments.sourceMap) ||
isModified(outputPrefixFile, k2jsCompilerArguments.outputPrefix) ||
isModified(outputPostfixFile, k2jsCompilerArguments.outputPostfix);
isModified(outputPostfixFile, k2jsCompilerArguments.outputPostfix) ||
!getSelectedModuleKind().equals(k2jsCompilerArguments.moduleKind);
}
private String getSelectedModuleKind() {
return moduleKindIds.get(moduleKindComboBox.getSelectedIndex());
}
@Override
@@ -137,6 +163,7 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co
k2jsCompilerArguments.sourceMap = generateSourceMapsCheckBox.isSelected();
k2jsCompilerArguments.outputPrefix = StringUtil.nullize(outputPrefixFile.getText(), true);
k2jsCompilerArguments.outputPostfix = StringUtil.nullize(outputPostfixFile.getText(), true);
k2jsCompilerArguments.moduleKind = getSelectedModuleKind();
BuildManager.getInstance().clearState(project);
}
@@ -154,6 +181,13 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co
generateSourceMapsCheckBox.setSelected(k2jsCompilerArguments.sourceMap);
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);
}
@Override