1+ package com.github.xepozz.gitattributes.ide.editor
2+
3+ import com.github.xepozz.gitattributes.language.AttributesFileType
4+ import com.intellij.ide.BrowserUtil
5+ import com.intellij.ide.util.PropertiesComponent
6+ import com.intellij.openapi.diagnostic.thisLogger
7+ import com.intellij.openapi.fileEditor.FileEditor
8+ import com.intellij.openapi.project.DumbAware
9+ import com.intellij.openapi.project.Project
10+ import com.intellij.openapi.vfs.VirtualFile
11+ import com.intellij.ui.EditorNotificationPanel
12+ import com.intellij.ui.EditorNotificationProvider
13+ import com.intellij.ui.EditorNotifications
14+ import java.util.function.Function
15+ import javax.swing.JComponent
16+
17+ private const val PROMO_RATE = " gitattributes.promo.rate"
18+
19+ class EditorNotificationProvider : EditorNotificationProvider , DumbAware {
20+ override fun collectNotificationData (
21+ project : Project ,
22+ file : VirtualFile
23+ ): Function <in FileEditor , out JComponent ?>? {
24+ if (file.fileType !is AttributesFileType ) return null
25+
26+ if (PropertiesComponent .getInstance().isTrueValue(PROMO_RATE )) return null
27+
28+ return Function { editor ->
29+ val panel = EditorNotificationPanel (editor, EditorNotificationPanel .Status .Promo )
30+ panel.text = " GitAttributes: Rate plugin on the Marketplace, help it grow"
31+ panel.createActionLabel(" Leave Review" ) {
32+ BrowserUtil .browse(" https://plugins.jetbrains.com/plugin/26477--gitattributes-support/reviews/new" )
33+ updateProperty(project)
34+ }
35+ panel.setCloseAction {
36+ thisLogger().info(" Close action clicked" )
37+ updateProperty(project)
38+ }
39+ panel
40+ }
41+ }
42+
43+ private fun updateProperty (project : Project ) {
44+ PropertiesComponent .getInstance().setValue(PROMO_RATE , true )
45+ EditorNotifications .getInstance(project).updateAllNotifications()
46+ }
47+ }
0 commit comments