[kotlin] Attach Kotlin feedback form to fir status icon

#KTIJ-30309 Fixed

GitOrigin-RevId: fec1721cb2fea27a0c43e52fa4c86bc12877ecd4
This commit is contained in:
Vladimir Dolzhenko
2024-06-17 21:02:50 +00:00
committed by intellij-monorepo-bot
parent 35a380dcfb
commit fb45acd022
4 changed files with 59 additions and 11 deletions
+2
View File
@@ -79,5 +79,7 @@
<orderEntry type="module" module-name="intellij.platform.workspace.jps" />
<orderEntry type="module" module-name="intellij.platform.backend.workspace" />
<orderEntry type="module" module-name="kotlin.refactorings.common" />
<orderEntry type="module" module-name="intellij.platform.feedback" />
<orderEntry type="module" module-name="kotlin.onboarding" />
</component>
</module>
@@ -10,11 +10,20 @@ import com.intellij.openapi.util.NlsSafe
import com.intellij.openapi.util.registry.Registry
import com.intellij.openapi.util.registry.RegistryValue
import com.intellij.openapi.util.registry.RegistryValueListener
import com.intellij.openapi.wm.CustomStatusBarWidget
import com.intellij.openapi.wm.StatusBarWidget
import com.intellij.openapi.wm.StatusBarWidgetFactory
import com.intellij.openapi.wm.impl.status.widget.StatusBarWidgetsManager
import com.intellij.platform.feedback.impl.OnDemandFeedbackResolver
import com.intellij.ui.ClickListener
import org.jetbrains.kotlin.idea.KotlinIcons
import org.jetbrains.kotlin.onboarding.k2.satisfaction.survey.K2FeedbackSurvey
import org.jetbrains.kotlin.onboarding.k2.satisfaction.survey.K2UserTracker
import java.awt.event.MouseEvent
import javax.swing.Icon
import javax.swing.JComponent
import javax.swing.JLabel
import javax.swing.SwingUtilities
private class FirStatusBarWidgetFactory : StatusBarWidgetFactory {
override fun getId(): String = ID
@@ -22,19 +31,19 @@ private class FirStatusBarWidgetFactory : StatusBarWidgetFactory {
override fun getDisplayName(): String = DISPLAY_NAME
override fun isAvailable(project: Project): Boolean {
return Registry.`is`(REGISTRY_KEY, /* defaultValue = */ false)
return Registry.`is`(REGISTRY_KEY, /* defaultValue = */ true)
}
override fun createWidget(project: Project): StatusBarWidget = Widget()
override fun createWidget(project: Project): StatusBarWidget = Widget(project)
companion object {
const val ID = "kotlin.fir.ide"
@NlsSafe
private const val DISPLAY_NAME = "K2 mode"
const val ID = "kotlin.k2.mode"
}
}
@NlsSafe
private const val DISPLAY_NAME = "Kotlin plugin K2 mode"
private class FirStatusBarWidgetListener : RegistryValueListener {
override fun afterValueChanged(value: RegistryValue) {
if (value.key != REGISTRY_KEY) return
@@ -50,9 +59,43 @@ private class FirStatusBarWidgetListener : RegistryValueListener {
private const val REGISTRY_KEY: String = "kotlin.k2.show.fir.statusbar.icon"
private class Widget : StatusBarWidget, StatusBarWidget.IconPresentation {
override fun getPresentation(): StatusBarWidget.WidgetPresentation = this
private class Widget(private val project: Project) : CustomStatusBarWidget, StatusBarWidget.IconPresentation {
private var icon: JLabel? = null
override fun ID(): String = FirStatusBarWidgetFactory.ID
override fun getTooltipText(): String = "K2 mode"
override fun getPresentation(): StatusBarWidget.WidgetPresentation = this
override fun getTooltipText(): String = DISPLAY_NAME
override fun getIcon(): Icon = KotlinIcons.FIR
override fun getComponent(): JComponent {
val icon = JLabel()
.apply {
object : ClickListener() {
override fun onClick(event: MouseEvent, clickCount: Int): Boolean {
if (SwingUtilities.isLeftMouseButton(event)) {
showFeedbackForm()
}
return true
}
}.installOn(this)
}.apply {
toolTipText = DISPLAY_NAME
icon = KotlinIcons.FIR
}
this.icon = icon
return icon
}
fun showFeedbackForm() {
val userTracker = K2UserTracker.getInstance()
userTracker.forced = true
OnDemandFeedbackResolver.getInstance()
.showFeedbackNotification(K2FeedbackSurvey::class, project) {
userTracker.forced = false
}
}
override fun dispose() {
icon = null
}
}
@@ -42,6 +42,8 @@ class K2UserTracker : PersistentStateComponent<K2UserTrackerState> {
}
}
var forced: Boolean = false
internal var switchedToK1 = false
internal var forUnitTests = false
internal var k2PluginModeForTests = false // Want the test to not depend on a real K1/K2 mode
@@ -69,6 +71,7 @@ class K2UserTracker : PersistentStateComponent<K2UserTrackerState> {
}
internal fun shouldShowK2FeedbackDialog(project: Project): Boolean {
if (forced) return true
LOG.debug("State: ${state}")
if (!Registry.`is`("test.k2.feedback.survey", false)) {
@@ -86,8 +86,8 @@
restartRequired="false"/>
<registryKey key="kotlin.k2.show.fir.statusbar.icon"
description="Show K2 FIR tree icon in the status bar"
defaultValue="false"
description="Show K2 mode tree icon in the status bar"
defaultValue="true"
restartRequired="false"/>
<registryKey