From 1d0c5413ded8d1947fb523278e5b51b037e7aad7 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Fri, 2 Mar 2018 15:01:45 +0300 Subject: [PATCH] MPP wizard: add combobox selecting common module position + extra checks So #KT-23097 Fixed --- .../KotlinGradleMultiplatformModuleBuilder.kt | 11 ++++++ .../KotlinGradleMultiplatformWizardStep.kt | 36 +++++++++++++++++-- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleMultiplatformModuleBuilder.kt b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleMultiplatformModuleBuilder.kt index af21e9e3f59..5f87ba60dec 100644 --- a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleMultiplatformModuleBuilder.kt +++ b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleMultiplatformModuleBuilder.kt @@ -22,6 +22,7 @@ import com.intellij.openapi.externalSystem.service.project.wizard.ExternalModule import com.intellij.openapi.fileEditor.FileDocumentManager import com.intellij.openapi.module.Module import com.intellij.openapi.projectRoots.Sdk +import com.intellij.openapi.roots.ModifiableRootModel import com.intellij.openapi.roots.ui.configuration.ModulesProvider import com.intellij.openapi.vfs.VfsUtil import com.intellij.openapi.vfs.VirtualFile @@ -56,6 +57,16 @@ class KotlinGradleMultiplatformModuleBuilder : GradleModuleBuilder() { ) } + override fun setupRootModel(modifiableRootModel: ModifiableRootModel) { + super.setupRootModel(modifiableRootModel) + if (commonModuleName.isNullOrEmpty()) { + val module = modifiableRootModel.module + val buildScriptData = getBuildScriptData(module) ?: return + val sdk = modifiableRootModel.sdk + GradleKotlinMPPCommonFrameworkSupportProvider().addSupport(buildScriptData, sdk) + } + } + override fun setupModule(module: Module) { super.setupModule(module) diff --git a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleMultiplatformWizardStep.kt b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleMultiplatformWizardStep.kt index f019ab848b9..9e477dec40f 100644 --- a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleMultiplatformWizardStep.kt +++ b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleMultiplatformWizardStep.kt @@ -42,6 +42,15 @@ class KotlinGradleMultiplatformWizardStep( private val wizardContext: WizardContext ) : ModuleWizardStep() { + private val hierarchyKindComponent: LabeledComponent> = + LabeledComponent.create( + JComboBox( + arrayOf( + "Root empty module with common and platform modules as children", + "Root common module with children platform modules" + ) + ), "Hierarchy kind", BorderLayout.WEST + ) private val rootModuleNameComponent: LabeledComponent = LabeledComponent.create(JTextField(), "Root module name:", BorderLayout.WEST) private val commonModuleNameComponent: LabeledComponent = @@ -66,12 +75,13 @@ class KotlinGradleMultiplatformWizardStep( init { panel = object : JPanel(GridBagLayout()), PanelWithAnchor { - private var anchor: JComponent? = rootModuleNameComponent.anchor + private var anchor: JComponent? = hierarchyKindComponent.anchor override fun getAnchor(): JComponent? = anchor override fun setAnchor(anchor: JComponent?) { this.anchor = anchor + hierarchyKindComponent.anchor = anchor rootModuleNameComponent.anchor = anchor commonModuleNameComponent.anchor = anchor jvmModuleNameComponent.anchor = anchor @@ -107,6 +117,9 @@ class KotlinGradleMultiplatformWizardStep( jdkComboBox.selectedJdk = jdkModel.projectSdk + hierarchyKindComponent.component.addActionListener { + commonModuleNameComponent.isEnabled = !commonModuleIsRoot + } jvmCheckBox.addItemListener { jvmModuleNameComponent.isEnabled = jvmCheckBox.isSelected jdkComboBox.isEnabled = jvmCheckBox.isSelected @@ -116,6 +129,14 @@ class KotlinGradleMultiplatformWizardStep( } panel.border = BorderFactory.createEmptyBorder(10, 10, 10, 10) + panel.add( + hierarchyKindComponent, + GridBagConstraints( + 0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, + GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, + JBUI.emptyInsets(), 0, 0 + ) + ) panel.add( rootModuleNameComponent, GridBagConstraints( @@ -208,10 +229,12 @@ class KotlinGradleMultiplatformWizardStep( override fun getComponent() = panel + private val commonModuleIsRoot: Boolean + get() = hierarchyKindComponent.component.selectedIndex != 0 private val rootModuleName: String get() = rootModuleNameComponent.component.text private val commonModuleName: String - get() = commonModuleNameComponent.component.text + get() = if (commonModuleIsRoot) "" else commonModuleNameComponent.component.text private val jvmModuleName: String get() = if (jvmCheckBox.isSelected) jvmModuleNameComponent.component.text else "" private val jdk: Sdk? @@ -223,6 +246,15 @@ class KotlinGradleMultiplatformWizardStep( if (rootModuleName.isEmpty()) { throw ConfigurationException("Please specify the root module name") } + if (!commonModuleIsRoot && commonModuleName.isEmpty()) { + throw ConfigurationException("Please specify the common module name") + } + if (jvmCheckBox.isSelected && jvmModuleName.isEmpty()) { + throw ConfigurationException("Please specify the JVM module name") + } + if (jsCheckBox.isSelected && jsModuleName.isEmpty()) { + throw ConfigurationException("Please specify the JS module name") + } if (commonModuleName.isNotEmpty() && (commonModuleName == rootModuleName || commonModuleName == jvmModuleName || commonModuleName == jsModuleName) ) {