initial commit
This commit is contained in:
22
src/main/kotlin/MyMessageBundle.kt
Normal file
22
src/main/kotlin/MyMessageBundle.kt
Normal file
@@ -0,0 +1,22 @@
|
||||
package dev.hgh
|
||||
|
||||
import com.intellij.DynamicBundle
|
||||
import org.jetbrains.annotations.Nls
|
||||
import org.jetbrains.annotations.PropertyKey
|
||||
import java.util.function.Supplier
|
||||
|
||||
private const val BUNDLE = "messages.MyMessageBundle"
|
||||
|
||||
internal object MyMessageBundle {
|
||||
private val instance = DynamicBundle(MyMessageBundle::class.java, BUNDLE)
|
||||
|
||||
@JvmStatic
|
||||
fun message(key: @PropertyKey(resourceBundle = BUNDLE) String, vararg params: Any?): @Nls String {
|
||||
return instance.getMessage(key, *params)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun lazyMessage(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any?): Supplier<@Nls String> {
|
||||
return instance.getLazyMessage(key, *params)
|
||||
}
|
||||
}
|
||||
37
src/main/kotlin/MyToolWindowFactory.kt
Normal file
37
src/main/kotlin/MyToolWindowFactory.kt
Normal file
@@ -0,0 +1,37 @@
|
||||
package dev.hgh
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.wm.ToolWindow
|
||||
import com.intellij.openapi.wm.ToolWindowFactory
|
||||
import com.intellij.ui.components.JBLabel
|
||||
import com.intellij.ui.components.JBPanel
|
||||
import com.intellij.ui.content.ContentFactory
|
||||
import javax.swing.JButton
|
||||
import kotlin.random.Random
|
||||
|
||||
class MyToolWindowFactory : ToolWindowFactory {
|
||||
override fun shouldBeAvailable(project: Project) = true
|
||||
|
||||
override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) {
|
||||
val myToolWindow = MyToolWindow()
|
||||
val content = ContentFactory.getInstance().createContent(myToolWindow.getContent(), null, false)
|
||||
toolWindow.contentManager.addContent(content)
|
||||
}
|
||||
|
||||
class MyToolWindow {
|
||||
private val content = JBPanel<JBPanel<*>>().apply {
|
||||
val label = JBLabel(MyMessageBundle.message("toolwindow.MyToolWindow.number.label", "?"))
|
||||
|
||||
add(label)
|
||||
add(JButton(MyMessageBundle.message("toolwindow.MyToolWindow.shuffle.button")).apply {
|
||||
addActionListener {
|
||||
label.text = MyMessageBundle.message(
|
||||
"toolwindow.MyToolWindow.number.label", Random(System.currentTimeMillis()).nextInt(1000)
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun getContent(): JBPanel<JBPanel<*>> = content
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user