Search code examples
intellij-ideaintellij-plugin

Notification pop-up add link to settings window


I've following code, this was copied from one of questions here on SOF,

private void showMyMessage() {
        ApplicationManager.getApplication().invokeLater(() -> {
            com.intellij.notification.Notification notification = GROUP_DISPLAY_ID_INFO
                    .createNotification("<html>TLogin failed", " Go to <a href=\"" + "LINK!!!" + "\" target=\"blank\">Settings</a> to setup login data!</html>",
                            NotificationType.ERROR,
                            new NotificationListener.UrlOpeningListener(true));
            Project[] projects = ProjectManager.getInstance().getOpenProjects();
            Notifications.Bus.notify(notification, projects[0]);
        });
    }

I would like to have a link instead text "LINK!!!", what can you suggest ? I think that I need to create action and add this action to my group GROUP_DISPLAY_ID_INFO, but this group is not in xml it's just in code exists.


Solution

  • If take my code above as an example, need to add right after new

    NotificationListener.UrlOpeningListener(true))
    
    addAction(new NotificationAction("Settings") {
        @Override
        public void actionPerformed (@NotNull AnActionEvent anActionEvent,
                @NotNull Notification notification){
            DataContext dataContext = anActionEvent.getDataContext();
            Project project = PlatformDataKeys.PROJECT.getData(dataContext)
            ShowSettingsUtil.getInstance().showSettingsDialog(project,
                    YOURCLASS.class);
        }
    

    Where yourclass.class is a class which implements Configurable interface

    And now on click on Settings you will see opened settings window (yourclass.class)