首页 > > > 开发属于自己的第一款IDEA插件!
阅读本文大概需要 4 分钟。
git clone --depth 1 git://git.jetbrains.org/idea/community.git idea
IDEA jdk来运行插件:
/lib/tools.jar到classpath中。File | Project Structure新建一个IntelliJ Platform SDK:
IDEA jdk:


IntellJ Platform Plugin,然后Project SDK指定刚刚新建的plugin sdk:

src和resources。src是插件代码目录,resource是插件资源目录,其中META-INF/plugin.xml是插件的描述文件,就像Java web项目的web.xml一样。<idea-plugin>
<id>com.your.company.unique.plugin.id</id>
<name>Plugin display name here</name>
<version>1.0</version>
<vendor email="support@yourcompany.com" url="http://www.yourcompany.com">YourCompany</vendor>
<description><![CDATA[
Enter short description for your plugin here.<br>
<em>most HTML tags may be used</em>
]]></description>
<change-notes><![CDATA[
Add change notes here.<br>
<em>most HTML tags may be used</em>
]]>
</change-notes>
<!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html for description -->
<idea-version since-build="145.0"/>
<!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/plugin_compatibility.html
on how to target different products -->
<!-- uncomment to enable plugin in all products
<depends>com.intellij.modules.lang</depends>
-->
<extensions defaultExtensionNs="com.intellij">
<!-- Add your extensions here -->
</extensions>
<actions>
<!-- Add your actions here -->
</actions>
</idea-plugin>
AnAction类,这个类有一个虚方法actionPerformed,这个方法会在每次菜单被点击时调用。AnAction类,在actionPerformed方法中实现插件逻辑plugin.xml注册public class TextBoxes extends AnAction {
// 如果通过Java代码来注册,这个构造函数会被调用,传给父类的字符串会被作为菜单项的名称
// 如果你通过plugin.xml来注册,可以忽略这个构造函数
public TextBoxes() {
// 设置菜单项名称
super("Text _Boxes");
// 还可以设置菜单项名称,描述,图标
// super("Text _Boxes","Item description",IconLoader.getIcon("/Mypackage/icon.png"));
}
public void actionPerformed(AnActionEvent event) {
Project project = event.getData(PlatformDataKeys.PROJECT);
String txt= Messages.showInputDialog(project, "What is your name?", "Input your name", Messages.getQuestionIcon());
Messages.showMessageDialog(project, "Hello, " + txt + "!\n I am glad to see you.", "Information", Messages.getInformationIcon());
}
}
plugin.xml中注册这个Action:<actions>
<group id="MyPlugin.SampleMenu" text="_Sample Menu" description="Sample menu">
<add-to-group group-id="MainMenu" anchor="last" />
<action id="Myplugin.Textboxes" class="Mypackage.TextBoxes" text="Text _Boxes" description="A test menu item" />
</group>
</actions>


<END>
推荐阅读:
懒人 IDEA 插件推荐: EasyCode 一键帮你生成所需代码~

微信扫描二维码,关注我的公众号
朕已阅 
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69902700/viewspace-3129272/ ,如需转载,请注明出处,否则将追究法律责任。