diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/NotificationEventAction.kt b/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/NotificationEventAction.kt index 493a719335ea..b7a82285f989 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/NotificationEventAction.kt +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/NotificationEventAction.kt @@ -4,25 +4,31 @@ package com.intellij.openapi.wm.impl.welcomeScreen import com.intellij.application.subscribe import com.intellij.notification.NotificationType import com.intellij.openapi.Disposable -import com.intellij.openapi.actionSystem.ActionUpdateThread -import com.intellij.openapi.actionSystem.AnActionEvent -import com.intellij.openapi.actionSystem.PlatformCoreDataKeys +import com.intellij.openapi.actionSystem.* +import com.intellij.openapi.actionSystem.ex.CustomComponentAction +import com.intellij.openapi.actionSystem.impl.ActionButton import com.intellij.openapi.project.DumbAwareToggleAction import com.intellij.openapi.wm.impl.welcomeScreen.WelcomeBalloonLayoutImpl.BalloonNotificationListener import com.intellij.openapi.wm.impl.welcomeScreen.WelcomeFrame.Companion.getInstance import javax.swing.JComponent -internal class NotificationEventAction(parentDisposable: Disposable) : DumbAwareToggleAction() { - +internal class NotificationEventAction(parentDisposable: Disposable) : DumbAwareToggleAction(), CustomComponentAction { private var notificationTypes = listOf() private var selected = false private var hideListenerInstalled = false + private var myAutoPopup = false init { WelcomeBalloonLayoutImpl.BALLOON_NOTIFICATION_TOPIC.subscribe( parentDisposable, - BalloonNotificationListener { types: List -> - notificationTypes = types.filterNotNull() + object : BalloonNotificationListener { + override fun notificationsChanged(types: List) { + notificationTypes = types.filterNotNull() + } + + override fun newNotifications() { + myAutoPopup = true + } }) } @@ -42,16 +48,42 @@ internal class NotificationEventAction(parentDisposable: Disposable) : DumbAware e.presentation.isEnabledAndVisible = notificationTypes.isNotEmpty() } + override fun createCustomComponent(presentation: Presentation, place: String): JComponent { + return object: ActionButton(this, presentation, place, ActionToolbar.DEFAULT_MINIMUM_BUTTON_SIZE) { + override fun setBounds(x: Int, y: Int, width: Int, height: Int) { + super.setBounds(x, y, width, height) + checkAutoPopup(this) + } + } + } + + override fun updateCustomComponent(component: JComponent, presentation: Presentation) { + checkAutoPopup(component) + } + + private fun checkAutoPopup(actionButton: JComponent) { + if (actionButton.parent != null && actionButton.width > 0 && actionButton.height > 0 && actionButton.isVisible) { + val balloonLayout = getInstance()?.balloonLayout as? WelcomeBalloonLayoutImpl + if (myAutoPopup && balloonLayout != null && !balloonLayout.myVisible) { + actionPerformed { balloonLayout.locationComponent as JComponent } + } + myAutoPopup = false + } + } + override fun getActionUpdateThread(): ActionUpdateThread { return ActionUpdateThread.EDT } override fun actionPerformed(e: AnActionEvent) { super.actionPerformed(e) + actionPerformed { getComponent(e) } + } + private fun actionPerformed(componentProvider: () -> JComponent) { val balloonLayout = getInstance()?.balloonLayout as? WelcomeBalloonLayoutImpl ?: return - if (!hideListenerInstalled) { + if (!hideListenerInstalled || balloonLayout.hideListener == null) { balloonLayout.setHideListener(Runnable { selected = false }) @@ -60,7 +92,7 @@ internal class NotificationEventAction(parentDisposable: Disposable) : DumbAware val locationComponent = balloonLayout.locationComponent if (locationComponent == null || locationComponent.parent == null) { - balloonLayout.locationComponent = getComponent(e) + balloonLayout.locationComponent = componentProvider.invoke() } selected = true diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/WelcomeBalloonLayoutImpl.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/WelcomeBalloonLayoutImpl.java index a328f1ea95a3..6a281831edf8 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/WelcomeBalloonLayoutImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/WelcomeBalloonLayoutImpl.java @@ -219,6 +219,7 @@ public class WelcomeBalloonLayoutImpl extends BalloonLayoutImpl { public interface BalloonNotificationListener { void notificationsChanged(List types); + default void newNotifications() {} } private static final class BalloonPanel extends NonOpaquePanel { diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/WelcomeSeparateBalloonLayoutImpl.kt b/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/WelcomeSeparateBalloonLayoutImpl.kt index 95c3a8eb2e22..6cfb3439b996 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/WelcomeSeparateBalloonLayoutImpl.kt +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/WelcomeSeparateBalloonLayoutImpl.kt @@ -73,6 +73,7 @@ class WelcomeSeparateBalloonLayoutImpl(parent: JRootPane, insets: Insets) : Welc newBalloon.component.isVisible = myVisible } updateBalloons() + ApplicationManager.getApplication().getMessageBus().syncPublisher(BALLOON_NOTIFICATION_TOPIC).newNotifications() } else { super.add(newBalloon, layoutData)