Prototype version for code style notifications (KT-23400)

Show information about code style update, when it is actually updated.
This commit is contained in:
Nikolay Krasko
2018-08-08 16:07:49 +03:00
parent d16b6f9874
commit 6920e3bd08
2 changed files with 59 additions and 1 deletions
@@ -27,7 +27,11 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.ModuleRootEvent
import com.intellij.openapi.roots.ModuleRootListener
import com.intellij.openapi.startup.StartupManager
import org.jetbrains.kotlin.idea.configuration.*
import org.jetbrains.kotlin.idea.configuration.checkHideNonConfiguredNotifications
import org.jetbrains.kotlin.idea.configuration.getModulesWithKotlinFiles
import org.jetbrains.kotlin.idea.configuration.notifyOutdatedBundledCompilerIfNecessary
import org.jetbrains.kotlin.idea.configuration.showConfigureKotlinNotificationIfNeeded
import org.jetbrains.kotlin.idea.configuration.ui.notifications.notifyKotlinStyleUpdateIfNeeded
import org.jetbrains.kotlin.idea.project.getAndCacheLanguageLevelByDependencies
import org.jetbrains.kotlin.idea.versions.collectModulesWithOutdatedRuntime
import org.jetbrains.kotlin.idea.versions.findOutdatedKotlinLibraries
@@ -68,6 +72,8 @@ class KotlinConfigurationCheckerComponent(project: Project) : AbstractProjectCom
connection.subscribe(ProjectDataImportListener.TOPIC, ProjectDataImportListener {
notifyOutdatedBundledCompilerIfNecessary(project)
})
notifyKotlinStyleUpdateIfNeeded(project)
}
override fun projectOpened() {
@@ -0,0 +1,52 @@
/*
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.idea.configuration.ui.notifications
import com.intellij.ide.util.PropertiesComponent
import com.intellij.notification.Notification
import com.intellij.notification.NotificationDisplayType
import com.intellij.notification.NotificationType
import com.intellij.notification.NotificationsConfiguration
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.idea.util.isDefaultOfficialCodeStyle
private const val KOTLIN_UPDATE_CODE_STYLE_GROUP_ID = "Update Kotlin code style"
private const val KOTLIN_UPDATE_CODE_STYLE_PROPERTY_NAME = "update.kotlin.code.style.notified"
fun notifyKotlinStyleUpdateIfNeeded(project: Project) {
if (PropertiesComponent.getInstance(project).getBoolean(KOTLIN_UPDATE_CODE_STYLE_PROPERTY_NAME, false)) {
return
}
if (!isDefaultOfficialCodeStyle) return
NotificationsConfiguration.getNotificationsConfiguration()
.register(KOTLIN_UPDATE_CODE_STYLE_GROUP_ID, NotificationDisplayType.STICKY_BALLOON, true)
val notification = KotlinCodeStyleChangedNotification(project)
notification.isImportant = true
if (ApplicationManager.getApplication().isUnitTestMode) {
return
}
PropertiesComponent.getInstance(project).setValue(KOTLIN_UPDATE_CODE_STYLE_PROPERTY_NAME, true, false)
notification.notify(project)
}
private class KotlinCodeStyleChangedNotification(val project: Project) : Notification(
KOTLIN_UPDATE_CODE_STYLE_GROUP_ID,
"Kotlin Code Style",
"""
<html>
Default code style was updated to Kotlin Coding Conventions.
</html>
""".trimIndent(),
NotificationType.WARNING,
null
)