mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-77574: Do not allow hyphen in Django Project and Application names.
`ProjectPathProvider.bindProjectName` is improved and support list of denied chars (as regex) and covered with test. Regex used both: for escaping and for substitution. GitOrigin-RevId: 6d4e4643a66358c485e4849ece347af8d1fa32aa
This commit is contained in:
committed by
intellij-monorepo-bot
parent
d1d1cf5e38
commit
650ae28b8a
@@ -1583,4 +1583,5 @@ python.survey.user.job.dialog.blocks.checkbox.ml=Machine learning
|
||||
python.survey.user.job.dialog.blocks.checkbox.web=Web development
|
||||
python.survey.user.job.dialog.blocks.checkbox.scripts=Writing automation scripts / parsers / tests / system administration
|
||||
python.survey.user.job.dialog.blocks.checkbox.other=Other
|
||||
validation.invalid.name=Invalid name
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.jetbrains.python.newProjectWizard
|
||||
|
||||
import com.intellij.openapi.ui.validation.DialogValidation
|
||||
import com.intellij.openapi.ui.validation.validationErrorIf
|
||||
import com.jetbrains.python.PyBundle
|
||||
|
||||
|
||||
/**
|
||||
* Kotlin DSL UI validator that makes sure no [deniedChars] are used
|
||||
*/
|
||||
fun deniedCharsValidation(deniedChars: Regex): DialogValidation.WithParameter<() -> String> =
|
||||
validationErrorIf<String>(PyBundle.message("validation.invalid.name")) {
|
||||
deniedChars.find(it) != null
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import com.intellij.ui.dsl.builder.bindText
|
||||
import com.intellij.ui.dsl.builder.text
|
||||
import com.intellij.ui.dsl.builder.trimmedTextValidation
|
||||
import com.intellij.util.concurrency.annotations.RequiresEdt
|
||||
import com.jetbrains.python.newProjectWizard.deniedCharsValidation
|
||||
import com.jetbrains.python.newProjectWizard.projectPath.ProjectPathProvider.Companion.bindProjectName
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
@@ -34,16 +35,22 @@ interface ProjectPathProvider {
|
||||
val projectPathFlows: ProjectPathFlows
|
||||
|
||||
companion object {
|
||||
|
||||
/**
|
||||
* Binds [com.jetbrains.python.newProjectWizard.PyV3ProjectTypeSpecificSettings] property to the certain cell and updates it each time project path is changes
|
||||
* [deniedChars] are added to validation and replaced with `_`
|
||||
*/
|
||||
@JvmOverloads
|
||||
@RequiresEdt
|
||||
fun Cell<JTextField>.bindProjectName(projectPathProvider: ProjectPathProvider, property: KMutableProperty0<@NlsSafe String>) = apply {
|
||||
fun Cell<JTextField>.bindProjectName(projectPathProvider: ProjectPathProvider, property: KMutableProperty0<@NlsSafe String>, deniedChars: Regex? = null) = apply {
|
||||
trimmedTextValidation(CHECK_NON_EMPTY, CHECK_NO_WHITESPACES)
|
||||
deniedChars?.let {
|
||||
trimmedTextValidation(deniedCharsValidation(it))
|
||||
}
|
||||
bindText(property)
|
||||
projectPathProvider.onProjectFileNameChanged {
|
||||
withContext(Dispatchers.EDT) {
|
||||
text(it)
|
||||
text(deniedChars?.replace(it, "_") ?: it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user