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 149e800ea4da..fe90156c6f56 100644 --- a/platform/platform-impl/src/com/intellij/ui/components/components.kt +++ b/platform/platform-impl/src/com/intellij/ui/components/components.kt @@ -11,7 +11,9 @@ import com.intellij.openapi.ui.* import com.intellij.openapi.ui.ComponentWithBrowseButton.BrowseFolderActionListener import com.intellij.openapi.ui.DialogWrapper.IdeModalityType import com.intellij.openapi.ui.ex.MultiLineLabel -import com.intellij.openapi.util.NlsContexts +import com.intellij.openapi.util.NlsContexts.* +import com.intellij.openapi.util.NlsContexts.Checkbox +import com.intellij.openapi.util.NlsContexts.Label import com.intellij.openapi.vcs.changes.issueLinks.LinkMouseListenerBase import com.intellij.openapi.vfs.VirtualFile import com.intellij.ui.* @@ -35,7 +37,7 @@ import javax.swing.text.Segment private val LINK_TEXT_ATTRIBUTES: SimpleTextAttributes get() = SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, JBUI.CurrentTheme.Link.linkColor()) -fun Label(text: String, style: UIUtil.ComponentStyle? = null, fontColor: UIUtil.FontColor? = null, bold: Boolean = false): JLabel { +fun Label(@Label text: String, style: UIUtil.ComponentStyle? = null, fontColor: UIUtil.FontColor? = null, bold: Boolean = false): JLabel { val finalText = BundleBase.replaceMnemonicAmpersand(text) val label: JLabel if (fontColor == null) { @@ -57,14 +59,14 @@ fun Label(text: String, style: UIUtil.ComponentStyle? = null, fontColor: UIUtil. return label } -fun Link(text: String, style: UIUtil.ComponentStyle? = null, action: () -> Unit): JComponent { +fun Link(@Label text: String, style: UIUtil.ComponentStyle? = null, action: () -> Unit): JComponent { val result = LinkLabel.create(text, action) style?.let { UIUtil.applyStyle(it, result) } return result } @JvmOverloads -fun noteComponent(note: String, linkHandler: ((url: String) -> Unit)? = null): JComponent { +fun noteComponent(@Label note: String, linkHandler: ((url: String) -> Unit)? = null): JComponent { val matcher = URLUtil.HREF_PATTERN.matcher(note) if (!matcher.find()) { return Label(note) @@ -94,7 +96,7 @@ fun noteComponent(note: String, linkHandler: ((url: String) -> Unit)? = null): J } @JvmOverloads -fun htmlComponent(text: String = "", +fun htmlComponent(@DetailedDescription text: String = "", font: Font? = null, background: Color? = null, foreground: Color? = null, @@ -110,32 +112,32 @@ fun htmlComponent(text: String = "", return pane } -fun RadioButton(text: String): JRadioButton = JRadioButton(BundleBase.replaceMnemonicAmpersand(text)) +fun RadioButton(@RadioButton text: String): JRadioButton = JRadioButton(BundleBase.replaceMnemonicAmpersand(text)) -fun CheckBox(text: String, selected: Boolean = false, toolTip: String? = null): JCheckBox { +fun CheckBox(@Checkbox text: String, selected: Boolean = false, toolTip: String? = null): JCheckBox { val component = JCheckBox(BundleBase.replaceMnemonicAmpersand(text), selected) toolTip?.let { component.toolTipText = it } return component } @JvmOverloads -fun Panel(@Nls(capitalization = Nls.Capitalization.Title) title: String? = null, layout: LayoutManager2? = BorderLayout()): JPanel { +fun Panel(@BorderTitle title: String? = null, layout: LayoutManager2? = BorderLayout()): JPanel { return Panel(title, false, layout) } -fun Panel(@Nls(capitalization = Nls.Capitalization.Title) title: String? = null, hasSeparator: Boolean = true, layout: LayoutManager2? = BorderLayout()): JPanel { +fun Panel(@BorderTitle title: String? = null, hasSeparator: Boolean = true, layout: LayoutManager2? = BorderLayout()): JPanel { val panel = JPanel(layout) title?.let { setTitledBorder(it, panel, hasSeparator) } return panel } -fun DialogPanel(@Nls(capitalization = Nls.Capitalization.Title) title: String? = null, layout: LayoutManager2? = BorderLayout()): DialogPanel { +fun DialogPanel(@BorderTitle title: String? = null, layout: LayoutManager2? = BorderLayout()): DialogPanel { val panel = DialogPanel(layout) title?.let { setTitledBorder(it, panel, hasSeparator = true) } return panel } -private fun setTitledBorder(@Nls(capitalization = Nls.Capitalization.Title) title: String, panel: JPanel, hasSeparator: Boolean) { +private fun setTitledBorder(@BorderTitle title: String, panel: JPanel, hasSeparator: Boolean) { val border = when { hasSeparator -> IdeBorderFactory.createTitledBorder(title, false) else -> IdeBorderFactory.createTitledBorder(title, false, JBUI.insetsTop(8)).setShowLine(false) @@ -148,7 +150,7 @@ private fun setTitledBorder(@Nls(capitalization = Nls.Capitalization.Title) titl * Consider using [UI DSL](http://www.jetbrains.org/intellij/sdk/docs/user_interface_components/kotlin_ui_dsl.html). */ @JvmOverloads -fun dialog(@NlsContexts.DialogTitle title: String, +fun dialog(@DialogTitle title: String, panel: JComponent, resizable: Boolean = false, focusedComponent: JComponent? = null, @@ -237,7 +239,7 @@ private abstract class MyDialogWrapper(project: Project?, fun installFileCompletionAndBrowseDialog(project: Project?, component: ComponentWithBrowseButton, textField: JTextField, - @Nls(capitalization = Nls.Capitalization.Title) browseDialogTitle: String?, + @DialogTitle browseDialogTitle: String?, fileChooserDescriptor: FileChooserDescriptor, textComponentAccessor: TextComponentAccessor, fileChosen: ((chosenFile: VirtualFile) -> String)? = null) { @@ -263,7 +265,7 @@ fun installFileCompletionAndBrowseDialog(project: Project?, @JvmOverloads fun textFieldWithHistoryWithBrowseButton(project: Project?, - @Nls(capitalization = Nls.Capitalization.Title) browseDialogTitle: String, + @DialogTitle browseDialogTitle: String, fileChooserDescriptor: FileChooserDescriptor, historyProvider: (() -> List)? = null, fileChosen: ((chosenFile: VirtualFile) -> String)? = null): TextFieldWithHistoryWithBrowseButton { @@ -288,7 +290,7 @@ fun textFieldWithHistoryWithBrowseButton(project: Project?, @JvmOverloads fun textFieldWithBrowseButton(project: Project?, - @Nls(capitalization = Nls.Capitalization.Title) browseDialogTitle: String?, + @DialogTitle browseDialogTitle: String?, fileChooserDescriptor: FileChooserDescriptor, fileChosen: ((chosenFile: VirtualFile) -> String)? = null): TextFieldWithBrowseButton { val component = TextFieldWithBrowseButton() @@ -306,7 +308,7 @@ fun textFieldWithBrowseButton(project: Project?, @JvmOverloads fun textFieldWithBrowseButton(project: Project?, - @Nls(capitalization = Nls.Capitalization.Title) browseDialogTitle: String, + @DialogTitle browseDialogTitle: String, textField: JTextField, fileChooserDescriptor: FileChooserDescriptor, fileChosen: ((chosenFile: VirtualFile) -> String)? = null): 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 3a6d6ca3d109..192b170a1e30 100644 --- a/platform/platform-impl/src/com/intellij/ui/layout/Cell.kt +++ b/platform/platform-impl/src/com/intellij/ui/layout/Cell.kt @@ -17,6 +17,7 @@ import com.intellij.openapi.ui.TextFieldWithBrowseButton import com.intellij.openapi.ui.ValidationInfo import com.intellij.openapi.ui.panel.ComponentPanelBuilder import com.intellij.openapi.ui.popup.JBPopupFactory +import com.intellij.openapi.util.NlsContexts.* import com.intellij.openapi.util.text.StringUtil import com.intellij.openapi.vfs.VirtualFile import com.intellij.ui.* @@ -92,14 +93,14 @@ inline fun KMutableProperty0.toNullableBinding(defaultValu } class ValidationInfoBuilder(val component: JComponent) { - fun error(@Nls message: String): ValidationInfo = ValidationInfo(message, component) - fun warning(@Nls message: String): ValidationInfo = ValidationInfo(message, component).asWarning().withOKEnabled() + fun error(@DialogMessage message: String): ValidationInfo = ValidationInfo(message, component) + fun warning(@DialogMessage message: String): ValidationInfo = ValidationInfo(message, component).asWarning().withOKEnabled() } interface CellBuilder { val component: T - fun comment(@Nls text: String, maxLineLength: Int = 70, forComponent: Boolean = false): CellBuilder + fun comment(@DetailedDescription text: String, maxLineLength: Int = 70, forComponent: Boolean = false): CellBuilder fun commentComponent(component: JComponent, forComponent: Boolean = false): CellBuilder fun focused(): CellBuilder fun withValidationOnApply(callback: ValidationInfoBuilder.(T) -> ValidationInfo?): CellBuilder @@ -137,7 +138,7 @@ interface CellBuilder { fun enabled(isEnabled: Boolean) fun enableIf(predicate: ComponentPredicate): CellBuilder - fun withErrorOnApplyIf(message: String, callback: (T) -> Boolean): CellBuilder { + fun withErrorOnApplyIf(@DialogMessage message: String, callback: (T) -> Boolean): CellBuilder { withValidationOnApply { if (callback(it)) error(message) else null } return this } @@ -212,7 +213,7 @@ abstract class Cell : BaseBuilder { val pushY = CCFlags.pushY val push = CCFlags.push - fun label(@Nls text: String, + fun label(@Label text: String, style: UIUtil.ComponentStyle? = null, fontColor: UIUtil.FontColor? = null, bold: Boolean = false): CellBuilder { @@ -220,7 +221,7 @@ abstract class Cell : BaseBuilder { return component(label) } - fun link(@Nls text: String, + fun link(@LinkLabel text: String, style: UIUtil.ComponentStyle? = null, action: () -> Unit): CellBuilder { val result = Link(text, action = action) @@ -228,26 +229,26 @@ abstract class Cell : BaseBuilder { return component(result) } - fun browserLink(@Nls text: String, url: String): CellBuilder { + fun browserLink(@LinkLabel text: String, url: String): CellBuilder { val result = HyperlinkLabel() result.setHyperlinkText(text) result.setHyperlinkTarget(url) return component(result) } - fun buttonFromAction(@Nls text: String, actionPlace: String, action: AnAction): CellBuilder { + fun buttonFromAction(@Button text: String, actionPlace: String, action: AnAction): CellBuilder { val button = JButton(BundleBase.replaceMnemonicAmpersand(text)) button.addActionListener { ActionUtil.invokeAction(action, button, actionPlace, null, null) } return component(button) } - fun button(@Nls text: String, actionListener: (event: ActionEvent) -> Unit): CellBuilder { + fun button(@Button text: String, actionListener: (event: ActionEvent) -> Unit): CellBuilder { val button = JButton(BundleBase.replaceMnemonicAmpersand(text)) button.addActionListener(actionListener) return component(button) } - inline fun checkBox(@Nls text: String, + inline fun checkBox(@Checkbox text: String, isSelected: Boolean = false, comment: String? = null, crossinline actionListener: (event: ActionEvent, component: JCheckBox) -> Unit): CellBuilder { @@ -258,47 +259,47 @@ abstract class Cell : BaseBuilder { } @JvmOverloads - fun checkBox(@Nls text: String, + fun checkBox(@Checkbox text: String, isSelected: Boolean = false, comment: String? = null): CellBuilder { val result = JBCheckBox(text, isSelected) return result(comment = comment) } - fun checkBox(@Nls text: String, prop: KMutableProperty0, comment: String? = null): CellBuilder { + fun checkBox(@Checkbox text: String, prop: KMutableProperty0, comment: String? = null): CellBuilder { return checkBox(text, prop.toBinding(), comment) } - fun checkBox(@Nls text: String, getter: () -> Boolean, setter: (Boolean) -> Unit, comment: String? = null): CellBuilder { + fun checkBox(@Checkbox text: String, getter: () -> Boolean, setter: (Boolean) -> Unit, comment: String? = null): CellBuilder { return checkBox(text, PropertyBinding(getter, setter), comment) } - private fun checkBox(@Nls text: String, + private fun checkBox(@Checkbox text: String, modelBinding: PropertyBinding, comment: String?): CellBuilder { val component = JBCheckBox(text, modelBinding.get()) return component(comment = comment).withSelectedBinding(modelBinding) } - fun checkBox(@Nls text: String, + fun checkBox(@Checkbox text: String, property: GraphProperty, comment: String? = null): CellBuilder { val component = JBCheckBox(text, property.get()) return component(comment = comment).withGraphProperty(property).applyToComponent { component.bind(property) } } - open fun radioButton(@Nls text: String, @Nls comment: String? = null): CellBuilder { + open fun radioButton(@RadioButton text: String, @Nls comment: String? = null): CellBuilder { val component = JBRadioButton(text) component.putClientProperty(UNBOUND_RADIO_BUTTON, true) return component(comment = comment) } - open fun radioButton(@Nls text: String, getter: () -> Boolean, setter: (Boolean) -> Unit, @Nls comment: String? = null): CellBuilder { + open fun radioButton(@RadioButton text: String, getter: () -> Boolean, setter: (Boolean) -> Unit, @Nls comment: String? = null): CellBuilder { val component = JBRadioButton(text, getter()) return component(comment = comment).withSelectedBinding(PropertyBinding(getter, setter)) } - open fun radioButton(@Nls text: String, prop: KMutableProperty0, @Nls comment: String? = null): CellBuilder { + open fun radioButton(@RadioButton text: String, prop: KMutableProperty0, @Nls comment: String? = null): CellBuilder { val component = JBRadioButton(text, prop.get()) return component(comment = comment).withSelectedBinding(prop.toBinding()) } @@ -392,7 +393,7 @@ abstract class Cell : BaseBuilder { } fun textFieldWithHistoryWithBrowseButton( - browseDialogTitle: String, + @DialogTitle browseDialogTitle: String, value: String? = null, project: Project? = null, fileChooserDescriptor: FileChooserDescriptor = FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor(), @@ -405,7 +406,7 @@ abstract class Cell : BaseBuilder { } fun textFieldWithBrowseButton( - browseDialogTitle: String? = null, + @DialogTitle browseDialogTitle: String? = null, value: String? = null, project: Project? = null, fileChooserDescriptor: FileChooserDescriptor = FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor(), @@ -418,7 +419,7 @@ abstract class Cell : BaseBuilder { fun textFieldWithBrowseButton( prop: KMutableProperty0, - browseDialogTitle: String? = null, + @DialogTitle browseDialogTitle: String? = null, project: Project? = null, fileChooserDescriptor: FileChooserDescriptor = FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor(), fileChosen: ((chosenFile: VirtualFile) -> String)? = null @@ -430,7 +431,7 @@ abstract class Cell : BaseBuilder { fun textFieldWithBrowseButton( getter: () -> String, setter: (String) -> Unit, - browseDialogTitle: String? = null, + @DialogTitle browseDialogTitle: String? = null, project: Project? = null, fileChooserDescriptor: FileChooserDescriptor = FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor(), fileChosen: ((chosenFile: VirtualFile) -> String)? = null @@ -441,7 +442,7 @@ abstract class Cell : BaseBuilder { fun textFieldWithBrowseButton( modelBinding: PropertyBinding, - browseDialogTitle: String? = null, + @DialogTitle browseDialogTitle: String? = null, project: Project? = null, fileChooserDescriptor: FileChooserDescriptor = FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor(), fileChosen: ((chosenFile: VirtualFile) -> String)? = null @@ -455,7 +456,7 @@ abstract class Cell : BaseBuilder { fun textFieldWithBrowseButton( property: GraphProperty, - browseDialogTitle: String? = null, + @DialogTitle browseDialogTitle: String? = null, project: Project? = null, fileChooserDescriptor: FileChooserDescriptor = FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor(), fileChosen: ((chosenFile: VirtualFile) -> String)? = null @@ -517,7 +518,7 @@ abstract class Cell : BaseBuilder { * @see LayoutBuilder.titledRow */ @JvmOverloads - fun panel(title: String, wrappedComponent: Component, hasSeparator: Boolean = true): CellBuilder { + fun panel(@BorderTitle title: String, wrappedComponent: Component, hasSeparator: Boolean = true): CellBuilder { val panel = Panel(title, hasSeparator) panel.add(wrappedComponent) return component(panel) @@ -527,11 +528,11 @@ abstract class Cell : BaseBuilder { return component(JBScrollPane(component)) } - fun comment(text: String, maxLineLength: Int = -1): CellBuilder { + fun comment(@DetailedDescription text: String, maxLineLength: Int = -1): CellBuilder { return component(ComponentPanelBuilder.createCommentComponent(text, true, maxLineLength, true)) } - fun commentNoWrap(text: String): CellBuilder { + fun commentNoWrap(@DetailedDescription text: String): CellBuilder { return component(ComponentPanelBuilder.createNonWrappingCommentComponent(text)) }