Support bindings for TextFieldWithBrowseButton

GitOrigin-RevId: 9d70964e9e79e3c301ccb830c039bd4fa88a798b
This commit is contained in:
Dmitry Jemerov
2019-07-03 01:13:10 +03:00
committed by intellij-monorepo-bot
parent f1dfa5e434
commit 42130bc347
2 changed files with 30 additions and 3 deletions
@@ -232,7 +232,7 @@ private abstract class MyDialogWrapper(project: Project?,
fun <T : JComponent> installFileCompletionAndBrowseDialog(project: Project?,
component: ComponentWithBrowseButton<T>,
textField: JTextField,
@Nls(capitalization = Nls.Capitalization.Title) browseDialogTitle: String,
@Nls(capitalization = Nls.Capitalization.Title) browseDialogTitle: String?,
fileChooserDescriptor: FileChooserDescriptor,
textComponentAccessor: TextComponentAccessor<T>,
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()
@@ -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<String>,
browseDialogTitle: String? = null,
project: Project? = null,
fileChooserDescriptor: FileChooserDescriptor = FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor(),
fileChosen: ((chosenFile: VirtualFile) -> String)? = null,
comment: String? = null
): CellBuilder<TextFieldWithBrowseButton> {
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<TextFieldWithBrowseButton> {
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