jetBrains 插件开发第一课-- 在主菜单栏新增一个菜单
环境搭建完了,接下来可以开始写代码了:
1、新建 plugin 项目
2、编辑 plugin.xml,修改一下里面的插件名那些信息,该文件的配置项可以看这里:plugin.xml
其中比较关键的有一个是 <depends>com.intellij.modules.platform</depends>,如果不加这个,你点击运行的时候插件可以正常运作,但是打包之后安装却会用不了。
<idea-plugin>
<id>com.eleven24.helloWorld</id>
<name>HelloWorld</name>
<version>1.0</version>
<vendor email="rubymay21s@gmail.com" url="http://www.cnblogs.com/eleven24">YourCompany</vendor> <description><![CDATA[
Hello World Plugin.
]]></description> <change-notes><![CDATA[
first version.
]]>
</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>
-->
<depends>com.intellij.modules.platform</depends> <extensions defaultExtensionNs="com.intellij">
<!-- Add your extensions here -->
</extensions> <actions>
<!-- Add your actions here -->
</actions> </idea-plugin>
基本的信息如上,下面会添加一些菜单项的配置以及注册插件的配置
3、初始化的方法
package com.eleven24; import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.openapi.components.ApplicationComponent;
import org.jetbrains.annotations.NotNull; public class HelloWorldRegistration implements ApplicationComponent {
@NotNull
public String getComponentName() {
return "HelloWorldPlugin";
} public void initComponent() {
ActionManager am = ActionManager.getInstance();
MenuAction menuAction = new MenuAction(); am.registerAction("menuAction", menuAction); DefaultActionGroup windowsM = (DefaultActionGroup) am.getAction("WindowMenu"); windowsM.addSeparator();
windowsM.add(menuAction);
} // Disposes system resources.
public void disposeComponent() {
}
}
4、添加应用组件的配置到 plugin.xml 中,这样 ide 才会知道我们这个插件要做什么
<application-components>
<component>
<implementation-class>com.eleven24.HelloWorldRegistration</implementation-class>
</component>
</application-components>
5、添加一个点击菜单之后的处理方法,需要继承 AnAction 类
package com.eleven24; import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.ui.Messages; public class MenuAction extends AnAction {
@Override
public void actionPerformed(AnActionEvent anActionEvent) {
Messages.showInfoMessage("Hello World!", "First Plugin");
}
}
5、添加菜单,这个的话在 plugin.xml 中配置,同时也要指定该菜单点击之后对应的处理类(上面的menuAction)
我们添加一个组名叫 "HelloWorld" 的菜单组,添加到主菜单栏末尾,然后在其下添加一个名为 "menu action" 的菜单。具体配置如下:
<actions>
<!-- Add your actions here -->
<group id="HelloWorld" text="_HelloWorld">
<add-to-group group-id="MainMenu" anchor="last" />
</group> <action class="com.eleven24.MenuAction" id="menuAction" text="menu action">
<add-to-group group-id="HelloWorld" anchor="first" />
</action>
</actions>
6、到此为止,我们已经完成了菜单的添加,点击右上角的运行按钮可以查看效果,运行的时候会再打开一个 ide,会有点慢。
7、效果图
8、下面是最终的配置文件
<idea-plugin>
<id>com.eleven24.helloWorld</id>
<name>HelloWorld</name>
<version>1.0</version>
<vendor email="rubymay21s@gmail.com" url="http://www.cnblogs.com/eleven24">YourCompany</vendor> <description><![CDATA[
Hello World Plugin.
]]></description> <change-notes><![CDATA[
first version.
]]>
</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>
-->
<depends>com.intellij.modules.platform</depends> <extensions defaultExtensionNs="com.intellij">
<!-- Add your extensions here -->
</extensions> <actions>
<!-- Add your actions here -->
<group id="HelloWorld" text="_HelloWorld" description="menu group">
<add-to-group group-id="MainMenu" anchor="last" />
<action class="com.eleven24.MenuAction" id="helloWorld.menuAction" text="menu action" />
</group>
</actions> <application-components>
<component>
<implementation-class>com.eleven24.HelloWorldRegistration</implementation-class>
</component>
</application-components> </idea-plugin>
好了,就这么多了。
jetBrains 插件开发第一课-- 在主菜单栏新增一个菜单的更多相关文章
- Spring MVC第一课:用IDEA构建一个基于Spring MVC, Hibernate, My SQL的Maven项目
作为一个Spring MVC新手最基本的功夫就是学会如何使用开发工具创建一个完整的Spring MVC项目,本文站在一个新手的角度讲述如何一步一步创建一个基于Spring MVC, Hibernate ...
- visual Studio 2017 扩展开发(一)《向Visual Studio菜单栏新增一个菜单》
最近有接触到关于visual studio 2017 扩展的开发,特此记录,也是为了督促自己去深入了解其原理. 开始开发Visual Studio 扩展,在这里我安装了visual studio 20 ...
- NeHe OpenGL教程 第一课:OpenGL窗口
转自[翻译]NeHe OpenGL 教程 前言 声明,此 NeHe OpenGL教程系列文章由51博客yarin翻译(2010-08-19),本博客为转载并稍加整理与修改.对NeHe的OpenGL管线 ...
- Python之路第一课Day6--随堂笔记(面向对象 )
本节内容: 1. 面向对象编程介绍 2. 为什么要用面向对象进行开发? 3. 面向对象的特性:封装.继承.多态 4. 类.方法 一.面向过程 VS 面向对象 1. 编程范式 编程是 程序 员 用 ...
- Octave Tutorial(《Machine Learning》)之第一课《数据表示和存储》
Octave Tutorial 第一课 Computation&Operation 数据表示和存储 1.简单的四则运算,布尔运算,赋值运算(a && b,a || b,xor( ...
- Android入门第一课之Java基础
通知:由于本周六场地申请没通过,所以本周的培训临时取消. 今天给大家带来的是Android入门的第一课,由于教室申请的不确定性,因此,每次培训的内容都会在博客先提前释放出来.首先Android的APP ...
- vue.js学习(第一课)
学习资料 来自台湾小凡! vue.js是javascript的一个库,只专注于UI层面,核心价值永远是 API的简洁. 第一课: 不支持IE8. 1.声明式渲染: el元素的简称 element : ...
- Magento学习第一课——目录结构介绍
Magento学习第一课--目录结构介绍 一.Magento为何强大 Magento是在Zend框架基础上建立起来的,这点保证了代码的安全性及稳定性.选择Zend的原因有很多,但是最基本的是因为zen ...
- <-0基础学python.第一课->
初衷:我电脑里面的歌曲很久没换了,我想听一下新的歌曲,把他们下载下来听,比如某个榜单的,但是一首一首的点击下载另存为真的很恶心 所以我想有没有办法通过程序的方式来实现,结果还真的有,而且网上已经有有人 ...
随机推荐
- windows更改MySQL存储路径
在C:\ProgramData\MySQL\MySQL Server 5.7文件夹 my.ini是默认的配置文件.在这里我们只更改数据存储路径.不更改配置文件 1 # Path to the data ...
- 在GPT格式的硬盘上,使用EFI启动的方式,安装Win7 64位系统
Win7 sp1 原装系统,用UltraISO(软碟通) 把U 盘制成Win7 安装的启动U盘 将bootmgfw.efi和shell.efi 加到已制好启动U盘的根目录,并在efi/boot/路径下 ...
- curl和file_get_contents 区别以及各自的优劣
PHP中fopen,file_get_contents,curl函数的区别: 1.fopen /file_get_contents 每次请求都会重新做DNS查询,并不对 DNS信息进行缓存.但是CUR ...
- C++ STL 全排列
摘自爱国师哥博客https://www.cnblogs.com/aiguona/p/7304945.html 一.概念 从n个不同元素中任取m(m≤n)个元素,按照一定的顺序排列起来,叫做从n个不同元 ...
- java包名命名规范
Java的包名都有小写单词组成,类名首字母大写:包的路径符合所开发的 系统模块的 定义,比如生产对生产,物资对物资,基础类对基础类.以便看了包名就明白是哪个模块,从而直接到对应包里找相应的实现. 由于 ...
- 2018软工实践—Alpha冲刺(4)
队名 火箭少男100 组长博客 林燊大哥 作业博客 Alpha 冲鸭鸭鸭鸭! 成员冲刺阶段情况 林燊(组长) 过去两天完成了哪些任务 协调各成员之间的工作 协助前后端接口的开发 测试项目运行的服务器环 ...
- lintcode-414-两个整数相除
414-两个整数相除 将两个整数相除,要求不使用乘法.除法和 mod 运算符. 如果溢出,返回 2147483647 . 样例 给定被除数 = 100 ,除数 = 9,返回 11. 标签 二分法 思路 ...
- c99标准的restrict关键字
参考自restrict restrict解释 restrict关键字出现于C99标准,wiki上的解释restrict from wiki. In the C programming language ...
- selenium 概念及练习 !
1.selenium中如何判断元素是否存在? 2.selenium中hidden或者是display = none的元素是否可以定位到? 3.selenium中如何保证操作元素的成功率?也就是说如何保 ...
- Maven 私服安装和启动
在安装私服的时候容易碰到的两个问题,一个是安装时拒绝访问,另一个是安装完成后服务无法启动: 拒绝访问问题: 原因:没有以管理员身份运行 cmd 解决办法: 如果是 win7 的话,可以直接在 [运行- ...