From 4ea05354c7b504edd5a6046493848ddaaa64a467 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Sat, 20 Feb 2016 16:15:52 +0100 Subject: [PATCH] move the calculation of configure kotlin notification out of EDT #KT-10541 Fixed --- .../ConfigureKotlinInProjectUtils.kt | 19 +++++++++++++++---- .../ConfigureKotlinNotification.kt | 10 +++++++--- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinInProjectUtils.kt b/idea/src/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinInProjectUtils.kt index 7176e02487e..f8b50885a95 100644 --- a/idea/src/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinInProjectUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinInProjectUtils.kt @@ -16,12 +16,16 @@ package org.jetbrains.kotlin.idea.configuration +import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.extensions.Extensions import com.intellij.openapi.module.Module +import com.intellij.openapi.project.DumbService import com.intellij.openapi.project.Project +import com.intellij.openapi.util.Computable import com.intellij.psi.search.FileTypeIndex import com.intellij.psi.search.GlobalSearchScope import org.jetbrains.kotlin.idea.KotlinFileType +import org.jetbrains.kotlin.idea.configuration.ui.notifications.ConfigureKotlinNotification import org.jetbrains.kotlin.idea.util.projectStructure.allModules import org.jetbrains.kotlin.utils.ifEmpty @@ -56,10 +60,17 @@ fun showConfigureKotlinNotificationIfNeeded(module: Module) { } fun showConfigureKotlinNotificationIfNeeded(project: Project, excludeModules: List = emptyList()) { - val modules = getModulesWithKotlinFiles(project) - excludeModules - if (modules.all { isModuleConfigured(it) }) return - - ConfigureKotlinNotificationManager.notify(project, excludeModules) + ApplicationManager.getApplication().executeOnPooledThread { + val notificationString = DumbService.getInstance(project).runReadActionInSmartMode(Computable { + val modules = getModulesWithKotlinFiles(project) - excludeModules + if (modules.all { isModuleConfigured(it) }) null else ConfigureKotlinNotification.getNotificationString(project, excludeModules) + }) + if (notificationString != null) { + ApplicationManager.getApplication().invokeLater { + ConfigureKotlinNotificationManager.notify(project, ConfigureKotlinNotification(project, excludeModules, notificationString)) + } + } + } } fun getAbleToRunConfigurators(project: Project): Collection { diff --git a/idea/src/org/jetbrains/kotlin/idea/configuration/ui/notifications/ConfigureKotlinNotification.kt b/idea/src/org/jetbrains/kotlin/idea/configuration/ui/notifications/ConfigureKotlinNotification.kt index c561f1583f2..21c29895e67 100644 --- a/idea/src/org/jetbrains/kotlin/idea/configuration/ui/notifications/ConfigureKotlinNotification.kt +++ b/idea/src/org/jetbrains/kotlin/idea/configuration/ui/notifications/ConfigureKotlinNotification.kt @@ -30,9 +30,10 @@ import javax.swing.event.HyperlinkEvent class ConfigureKotlinNotification( project: Project, - excludeModules: List) : Notification(KotlinConfigurationCheckerComponent.CONFIGURE_NOTIFICATION_GROUP_ID, "Configure Kotlin", - getNotificationString(project, excludeModules), - NotificationType.WARNING, NotificationListener { notification, event -> + excludeModules: List, + notificationString: String) : Notification(KotlinConfigurationCheckerComponent.CONFIGURE_NOTIFICATION_GROUP_ID, "Configure Kotlin", + notificationString, + NotificationType.WARNING, NotificationListener { notification, event -> if (event.eventType == HyperlinkEvent.EventType.ACTIVATED) { val configurator = getConfiguratorByName(event.description) ?: throw AssertionError("Missed action: " + event.description) notification.expire() @@ -41,6 +42,9 @@ class ConfigureKotlinNotification( } }) { + constructor(project: Project, excludeModules: List) + : this(project, excludeModules, getNotificationString(project, excludeModules)) + override fun equals(o: Any?): Boolean { if (this === o) return true if (o !is ConfigureKotlinNotification) return false