From 6ca1e2f44ef24bac6e8657889be3e00d195be76e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Quentin=20Guid=C3=A9e?= Date: Sat, 24 Feb 2024 21:30:33 -0500 Subject: [PATCH] refactor: unified Icons instance --- .../com/github/catppuccin/jetbrains_icons/IconPack.kt | 11 +++++++++++ .../github/catppuccin/jetbrains_icons/IconProvider.kt | 2 +- .../decorators/PythonProjectViewNodeDecorator.kt | 11 +++++------ 3 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 src/main/kotlin/com/github/catppuccin/jetbrains_icons/IconPack.kt diff --git a/src/main/kotlin/com/github/catppuccin/jetbrains_icons/IconPack.kt b/src/main/kotlin/com/github/catppuccin/jetbrains_icons/IconPack.kt new file mode 100644 index 0000000..067cd91 --- /dev/null +++ b/src/main/kotlin/com/github/catppuccin/jetbrains_icons/IconPack.kt @@ -0,0 +1,11 @@ +package com.github.catppuccin.jetbrains_icons + +import com.github.catppuccin.jetbrains_icons.settings.PluginSettingsState + +class IconPack { + val icons = Icons(PluginSettingsState.instance.variant) + + companion object { + val instance = IconPack() + } +} diff --git a/src/main/kotlin/com/github/catppuccin/jetbrains_icons/IconProvider.kt b/src/main/kotlin/com/github/catppuccin/jetbrains_icons/IconProvider.kt index 3b7f3d1..8f784b8 100644 --- a/src/main/kotlin/com/github/catppuccin/jetbrains_icons/IconProvider.kt +++ b/src/main/kotlin/com/github/catppuccin/jetbrains_icons/IconProvider.kt @@ -7,7 +7,7 @@ import com.intellij.psi.util.PsiUtilCore import javax.swing.Icon class IconProvider : IconProvider() { - private var icons = Icons(PluginSettingsState.instance.variant) + private var icons = IconPack.instance.icons override fun getIcon(element: PsiElement, flags: Int): Icon { val file = PsiUtilCore.getVirtualFile(element) diff --git a/src/main/kotlin/com/github/catppuccin/jetbrains_icons/decorators/PythonProjectViewNodeDecorator.kt b/src/main/kotlin/com/github/catppuccin/jetbrains_icons/decorators/PythonProjectViewNodeDecorator.kt index 1d05b36..0a74211 100644 --- a/src/main/kotlin/com/github/catppuccin/jetbrains_icons/decorators/PythonProjectViewNodeDecorator.kt +++ b/src/main/kotlin/com/github/catppuccin/jetbrains_icons/decorators/PythonProjectViewNodeDecorator.kt @@ -1,19 +1,18 @@ package com.github.catppuccin.jetbrains_icons.decorators -import com.github.catppuccin.jetbrains_icons.Icons -import com.github.catppuccin.jetbrains_icons.settings.PluginSettingsState +import com.github.catppuccin.jetbrains_icons.IconPack import com.intellij.ide.projectView.ProjectViewNode import com.intellij.ide.projectView.PresentationData import com.intellij.ide.projectView.ProjectViewNodeDecorator class PythonProjectViewNodeDecorator : ProjectViewNodeDecorator { - private var icons = Icons(PluginSettingsState.instance.variant) + private var icons = IconPack.instance.icons override fun decorate(node: ProjectViewNode<*>, data: PresentationData) { - val fileType = node.virtualFile?.name?.split(".")?.last() + val extension = node.virtualFile?.name?.split(".")?.last() - if (fileType.equals("py")) { - data.setIcon(icons.EXT_TO_ICONS["py"]) + if (extension.equals("py")) { + data.setIcon(icons.EXT_TO_ICONS[extension]) } } }