(六)IntelliJ 插件开发—— Notifications(通知)

官方文档

https://www.jetbrains.org/intellij/sdk/docs/user_interface_components/notifications.html
https://www.jetbrains.org/intellij/sdk/docs/tutorials/editor_basics/working_with_text.html

Github

https://github.com/kungyutucheng/my_gradle_plugin

运行环境

macOS 10.14.5
IntelliJ idea 2019.2.4

1、Dialogs

对话框式通知,请移步(四)IntelliJ 插件开发——Dialog(对话框)中的“校验不通过”图片


2、Editor Hints

这块比较简单,直接上代码

showErrorHint

showErrorHint
HintManager.getInstance().showErrorHint(CommonDataKeys.EDITOR.getData(e.getDataContext()),"错误信息");

showQuestionHint

showQuestionHint
HintManager.getInstance().showQuestionHint(CommonDataKeys.EDITOR.getData(e.getDataContext()), "questionAction", 0, 0, () -> {
    Messages.showMessageDialog("question", "Question", Messages.getInformationIcon());
    return true;
});
showInformationHint
showInformationHint
HintManager.getInstance().showInformationHint(CommonDataKeys.EDITOR.getData(e.getDataContext()),"information");

3、Top-Level Notifications

这是最常用的用于非模态框式通知方式
主要有以下俩个优势:

  • 用户可以在Settings | Appearance & Behavior | Notifications处设置每项通知的展示方式
  • 所有的通知展示信息都会被记录在Event Log工具窗内,以便追溯
notification

event log
设置通知展示方式
NotificationGroup notificationGroup = new NotificationGroup("notificationGroup", NotificationDisplayType.BALLOON, true);
Notification notification = notificationGroup.createNotification("notification",NotificationType.ERROR);
Notifications.Bus.notify(notification);

其中,NotificationGroup构造方法如下:

public NotificationGroup(@NotNull String displayId, @NotNull NotificationDisplayType defaultDisplayType, boolean logByDefault) {
    this(displayId, defaultDisplayType, logByDefault, null);
 }

其中,NotificationDisplayType可以是以下几种:

  • NONE:无弹框,不展示
  • BALLOON:自动消失
  • STICKY_BALLOON:用户点击关闭按钮消失
  • TOOL_WINDOW:实例效果同STICKY_BALLOON,源码亦未注释,建议自己尝试一下,可能发现与我不一样的结果
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 逼自己转身,一辈子不见 记得文曾说过一句话:烦恼可以解决烦恼。叶不以为然,烦恼只会加深烦恼。 面对突如其来的极致痛...
    带轮的高跟鞋阅读 690评论 0 2
  • 2019年6月13日星期四雨 亲爱的毛毛,今天妈妈出院了,虽然我感觉还有宫缩,不过医生说没有也是不可能的,医...
    剪烛西窗_d70d阅读 341评论 2 7
  • 他与李白,李商隐并称为唐代三李,他是唐宗室郑王李亮的后裔,他有“诗鬼”之称,是与“诗圣”杜甫、“诗仙”李白...
    吖溚zxyw1401阅读 784评论 2 2
  • 无题 文/舟亮 新叶不知冬雪冷,轻涂秀面绽春花。 妒嫉老练白头染,未洗朝阳沐晚霞!
    舟亮阅读 499评论 0 0