diff --git a/platform/platform-api/src/com/intellij/notification/Notification.java b/platform/platform-api/src/com/intellij/notification/Notification.java index a4edab4c2fdf..199e0795bf1a 100644 --- a/platform/platform-api/src/com/intellij/notification/Notification.java +++ b/platform/platform-api/src/com/intellij/notification/Notification.java @@ -33,6 +33,9 @@ import java.util.concurrent.atomic.AtomicBoolean; *

* Warning: be careful not to use the links in HTML content, use {@link #addAction(AnAction)} * + * @see NotificationAction + * @see com.intellij.notification.SingletonNotificationManager + * * @author spleaner * @author Alexander Lobas */ diff --git a/platform/platform-api/src/com/intellij/notification/NotificationAction.java b/platform/platform-api/src/com/intellij/notification/NotificationAction.java index eb31222e5fdb..ea66734ff640 100644 --- a/platform/platform-api/src/com/intellij/notification/NotificationAction.java +++ b/platform/platform-api/src/com/intellij/notification/NotificationAction.java @@ -1,20 +1,7 @@ -/* - * Copyright 2000-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.notification; +import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.project.DumbAwareAction; import org.jetbrains.annotations.NotNull; @@ -23,6 +10,8 @@ import org.jetbrains.annotations.Nullable; import java.util.function.BiConsumer; /** + * @see Notification#addAction(AnAction) + * * @author Alexander Lobas */ public abstract class NotificationAction extends DumbAwareAction { diff --git a/platform/platform-api/src/com/intellij/notification/NotificationListener.java b/platform/platform-api/src/com/intellij/notification/NotificationListener.java index e88204f6888a..90ea81c47eb1 100644 --- a/platform/platform-api/src/com/intellij/notification/NotificationListener.java +++ b/platform/platform-api/src/com/intellij/notification/NotificationListener.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2014 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.notification; import com.intellij.ide.BrowserUtil; @@ -21,6 +7,11 @@ import org.jetbrains.annotations.NotNull; import javax.swing.event.HyperlinkEvent; import java.net.URL; +/** + * Consider using {@link NotificationAction} instead of links in HTML content. + * + * @see NotificationAction + */ public interface NotificationListener { void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event); diff --git a/platform/platform-impl/src/com/intellij/notification/SingletonNotificationManager.kt b/platform/platform-impl/src/com/intellij/notification/SingletonNotificationManager.kt index 31e296673afd..4796031f8ebf 100644 --- a/platform/platform-impl/src/com/intellij/notification/SingletonNotificationManager.kt +++ b/platform/platform-impl/src/com/intellij/notification/SingletonNotificationManager.kt @@ -1,6 +1,7 @@ // Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.notification +import com.intellij.openapi.actionSystem.AnAction import com.intellij.openapi.project.Project import com.intellij.openapi.wm.ToolWindowManager @@ -9,21 +10,19 @@ import java.util.concurrent.atomic.AtomicReference class SingletonNotificationManager(private val group: NotificationGroup, private val type: NotificationType, private val defaultListener: NotificationListener? = null) { private val notification = AtomicReference() - private val expiredListener by lazy { - Runnable { - val currentNotification = notification.get() - if (currentNotification != null && currentNotification.isExpired) { - notification.compareAndSet(currentNotification, null) - } + private val expiredListener = Runnable { + val currentNotification = notification.get() + if (currentNotification != null && currentNotification.isExpired) { + notification.compareAndSet(currentNotification, null) } } fun notify(content: String, project: Project?): Boolean { - return notify("", content, project, defaultListener) + return notify("", content, project) } @JvmOverloads - fun notify(title: String, content: String, project: Project? = null, listener: NotificationListener? = defaultListener): Boolean { + fun notify(title: String = "", content: String, project: Project? = null, listener: NotificationListener? = defaultListener, action: AnAction? = null): Boolean { val oldNotification = notification.get() // !oldNotification.isExpired() is not enough - notification could be closed, but not expired if (oldNotification != null) { @@ -37,6 +36,9 @@ class SingletonNotificationManager(private val group: NotificationGroup, private } val newNotification = group.createNotification(title, content, type, listener) + if (action != null) { + newNotification.addAction(action) + } newNotification.whenExpired(expiredListener) notification.set(newNotification) newNotification.notify(project)