IntelliJ idea插件开发(一)

本文详细介绍如何在IntelliJ IDEA中开发插件,包括创建工程、定义动作、注册动作及打包使用等步骤。

官方参考文档

1.创建新工程点击plantform plugin(什么也不用选择),并选择工程名和工程目录


2.finish完成创建

3.创建action。在scr下面创建包名,我的为com.dyc.test.然后添加如下action类。

public class TextBoxes extends AnAction {
    // If you register the action from Java code, this constructor is used to set the menu item name
    // (optionally, you can specify the menu description and an icon to display next to the menu item).
    // You can omit this constructor when registering the action in the plugin.xml file.
    public TextBoxes() {
        // Set the menu item name.
        super("Text _Boxes");
        // Set the menu item name, description and icon.
        // 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());
    }
}
4.注册action,注册位置:工程目录->meta-inf->plugin.xml,选择与action同级的地方copy这段代码

<actions>
<!--
group id="MyPlugin.SampleMenu" text="_Sample Menu"
text是显示在工具栏的那个标题
-->
<group id="MyPlugin.SampleMenu" text="_Sample Menu" description="Sample menu">
<!-- 
<add-to-group group-id="MainMenu" anchor="last" 
group-id指的是子action要加入的gruop类型,这个是api自带的名称,有很多种,MainMenu只是其中一种
anchor 指的是子菜单显示位置
一个action,表示一个选项,class是对应的类名,text是要展示的子菜单名字
 -->
<add-to-group group-id="MainMenu" anchor="last" />
<action id="Myplugin.Textboxes" class="com.dyc.test.TextBoxes" text="Text _Boxes" description="A test menu item" /> 
</group>
</actions>

5.点击运行,可以看到工具栏多了一个选项。其实是执行了actionPerformed.
6.action也可以通过new->action的方式进行创建


7.打包插件

  a.build->buildproject 

  b.build->prepare plugin modle for"xxxxxx" .....  

  

8.使用

  在idea,或android studio,或其他idea安装目录下面,进入plugin文件夹,然后 创建文件夹myplugin,进入myplugin,创建lib,将上面生成的jar包放入lib里面,重启idea就可以使用插件包了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值