From 42130bc34759d885a91804ef7274283f768f3623 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 2 Jul 2019 19:12:54 +0200 Subject: [PATCH] Support bindings for TextFieldWithBrowseButton GitOrigin-RevId: 9d70964e9e79e3c301ccb830c039bd4fa88a798b --- .../com/intellij/ui/components/components.kt | 4 +-- .../src/com/intellij/ui/layout/Cell.kt | 29 ++++++++++++++++++- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ui/components/components.kt b/platform/platform-impl/src/com/intellij/ui/components/components.kt index a876746a53b9..363ec9e2afd0 100644 --- a/platform/platform-impl/src/com/intellij/ui/components/components.kt +++ b/platform/platform-impl/src/com/intellij/ui/components/components.kt @@ -232,7 +232,7 @@ private abstract class MyDialogWrapper(project: Project?, fun installFileCompletionAndBrowseDialog(project: Project?, component: ComponentWithBrowseButton, textField: JTextField, - @Nls(capitalization = Nls.Capitalization.Title) browseDialogTitle: String, + @Nls(capitalization = Nls.Capitalization.Title) browseDialogTitle: String?, fileChooserDescriptor: FileChooserDescriptor, textComponentAccessor: TextComponentAccessor, fileChosen: ((chosenFile: VirtualFile) -> String)? = null) { @@ -282,7 +282,7 @@ fun textFieldWithHistoryWithBrowseButton(project: Project?, @JvmOverloads fun textFieldWithBrowseButton(project: Project?, - browseDialogTitle: String, + browseDialogTitle: String?, fileChooserDescriptor: FileChooserDescriptor, fileChosen: ((chosenFile: VirtualFile) -> String)? = null): TextFieldWithBrowseButton { val component = TextFieldWithBrowseButton() diff --git a/platform/platform-impl/src/com/intellij/ui/layout/Cell.kt b/platform/platform-impl/src/com/intellij/ui/layout/Cell.kt index 4469fa99547b..046bc066d352 100644 --- a/platform/platform-impl/src/com/intellij/ui/layout/Cell.kt +++ b/platform/platform-impl/src/com/intellij/ui/layout/Cell.kt @@ -292,7 +292,7 @@ abstract class Cell { return component } - fun textFieldWithBrowseButton(browseDialogTitle: String, + fun textFieldWithBrowseButton(browseDialogTitle: String? = null, value: String? = null, project: Project? = null, fileChooserDescriptor: FileChooserDescriptor = FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor(), @@ -304,6 +304,33 @@ abstract class Cell { return component } + fun textFieldWithBrowseButton( + prop: KMutableProperty0, + browseDialogTitle: String? = null, + project: Project? = null, + fileChooserDescriptor: FileChooserDescriptor = FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor(), + fileChosen: ((chosenFile: VirtualFile) -> String)? = null, + comment: String? = null + ): CellBuilder { + val component = textFieldWithBrowseButton(project, browseDialogTitle, fileChooserDescriptor, fileChosen) + component.text = prop.get() + return component(comment = comment).withBinding(TextFieldWithBrowseButton::getText, TextFieldWithBrowseButton::setText, prop.toBinding()) + } + + fun textFieldWithBrowseButton( + getter: () -> String, + setter: (String) -> Unit, + browseDialogTitle: String? = null, + project: Project? = null, + fileChooserDescriptor: FileChooserDescriptor = FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor(), + fileChosen: ((chosenFile: VirtualFile) -> String)? = null, + comment: String? = null + ): CellBuilder { + val component = textFieldWithBrowseButton(project, browseDialogTitle, fileChooserDescriptor, fileChosen) + component.text = getter() + return component(comment = comment).withBinding(TextFieldWithBrowseButton::getText, TextFieldWithBrowseButton::setText, PropertyBinding(getter, setter)) + } + fun gearButton(vararg actions: AnAction) { val label = JLabel(AllIcons.General.GearPlain) label.disabledIcon = AllIcons.General.GearPlain