IDEA-318666: Port `ManualPathEntryDialog` to Kotlin UI DSL 2

Merge-request: IJ-MR-106615
Merged-by: Ilya Kazakevich <ilya.kazakevich@jetbrains.com>

GitOrigin-RevId: d309ba087cbbea1b172372ae4a90a018b7787a36
This commit is contained in:
Ilya.Kazakevich
2023-04-24 11:14:35 +00:00
committed by intellij-monorepo-bot
parent 64fd19dc27
commit d356803b69
2 changed files with 9 additions and 6 deletions

View File

@@ -48,14 +48,15 @@ fun com.intellij.ui.dsl.builder.Row.textFieldWithBrowseTargetButton(targetType:
targetSupplier: Supplier<out TargetEnvironmentConfiguration>,
project: Project,
@NlsContexts.DialogTitle title: String,
property: MutableProperty<String>): Cell<TextFieldWithBrowseButton> {
property: MutableProperty<String>,
targetBrowserHints: TargetBrowserHints = TargetBrowserHints(true)): Cell<TextFieldWithBrowseButton> {
val textFieldWithBrowseButton = TextFieldWithBrowseButton()
val browser = targetType.createBrowser(project,
title,
TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT,
textFieldWithBrowseButton.textField,
targetSupplier,
TargetBrowserHints(true))
targetBrowserHints)
textFieldWithBrowseButton.addActionListener(browser)
return cell(textFieldWithBrowseButton)
.bind(TextFieldWithBrowseButton::getText, TextFieldWithBrowseButton::setText, property)

View File

@@ -6,7 +6,9 @@ import com.intellij.execution.target.*
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.DialogWrapper
import com.intellij.openapi.util.io.OSAgnosticPathUtil
import com.intellij.ui.layout.*
import com.intellij.ui.dsl.builder.bindText
import com.intellij.ui.dsl.builder.panel
import com.intellij.ui.dsl.builder.toMutableProperty
import com.jetbrains.python.PyBundle
import java.util.function.Supplier
import javax.swing.JComponent
@@ -36,10 +38,10 @@ class ManualPathEntryDialog(private val project: Project?,
return panel {
row(label = label) {
val textFieldComponent = if (targetConfigAndType == null)
textField(prop = ::path)
textField().bindText(::path)
else
textFieldWithBrowseTargetButton(this, targetConfigAndType.second, Supplier { targetConfigAndType.first }, project!!, label, this@ManualPathEntryDialog::path.toBinding(), TargetBrowserHints(true))
textFieldComponent.withValidationOnApply { textField ->
textFieldWithBrowseTargetButton(targetConfigAndType.second, Supplier { targetConfigAndType.first }, project!!, label, this@ManualPathEntryDialog::path.toMutableProperty(), TargetBrowserHints(true))
textFieldComponent.validationOnApply { textField ->
val text = textField.text
when {
text.isBlank() -> error(PyBundle.message("path.must.not.be.empty.error.message"))