mirror of
https://github.com/JetBrains/intellij-platform-plugin-template.git
synced 2024-10-27 20:44:05 +00:00
Example code - MyToolWindowFactory
tool window basic implementation
This commit is contained in:
parent
5bda710503
commit
f686654cbb
@ -7,6 +7,7 @@
|
|||||||
### Added
|
### Added
|
||||||
- Migrate to Gradle Provider API improving configuration cache compatibility
|
- Migrate to Gradle Provider API improving configuration cache compatibility
|
||||||
- Example code - `FrameStateListener` application listener
|
- Example code - `FrameStateListener` application listener
|
||||||
|
- Example code - `MyToolWindowFactory` tool window basic implementation
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- Update `platformVersion` to `2022.1.4`
|
- Update `platformVersion` to `2022.1.4`
|
||||||
|
@ -10,13 +10,8 @@ class MyProjectService(project: Project) {
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
thisLogger().info(MyBundle.message("projectService", project.name))
|
thisLogger().info(MyBundle.message("projectService", project.name))
|
||||||
|
thisLogger().warn("Don't forget to remove all non-needed sample code files with their corresponding registration entries in `plugin.xml`.")
|
||||||
System.getenv("CI")
|
|
||||||
?: TODO("Don't forget to remove all non-needed sample code files with their corresponding registration entries in `plugin.xml`.")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
fun getRandomNumber() = (1..100).random()
|
||||||
* Chosen by fair dice roll, guaranteed to be random.
|
|
||||||
*/
|
|
||||||
fun getRandomNumber() = 4
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,47 @@
|
|||||||
|
package org.jetbrains.plugins.template.toolWindow
|
||||||
|
|
||||||
|
import com.intellij.openapi.components.service
|
||||||
|
import com.intellij.openapi.diagnostic.thisLogger
|
||||||
|
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 org.jetbrains.plugins.template.MyBundle
|
||||||
|
import org.jetbrains.plugins.template.services.MyProjectService
|
||||||
|
import javax.swing.JButton
|
||||||
|
|
||||||
|
|
||||||
|
class MyToolWindowFactory : ToolWindowFactory {
|
||||||
|
|
||||||
|
init {
|
||||||
|
thisLogger().warn("Don't forget to remove all non-needed sample code files with their corresponding registration entries in `plugin.xml`.")
|
||||||
|
}
|
||||||
|
|
||||||
|
private val contentFactory = ContentFactory.SERVICE.getInstance()
|
||||||
|
|
||||||
|
override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) {
|
||||||
|
val myToolWindow = MyToolWindow(toolWindow)
|
||||||
|
val content = contentFactory.createContent(myToolWindow.getContent(), null, false)
|
||||||
|
toolWindow.contentManager.addContent(content)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldBeAvailable(project: Project) = true
|
||||||
|
|
||||||
|
class MyToolWindow(toolWindow: ToolWindow) {
|
||||||
|
|
||||||
|
private val service = toolWindow.project.service<MyProjectService>()
|
||||||
|
|
||||||
|
fun getContent() = JBPanel<JBPanel<*>>().apply {
|
||||||
|
val label = JBLabel(MyBundle.message("randomLabel", "?"))
|
||||||
|
|
||||||
|
add(label)
|
||||||
|
add(JButton(MyBundle.message("shuffle")).apply {
|
||||||
|
addActionListener {
|
||||||
|
label.text = MyBundle.message("randomLabel", service.getRandomNumber())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -8,8 +8,11 @@
|
|||||||
|
|
||||||
<resource-bundle>messages.MyBundle</resource-bundle>
|
<resource-bundle>messages.MyBundle</resource-bundle>
|
||||||
|
|
||||||
|
<extensions defaultExtensionNs="com.intellij">
|
||||||
|
<toolWindow factoryClass="org.jetbrains.plugins.template.toolWindow.MyToolWindowFactory" id="MyToolWindow"/>
|
||||||
|
</extensions>
|
||||||
|
|
||||||
<applicationListeners>
|
<applicationListeners>
|
||||||
<listener class="org.jetbrains.plugins.template.listeners.MyFrameStateListener"
|
<listener class="org.jetbrains.plugins.template.listeners.MyFrameStateListener" topic="com.intellij.ide.FrameStateListener"/>
|
||||||
topic="com.intellij.ide.FrameStateListener"/>
|
|
||||||
</applicationListeners>
|
</applicationListeners>
|
||||||
</idea-plugin>
|
</idea-plugin>
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
name=My Plugin
|
name=My Plugin
|
||||||
applicationService=Application service
|
|
||||||
projectService=Project service: {0}
|
projectService=Project service: {0}
|
||||||
|
randomLabel=The random number is: {0}
|
||||||
|
shuffle=Shuffle
|
||||||
|
@ -32,7 +32,7 @@ class MyPluginTest : BasePlatformTestCase() {
|
|||||||
fun testProjectService() {
|
fun testProjectService() {
|
||||||
val projectService = project.service<MyProjectService>()
|
val projectService = project.service<MyProjectService>()
|
||||||
|
|
||||||
assertEquals(4, projectService.getRandomNumber())
|
assertNotSame(projectService.getRandomNumber(), projectService.getRandomNumber())
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getTestDataPath() = "src/test/testData/rename"
|
override fun getTestDataPath() = "src/test/testData/rename"
|
||||||
|
Loading…
Reference in New Issue
Block a user