通知弹出窗口将 link 添加到设置 window
Notification pop-up add link to settings window
我在跟踪代码,这是从 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]);
});
}
我想要 link 而不是文本 "LINK!!!",你有什么建议吗?
我认为我需要创建操作并将此操作添加到我的组 GROUP_DISPLAY_ID_INFO,但该组不在 xml 中,它只是在代码中存在。
private static void showMyMessage(String LINK) {
ApplicationManager.getApplication().invokeLater(() -> {
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]);
});
}
只需将link替换为参数,并像showMyMessage("http://google.com")
一样使用它
另外xml中组显示id不需要配置,直接在代码中写即可
如果以我上面的代码为例,需要在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);
}
其中 yourclass.class 是实现可配置接口的 class
现在点击“设置”,您将看到打开的设置 window (yourclass.class)
我在跟踪代码,这是从 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]);
});
}
我想要 link 而不是文本 "LINK!!!",你有什么建议吗? 我认为我需要创建操作并将此操作添加到我的组 GROUP_DISPLAY_ID_INFO,但该组不在 xml 中,它只是在代码中存在。
private static void showMyMessage(String LINK) {
ApplicationManager.getApplication().invokeLater(() -> {
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]);
});
}
只需将link替换为参数,并像showMyMessage("http://google.com")
另外xml中组显示id不需要配置,直接在代码中写即可
如果以我上面的代码为例,需要在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);
}
其中 yourclass.class 是实现可配置接口的 class
现在点击“设置”,您将看到打开的设置 window (yourclass.class)