Skip to content

Commit c3cc2bf

Browse files
committed
Display toast notifications with actions
1 parent 0b2cc44 commit c3cc2bf

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package software.aws.toolkits.jetbrains.core.notifications
5+
6+
import com.intellij.notification.NotificationType
7+
import com.intellij.openapi.actionSystem.AnAction
8+
import software.aws.toolkits.jetbrains.utils.notifySticky
9+
10+
object DisplayToastNotifications {
11+
fun show(title: String, message: String, action: List<AnAction>, notificationType: ToastNotificationType) {
12+
val notifyType = when (notificationType) {
13+
ToastNotificationType.CRITICAL -> NotificationType.ERROR
14+
ToastNotificationType.WARNING -> NotificationType.WARNING
15+
ToastNotificationType.PRODUCT_UPDATE -> NotificationType.INFORMATION
16+
}
17+
notifySticky(notifyType, title, message, null, action)
18+
}
19+
}
20+
21+
enum class ToastNotificationType {
22+
CRITICAL,
23+
WARNING,
24+
PRODUCT_UPDATE,
25+
}

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/utils/NotificationUtils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ private fun notify(type: NotificationType, title: String, content: String = "",
4848
notify(notification, project)
4949
}
5050

51-
private fun notifySticky(type: NotificationType, title: String, content: String = "", project: Project? = null, notificationActions: Collection<AnAction>) {
51+
fun notifySticky(type: NotificationType, title: String, content: String = "", project: Project? = null, notificationActions: Collection<AnAction>) {
5252
val notification = Notification(GROUP_DISPLAY_ID_STICKY, title, content, type)
5353
notificationActions.forEach {
5454
notification.addAction(if (it !is NotificationAction) createNotificationExpiringAction(it) else it)

0 commit comments

Comments
 (0)