建立plugin项目
建立后结果下所示
➜ my-plugin tree .
.
├── my-plugin.iml
├── resources
│ └── META-INF
│ └── plugin.xml
└── src
└── com
└── chenshun
└── test
├── TestOtherAction.java //后续补充的,新建立项目还没有
└── TranslateAction.java //后续补充的,新建立项目还没有
hello world
建立Action
plugin.xml 的action
<actions>
<!-- Add your actions here -->
<action id="TestTranslation.TranslateAction" class="com.chenshun.test.TranslateAction" text="Translate"
description="translate from select word">
<add-to-group group-id="EditorPopupMenu" anchor="first"/>
<keyboard-shortcut keymap="$default" first-keystroke="meta I"/>
</action>
<action id="TestOtherAction" class="com.chenshun.test.TestOtherAction" text="test" description="这个是菜单的一个测试">
<add-to-group group-id="ToolsMenu" anchor="first"/>
<keyboard-shortcut keymap="$default" first-keystroke="ctrl meta alt P"/>
</action>
<action id="MyFirstPluginAction" class="com.chenshun.test.MyFirstPluginAction" text="MyFirstPlugin"
description="这是我的一个插件">
<add-to-group group-id="EditorPopupMenu" anchor="first"/>
<keyboard-shortcut keymap="$default" first-keystroke="CAPS_LOCK"/>
</action>
</actions>
/**
* @author chenshun00
* @since 2020/2/23 3:06 PM
*/
public class MyFirstPluginAction extends AnAction {
@Override
public void actionPerformed(AnActionEvent e) {
Messages.showMessageDialog("我的第一个插件", "Information", Messages.getInformationIcon());
}
}
运行插件后,会新建立一个IDEA界面.
在新界面执行快捷键
总结
刚入门写的比较简单,刚入门的资料也不算多,下边弄一个复杂点的 :)