move the calculation of configure kotlin notification out of EDT

#KT-10541 Fixed
This commit is contained in:
Dmitry Jemerov
2016-02-20 16:15:52 +01:00
parent 1976e5f3b0
commit 4ea05354c7
2 changed files with 22 additions and 7 deletions
@@ -16,12 +16,16 @@
package org.jetbrains.kotlin.idea.configuration package org.jetbrains.kotlin.idea.configuration
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.extensions.Extensions import com.intellij.openapi.extensions.Extensions
import com.intellij.openapi.module.Module import com.intellij.openapi.module.Module
import com.intellij.openapi.project.DumbService
import com.intellij.openapi.project.Project import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Computable
import com.intellij.psi.search.FileTypeIndex import com.intellij.psi.search.FileTypeIndex
import com.intellij.psi.search.GlobalSearchScope import com.intellij.psi.search.GlobalSearchScope
import org.jetbrains.kotlin.idea.KotlinFileType 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.idea.util.projectStructure.allModules
import org.jetbrains.kotlin.utils.ifEmpty import org.jetbrains.kotlin.utils.ifEmpty
@@ -56,10 +60,17 @@ fun showConfigureKotlinNotificationIfNeeded(module: Module) {
} }
fun showConfigureKotlinNotificationIfNeeded(project: Project, excludeModules: List<Module> = emptyList()) { fun showConfigureKotlinNotificationIfNeeded(project: Project, excludeModules: List<Module> = emptyList()) {
val modules = getModulesWithKotlinFiles(project) - excludeModules ApplicationManager.getApplication().executeOnPooledThread {
if (modules.all { isModuleConfigured(it) }) return val notificationString = DumbService.getInstance(project).runReadActionInSmartMode(Computable {
val modules = getModulesWithKotlinFiles(project) - excludeModules
ConfigureKotlinNotificationManager.notify(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<KotlinProjectConfigurator> { fun getAbleToRunConfigurators(project: Project): Collection<KotlinProjectConfigurator> {
@@ -30,9 +30,10 @@ import javax.swing.event.HyperlinkEvent
class ConfigureKotlinNotification( class ConfigureKotlinNotification(
project: Project, project: Project,
excludeModules: List<Module>) : Notification(KotlinConfigurationCheckerComponent.CONFIGURE_NOTIFICATION_GROUP_ID, "Configure Kotlin", excludeModules: List<Module>,
getNotificationString(project, excludeModules), notificationString: String) : Notification(KotlinConfigurationCheckerComponent.CONFIGURE_NOTIFICATION_GROUP_ID, "Configure Kotlin",
NotificationType.WARNING, NotificationListener { notification, event -> notificationString,
NotificationType.WARNING, NotificationListener { notification, event ->
if (event.eventType == HyperlinkEvent.EventType.ACTIVATED) { if (event.eventType == HyperlinkEvent.EventType.ACTIVATED) {
val configurator = getConfiguratorByName(event.description) ?: throw AssertionError("Missed action: " + event.description) val configurator = getConfiguratorByName(event.description) ?: throw AssertionError("Missed action: " + event.description)
notification.expire() notification.expire()
@@ -41,6 +42,9 @@ class ConfigureKotlinNotification(
} }
}) { }) {
constructor(project: Project, excludeModules: List<Module>)
: this(project, excludeModules, getNotificationString(project, excludeModules))
override fun equals(o: Any?): Boolean { override fun equals(o: Any?): Boolean {
if (this === o) return true if (this === o) return true
if (o !is ConfigureKotlinNotification) return false if (o !is ConfigureKotlinNotification) return false