Skip to content

Commit b7a0986

Browse files
committed
feat: add rate notification
1 parent 1ed5da4 commit b7a0986

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
}

src/main/resources/META-INF/plugin.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,7 @@
5656
<!-- <className>com.github.xepozz.gitattributes.ide.actions.AttributesGuruIntention</className>-->
5757
<!-- <category>Gitattributes intentions</category>-->
5858
<!-- </intentionAction>-->
59+
<editorNotificationProvider
60+
implementation="com.github.xepozz.gitattributes.ide.editor.EditorNotificationProvider"/>
5961
</extensions>
6062
</idea-plugin>

0 commit comments

Comments
 (0)