From 7002e86d6bfcabe51297004e8e74b61eb2272b68 Mon Sep 17 00:00:00 2001 From: Ilya Kirillov Date: Mon, 7 Sep 2020 19:08:22 +0300 Subject: [PATCH] Wizard: fix path & artifactId updating on name update #KT-41695 fixed --- .../ui/components/PathFieldComponent.kt | 10 +++++- .../ui/components/TextFieldComponent.kt | 8 +++++ .../wizard/ui/components/UIComponent.kt | 1 - .../ui/firstStep/FirstWizardStepComponent.kt | 36 ++++++++++++------- .../ui/setting/DefaultSettingComponent.kt | 10 ++++++ 5 files changed, 51 insertions(+), 14 deletions(-) diff --git a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/components/PathFieldComponent.kt b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/components/PathFieldComponent.kt index 802c617798b..1016ade2777 100644 --- a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/components/PathFieldComponent.kt +++ b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/components/PathFieldComponent.kt @@ -8,6 +8,8 @@ import org.jetbrains.kotlin.tools.projectWizard.core.asPath import org.jetbrains.kotlin.tools.projectWizard.core.entity.SettingValidator import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.componentWithCommentAtBottom import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.withOnUpdatedListener +import java.awt.event.KeyAdapter +import java.awt.event.KeyEvent import java.nio.file.Path import java.nio.file.Paths import javax.swing.JComponent @@ -25,7 +27,7 @@ class PathFieldComponent( validator, onValueUpdate ) { - val textFieldWithBrowseButton = TextFieldWithBrowseButton().apply { + private val textFieldWithBrowseButton = TextFieldWithBrowseButton().apply { textField.text = initialValue?.toString().orEmpty() textField.withOnUpdatedListener { path -> fireValueUpdated(path.trim().asPath()) } addBrowseFolderListener( @@ -36,6 +38,12 @@ class PathFieldComponent( ) } + fun onUserType(action: () -> Unit) { + textFieldWithBrowseButton.textField.addKeyListener(object : KeyAdapter() { + override fun keyReleased(e: KeyEvent?) = action() + }) + } + override val alignTarget: JComponent? get() = textFieldWithBrowseButton override val uiComponent = componentWithCommentAtBottom(textFieldWithBrowseButton, description) diff --git a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/components/TextFieldComponent.kt b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/components/TextFieldComponent.kt index ad0f1e9f0ba..229d37c69dc 100644 --- a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/components/TextFieldComponent.kt +++ b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/components/TextFieldComponent.kt @@ -6,6 +6,8 @@ import org.jetbrains.kotlin.tools.projectWizard.core.Context import org.jetbrains.kotlin.tools.projectWizard.core.entity.SettingValidator import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.componentWithCommentAtBottom import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.textField +import java.awt.event.KeyAdapter +import java.awt.event.KeyEvent import javax.swing.JComponent class TextFieldComponent( @@ -34,6 +36,12 @@ class TextFieldComponent( textField.text = newValue } + fun onUserType(action: () -> Unit) { + textField.addKeyListener(object : KeyAdapter() { + override fun keyReleased(e: KeyEvent?) = action() + }) + } + fun disable(@Nls message: String) { cachedValueWhenDisabled = getUiValue() textField.isEditable = false diff --git a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/components/UIComponent.kt b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/components/UIComponent.kt index db0bc0869b2..be168fc07b8 100644 --- a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/components/UIComponent.kt +++ b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/components/UIComponent.kt @@ -87,7 +87,6 @@ abstract class UIComponent( uiComponent.requestFocus() } - override fun navigateTo(error: ValidationResult.ValidationError) { val errorInThisComponent = read { getUiValue()?.let { validator?.validate?.invoke(this, it)?.isSpecificError(error) } == true diff --git a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/firstStep/FirstWizardStepComponent.kt b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/firstStep/FirstWizardStepComponent.kt index ada41a4ed38..419f6f80777 100644 --- a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/firstStep/FirstWizardStepComponent.kt +++ b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/firstStep/FirstWizardStepComponent.kt @@ -22,12 +22,15 @@ import org.jetbrains.kotlin.tools.projectWizard.wizard.IdeWizard import org.jetbrains.kotlin.tools.projectWizard.wizard.KotlinNewProjectWizardUIBundle import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.* import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.secondStep.modulesEditor.ModulesEditorComponent +import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.setting.PathSettingComponent +import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.setting.StringSettingComponent import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.setting.TitledComponentsList import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.setting.createSettingComponent import java.awt.Cursor import java.awt.event.MouseAdapter import java.awt.event.MouseEvent import javax.swing.JComponent +import javax.swing.tree.DefaultTreeCellEditor class FirstWizardStepComponent(ideWizard: IdeWizard) : WizardStepComponent(ideWizard.context) { private val context = ideWizard.context @@ -47,13 +50,23 @@ class ProjectSettingsComponent(ideWizard: IdeWizard) : DynamicComponent(ideWizar private val buildSystemSetting = BuildSystemTypeSettingComponent(context).asSubComponent().apply { component.addBorder(JBUI.Borders.empty(0, /*left&right*/4)) } - private val buildSystemAdditionalSettingsComponent = BuildSystemAdditionalSettingsComponent(ideWizard).asSubComponent() + + private var locationWasUpdatedByHand: Boolean = false + private var artifactIdWasUpdatedByHand: Boolean = false + + private val buildSystemAdditionalSettingsComponent = + BuildSystemAdditionalSettingsComponent( + ideWizard, + onUserTypeInArtifactId = { artifactIdWasUpdatedByHand = true }, + ).asSubComponent() private val jdkComponent = JdkComponent(ideWizard).asSubComponent() private val nameAndLocationComponent = TitledComponentsList( listOf( StructurePlugin.name.reference.createSettingComponent(context), - StructurePlugin.projectPath.reference.createSettingComponent(context), + StructurePlugin.projectPath.reference.createSettingComponent(context).also { + (it as? PathSettingComponent)?.onUserType { locationWasUpdatedByHand = true } + }, projectTemplateComponent, buildSystemSetting, jdkComponent @@ -77,9 +90,6 @@ class ProjectSettingsComponent(ideWizard: IdeWizard) : DynamicComponent(ideWizar } } - private var locationWasUpdatedByHand: Boolean = false - private var artifactIdWasUpdatedByHand: Boolean = false - override fun onValueUpdated(reference: SettingReference<*, *>?) { super.onValueUpdated(reference) when (reference?.path) { @@ -93,9 +103,6 @@ class ProjectSettingsComponent(ideWizard: IdeWizard) : DynamicComponent(ideWizar StructurePlugin.artifactId.path -> { artifactIdWasUpdatedByHand = true } - StructurePlugin.projectPath.path -> { - locationWasUpdatedByHand = true - } } } @@ -117,8 +124,11 @@ class ProjectSettingsComponent(ideWizard: IdeWizard) : DynamicComponent(ideWizar } } -class BuildSystemAdditionalSettingsComponent(ideWizard: IdeWizard) : DynamicComponent(ideWizard.context) { - private val pomSettingsList = PomSettingsComponent(ideWizard.context).asSubComponent() +class BuildSystemAdditionalSettingsComponent( + ideWizard: IdeWizard, + onUserTypeInArtifactId: () -> Unit, +) : DynamicComponent(ideWizard.context) { + private val pomSettingsList = PomSettingsComponent(ideWizard.context, onUserTypeInArtifactId).asSubComponent() private val kotlinJpsRuntimeComponent = KotlinJpsRuntimeComponent(ideWizard).asSubComponent() override fun onValueUpdated(reference: SettingReference<*, *>?) { @@ -159,10 +169,12 @@ class BuildSystemAdditionalSettingsComponent(ideWizard: IdeWizard) : DynamicComp override val component: JComponent = section } -private class PomSettingsComponent(context: Context) : TitledComponentsList( +private class PomSettingsComponent(context: Context, onUserTypeInArtifactId: () -> Unit) : TitledComponentsList( listOf( StructurePlugin.groupId.reference.createSettingComponent(context), - StructurePlugin.artifactId.reference.createSettingComponent(context), + StructurePlugin.artifactId.reference.createSettingComponent(context).also { + (it as? StringSettingComponent)?.onUserType(onUserTypeInArtifactId) + }, StructurePlugin.version.reference.createSettingComponent(context) ), context, diff --git a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/setting/DefaultSettingComponent.kt b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/setting/DefaultSettingComponent.kt index 57864cf82f8..9672759c79d 100644 --- a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/setting/DefaultSettingComponent.kt +++ b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/setting/DefaultSettingComponent.kt @@ -14,6 +14,8 @@ import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.label import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.customPanel import java.awt.BorderLayout import java.awt.event.ItemEvent +import java.awt.event.KeyAdapter +import java.awt.event.KeyEvent import java.nio.file.Path import javax.swing.DefaultComboBoxModel import javax.swing.JComponent @@ -160,6 +162,10 @@ class StringSettingComponent( validator = setting.validator, onValueUpdate = { newValue -> value = newValue } ).asSubComponent() + + fun onUserType(action: () -> Unit) { + uiComponent.onUserType(action) + } } class PathSettingComponent( @@ -177,4 +183,8 @@ class PathSettingComponent( validator = settingValidator { path -> setting.validator.validate(this, path) }, onValueUpdate = { newValue -> value = newValue } ).asSubComponent() + + fun onUserType(action: () -> Unit) { + uiComponent.onUserType(action) + } } \ No newline at end of file