插件项目中的 plugin.xml 是一个很重要的文件,它向 IntelliJ Platform 描述了我们插件的样子,如下:
<idea-plugin><id>top.smallzh.background-image-x</id><name>BackgroundImageX</name><vendor email="smallzh@yeah.net" url="https://smallzh.top">smallzh</vendor><!-- please see https://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/plugin_compatibility.htmlon how to target different products --><depends>com.intellij.modules.platform</depends><extensions defaultExtensionNs="com.intellij"><toolWindow id="Background Image X" anchor="right" icon="/top/smallzh/tools/bix/icons/bix.svg"factoryClass="top.smallzh.tools.bix.ui.BixToolWindowFactory" /><applicationConfigurable id="backgroundImageXConfiguration" displayName="Background Image X"instance="top.smallzh.tools.bix.ui.BixConfiguration" groupId="tools"/><applicationService serviceImplementation="top.smallzh.tools.bix.BixImagesStorage" /></extensions><actions><group id="backgroundImageX" text="Background Image X" description="Background Image X"><add-to-group group-id="ViewMenu" anchor="before" relative-to-action="ToggleFullScreenGroup"/><separator/><action id="randomBackgroundImage" class="top.smallzh.tools.bix.action.RandomBackground"text="Random Background Image"/><action id="clearBackgroundImage" class="top.smallzh.tools.bix.action.ClearBackground"text="Clear Background Image"/><action id="downloadBackgroundImage" class="top.smallzh.tools.bix.action.DownloadBackground"text="Download Background Image" /><action id="removeBackgroundImage" class="top.smallzh.tools.bix.action.RemoveBackground"text="Remove Background Image" /></group></actions></idea-plugin>
1 关键Tag说明
1.1 actions节点
格式如下:
<!-- Actions --><actions><action id="VssIntegration.GarbageCollection" class="com.foo.impl.CollectGarbage" text="Collect _Garbage" description="Run garbage collector"><keyboard-shortcut first-keystroke="control alt G" second-keystroke="C" keymap="$default"/></action></actions>
其中,每一个 action 表示一个按钮,详细的,我们在 创建按钮部分 说明。
1.2 extensions节点
格式如下:
<extensions defaultExtensionNs="VssIntegration"><testExtensionPoint implementation="com.foo.impl.MyExtensionImpl"/></extensions>
其中,每一个子节点表示一种更通用的 扩展内容,如 toolWindow。
1.3 listener监听器
包含2种,application级别和project级别,如下:
<!-- Application-level listeners --><applicationListeners><listener class="com.foo.impl.MyListener" topic="com.intellij.openapi.vfs.newvfs.BulkFileListener"/></applicationListeners><!-- Project-level listeners --><projectListeners><listener class="com.foo.impl.MyToolwindowListener" topic="com.intellij.openapi.wm.ex.ToolWindowManagerListener"/></projectListeners>
2 关键Tag的理解
| Tag | 说明 |
|---|---|
| 按钮(Action) | IntelliJ平台上在Menu、toolBar上的拓展点 |
| 扩展(Extension) | 在其他窗口上提供扩展,如配置页、toolWindow等等 |
| 服务(Service) | 是插件中一个运行在后台的组件,通过ServiceManager.getService()获取,IntelliJ平台保证服务只有一个 |
| 监听器(Listener) | 插件用来监听消息栈中的事件消息,采用懒加载模式,当第一次收到消息时创建实例 |
