first commit

This commit is contained in:
2023-12-29 00:20:04 +08:00
commit 231a337373
30 changed files with 947 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
package com.github.cirry.wxreaderjetbrainsplugin
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.PlatformDataKeys
import com.intellij.openapi.project.DumbAwareAction
import com.intellij.openapi.ui.Messages
class HelloAction : DumbAwareAction() {
override fun actionPerformed(event: AnActionEvent) {
val project = event.getData(PlatformDataKeys.PROJECT)
Messages.showMessageDialog(project, "Hello from Kotlin!", "Greeting", Messages.getInformationIcon())
}
}

View File

@@ -0,0 +1,20 @@
package com.github.cirry.wxreaderjetbrainsplugin
import com.intellij.DynamicBundle
import org.jetbrains.annotations.NonNls
import org.jetbrains.annotations.PropertyKey
@NonNls
private const val BUNDLE = "messages.MyBundle"
object MyBundle : DynamicBundle(BUNDLE) {
@JvmStatic
fun message(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any) =
getMessage(key, *params)
@Suppress("unused")
@JvmStatic
fun messagePointer(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any) =
getLazyMessage(key, *params)
}

View File

@@ -0,0 +1,12 @@
package com.github.cirry.wxreaderjetbrainsplugin.listeners
import com.intellij.openapi.application.ApplicationActivationListener
import com.intellij.openapi.diagnostic.thisLogger
import com.intellij.openapi.wm.IdeFrame
internal class MyApplicationActivationListener : ApplicationActivationListener {
override fun applicationActivated(ideFrame: IdeFrame) {
thisLogger().warn("Don't forget to remove all non-needed sample code files with their corresponding registration entries in `plugin.xml`.")
}
}

View File

@@ -0,0 +1,16 @@
package com.github.cirry.wxreaderjetbrainsplugin.services
import com.intellij.openapi.components.Service
import com.intellij.openapi.diagnostic.thisLogger
import com.intellij.openapi.project.Project
import com.github.cirry.wxreaderjetbrainsplugin.MyBundle
@Service(Service.Level.PROJECT)
class MyProjectService(project: Project) {
init {
thisLogger().info(MyBundle.message("projectService", project.name))
}
fun getRandomNumber() = (1..100).random()
}

View File

@@ -0,0 +1,43 @@
package com.github.cirry.wxreaderjetbrainsplugin.toolWindow
import com.github.cirry.wxreaderjetbrainsplugin.MyBundle
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 com.intellij.ui.jcef.JBCefApp
import com.intellij.ui.jcef.JBCefBrowser
import java.awt.BorderLayout
import java.awt.Dimension
class MyToolWindowFactory : ToolWindowFactory {
init {
}
override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) {
val myToolWindow = MyToolWindow(toolWindow)
val content = ContentFactory.getInstance().createContent(myToolWindow.getContent(), "", false)
toolWindow.contentManager.addContent(content)
}
override fun shouldBeAvailable(project: Project) = true
class MyToolWindow(toolWindow: ToolWindow) {
fun getContent() = JBPanel<JBPanel<*>>().apply {
val noSupportLabel = JBLabel(MyBundle.message("noSupport"))
if (JBCefApp.isSupported()) {
val jbcef = JBCefBrowser()
jbcef.component.preferredSize = Dimension(800,900)
add(jbcef.component, BorderLayout.CENTER)
jbcef.loadURL("https://weread.qq.com/")
} else {
add(noSupportLabel)
}
}
}
}

View File

@@ -0,0 +1,33 @@
<!-- Plugin Configuration File. Read more: https://plugins.jetbrains.com/docs/intellij/plugin-configuration-file.html -->
<idea-plugin>
<id>com.github.cirry.wxreaderjetbrainsplugin</id>
<name>Weread</name>
<vendor email="cdxtrv@qq.com" url="https://cirry.cn">Cirry</vendor>
<depends>com.intellij.modules.platform</depends>
<description><![CDATA[
Provides support for My Framework.
The support includes:
<ul>
<li>code completion</li>
<li>references</li>
</ul>
For more information visit the
<a href="https://example.com">project site</a>.
]]></description>
<resource-bundle>messages.MyBundle</resource-bundle>
<extensions defaultExtensionNs="com.intellij">
<toolWindow factoryClass="com.github.cirry.wxreaderjetbrainsplugin.toolWindow.MyToolWindowFactory"
icon="/icons/toolWindowIcon.svg" id="WeReader"/>
</extensions>
<applicationListeners>
<listener class="com.github.cirry.wxreaderjetbrainsplugin.listeners.MyApplicationActivationListener"
topic="com.intellij.openapi.application.ApplicationActivationListener"/>
</applicationListeners>
<actions>
</actions>
</idea-plugin>

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="36" height="36"><path d="M3 18.5V5C3 3.34315 4.34315 2 6 2H20C20.5523 2 21 2.44772 21 3V21C21 21.5523 20.5523 22 20 22H6.5C4.567 22 3 20.433 3 18.5ZM19 20V17H6.5C5.67157 17 5 17.6716 5 18.5C5 19.3284 5.67157 20 6.5 20H19ZM5 15.3368C5.45463 15.1208 5.9632 15 6.5 15H19V4H6C5.44772 4 5 4.44772 5 5V15.3368Z" fill="rgba(193,193,193,1)"></path></svg>

After

Width:  |  Height:  |  Size: 413 B

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="16" height="16"><path d="M3 18.5V5C3 3.34315 4.34315 2 6 2H20C20.5523 2 21 2.44772 21 3V21C21 21.5523 20.5523 22 20 22H6.5C4.567 22 3 20.433 3 18.5ZM19 20V17H6.5C5.67157 17 5 17.6716 5 18.5C5 19.3284 5.67157 20 6.5 20H19ZM5 15.3368C5.45463 15.1208 5.9632 15 6.5 15H19V4H6C5.44772 4 5 4.44772 5 5V15.3368Z" fill="rgba(193,193,193,1)"></path></svg>

After

Width:  |  Height:  |  Size: 413 B

View File

@@ -0,0 +1 @@
noSupport=Your IDEA doesn't support it, please enable JCEF.

View File

@@ -0,0 +1,18 @@
.os-scrollbar {
--os-size: 4px;
--os-padding-perpendicular: 2px;
--os-handle-border-radius: 0px;
--os-track-border-radius: 0; --os-track-bg: rgba(128, 128, 128, 0.000000);
--os-track-bg-active: rgba(128, 128, 128, 0.000000);
--os-track-bg-hover: rgba(128, 128, 128, 0.000000);
--os-handle-bg: rgba(166, 166, 166, 0.278431);
--os-handle-bg-active: rgba(166, 166, 166, 0.278431);
--os-handle-bg-hover: rgba(166, 166, 166, 0.349020);
--os-handle-perpendicular-size: 100%;
--os-handle-perpendicular-size-hover: 100%;
--os-handle-perpendicular-size-active: 100%;
}
.os-scrollbar-handle { outline: 1px solid rgba(56, 56, 56, 0.278431);
}.os-scrollbar-handle:hover { outline: 1px solid rgba(56, 56, 56, 0.349020);
}.os-scrollbar-handle:active { outline: 1px solid rgba(56, 56, 56, 0.349020);
}

View File

@@ -0,0 +1,39 @@
package com.github.cirry.wxreaderjetbrainsplugin
import com.intellij.ide.highlighter.XmlFileType
import com.intellij.openapi.components.service
import com.intellij.psi.xml.XmlFile
import com.intellij.testFramework.TestDataPath
import com.intellij.testFramework.fixtures.BasePlatformTestCase
import com.intellij.util.PsiErrorElementUtil
import com.github.cirry.wxreaderjetbrainsplugin.services.MyProjectService
@TestDataPath("\$CONTENT_ROOT/src/test/testData")
class MyPluginTest : BasePlatformTestCase() {
fun testXMLFile() {
val psiFile = myFixture.configureByText(XmlFileType.INSTANCE, "<foo>bar</foo>")
val xmlFile = assertInstanceOf(psiFile, XmlFile::class.java)
assertFalse(PsiErrorElementUtil.hasErrors(project, xmlFile.virtualFile))
assertNotNull(xmlFile.rootTag)
xmlFile.rootTag?.let {
assertEquals("foo", it.name)
assertEquals("bar", it.value.text)
}
}
// fun testRename() {
// myFixture.testRename("foo.xml", "foo_after.xml", "a2")
// }
// fun testProjectService() {
// val projectService = project.service<MyProjectService>()
//
// assertNotSame(projectService.getRandomNumber(), projectService.getRandomNumber())
// }
override fun getTestDataPath() = "src/test/testData/rename"
}

View File

@@ -0,0 +1,3 @@
<root>
<a<caret>1>Foo</a1>
</root>

View File

@@ -0,0 +1,3 @@
<root>
<a2>Foo</a2>
</root>