MPP wizard: add combo-box with JDK for JVM platform, if any
Related to KT-23097
This commit is contained in:
+8
-5
@@ -36,6 +36,7 @@ import javax.swing.Icon
|
||||
class KotlinGradleMultiplatformModuleBuilder : GradleModuleBuilder() {
|
||||
var commonModuleName: String? = null
|
||||
var jvmModuleName: String? = null
|
||||
var jdk: Sdk? = null
|
||||
var jsModuleName: String? = null
|
||||
|
||||
override fun getBuilderId() = "kotlin.gradle.multiplatform"
|
||||
@@ -60,7 +61,7 @@ class KotlinGradleMultiplatformModuleBuilder : GradleModuleBuilder() {
|
||||
|
||||
val contentRoot = module.rootManager.contentRoots.firstOrNull() ?: return
|
||||
setupCommonModule(module, contentRoot)
|
||||
setupPlatformModule(module, contentRoot, jvmModuleName, GradleKotlinMPPJavaFrameworkSupportProvider())
|
||||
setupPlatformModule(module, contentRoot, jvmModuleName, GradleKotlinMPPJavaFrameworkSupportProvider(), jdk)
|
||||
setupPlatformModule(module, contentRoot, jsModuleName, GradleKotlinMPPJSFrameworkSupportProvider())
|
||||
|
||||
val settingsGradle = contentRoot.findChild("settings.gradle")
|
||||
@@ -78,13 +79,14 @@ class KotlinGradleMultiplatformModuleBuilder : GradleModuleBuilder() {
|
||||
rootModule: Module,
|
||||
contentRoot: VirtualFile,
|
||||
childModuleName: String?,
|
||||
sdk: Sdk? = null,
|
||||
extendScript: (BuildScriptDataBuilder, Sdk?) -> Unit = { _, _ -> }
|
||||
) {
|
||||
if (childModuleName.isNullOrEmpty()) return
|
||||
val moduleDir = contentRoot.createChildDirectory(this, childModuleName!!)
|
||||
val buildGradle = moduleDir.createChildData(null, "build.gradle")
|
||||
val buildScriptData = BuildScriptDataBuilder(buildGradle)
|
||||
extendScript(buildScriptData, rootModule.rootManager.sdk)
|
||||
extendScript(buildScriptData, sdk ?: rootModule.rootManager.sdk)
|
||||
VfsUtil.saveText(buildGradle, buildScriptData.buildConfigurationPart() + buildScriptData.buildMainPart())
|
||||
}
|
||||
|
||||
@@ -99,9 +101,10 @@ class KotlinGradleMultiplatformModuleBuilder : GradleModuleBuilder() {
|
||||
rootModule: Module,
|
||||
contentRoot: VirtualFile,
|
||||
platformModuleName: String?,
|
||||
supportProvider: GradleKotlinFrameworkSupportProvider
|
||||
) = setupChildModule(rootModule, contentRoot, platformModuleName) { builder, sdk ->
|
||||
supportProvider.addSupport(builder, sdk)
|
||||
supportProvider: GradleKotlinFrameworkSupportProvider,
|
||||
sdk: Sdk? = null
|
||||
) = setupChildModule(rootModule, contentRoot, platformModuleName, sdk) { builder, finalSdk ->
|
||||
supportProvider.addSupport(builder, finalSdk)
|
||||
val dependency = commonModuleName ?: ""
|
||||
builder.addDependencyNotation("expectedBy project(\":$dependency\")")
|
||||
}
|
||||
|
||||
+20
@@ -21,6 +21,10 @@ import com.intellij.ide.util.projectWizard.ProjectWizardUtil
|
||||
import com.intellij.ide.util.projectWizard.WizardContext
|
||||
import com.intellij.openapi.externalSystem.model.project.ProjectId
|
||||
import com.intellij.openapi.options.ConfigurationException
|
||||
import com.intellij.openapi.projectRoots.JavaSdk
|
||||
import com.intellij.openapi.projectRoots.Sdk
|
||||
import com.intellij.openapi.roots.ui.configuration.JdkComboBox
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel
|
||||
import com.intellij.openapi.ui.LabeledComponent
|
||||
import com.intellij.ui.DocumentAdapter
|
||||
import com.intellij.ui.PanelWithAnchor
|
||||
@@ -43,6 +47,10 @@ class KotlinGradleMultiplatformWizardStep(
|
||||
LabeledComponent.create(JTextField(), "Common module name:", BorderLayout.WEST)
|
||||
private val jvmCheckBox: JCheckBox =
|
||||
JCheckBox("Create JVM module", true)
|
||||
private val jdkComboBox: JdkComboBox =
|
||||
JdkComboBox(ProjectSdksModel().also {
|
||||
it.reset(null)
|
||||
}) { it is JavaSdk }
|
||||
private val jvmModuleNameComponent: LabeledComponent<JTextField> =
|
||||
LabeledComponent.create(JTextField(), "JVM module name:", BorderLayout.WEST)
|
||||
private val jsCheckBox: JCheckBox =
|
||||
@@ -97,6 +105,7 @@ class KotlinGradleMultiplatformWizardStep(
|
||||
|
||||
jvmCheckBox.addItemListener {
|
||||
jvmModuleNameComponent.isEnabled = jvmCheckBox.isSelected
|
||||
jdkComboBox.isEnabled = jvmCheckBox.isSelected
|
||||
}
|
||||
jsCheckBox.addItemListener {
|
||||
jsModuleNameComponent.isEnabled = jsCheckBox.isSelected
|
||||
@@ -127,6 +136,14 @@ class KotlinGradleMultiplatformWizardStep(
|
||||
JBUI.emptyInsets(), 0, 0
|
||||
)
|
||||
)
|
||||
panel.add(
|
||||
jdkComboBox,
|
||||
GridBagConstraints(
|
||||
0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0,
|
||||
GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL,
|
||||
JBUI.emptyInsets(), 0, 0
|
||||
)
|
||||
)
|
||||
panel.add(
|
||||
jvmModuleNameComponent,
|
||||
GridBagConstraints(
|
||||
@@ -181,6 +198,7 @@ class KotlinGradleMultiplatformWizardStep(
|
||||
builder.projectId = ProjectId("", rootModuleName, "")
|
||||
builder.commonModuleName = commonModuleName
|
||||
builder.jvmModuleName = jvmModuleName
|
||||
builder.jdk = jdk
|
||||
builder.jsModuleName = jsModuleName
|
||||
}
|
||||
|
||||
@@ -192,6 +210,8 @@ class KotlinGradleMultiplatformWizardStep(
|
||||
get() = commonModuleNameComponent.component.text
|
||||
private val jvmModuleName: String
|
||||
get() = if (jvmCheckBox.isSelected) jvmModuleNameComponent.component.text else ""
|
||||
private val jdk: Sdk?
|
||||
get() = if (jvmCheckBox.isSelected) jdkComboBox.selectedJdk else null
|
||||
private val jsModuleName: String
|
||||
get() = if (jsCheckBox.isSelected) jsModuleNameComponent.component.text else ""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user