我正在创建一个简单的IntelliJ插件,允许直接从IDE创建新的Pastebin贴纸。
当粘贴成功发布到Pastebin后,我想显示气球通知。
目前通知显示如下:
final Response<String> postResult = Constants.PASTEBIN.post(paste);
NotificationGroup balloonNotifications = new NotificationGroup("Notification group", NotificationDisplayType.BALLOON, true);
if (postResult.hasError()) {
//Display error notification
} else {
//Display success notification
Notification success = balloonNotifications.createNotification("Successful Paste", "<a href=\"" + postResult.get() + "\">Paste</a> successfully posted!", NotificationType.INFORMATION, null);
Notifications.Bus.notify(success, project);
}
现在,此气球通知包含新创建的粘贴的URL,但遗憾的是,单击它不会在浏览器中打开链接。怎么能实现呢?
答案 0 :(得分:1)
经过一番搜索,我自己找到了答案。实际上并不太难。
如果我按如下方式实例化通知,则可以根据需要点击链接。
Notification success = balloonNotifications.createNotification("<html>Successful Paste", "<a href=\"" + postResult.get() + "\" target=\"blank\">Paste</a> successfully posted!</html>", NotificationType.INFORMATION, (notification, hyperlinkEvent) -> {
if (hyperlinkEvent.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
BrowserUtil.browse(hyperlinkEvent.getURL());
}
});
注意:事件日志中的链接现在也可以点击,这也很有用。
答案 1 :(得分:1)
NotificationListener可在通知中打开网址: com.intellij.notification.UrlOpeningListener
所以你可以写:
Notification success = balloonNotifications.createNotification(
"<html>Successful Paste", "<a href=\"" + postResult.get() + "\" target=\"blank\">Paste</a> successfully posted!</html>",
NotificationType.INFORMATION, new NotificationListener.UrlOpeningListener(true));