diff --git a/src/main/kotlin/com/github/biomejs/intellijbiome/BiomeConfigIconProvider.kt b/src/main/kotlin/com/github/biomejs/intellijbiome/BiomeConfigIconProvider.kt new file mode 100644 index 0000000..8656871 --- /dev/null +++ b/src/main/kotlin/com/github/biomejs/intellijbiome/BiomeConfigIconProvider.kt @@ -0,0 +1,23 @@ +package com.github.biomejs.intellijbiome + +import com.intellij.ide.IconProvider +import com.intellij.psi.PsiElement +import com.intellij.psi.PsiFile +import javax.swing.Icon + +class BiomeConfigIconProvider : IconProvider() { + override fun getIcon(element: PsiElement, flags: Int): Icon? { + val file = element as? PsiFile ?: return null + if (!file.isValid || file.isDirectory) return null + val virtualFile = file.virtualFile ?: return null + + // Check if the file is a valid Biome config file + if (virtualFile.name.contains(BiomePackage.configName) && + BiomePackage.configValidExtensions.contains(virtualFile.extension) + ) { + return BiomeIcons.BiomeIcon + } + + return null + } +} diff --git a/src/main/kotlin/com/github/biomejs/intellijbiome/settings/BiomeConfigurable.kt b/src/main/kotlin/com/github/biomejs/intellijbiome/settings/BiomeConfigurable.kt index a6b9536..1fd97b6 100644 --- a/src/main/kotlin/com/github/biomejs/intellijbiome/settings/BiomeConfigurable.kt +++ b/src/main/kotlin/com/github/biomejs/intellijbiome/settings/BiomeConfigurable.kt @@ -47,7 +47,7 @@ class BiomeConfigurable(internal val project: Project) : lateinit var runForFilesField: JBTextField - private lateinit var disabledConfiguration: JRadioButton + lateinit var disabledConfiguration: JRadioButton private lateinit var automaticConfiguration: JRadioButton private lateinit var manualConfiguration: JRadioButton override fun createPanel(): DialogPanel { diff --git a/src/main/kotlin/com/github/biomejs/intellijbiome/settings/BiomeOnSaveApplySafeFixesActionInfo.kt b/src/main/kotlin/com/github/biomejs/intellijbiome/settings/BiomeOnSaveApplySafeFixesActionInfo.kt index 7ba9818..fce365f 100644 --- a/src/main/kotlin/com/github/biomejs/intellijbiome/settings/BiomeOnSaveApplySafeFixesActionInfo.kt +++ b/src/main/kotlin/com/github/biomejs/intellijbiome/settings/BiomeOnSaveApplySafeFixesActionInfo.kt @@ -17,6 +17,12 @@ class BiomeOnSaveApplySafeFixesActionInfo(actionOnSaveContext: ActionOnSaveConte override fun getActionOnSaveName() = BiomeBundle.message("biome.run.safe.fixes.on.save.checkbox.on.actions.on.save.page") + override fun isApplicableAccordingToStoredState(): Boolean = + BiomeSettings.getInstance(project).configurationMode != ConfigurationMode.DISABLED + + override fun isApplicableAccordingToUiState(configurable: BiomeConfigurable): Boolean = + !configurable.disabledConfiguration.isSelected + override fun isActionOnSaveEnabledAccordingToStoredState() = BiomeSettings.getInstance(project).applySafeFixesOnSave override fun isActionOnSaveEnabledAccordingToUiState(configurable: BiomeConfigurable) = @@ -27,6 +33,8 @@ class BiomeOnSaveApplySafeFixesActionInfo(actionOnSaveContext: ActionOnSaveConte } override fun getCommentAccordingToUiState(configurable: BiomeConfigurable): ActionOnSaveComment? { + if (!isSaveActionApplicable) return ActionOnSaveComment.info(BiomeBundle.message("biome.on.save.comment.disabled")) + val biomePackage = BiomePackage(project) val version = runWithModalProgressBlocking(project, BiomeBundle.message("biome.version")) { biomePackage.versionNumber() @@ -35,6 +43,8 @@ class BiomeOnSaveApplySafeFixesActionInfo(actionOnSaveContext: ActionOnSaveConte } override fun getCommentAccordingToStoredState(): ActionOnSaveComment? { + if (!isSaveActionApplicable) return ActionOnSaveComment.info(BiomeBundle.message("biome.on.save.comment.disabled")) + val biomePackage = BiomePackage(project) val settings = BiomeSettings.getInstance(project) val version = runWithModalProgressBlocking(project, BiomeBundle.message("biome.version")) { diff --git a/src/main/kotlin/com/github/biomejs/intellijbiome/settings/BiomeOnSaveApplyUnsafeFixesActionInfo.kt b/src/main/kotlin/com/github/biomejs/intellijbiome/settings/BiomeOnSaveApplyUnsafeFixesActionInfo.kt index a162a88..0f36c1a 100644 --- a/src/main/kotlin/com/github/biomejs/intellijbiome/settings/BiomeOnSaveApplyUnsafeFixesActionInfo.kt +++ b/src/main/kotlin/com/github/biomejs/intellijbiome/settings/BiomeOnSaveApplyUnsafeFixesActionInfo.kt @@ -17,6 +17,12 @@ class BiomeOnSaveApplyUnsafeFixesActionInfo(actionOnSaveContext: ActionOnSaveCon override fun getActionOnSaveName() = BiomeBundle.message("biome.run.unsafe.fixes.on.save.checkbox.on.actions.on.save.page") + override fun isApplicableAccordingToStoredState(): Boolean = + BiomeSettings.getInstance(project).configurationMode != ConfigurationMode.DISABLED + + override fun isApplicableAccordingToUiState(configurable: BiomeConfigurable): Boolean = + !configurable.disabledConfiguration.isSelected + override fun isActionOnSaveEnabledAccordingToStoredState() = BiomeSettings.getInstance(project).applyUnsafeFixesOnSave @@ -29,6 +35,8 @@ class BiomeOnSaveApplyUnsafeFixesActionInfo(actionOnSaveContext: ActionOnSaveCon } override fun getCommentAccordingToUiState(configurable: BiomeConfigurable): ActionOnSaveComment? { + if (!isSaveActionApplicable) return ActionOnSaveComment.info(BiomeBundle.message("biome.on.save.comment.disabled")) + val biomePackage = BiomePackage(project) val version = runWithModalProgressBlocking(project, BiomeBundle.message("biome.version")) { biomePackage.versionNumber() @@ -37,6 +45,8 @@ class BiomeOnSaveApplyUnsafeFixesActionInfo(actionOnSaveContext: ActionOnSaveCon } override fun getCommentAccordingToStoredState(): ActionOnSaveComment? { + if (!isSaveActionApplicable) return ActionOnSaveComment.info(BiomeBundle.message("biome.on.save.comment.disabled")) + val biomePackage = BiomePackage(project) val settings = BiomeSettings.getInstance(project) val version = runWithModalProgressBlocking(project, BiomeBundle.message("biome.version")) { diff --git a/src/main/kotlin/com/github/biomejs/intellijbiome/settings/BiomeOnSaveFormatActionInfo.kt b/src/main/kotlin/com/github/biomejs/intellijbiome/settings/BiomeOnSaveFormatActionInfo.kt new file mode 100644 index 0000000..9df03fc --- /dev/null +++ b/src/main/kotlin/com/github/biomejs/intellijbiome/settings/BiomeOnSaveFormatActionInfo.kt @@ -0,0 +1,58 @@ +package com.github.biomejs.intellijbiome.settings + +import com.github.biomejs.intellijbiome.BiomeBundle +import com.github.biomejs.intellijbiome.BiomePackage +import com.intellij.ide.actionsOnSave.ActionOnSaveBackedByOwnConfigurable +import com.intellij.ide.actionsOnSave.ActionOnSaveComment +import com.intellij.ide.actionsOnSave.ActionOnSaveContext +import com.intellij.platform.ide.progress.runWithModalProgressBlocking + +class BiomeOnSaveFormatActionInfo(actionOnSaveContext: ActionOnSaveContext) : + ActionOnSaveBackedByOwnConfigurable( + actionOnSaveContext, + BiomeConfigurable.CONFIGURABLE_ID, + BiomeConfigurable::class.java + ) { + + override fun getActionOnSaveName() = + BiomeBundle.message("biome.run.format.on.save.checkbox.on.actions.on.save.page") + + override fun isApplicableAccordingToStoredState(): Boolean = + BiomeSettings.getInstance(project).configurationMode != ConfigurationMode.DISABLED + + override fun isActionOnSaveEnabledAccordingToStoredState() = BiomeSettings.getInstance(project).formatOnSave + + override fun isApplicableAccordingToUiState(configurable: BiomeConfigurable): Boolean = + !configurable.disabledConfiguration.isSelected + + override fun isActionOnSaveEnabledAccordingToUiState(configurable: BiomeConfigurable) = + configurable.runFormatOnSaveCheckBox.isSelected + + override fun setActionOnSaveEnabled(configurable: BiomeConfigurable, enabled: Boolean) { + configurable.runFormatOnSaveCheckBox.isSelected = enabled + } + + override fun getActionLinks() = listOf(createGoToPageInSettingsLink(BiomeConfigurable.CONFIGURABLE_ID)) + + override fun getCommentAccordingToUiState(configurable: BiomeConfigurable): ActionOnSaveComment? { + if (!isSaveActionApplicable) return ActionOnSaveComment.info(BiomeBundle.message("biome.on.save.comment.disabled")) + + val biomePackage = BiomePackage(project) + val version = runWithModalProgressBlocking(project, BiomeBundle.message("biome.version")) { + biomePackage.versionNumber() + } + return ActionInfo.defaultComment(version, configurable.runForFilesField.text.trim(), isActionOnSaveEnabled) + } + + override fun getCommentAccordingToStoredState(): ActionOnSaveComment? { + if (!isSaveActionApplicable) return ActionOnSaveComment.info(BiomeBundle.message("biome.on.save.comment.disabled")) + + val biomePackage = BiomePackage(project) + val settings = BiomeSettings.getInstance(project) + val version = runWithModalProgressBlocking(project, BiomeBundle.message("biome.version")) { + biomePackage.versionNumber() + } + + return ActionInfo.defaultComment(version, settings.filePattern, isActionOnSaveEnabled) + } +} diff --git a/src/main/kotlin/com/github/biomejs/intellijbiome/settings/BiomeOnSaveInfoProvider.kt b/src/main/kotlin/com/github/biomejs/intellijbiome/settings/BiomeOnSaveInfoProvider.kt index fc8ae4c..a3a7045 100644 --- a/src/main/kotlin/com/github/biomejs/intellijbiome/settings/BiomeOnSaveInfoProvider.kt +++ b/src/main/kotlin/com/github/biomejs/intellijbiome/settings/BiomeOnSaveInfoProvider.kt @@ -8,6 +8,7 @@ import com.intellij.ide.actionsOnSave.ActionOnSaveInfoProvider class BiomeOnSaveInfoProvider : ActionOnSaveInfoProvider() { override fun getActionOnSaveInfos(context: ActionOnSaveContext): List = listOf( + BiomeOnSaveFormatActionInfo(context), BiomeOnSaveApplySafeFixesActionInfo(context), BiomeOnSaveApplyUnsafeFixesActionInfo(context) ) diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 5d05fbc..de5a228 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -49,6 +49,7 @@ +