From e566ce7752754363c8fb190b711e36399be3b4d8 Mon Sep 17 00:00:00 2001 From: Jakub Chrzanowski Date: Mon, 4 May 2026 10:25:36 +0200 Subject: [PATCH] Add operator function for resource bundle key access in `MyBundle` --- CHANGELOG.md | 4 ++++ src/main/kotlin/org/jetbrains/plugins/template/MyBundle.kt | 3 +++ .../jetbrains/plugins/template/services/MyProjectService.kt | 2 +- .../plugins/template/toolWindow/MyToolWindowFactory.kt | 6 +++--- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 612a590..7b887a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ ## [Unreleased] +### Added + +- Add operator function for resource bundle key access in `MyBundle` + ### Changed - Dependencies - upgrade `org.jetbrains.intellij.platform` to `2.16.0` diff --git a/src/main/kotlin/org/jetbrains/plugins/template/MyBundle.kt b/src/main/kotlin/org/jetbrains/plugins/template/MyBundle.kt index 0bcd9fd..ed5dd8b 100644 --- a/src/main/kotlin/org/jetbrains/plugins/template/MyBundle.kt +++ b/src/main/kotlin/org/jetbrains/plugins/template/MyBundle.kt @@ -9,6 +9,9 @@ private const val BUNDLE = "messages.MyBundle" object MyBundle : DynamicBundle(BUNDLE) { + operator fun get(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any) = + getMessage(key, *params) + @JvmStatic fun message(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any) = getMessage(key, *params) diff --git a/src/main/kotlin/org/jetbrains/plugins/template/services/MyProjectService.kt b/src/main/kotlin/org/jetbrains/plugins/template/services/MyProjectService.kt index afa770f..1ea70bc 100644 --- a/src/main/kotlin/org/jetbrains/plugins/template/services/MyProjectService.kt +++ b/src/main/kotlin/org/jetbrains/plugins/template/services/MyProjectService.kt @@ -9,7 +9,7 @@ import org.jetbrains.plugins.template.MyBundle class MyProjectService(project: Project) { init { - thisLogger().info(MyBundle.message("projectService", project.name)) + thisLogger().info(MyBundle["projectService", project.name]) thisLogger().warn("Don't forget to remove all non-needed sample code files with their corresponding registration entries in `plugin.xml`.") } diff --git a/src/main/kotlin/org/jetbrains/plugins/template/toolWindow/MyToolWindowFactory.kt b/src/main/kotlin/org/jetbrains/plugins/template/toolWindow/MyToolWindowFactory.kt index 0e61940..4f38940 100644 --- a/src/main/kotlin/org/jetbrains/plugins/template/toolWindow/MyToolWindowFactory.kt +++ b/src/main/kotlin/org/jetbrains/plugins/template/toolWindow/MyToolWindowFactory.kt @@ -32,12 +32,12 @@ class MyToolWindowFactory : ToolWindowFactory { private val service = toolWindow.project.service() fun getContent() = JBPanel>().apply { - val label = JBLabel(MyBundle.message("randomLabel", "?")) + val label = JBLabel(MyBundle["randomLabel", "?"]) add(label) - add(JButton(MyBundle.message("shuffle")).apply { + add(JButton(MyBundle["shuffle"]).apply { addActionListener { - label.text = MyBundle.message("randomLabel", service.getRandomNumber()) + label.text = MyBundle["randomLabel", service.getRandomNumber()] } }) }