网络知识 娱乐 Idea 插件之Notification

Idea 插件之Notification

插件开发过程中,往往会有很多Action, 操作完后界面上可能没有任何反映,如果通过输出日志的方式来感知是否操作成功,操作起来不方便,此时Notification不失为一种更方便的展现形式。

配置通知对象

在 plugin.xml 中添加通知组

<extensions defaultExtensionNs="com.intellij">n <!-- hideFromSettings 决定是否在配置中展示[Notifications - SequenceOutlineNotifier]即被修改 -->n <notificationGroup id="SequenceOutlineNotifier" displayType="STICKY_BALLOON" hideFromSettings="true"/>n</extensions>

代码中可调用的通知对象

通过通知组id获取通知对象

public class SequenceOutlineNotifier {nn private SequenceOutlineNotifier() {n }nn public static void notify(String content) {n if (null == content) {n content = "";n }n // 获取配置的对象,id 必须对应n NotificationGroup notificationGroup = NotificationGroupManager.getInstance().getNotificationGroup("SequenceOutlineNotifier");n final Notification notification = notificationGroup.createNotification(content, NotificationType.INFORMATION);n notification.notify(null);n }nn public static void notifyError(String content) {n if (null == content) {n content = "";n }n NotificationGroup notificationGroup = NotificationGroupManager.getInstance().getNotificationGroup("SequenceOutlineNotifier");n // 通知的内容及通知的类型 n final Notification notification = notificationGroup.createNotification(content, NotificationType.ERROR);n notification.notify(null);n }n}

动态修改通知配置

通知配置位置

不同类型通知展示

1.NONE

No popup 不展示弹窗

2.BALLOON

展示弹窗,时间到自动消失

3.STICKY_BALLOON

展示弹窗,需要点击才会消失

通知展示形式