mirror of
https://github.com/chylex/IntelliJ-Rainbow-Brackets.git
synced 2025-06-01 19:34:06 +02:00
Fix #1067 Don't rainbowify big files notification annoying
This commit is contained in:
parent
709d3e10b1
commit
8ddbc17c72
src/main
@ -0,0 +1,85 @@
|
|||||||
|
package com.github.izhangzhihao.rainbow.brackets
|
||||||
|
|
||||||
|
import com.github.izhangzhihao.rainbow.brackets.settings.RainbowConfigurable
|
||||||
|
import com.github.izhangzhihao.rainbow.brackets.settings.RainbowSettings
|
||||||
|
import com.github.izhangzhihao.rainbow.brackets.util.memoizedFileExtension
|
||||||
|
import com.github.izhangzhihao.rainbow.brackets.visitor.RainbowHighlightVisitor.Companion.checkForBigFile
|
||||||
|
import com.intellij.icons.AllIcons
|
||||||
|
import com.intellij.ide.actions.ShowSettingsUtilImpl
|
||||||
|
import com.intellij.openapi.fileEditor.FileEditor
|
||||||
|
import com.intellij.openapi.project.Project
|
||||||
|
import com.intellij.openapi.util.Key
|
||||||
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
|
import com.intellij.ui.EditorNotificationPanel
|
||||||
|
import com.intellij.ui.EditorNotifications
|
||||||
|
import org.jetbrains.kotlin.idea.core.util.toPsiFile
|
||||||
|
import org.jetbrains.kotlin.idea.versions.createComponentActionLabel
|
||||||
|
|
||||||
|
class RainbowifyBanner(private val project: Project) : EditorNotifications.Provider<EditorNotificationPanel>() {
|
||||||
|
override fun getKey(): Key<EditorNotificationPanel> = KEY
|
||||||
|
|
||||||
|
override fun createNotificationPanel(file: VirtualFile, fileEditor: FileEditor): EditorNotificationPanel? {
|
||||||
|
|
||||||
|
if (!RainbowSettings.instance.isRainbowEnabled) {
|
||||||
|
if (RainbowSettings.instance.suppressDisabledCheck) return null
|
||||||
|
return EditorNotificationPanel().apply {
|
||||||
|
text("Rainbow Brackets is now disabled.")
|
||||||
|
icon(AllIcons.General.Warning)
|
||||||
|
createComponentActionLabel("got it, don't show again") {
|
||||||
|
RainbowSettings.instance.suppressDisabledCheck = true
|
||||||
|
EditorNotifications.getInstance(project).updateAllNotifications()
|
||||||
|
}
|
||||||
|
|
||||||
|
createComponentActionLabel("open setting") {
|
||||||
|
ShowSettingsUtilImpl.showSettingsDialog(project, RainbowConfigurable.ID, "")
|
||||||
|
EditorNotifications.getInstance(project).updateAllNotifications()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val psiFile = file.toPsiFile(project)
|
||||||
|
if (psiFile != null && !checkForBigFile(psiFile)) {
|
||||||
|
if (RainbowSettings.instance.suppressBigFileCheck) return null
|
||||||
|
return EditorNotificationPanel().apply {
|
||||||
|
text("Rainbowify is disabled by default for files > 1000 lines.")
|
||||||
|
icon(AllIcons.General.Information)
|
||||||
|
createComponentActionLabel("got it, don't show again") {
|
||||||
|
RainbowSettings.instance.suppressBigFileCheck = true
|
||||||
|
EditorNotifications.getInstance(project).updateAllNotifications()
|
||||||
|
}
|
||||||
|
|
||||||
|
createComponentActionLabel("open setting") {
|
||||||
|
ShowSettingsUtilImpl.showSettingsDialog(project, RainbowConfigurable.ID, "")
|
||||||
|
EditorNotifications.getInstance(project).updateAllNotifications()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
RainbowSettings.instance.languageBlacklist.contains(file.fileType.name) ||
|
||||||
|
RainbowSettings.instance.languageBlacklist.contains(memoizedFileExtension(file.name))
|
||||||
|
) {
|
||||||
|
if (RainbowSettings.instance.suppressBlackListCheck) return null
|
||||||
|
return EditorNotificationPanel().apply {
|
||||||
|
text("This language/file extensions is in the black list, will not be rainbowify")
|
||||||
|
icon(AllIcons.General.Information)
|
||||||
|
|
||||||
|
createComponentActionLabel("got it, don't show again") {
|
||||||
|
RainbowSettings.instance.suppressBlackListCheck = true
|
||||||
|
EditorNotifications.getInstance(project).updateAllNotifications()
|
||||||
|
}
|
||||||
|
|
||||||
|
createComponentActionLabel("open setting") {
|
||||||
|
ShowSettingsUtilImpl.showSettingsDialog(project, RainbowConfigurable.ID, "")
|
||||||
|
EditorNotifications.getInstance(project).updateAllNotifications()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val KEY = Key.create<EditorNotificationPanel>("RainbowifyBanner")
|
||||||
|
}
|
||||||
|
}
|
@ -1,12 +1,12 @@
|
|||||||
package com.github.izhangzhihao.rainbow.brackets.settings
|
package com.github.izhangzhihao.rainbow.brackets.settings
|
||||||
|
|
||||||
import com.github.izhangzhihao.rainbow.brackets.settings.form.RainbowSettingsForm
|
import com.github.izhangzhihao.rainbow.brackets.settings.form.RainbowSettingsForm
|
||||||
import com.intellij.openapi.options.Configurable
|
|
||||||
import com.intellij.openapi.options.ConfigurationException
|
import com.intellij.openapi.options.ConfigurationException
|
||||||
|
import com.intellij.openapi.options.SearchableConfigurable
|
||||||
import org.jetbrains.annotations.Nls
|
import org.jetbrains.annotations.Nls
|
||||||
import javax.swing.JComponent
|
import javax.swing.JComponent
|
||||||
|
|
||||||
class RainbowConfigurable : Configurable {
|
class RainbowConfigurable : SearchableConfigurable {
|
||||||
var settingsForm: RainbowSettingsForm? = null
|
var settingsForm: RainbowSettingsForm? = null
|
||||||
|
|
||||||
override fun createComponent(): JComponent? {
|
override fun createComponent(): JComponent? {
|
||||||
@ -55,4 +55,10 @@ class RainbowConfigurable : Configurable {
|
|||||||
|
|
||||||
@Nls
|
@Nls
|
||||||
override fun getDisplayName() = "Rainbow Brackets"
|
override fun getDisplayName() = "Rainbow Brackets"
|
||||||
|
|
||||||
|
override fun getId(): String = ID
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val ID = "preferences.rainbow.brackets"
|
||||||
|
}
|
||||||
}
|
}
|
@ -43,6 +43,10 @@ class RainbowSettings : PersistentStateComponent<RainbowSettings> {
|
|||||||
|
|
||||||
var languageBlacklist: Set<String> = setOf("hocon", "mxml")
|
var languageBlacklist: Set<String> = setOf("hocon", "mxml")
|
||||||
|
|
||||||
|
var suppressDisabledCheck = false
|
||||||
|
var suppressBigFileCheck = false
|
||||||
|
var suppressBlackListCheck = false
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
override fun getState() = this
|
override fun getState() = this
|
||||||
|
|
||||||
|
@ -2,15 +2,11 @@ package com.github.izhangzhihao.rainbow.brackets.visitor
|
|||||||
|
|
||||||
import com.github.izhangzhihao.rainbow.brackets.RainbowHighlighter.getHighlightInfo
|
import com.github.izhangzhihao.rainbow.brackets.RainbowHighlighter.getHighlightInfo
|
||||||
import com.github.izhangzhihao.rainbow.brackets.RainbowInfo
|
import com.github.izhangzhihao.rainbow.brackets.RainbowInfo
|
||||||
import com.github.izhangzhihao.rainbow.brackets.RainbowUpdateNotifyActivity.Companion.pluginId
|
|
||||||
import com.github.izhangzhihao.rainbow.brackets.settings.RainbowSettings
|
import com.github.izhangzhihao.rainbow.brackets.settings.RainbowSettings
|
||||||
import com.github.izhangzhihao.rainbow.brackets.util.memoizedFileExtension
|
import com.github.izhangzhihao.rainbow.brackets.util.memoizedFileExtension
|
||||||
import com.intellij.codeInsight.daemon.impl.HighlightVisitor
|
import com.intellij.codeInsight.daemon.impl.HighlightVisitor
|
||||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightInfoHolder
|
import com.intellij.codeInsight.daemon.impl.analysis.HighlightInfoHolder
|
||||||
import com.intellij.ide.plugins.PluginManagerCore
|
import com.intellij.ide.plugins.PluginManagerCore
|
||||||
import com.intellij.notification.NotificationDisplayType
|
|
||||||
import com.intellij.notification.NotificationGroup
|
|
||||||
import com.intellij.notification.NotificationType
|
|
||||||
import com.intellij.openapi.editor.colors.EditorColorsManager
|
import com.intellij.openapi.editor.colors.EditorColorsManager
|
||||||
import com.intellij.openapi.extensions.PluginId
|
import com.intellij.openapi.extensions.PluginId
|
||||||
import com.intellij.openapi.util.TextRange
|
import com.intellij.openapi.util.TextRange
|
||||||
@ -33,36 +29,7 @@ abstract class RainbowHighlightVisitor : HighlightVisitor {
|
|||||||
fileIsNotHaskellOrIntelliJHaskellPluginNotEnabled(file.fileType.name)
|
fileIsNotHaskellOrIntelliJHaskellPluginNotEnabled(file.fileType.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkForBigFile(file: PsiFile): Boolean {
|
final override fun analyze(file: PsiFile, updateWholeFile: Boolean, holder: HighlightInfoHolder, action: Runnable): Boolean {
|
||||||
if (RainbowSettings.instance.doNOTRainbowifyBigFiles && file.getLineCount() > 1000) {
|
|
||||||
|
|
||||||
if (!bigFilesNotified) {
|
|
||||||
bigFilesNotified = true
|
|
||||||
val group = NotificationGroup(
|
|
||||||
pluginId,
|
|
||||||
NotificationDisplayType.BALLOON,
|
|
||||||
true
|
|
||||||
)
|
|
||||||
|
|
||||||
val notification = group.createNotification(
|
|
||||||
"Rainbowify big files is disabled by default",
|
|
||||||
"File with line count > 1000 will not rainbowify by default. If you still want to rainbowify it, please config it in <b>Settings > Other Settings > Rainbow Brackets > Do NOT rainbowify big files</b>",
|
|
||||||
NotificationType.INFORMATION
|
|
||||||
)
|
|
||||||
|
|
||||||
notification.notify(file.project)
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun fileIsNotHaskellOrIntelliJHaskellPluginNotEnabled(fileType: String) =
|
|
||||||
fileType != "Haskell" || !isIntelliJHaskellEnabled
|
|
||||||
|
|
||||||
final override fun analyze(file: PsiFile, updateWholeFile: Boolean, holder: HighlightInfoHolder, action: Runnable)
|
|
||||||
: Boolean {
|
|
||||||
highlightInfoHolder = holder
|
highlightInfoHolder = holder
|
||||||
onBeforeAnalyze(file, updateWholeFile)
|
onBeforeAnalyze(file, updateWholeFile)
|
||||||
action.run()
|
action.run()
|
||||||
@ -81,7 +48,7 @@ abstract class RainbowHighlightVisitor : HighlightVisitor {
|
|||||||
startElement: PsiElement?,
|
startElement: PsiElement?,
|
||||||
endElement: PsiElement?) {
|
endElement: PsiElement?) {
|
||||||
val holder = highlightInfoHolder ?: return
|
val holder = highlightInfoHolder ?: return
|
||||||
@Suppress("USELESS_ELVIS") val schema = holder.colorsScheme?: EditorColorsManager.getInstance().globalScheme
|
@Suppress("USELESS_ELVIS") val schema = holder.colorsScheme ?: EditorColorsManager.getInstance().globalScheme
|
||||||
getHighlightInfo(schema, this, level)
|
getHighlightInfo(schema, this, level)
|
||||||
?.also {
|
?.also {
|
||||||
holder.add(it)
|
holder.add(it)
|
||||||
@ -113,11 +80,15 @@ abstract class RainbowHighlightVisitor : HighlightVisitor {
|
|||||||
PluginManagerCore.getPlugin(
|
PluginManagerCore.getPlugin(
|
||||||
PluginId.getId("intellij.haskell"))?.isEnabled ?: false
|
PluginId.getId("intellij.haskell"))?.isEnabled ?: false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun checkForBigFile(file: PsiFile): Boolean =
|
||||||
|
!(RainbowSettings.instance.doNOTRainbowifyBigFiles && file.getLineCount() > 1000)
|
||||||
|
|
||||||
|
private fun fileIsNotHaskellOrIntelliJHaskellPluginNotEnabled(fileType: String) =
|
||||||
|
fileType != "Haskell" || !isIntelliJHaskellEnabled
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private var bigFilesNotified = false
|
|
||||||
|
|
||||||
fun PsiElement.getLineCount(): Int {
|
fun PsiElement.getLineCount(): Int {
|
||||||
try {
|
try {
|
||||||
val doc = containingFile?.let { PsiDocumentManager.getInstance(project).getDocument(it) }
|
val doc = containingFile?.let { PsiDocumentManager.getInstance(project).getDocument(it) }
|
||||||
|
@ -704,6 +704,7 @@
|
|||||||
<errorHandler implementation="com.github.izhangzhihao.rainbow.brackets.util.GitHubErrorReporter"/>
|
<errorHandler implementation="com.github.izhangzhihao.rainbow.brackets.util.GitHubErrorReporter"/>
|
||||||
<highlightingPassFactory implementation="com.github.izhangzhihao.rainbow.brackets.indents.RainbowIndentsPassFactory"/>
|
<highlightingPassFactory implementation="com.github.izhangzhihao.rainbow.brackets.indents.RainbowIndentsPassFactory"/>
|
||||||
<applicationService serviceImplementation="com.github.izhangzhihao.rainbow.brackets.ApplicationServicePlaceholder" id="ApplicationServicePlaceholder"/>
|
<applicationService serviceImplementation="com.github.izhangzhihao.rainbow.brackets.ApplicationServicePlaceholder" id="ApplicationServicePlaceholder"/>
|
||||||
|
<editorNotificationProvider implementation="com.github.izhangzhihao.rainbow.brackets.RainbowifyBanner"/>
|
||||||
</extensions>
|
</extensions>
|
||||||
|
|
||||||
<applicationListeners>
|
<applicationListeners>
|
||||||
|
Loading…
Reference in New Issue
Block a user