Wizard: don't show error dialog on validation, instead navigate to the error

This commit is contained in:
Ilya Kirillov
2020-03-16 19:53:48 +03:00
parent f640477464
commit c71972afc9
13 changed files with 154 additions and 345 deletions
@@ -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
}
@@ -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
@@ -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 }