mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
i18n: more @NlsContext annotations for Cell/components
GitOrigin-RevId: 53a60e0ab5e30332e0ceed118e58cb75f138309e
This commit is contained in:
committed by
intellij-monorepo-bot
parent
2379ff4bc7
commit
1d899092b1
@@ -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 <T : JComponent> installFileCompletionAndBrowseDialog(project: Project?,
|
||||
component: ComponentWithBrowseButton<T>,
|
||||
textField: JTextField,
|
||||
@Nls(capitalization = Nls.Capitalization.Title) browseDialogTitle: String?,
|
||||
@DialogTitle browseDialogTitle: String?,
|
||||
fileChooserDescriptor: FileChooserDescriptor,
|
||||
textComponentAccessor: TextComponentAccessor<T>,
|
||||
fileChosen: ((chosenFile: VirtualFile) -> String)? = null) {
|
||||
@@ -263,7 +265,7 @@ fun <T : JComponent> installFileCompletionAndBrowseDialog(project: Project?,
|
||||
|
||||
@JvmOverloads
|
||||
fun textFieldWithHistoryWithBrowseButton(project: Project?,
|
||||
@Nls(capitalization = Nls.Capitalization.Title) browseDialogTitle: String,
|
||||
@DialogTitle browseDialogTitle: String,
|
||||
fileChooserDescriptor: FileChooserDescriptor,
|
||||
historyProvider: (() -> List<String>)? = 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 {
|
||||
|
||||
@@ -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 <reified T : Any> KMutableProperty0<T?>.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<out T : JComponent> {
|
||||
val component: T
|
||||
|
||||
fun comment(@Nls text: String, maxLineLength: Int = 70, forComponent: Boolean = false): CellBuilder<T>
|
||||
fun comment(@DetailedDescription text: String, maxLineLength: Int = 70, forComponent: Boolean = false): CellBuilder<T>
|
||||
fun commentComponent(component: JComponent, forComponent: Boolean = false): CellBuilder<T>
|
||||
fun focused(): CellBuilder<T>
|
||||
fun withValidationOnApply(callback: ValidationInfoBuilder.(T) -> ValidationInfo?): CellBuilder<T>
|
||||
@@ -137,7 +138,7 @@ interface CellBuilder<out T : JComponent> {
|
||||
fun enabled(isEnabled: Boolean)
|
||||
fun enableIf(predicate: ComponentPredicate): CellBuilder<T>
|
||||
|
||||
fun withErrorOnApplyIf(message: String, callback: (T) -> Boolean): CellBuilder<T> {
|
||||
fun withErrorOnApplyIf(@DialogMessage message: String, callback: (T) -> Boolean): CellBuilder<T> {
|
||||
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<JLabel> {
|
||||
@@ -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<JComponent> {
|
||||
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<JComponent> {
|
||||
fun browserLink(@LinkLabel text: String, url: String): CellBuilder<JComponent> {
|
||||
val result = HyperlinkLabel()
|
||||
result.setHyperlinkText(text)
|
||||
result.setHyperlinkTarget(url)
|
||||
return component(result)
|
||||
}
|
||||
|
||||
fun buttonFromAction(@Nls text: String, actionPlace: String, action: AnAction): CellBuilder<JButton> {
|
||||
fun buttonFromAction(@Button text: String, actionPlace: String, action: AnAction): CellBuilder<JButton> {
|
||||
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<JButton> {
|
||||
fun button(@Button text: String, actionListener: (event: ActionEvent) -> Unit): CellBuilder<JButton> {
|
||||
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<JBCheckBox> {
|
||||
@@ -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<JBCheckBox> {
|
||||
val result = JBCheckBox(text, isSelected)
|
||||
return result(comment = comment)
|
||||
}
|
||||
|
||||
fun checkBox(@Nls text: String, prop: KMutableProperty0<Boolean>, comment: String? = null): CellBuilder<JBCheckBox> {
|
||||
fun checkBox(@Checkbox text: String, prop: KMutableProperty0<Boolean>, comment: String? = null): CellBuilder<JBCheckBox> {
|
||||
return checkBox(text, prop.toBinding(), comment)
|
||||
}
|
||||
|
||||
fun checkBox(@Nls text: String, getter: () -> Boolean, setter: (Boolean) -> Unit, comment: String? = null): CellBuilder<JBCheckBox> {
|
||||
fun checkBox(@Checkbox text: String, getter: () -> Boolean, setter: (Boolean) -> Unit, comment: String? = null): CellBuilder<JBCheckBox> {
|
||||
return checkBox(text, PropertyBinding(getter, setter), comment)
|
||||
}
|
||||
|
||||
private fun checkBox(@Nls text: String,
|
||||
private fun checkBox(@Checkbox text: String,
|
||||
modelBinding: PropertyBinding<Boolean>,
|
||||
comment: String?): CellBuilder<JBCheckBox> {
|
||||
val component = JBCheckBox(text, modelBinding.get())
|
||||
return component(comment = comment).withSelectedBinding(modelBinding)
|
||||
}
|
||||
|
||||
fun checkBox(@Nls text: String,
|
||||
fun checkBox(@Checkbox text: String,
|
||||
property: GraphProperty<Boolean>,
|
||||
comment: String? = null): CellBuilder<JBCheckBox> {
|
||||
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<JBRadioButton> {
|
||||
open fun radioButton(@RadioButton text: String, @Nls comment: String? = null): CellBuilder<JBRadioButton> {
|
||||
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<JBRadioButton> {
|
||||
open fun radioButton(@RadioButton text: String, getter: () -> Boolean, setter: (Boolean) -> Unit, @Nls comment: String? = null): CellBuilder<JBRadioButton> {
|
||||
val component = JBRadioButton(text, getter())
|
||||
return component(comment = comment).withSelectedBinding(PropertyBinding(getter, setter))
|
||||
}
|
||||
|
||||
open fun radioButton(@Nls text: String, prop: KMutableProperty0<Boolean>, @Nls comment: String? = null): CellBuilder<JBRadioButton> {
|
||||
open fun radioButton(@RadioButton text: String, prop: KMutableProperty0<Boolean>, @Nls comment: String? = null): CellBuilder<JBRadioButton> {
|
||||
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<String>,
|
||||
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<String>,
|
||||
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<String>,
|
||||
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<JPanel> {
|
||||
fun panel(@BorderTitle title: String, wrappedComponent: Component, hasSeparator: Boolean = true): CellBuilder<JPanel> {
|
||||
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<JLabel> {
|
||||
fun comment(@DetailedDescription text: String, maxLineLength: Int = -1): CellBuilder<JLabel> {
|
||||
return component(ComponentPanelBuilder.createCommentComponent(text, true, maxLineLength, true))
|
||||
}
|
||||
|
||||
fun commentNoWrap(text: String): CellBuilder<JLabel> {
|
||||
fun commentNoWrap(@DetailedDescription text: String): CellBuilder<JLabel> {
|
||||
return component(ComponentPanelBuilder.createNonWrappingCommentComponent(text))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user