Wizard: save some setting values in UI
#KT-35585 fixed
This commit is contained in:
+3
-1
@@ -29,7 +29,9 @@ class IdeWizard(
|
||||
private val allSettings = plugins.flatMap { it.declaredSettings }
|
||||
|
||||
init {
|
||||
context.settingContext.initPluginSettings(allSettings)
|
||||
with(valuesReadingContext) {
|
||||
context.settingContext.apply { initPluginSettings(allSettings) }
|
||||
}
|
||||
}
|
||||
|
||||
var projectPath by setting(StructurePlugin::projectPath.reference)
|
||||
|
||||
+3
-1
@@ -65,6 +65,7 @@ class NewProjectWizardModuleBuilder : EmptyModuleBuilder() {
|
||||
override fun isAvailable(): Boolean = ExperimentalFeatures.NewWizard.isEnabled
|
||||
|
||||
private var wizardContext: WizardContext? = null
|
||||
private var pomValuesAreSet: Boolean = false
|
||||
|
||||
override fun getModuleType(): ModuleType<*> = NewProjectWizardModuleType()
|
||||
override fun getParentGroup(): String = KotlinTemplatesFactory.KOTLIN_PARENT_GROUP_NAME
|
||||
@@ -137,7 +138,7 @@ class NewProjectWizardModuleBuilder : EmptyModuleBuilder() {
|
||||
}
|
||||
|
||||
private fun updateProjectNameAndPomDate(settingsStep: SettingsStep) {
|
||||
if (wizard.artifactId != null || wizard.groupId != null) return
|
||||
if (pomValuesAreSet) return
|
||||
val suggestedProjectName = with(wizard.valuesReadingContext) {
|
||||
ProjectTemplatesPlugin::template.settingValue.suggestedProjectName.decapitalize()
|
||||
}
|
||||
@@ -150,6 +151,7 @@ class NewProjectWizardModuleBuilder : EmptyModuleBuilder() {
|
||||
|
||||
wizard.artifactId = suggestedProjectName
|
||||
wizard.groupId = suggestGroupId()
|
||||
pomValuesAreSet = true
|
||||
}
|
||||
|
||||
private fun suggestGroupId(): String {
|
||||
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.tools.projectWizard.wizard.service
|
||||
|
||||
import com.intellij.ide.util.PropertiesComponent
|
||||
import org.jetbrains.kotlin.idea.util.application.runReadAction
|
||||
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.service.SettingSavingWizardService
|
||||
|
||||
class IdeaSettingSavingWizardService : SettingSavingWizardService, IdeaWizardService {
|
||||
override fun saveSettingValue(settingPath: String, settingValue: String) = runWriteAction {
|
||||
PropertiesComponent.getInstance().setValue(PATH_PREFIX + settingPath, settingValue)
|
||||
}
|
||||
|
||||
override fun getSettingValue(settingPath: String): String? = runReadAction {
|
||||
PropertiesComponent.getInstance().getValue(PATH_PREFIX + settingPath)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val PATH_PREFIX = "NewKotlinWizard."
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -16,7 +16,8 @@ object IdeaServices {
|
||||
val PROJECT_INDEPENDENT: List<IdeaWizardService> = listOf(
|
||||
IdeaFileSystemWizardService(),
|
||||
IdeaBuildSystemAvailabilityWizardService(),
|
||||
IdeaKotlinVersionProviderService()
|
||||
IdeaKotlinVersionProviderService(),
|
||||
IdeaSettingSavingWizardService()
|
||||
)
|
||||
|
||||
fun createScopeDependent(project: Project, model: ModifiableModuleModel) = listOf(
|
||||
|
||||
+5
-4
@@ -8,14 +8,13 @@ package org.jetbrains.kotlin.tools.projectWizard.wizard.ui.components
|
||||
import com.intellij.openapi.Disposable
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ValuesReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.*
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.service.SettingSavingWizardService
|
||||
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.DynamicComponent
|
||||
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.FocusableComponent
|
||||
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.label
|
||||
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.panel
|
||||
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.setting.ErrorAwareComponent
|
||||
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.setting.IdeaBasedComponentValidator
|
||||
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.setting.SettingComponent
|
||||
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.setting.ValidationIndicator
|
||||
import java.awt.BorderLayout
|
||||
import javax.swing.JComponent
|
||||
|
||||
@@ -83,5 +82,7 @@ abstract class UIComponent<V : Any>(
|
||||
}
|
||||
}
|
||||
|
||||
fun <V : Any> UIComponent<V>.valueForSetting(setting: Setting<V, SettingType<V>>): V? =
|
||||
setting.defaultValue ?: getUiValue()
|
||||
fun <V : Any> ValuesReadingContext.valueForSetting(
|
||||
uiComponent: UIComponent<V>,
|
||||
setting: Setting<V, SettingType<V>>
|
||||
): V? = setting.savedOrDefaultValue ?: uiComponent.getUiValue()
|
||||
+4
-2
@@ -55,8 +55,10 @@ class TemplatesSubStep(valuesReadingContext: ValuesReadingContext) :
|
||||
// TODO do not use settingContext directly
|
||||
context.settingContext[setting] = value
|
||||
}
|
||||
allModules().forEach { module ->
|
||||
module.initDefaultValuesForSettings(valuesReadingContext.context)
|
||||
read {
|
||||
allModules().forEach { module ->
|
||||
module.apply { initDefaultValuesForSettings(valuesReadingContext.context) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ class ModulesEditorComponent(
|
||||
}
|
||||
)
|
||||
|
||||
private val model = TargetsModel(tree, ::value, valuesReadingContext.context, uiEditorUsagesStats)
|
||||
private val model = TargetsModel(tree, ::value, valuesReadingContext, uiEditorUsagesStats)
|
||||
|
||||
override fun onInit() {
|
||||
super.onInit()
|
||||
|
||||
+5
-2
@@ -2,6 +2,7 @@ package org.jetbrains.kotlin.tools.projectWizard.wizard.ui.secondStep.modulesEdi
|
||||
|
||||
import org.jetbrains.kotlin.idea.projectWizard.UiEditorUsageStats
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.Context
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ValuesReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.Module
|
||||
import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.ModuleKind
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
@@ -12,7 +13,7 @@ import kotlin.reflect.KMutableProperty0
|
||||
class TargetsModel(
|
||||
private val tree: ModulesEditorTree,
|
||||
private val value: KMutableProperty0<List<Module>?>,
|
||||
private val context: Context,
|
||||
private val valuesReadingContext: ValuesReadingContext,
|
||||
private val uiEditorUsagesStats: UiEditorUsageStats
|
||||
) {
|
||||
private val root get() = tree.model.root as DefaultMutableTreeNode
|
||||
@@ -64,7 +65,9 @@ class TargetsModel(
|
||||
|
||||
fun add(module: Module) {
|
||||
uiEditorUsagesStats.modulesCreated++
|
||||
module.initDefaultValuesForSettings(context)
|
||||
with(valuesReadingContext) {
|
||||
module.apply { initDefaultValuesForSettings(context) }
|
||||
}
|
||||
addToTheTree(module, modifyValue = true, parent = tree.selectedNode ?: root)
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -65,7 +65,7 @@ class VersionSettingComponent(
|
||||
|
||||
override fun onInit() {
|
||||
super.onInit()
|
||||
val values = setting.defaultValue?.let(::listOf).orEmpty()
|
||||
val values = read { setting.savedOrDefaultValue }?.let(::listOf).orEmpty()
|
||||
comboBox.model = DefaultComboBoxModel<Version>(values.toTypedArray())
|
||||
|
||||
if (values.isNotEmpty()) {
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ abstract class UIComponentDelegatingSettingComponent<V : Any, T : SettingType<V>
|
||||
override fun onInit() {
|
||||
super.onInit()
|
||||
if (value == null) {
|
||||
uiComponent.valueForSetting(setting)?.let { value = it }
|
||||
read { valueForSetting(uiComponent, setting) }?.let { value = it }
|
||||
}
|
||||
value?.let(uiComponent::updateUiValue)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user