美文网首页
(六)IntelliJ 插件开发—— Notifications

(六)IntelliJ 插件开发—— Notifications

作者: 秋水畏寒 | 来源:发表于2020-03-05 23:18 被阅读0次

    官方文档

    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,源码亦未注释,建议自己尝试一下,可能发现与我不一样的结果

    相关文章

      网友评论

          本文标题:(六)IntelliJ 插件开发—— Notifications

          本文链接:https://www.haomeiwen.com/subject/rixglhtx.html