Mrli
别装作很努力,
因为结局不会陪你演戏。
Contacts:
QQ博客园

IDEA插件开发

2020/07/11 Java
Word count: 492 | Reading time: 3min

新建IDEA 插件工程

File -> new -> Project -> Plugin即可

初始会生成一个项目xml配置文件, 以下是我进行修改后的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<idea-plugin>
<id>top.nymrli.privatesee</id>
<name>privateSee</name>
<version>1.0</version>
<vendor email="nymrli99@163.com" url="http://nymrli.top">Mrli</vendor>

<description><![CDATA[
Highlight when private methods are called.
]]></description>

<change-notes><![CDATA[
<br>
<em>First created. This time will be tried</em>
<br>
]]>
</change-notes>

<!-- please see https://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html for description -->
<idea-version since-build="173.0"/>

<!-- please see https://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/plugin_compatibility.html
on how to target different products -->
<depends>com.intellij.modules.platform</depends>

<extensions defaultExtensionNs="com.intellij">
<!-- Add your extensions here -->
</extensions>

<actions>
<!-- Add your actions here -->
<action id="FirstPluginActionId" class="top.nymrli.privatesee.FirstPluginAction" text="测试" description="测试描述">
<add-to-group group-id="ToolsMenu" anchor="first"/>
<keyboard-shortcut keymap="$default" first-keystroke="ctrl I"/>
</action>
</actions>

</idea-plugin>

新建action

1
2
3
4
5
6
7
8
9
10
11
12

public class FirstPluginAction extends AnAction {

@Override
public void actionPerformed(AnActionEvent e) {
// TODO: insert action logic here
NotificationGroup notificationgroup = new NotificationGroup("flugin_id", NotificationDisplayType.BALLOON, true);
Notification notification = notificationgroup.createNotification("点击测试", MessageType.INFO);
Notifications.Bus.notify(notification);

}
}

运行测试: edit configuration选择plugin, 然后选择运行

启动初始化

新建一个类

1
2
3
4
5
6
7
8
9
public class MyApplicationComponent implements ApplicationComponent {

@Override
public void initComponent() {
System.out.println("插件初始化");
TanChuanDialog dialog = new TanChuanDialog();
dialog.show();
}
}

在xml配置指定

1
2
3
4
5
6
7
<application-components>
<component>
<implementation-class>
top.nymrli.privatesee.MyApplicationComponent
</implementation-class>
</component>
</application-components>

弹窗效果

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
public class TanChuanDialog extends DialogWrapper {
JPanel jPanel;
JLabel label;
JButton btn;

public TanChuanDialog() {
super(true);
// 设置弹窗的标题
setTitle("启动弹窗");
init();
}

// 设置弹窗中间展示内容
@Nullable
@Override
protected JComponent createCenterPanel() {
jPanel = new JPanel();
label = new JLabel("显示内容");
jPanel.add(label);
return jPanel;
}


// 自定义设置底部的按钮
@Override
protected JComponent createSouthPanel() {
jPanel = new JPanel();
btn = new JButton("再干一杯");
btn.addActionListener(e->{
label.setText("被点击了哦");
});
jPanel.add(btn);
return jPanel;
}
}

Author: Mrli

Link: https://nymrli.top/2020/07/11/IDEA插件开发/

Copyright: All articles in this blog are licensed under CC BY-NC-SA 3.0 unless stating additionally.

< PreviousPost
SQL练习
NextPost >
getBargains的record和Solution
CATALOG
  1. 1. 新建IDEA 插件工程
  2. 2. 新建action
  3. 3. 启动初始化
  4. 4. 弹窗效果