Wizard: don't show error dialog on validation, instead navigate to the error
This commit is contained in:
+1
-1
@@ -61,7 +61,7 @@ sealed class ValidationResult {
|
||||
|
||||
infix fun and(other: ValidationResult) = when {
|
||||
this is OK -> other
|
||||
this is ValidationError && other is ValidationError -> ValidationError(messages + other.messages)
|
||||
this is ValidationError && other is ValidationError -> ValidationError(messages + other.messages, target ?: other.target)
|
||||
else -> this
|
||||
}
|
||||
|
||||
|
||||
+5
-1
@@ -8,6 +8,7 @@ import org.jetbrains.kotlin.tools.projectWizard.core.entity.settings.reference
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.service.FileSystemWizardService
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.PomIR
|
||||
import org.jetbrains.kotlin.tools.projectWizard.phases.GenerationPhase
|
||||
import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.Module
|
||||
import org.jetbrains.kotlin.tools.projectWizard.settings.version.Version
|
||||
import java.nio.file.Paths
|
||||
|
||||
@@ -15,7 +16,10 @@ class StructurePlugin(context: Context) : Plugin(context) {
|
||||
val projectPath by pathSetting("Location", GenerationPhase.PROJECT_GENERATION) {
|
||||
defaultValue = value(Paths.get("."))
|
||||
}
|
||||
val name by stringSetting("Name", GenerationPhase.PROJECT_GENERATION)
|
||||
val name by stringSetting("Name", GenerationPhase.PROJECT_GENERATION) {
|
||||
shouldNotBeBlank()
|
||||
validate(StringValidators.shouldBeValidIdentifier("Name", Module.ALLOWED_SPECIAL_CHARS_IN_MODULE_NAMES))
|
||||
}
|
||||
|
||||
val groupId by stringSetting("Group ID", GenerationPhase.PROJECT_GENERATION) {
|
||||
isSavable = true
|
||||
|
||||
+3
-3
@@ -39,13 +39,13 @@ abstract class Wizard(createPlugins: PluginsCreator, servicesManager: ServicesMa
|
||||
}
|
||||
}
|
||||
|
||||
fun validate(phases: Set<GenerationPhase>): TaskResult<Unit> = context.read {
|
||||
fun validate(phases: Set<GenerationPhase>): ValidationResult = context.read {
|
||||
pluginSettings.map { setting ->
|
||||
val value = setting.reference.notRequiredSettingValue ?: return@map ValidationResult.OK
|
||||
if (setting.neededAtPhase in phases && setting.isActive(this))
|
||||
(setting.validator as SettingValidator<Any>).validate(this, value)
|
||||
else ValidationResult.OK
|
||||
}.fold().toResult()
|
||||
}.fold()
|
||||
}
|
||||
|
||||
private fun saveSettingValues(phases: Set<GenerationPhase>) = context.read {
|
||||
@@ -69,7 +69,7 @@ abstract class Wizard(createPlugins: PluginsCreator, servicesManager: ServicesMa
|
||||
initPluginSettingsDefaultValues()
|
||||
initNonPluginDefaultValues()
|
||||
checkAllRequiredSettingPresent(phases).ensure()
|
||||
validate(phases).ensure()
|
||||
validate(phases).toResult().ensure()
|
||||
saveSettingValues(phases)
|
||||
val (tasksSorted) = context.sortTasks().map { tasks ->
|
||||
tasks.groupBy { it.phase }.toList().sortedBy { it.first }.flatMap { it.second }
|
||||
|
||||
Reference in New Issue
Block a user