IDEA插件开发(一)——初识

下面我们通过创建一个小示例来学习。

  1. 这里是列表文本打开IDEA,新建项目-->选择Idea Plateform Plugin,界面如下所示: 截图1

  2. 输入项目名称,点击finish创建完成后打开。会看到项目resources目录生成了一个plugin.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="173.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>

配置文件主要包含了一些插件的说明信息和维护信息:

  • name 插件名称
  • version 版本号
  • vendor 维护信息,当插件奔溃或出现问题时,方面使用者反馈信息
  • description 对插件的简短描述
  • change-notes 插件更新记录
  • actions 是插件配置文件的重要组成部分,用于插件组件的注册。一般包含group等信息,具体后面会说到。
  1. 在src目录上右键-->New-->Plugin Dev Kit-->Action,创建一个action类,具体如图: 创建action 这个类需要继承AnAction。下面是我的action内容:

    public class TextBoxAction extends AnAction {

    1// If you register the action from Java code, this constructor is used to set the menu item name 2// (optionally, you can specify the menu description and an icon to display next to the menu item). 3// You can omit this constructor when registering the action in the plugin.xml file. 4public TextBoxAction() { 5 // Set the menu item name. 6 super("Test _Boxes"); 7 // Set the menu item name, description and icon. 8 // super("Text _Boxes","Item description",IconLoader.getIcon("/Mypackage/icon.png")); 9} 10 11@Override 12public void actionPerformed(AnActionEvent event) { 13 // TODO: insert action logic here 14 Project project = event.getData(PlatformDataKeys.PROJECT); 15 String txt = Messages.showInputDialog(project, "What is your name?", "Input your name", Messages.getQuestionIcon()); 16 Messages.showMessageDialog(project, "Hello, " + txt + "!\n I am glad to see you.", "Information", Messages.getInformationIcon()); 17 18}

    }

在actions节点中增加如下内容:

1<group id="HelloPlugin.SampleMenu" text="_My Menu" description="测试插件示例"> 2 <add-to-group group-id="MainMenu" anchor="last" /> 3 <action id="HelloPlugin.Textboxes" class="com.mark.TextBoxAction" text="Text _Boxes" description="A test menu item" /> 4 </group>
  • action:是action关联配置,比如text是在开发工具的显示菜单名称,description是描述信息,id要保证唯一性
  • add-to-group:表示添加到某个功能组,由group-id指定,示例中是在idea工具菜单栏添加了一个菜单选项,anchor指定菜单出现的位置。有before,first,after,last等选择。
  1. 调试(默认按键) 调试 Shift + F9. 运行 Shift + F10. 相当于会再启动一个IDE,此时已将我们自定义的功能加入。具体界面如下:

调试界面

会发现,我们的菜单已经出现在菜单栏上了。 5. 打包插件或导出 一个插件写好肯定是需要和大家共享使用的,IDEA的插件发布很简单。具体如下:

输入图片说明

然后就可以在项目路径下看见我们打的jar。

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )

IDEA00 IDEA知识点汇总

一、从头搭建IDEA开发环境https://mp.weixin.qq.com/s/6jXHzkU8JfubhDsQJbwl8Q(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fmp.weixin.qq.com%2Fs%2F6jXHzkU8JfubhDsQJbwl8Q)1下