Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: plugin defects, exception class logic & add visibility icons #116

Merged
merged 13 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@

### Changed

- Load Java Support optionally ([#116](https://github.com/catppuccin/jetbrains-icons/pull/116))

### Deprecated

### Removed

### Fixed

- Visibility Icons for Java Files in the structure view are not hidden anymore ([#116](https://github.com/catppuccin/jetbrains-icons/pull/116))

### Security

## 1.8.0 - 2024-09-13
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
package com.github.catppuccin.jetbrains_icons

import com.github.catppuccin.jetbrains_icons.settings.PluginSettingsState
import com.github.catppuccin.jetbrains_icons.util.PsiClassUtils
import com.intellij.ide.IconProvider
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiClass
import com.intellij.psi.PsiFile
import com.intellij.psi.PsiManager
import com.intellij.psi.JavaRecursiveElementVisitor
import com.intellij.psi.util.PsiUtilCore
import javax.swing.Icon

Expand All @@ -16,18 +11,22 @@ class IconProvider : IconProvider() {

private val fileTypes = mapOf(
"Dockerfile" to icons.docker,
) + provideJavaIcons()
)

override fun getIcon(element: PsiElement, flags: Int): Icon {
override fun getIcon(element: PsiElement, flags: Int): Icon? {
val virtualFile = PsiUtilCore.getVirtualFile(element)

// File types
if (virtualFile != null) {
val file = PsiManager.getInstance(element.project).findFile(virtualFile)
if (file != null) {
val fileType = when {
file.name.endsWith(".java") -> determineJavaFileType(file)
else -> file.fileType.name
file.name.endsWith(".java") -> {
return null
}
else -> {
file.fileType.name
}
}
val icon = fileTypes[fileType]
if (icon != null) {
Expand Down Expand Up @@ -67,38 +66,4 @@ class IconProvider : IconProvider() {
return icons._file
}


private fun determineJavaFileType(file: PsiFile): String {
var fileType = "JAVA_CLASS"
if (!PluginSettingsState.instance.javaSupport) return fileType
file.accept(object : JavaRecursiveElementVisitor() {
override fun visitClass(aClass: PsiClass) {
when {
aClass.isAnnotationType -> fileType = "JAVA_ANNOTATION"
aClass.isInterface -> fileType = "JAVA_INTERFACE"
aClass.isEnum -> fileType = "JAVA_ENUM"
aClass.isRecord -> fileType = "JAVA_RECORD"
PsiClassUtils.isException(aClass) -> fileType = "JAVA_EXCEPTION"
PsiClassUtils.isSealed(aClass) -> fileType = "JAVA_SEALED"
PsiClassUtils.isFinal(aClass) -> fileType = "JAVA_FINAL"
PsiClassUtils.isAbstract(aClass) -> fileType = "JAVA_ABSTRACT"
}
}
})
return fileType
}

private fun provideJavaIcons(): Map<String, Icon> {
return mapOf(
"JAVA_ANNOTATION" to icons.java_annotation,
"JAVA_INTERFACE" to icons.java_interface,
"JAVA_ENUM" to icons.java_enum,
"JAVA_RECORD" to icons.java_record,
"JAVA_EXCEPTION" to icons.java_exception,
"JAVA_ABSTRACT" to icons.java_class_abstract,
"JAVA_SEALED" to icons.java_class_sealed,
"JAVA_FINAL" to icons.java_class_final,
"JAVA_CLASS" to icons.java_class,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.github.catppuccin.jetbrains_icons.providers

import com.github.catppuccin.jetbrains_icons.IconPack
import com.github.catppuccin.jetbrains_icons.settings.PluginSettingsState
import com.github.catppuccin.jetbrains_icons.util.PsiClassUtils
import com.intellij.ide.IconProvider
import com.intellij.psi.*
import com.intellij.psi.util.PsiUtilCore
import javax.swing.Icon

class JavaIconProvider : IconProvider() {
private val icons = IconPack.instance.icons
private val javaIcons = mapOf(
"JAVA_INTERFACE" to icons.java_interface,
"JAVA_ENUM" to icons.java_enum,
"JAVA_ANNOTATION" to icons.java_annotation,
"JAVA_RECORD" to icons.java_record,
"JAVA_EXCEPTION" to icons.java_exception,
"JAVA_ABSTRACT" to icons.java_class_abstract,
"JAVA_SEALED" to icons.java_class_sealed,
"JAVA_FINAL" to icons.java_class_final,
"JAVA_CLASS" to icons.java_class,
)

override fun getIcon(element: PsiElement, flags: Int): Icon? {
if (!PluginSettingsState.instance.javaSupport) return icons.java

if (element !is PsiClass) return null

val virtualFile = PsiUtilCore.getVirtualFile(element) ?: return null
if (!virtualFile.name.endsWith(".java")) return null

return javaIcons[determineJavaFileType(element)]
}

private fun determineJavaFileType(aClass: PsiClass): String = when {
aClass.isAnnotationType -> "JAVA_ANNOTATION"
aClass.isInterface -> "JAVA_INTERFACE"
aClass.isEnum -> "JAVA_ENUM"
aClass.isRecord -> "JAVA_RECORD"
PsiClassUtils.isException(aClass) -> "JAVA_EXCEPTION"
PsiClassUtils.isSealed(aClass) -> "JAVA_SEALED"
PsiClassUtils.isFinal(aClass) -> "JAVA_FINAL"
PsiClassUtils.isAbstract(aClass) -> "JAVA_ABSTRACT"
else -> "JAVA_CLASS"
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.github.catppuccin.jetbrains_icons.settings

import com.intellij.ide.plugins.PluginManager.*
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.PersistentStateComponent
import com.intellij.openapi.components.State
import com.intellij.openapi.components.Storage
import com.intellij.openapi.extensions.PluginId.findId
import com.intellij.util.xmlb.XmlSerializerUtil

@State(
Expand All @@ -14,7 +16,7 @@ class PluginSettingsState : PersistentStateComponent<PluginSettingsState> {
var variant = Variant.MOCHA.id

var pythonSupport = true
var javaSupport = true
var javaSupport = isPluginInstalled(findId("com.intellij.java"))

companion object {
val instance: PluginSettingsState
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package com.github.catppuccin.jetbrains_icons.settings.views

import com.github.catppuccin.jetbrains_icons.settings.PluginSettingsState
import com.intellij.ide.plugins.PluginManager.isPluginInstalled
import com.intellij.openapi.extensions.PluginId.*
import com.intellij.ui.components.JBCheckBox
import com.intellij.util.ui.FormBuilder
import java.awt.FlowLayout
import javax.swing.JPanel

class SettingsAdditionalSupportView : JPanel() {
val python = JBCheckBox("Python", PluginSettingsState.instance.pythonSupport)
val java = JBCheckBox("Java Filetypes", PluginSettingsState.instance.javaSupport)
val java = JBCheckBox("Java Filetypes", PluginSettingsState.instance.javaSupport).apply {
isEnabled = isPluginInstalled(findId("com.intellij.java"))
}

init {
val form = FormBuilder.createFormBuilder()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<idea-plugin>
<extensions defaultExtensionNs="com.intellij">
<iconProvider
implementation="com.github.catppuccin.jetbrains_icons.providers.JavaIconProvider"
order="first"
id="JavaIconProvider"
/>
</extensions>
</idea-plugin>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<idea-plugin>
</idea-plugin>
4 changes: 2 additions & 2 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ For further help, see also:
<p>LICENSE: <a href="https://github.com/catppuccin/jetbrains-icons/blob/main/LICENSE">MIT</a></p>
]]></description>
<depends>com.intellij.modules.platform</depends>
<depends optional="true">org.jetbrains.kotlin</depends>
<depends optional="true">com.intellij.java</depends>
<depends optional="true" config-file="com.github.catppuccin.jetbrains_icons-withKotlin.xml">org.jetbrains.kotlin</depends>
<depends optional="true" config-file="com.github.catppuccin.jetbrains_icons-withJava.xml">com.intellij.java</depends>
<extensions defaultExtensionNs="com.intellij">
<iconProvider
implementation="com.github.catppuccin.jetbrains_icons.IconProvider"
Expand Down