Hide "Configure Kotlin" notification after Kotlin has been configured
#KT-17289 Fixed
This commit is contained in:
+18
-6
@@ -21,6 +21,7 @@ import com.intellij.notification.NotificationsManager
|
|||||||
import com.intellij.openapi.module.Module
|
import com.intellij.openapi.module.Module
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import org.jetbrains.kotlin.idea.configuration.ui.notifications.ConfigureKotlinNotification
|
import org.jetbrains.kotlin.idea.configuration.ui.notifications.ConfigureKotlinNotification
|
||||||
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
object ConfigureKotlinNotificationManager: KotlinSingleNotificationManager<ConfigureKotlinNotification> {
|
object ConfigureKotlinNotificationManager: KotlinSingleNotificationManager<ConfigureKotlinNotification> {
|
||||||
fun notify(project: Project, excludeModules: List<Module> = emptyList()) {
|
fun notify(project: Project, excludeModules: List<Module> = emptyList()) {
|
||||||
@@ -29,26 +30,37 @@ object ConfigureKotlinNotificationManager: KotlinSingleNotificationManager<Confi
|
|||||||
notify(project, ConfigureKotlinNotification(project, excludeModules, notificationString))
|
notify(project, ConfigureKotlinNotification(project, excludeModules, notificationString))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getVisibleNotifications(project: Project): Array<out ConfigureKotlinNotification> {
|
||||||
|
return NotificationsManager.getNotificationsManager().getNotificationsOfType(ConfigureKotlinNotification::class.java, project)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun expireOldNotifications(project: Project) {
|
||||||
|
expireOldNotifications(project, ConfigureKotlinNotification::class)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface KotlinSingleNotificationManager<in T: Notification> {
|
interface KotlinSingleNotificationManager<in T: Notification> {
|
||||||
fun notify(project: Project, notification: T) {
|
fun notify(project: Project, notification: T) {
|
||||||
val notificationsManager = NotificationsManager.getNotificationsManager() ?: return
|
if (!expireOldNotifications(project, notification::class, notification)) {
|
||||||
|
notification.notify(project)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun expireOldNotifications(project: Project, notificationClass: KClass<out T>, notification: T? = null): Boolean {
|
||||||
|
val notificationsManager = NotificationsManager.getNotificationsManager()
|
||||||
var isNotificationExists = false
|
var isNotificationExists = false
|
||||||
|
|
||||||
val notifications = notificationsManager.getNotificationsOfType(notification::class.java, project)
|
val notifications = notificationsManager.getNotificationsOfType(notificationClass.java, project)
|
||||||
for (oldNotification in notifications) {
|
for (oldNotification in notifications) {
|
||||||
if (oldNotification == notification) {
|
if (oldNotification == notification) {
|
||||||
isNotificationExists = true
|
isNotificationExists = true
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
oldNotification.expire()
|
oldNotification?.expire()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!isNotificationExists) {
|
return isNotificationExists
|
||||||
notification.notify(project)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+10
@@ -25,7 +25,9 @@ import com.intellij.openapi.project.Project
|
|||||||
import com.intellij.openapi.roots.ModuleRootAdapter
|
import com.intellij.openapi.roots.ModuleRootAdapter
|
||||||
import com.intellij.openapi.roots.ModuleRootEvent
|
import com.intellij.openapi.roots.ModuleRootEvent
|
||||||
import com.intellij.openapi.startup.StartupManager
|
import com.intellij.openapi.startup.StartupManager
|
||||||
|
import org.jetbrains.kotlin.idea.configuration.ConfigureKotlinNotificationManager
|
||||||
import org.jetbrains.kotlin.idea.configuration.getModulesWithKotlinFiles
|
import org.jetbrains.kotlin.idea.configuration.getModulesWithKotlinFiles
|
||||||
|
import org.jetbrains.kotlin.idea.configuration.isModuleConfigured
|
||||||
import org.jetbrains.kotlin.idea.configuration.showConfigureKotlinNotificationIfNeeded
|
import org.jetbrains.kotlin.idea.configuration.showConfigureKotlinNotificationIfNeeded
|
||||||
import org.jetbrains.kotlin.idea.project.getAndCacheLanguageLevelByDependencies
|
import org.jetbrains.kotlin.idea.project.getAndCacheLanguageLevelByDependencies
|
||||||
import org.jetbrains.kotlin.idea.versions.collectModulesWithOutdatedRuntime
|
import org.jetbrains.kotlin.idea.versions.collectModulesWithOutdatedRuntime
|
||||||
@@ -52,6 +54,14 @@ class KotlinConfigurationCheckerComponent(project: Project) : AbstractProjectCom
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ConfigureKotlinNotificationManager.getVisibleNotifications(project).isNotEmpty()) {
|
||||||
|
DumbService.getInstance(myProject).smartInvokeLater {
|
||||||
|
if (getModulesWithKotlinFiles(project).all(::isModuleConfigured)) {
|
||||||
|
ConfigureKotlinNotificationManager.expireOldNotifications(project)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user