mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-313945 Update notifications in welcome screen in new UI
GitOrigin-RevId: 06a3583e63bf210bfca6259fe92a04f9be29cf0f
This commit is contained in:
committed by
intellij-monorepo-bot
parent
bed8faeb52
commit
c8dcb86dee
+41
-9
@@ -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<NotificationType>()
|
||||
private var selected = false
|
||||
private var hideListenerInstalled = false
|
||||
private var myAutoPopup = false
|
||||
|
||||
init {
|
||||
WelcomeBalloonLayoutImpl.BALLOON_NOTIFICATION_TOPIC.subscribe<BalloonNotificationListener>(
|
||||
parentDisposable,
|
||||
BalloonNotificationListener { types: List<NotificationType?> ->
|
||||
notificationTypes = types.filterNotNull()
|
||||
object : BalloonNotificationListener {
|
||||
override fun notificationsChanged(types: List<NotificationType?>) {
|
||||
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
|
||||
|
||||
+1
@@ -219,6 +219,7 @@ public class WelcomeBalloonLayoutImpl extends BalloonLayoutImpl {
|
||||
|
||||
public interface BalloonNotificationListener {
|
||||
void notificationsChanged(List<NotificationType> types);
|
||||
default void newNotifications() {}
|
||||
}
|
||||
|
||||
private static final class BalloonPanel extends NonOpaquePanel {
|
||||
|
||||
+1
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user