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