Skip to content

Commit

Permalink
feature: grazie pro incompatibility notification
Browse files Browse the repository at this point in the history
  • Loading branch information
popovanton0 committed May 22, 2024
1 parent 91944ab commit c6e6dfd
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 30 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ enum class MyColorTokens {
Using this convention, there is **no need** to connect a configuration file with
color values to the plugin per project.

> [!WARNING]
> Until [this issue](https://youtrack.jetbrains.com/issue/GRZ-4351) is resolved, **Grazie Pro** plugin
> is incompatible with color previews in the gutter.
>
> Please, disable the Grazie Pro plugin if you want to use this feature.
## Installation

1. Make sure that you are using **Android Studio Koala | 2024.1.1 Canary 3** or later
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pluginGroup = ru.ozon.ideplugin.kelp
pluginName = Kelp
pluginRepositoryUrl = https://github.com/ozontech/kelp
# SemVer format -> https://semver.org
pluginVersion = 0.0.6
pluginVersion = 0.0.7

# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
# https://plugins.jetbrains.com/docs/intellij/android-studio-releases-list.html
Expand Down
24 changes: 0 additions & 24 deletions src/main/kotlin/ru/ozon/ideplugin/kelp/ThemeQuickTypeAction.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.jdom.Element
import ru.ozon.ideplugin.kelp.pluginConfig.KelpConfig

internal object AddLiveTemplates {
private val kotlinTemplateContexts by lazy {
private val kotlinTemplateContext by lazy {
Element("a").apply {
listOf("KOTLIN_EXPRESSION", "KOTLIN_STATEMENT").forEach { name ->
addContent(
Expand All @@ -22,9 +22,7 @@ internal object AddLiveTemplates {
fun execute(config: KelpConfig, projectName: String) {
val templates = config.liveTemplates.orEmpty()
val templateSettings = TemplateSettings.getInstance()
templateSettings.templates.forEach {
if (it.groupName == "Kelp ($projectName)") templateSettings.removeTemplate(it)
}
removeAllTemplates(templateSettings, projectName)
templates.forEach { template ->
TemplateImpl(
/* key = */ template.abbreviation,
Expand All @@ -33,9 +31,18 @@ internal object AddLiveTemplates {
).apply {
template.description?.let { description = it }
addVariable("CODE_COMPLETION", "complete()", "", true)
templateContext.readTemplateContext(kotlinTemplateContexts)
templateContext.readTemplateContext(kotlinTemplateContext)
templateSettings.addTemplate(this)
}
}
}

private fun removeAllTemplates(
templateSettings: TemplateSettings,
projectName: String
) {
templateSettings.templates.forEach {
if (it.groupName == "Kelp ($projectName)") templateSettings.removeTemplate(it)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package ru.ozon.ideplugin.kelp.pluginConfig

import com.intellij.ide.plugins.PluginManagerCore
import com.intellij.notification.NotificationGroupManager
import com.intellij.notification.NotificationType
import com.intellij.openapi.application.invokeLater
import com.intellij.openapi.components.Service
import com.intellij.openapi.extensions.PluginId
import com.intellij.openapi.project.Project
import ru.ozon.ideplugin.kelp.KelpBundle

/**
* [Issue](https://youtrack.jetbrains.com/issue/GRZ-4351)
*/
@Service(Service.Level.PROJECT)
class GrazieProNotification {
private var notified = false

fun notifyIfNeeded(project: Project, previousConfig: KelpConfig?, kelpConfig: KelpConfig) = invokeLater {
if (!notified &&
kelpConfig.iconsRendering?.gutterEnabled == true &&
previousConfig?.iconsRendering?.gutterEnabled != true &&
isGrazieProPluginEnabled()
) {
NotificationGroupManager.getInstance()
.getNotificationGroup(KelpBundle.message("grazieProNotificationGroup"))
.createNotification(
title = KelpBundle.message("grazieProNotificationTitle"),
content = KelpBundle.message("grazieProNotificationMessage"),
type = NotificationType.WARNING,
)
.notify(project)

notified = true
}
}

private fun isGrazieProPluginEnabled(): Boolean {
val pluginId = PluginId.getId(GRAZIE_PRO_PLUGIN_ID)
return PluginManagerCore.getPlugin(pluginId) != null && !PluginManagerCore.isDisabled(pluginId)
}
}

private const val GRAZIE_PRO_PLUGIN_ID = "com.intellij.grazie.pro"
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.intellij.openapi.Disposable
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.invokeLater
import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
import com.intellij.openapi.components.serviceOrNull
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.AsyncFileListener.ChangeApplier
Expand Down Expand Up @@ -50,6 +51,7 @@ private class KelpConfigService(val project: Project) : Disposable {
application.executeOnPooledThread {
application.runReadAction {
runCatching {
val previousConfig = data
configText = VirtualFileManager.getInstance()
.findFileByNioPath(configFilePath)
?.readText()
Expand All @@ -58,6 +60,7 @@ private class KelpConfigService(val project: Project) : Disposable {
data = kelpConfig
AddLiveTemplates.execute(kelpConfig, project.name)
if (!isFirstRun) reloadNotification()
service<GrazieProNotification>().notifyIfNeeded(project, previousConfig, kelpConfig)
}.onFailure {
invalidConfigError(it)
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<category>Kelp intentions</category>
</intentionAction>

<notificationGroup displayType="STICKY_BALLOON" id="KelpGrazie"/>
<notificationGroup displayType="BALLOON" id="KelpConfigReload"/>
<notificationGroup displayType="BALLOON" id="Kelp"/>

Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/messages/KelpBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ invalidConfigNotificationTitle=Kelp
invalidConfigNotificationMessage=Config file isn't valid. Please, follow plugin setup instructions to create a valid config file
configReloadSuccessTitle=Kelp
configReloadSuccessMessage=Kelp config reloaded successfully
grazieProNotificationGroup=KelpGrazie
grazieProNotificationTitle=Kelp
grazieProNotificationMessage=Disable Grazie Pro plugin to enable color previews in the gutter
colorPreviewDescriptorName=Kelp color previews
colorPreviewDescriptorTooltip=Color: #{0}
Expand Down

0 comments on commit c6e6dfd

Please sign in to comment.