Hide "Configure Kotlin" notification after Kotlin has been configured

#KT-17289 Fixed
This commit is contained in:
Dmitry Jemerov
2017-04-06 18:29:19 +02:00
parent 29eafcbc97
commit 2e33850981
2 changed files with 28 additions and 6 deletions
@@ -21,6 +21,7 @@ import com.intellij.notification.NotificationsManager
import com.intellij.openapi.module.Module
import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.idea.configuration.ui.notifications.ConfigureKotlinNotification
import kotlin.reflect.KClass
object ConfigureKotlinNotificationManager: KotlinSingleNotificationManager<ConfigureKotlinNotification> {
fun notify(project: Project, excludeModules: List<Module> = emptyList()) {
@@ -29,26 +30,37 @@ object ConfigureKotlinNotificationManager: KotlinSingleNotificationManager<Confi
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> {
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
val notifications = notificationsManager.getNotificationsOfType(notification::class.java, project)
val notifications = notificationsManager.getNotificationsOfType(notificationClass.java, project)
for (oldNotification in notifications) {
if (oldNotification == notification) {
isNotificationExists = true
}
else {
oldNotification.expire()
oldNotification?.expire()
}
}
if (!isNotificationExists) {
notification.notify(project)
}
return isNotificationExists
}
}
@@ -25,7 +25,9 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.ModuleRootAdapter
import com.intellij.openapi.roots.ModuleRootEvent
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.isModuleConfigured
import org.jetbrains.kotlin.idea.configuration.showConfigureKotlinNotificationIfNeeded
import org.jetbrains.kotlin.idea.project.getAndCacheLanguageLevelByDependencies
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)
}
}
}
}
})
}