Can I modify `*.groovy` file icon when certain criteria are met?
Hello there.
I've been trying hard the whole day today to figure out a solution to my use case. No luck, that's why I'm asking the community here.
I am developing a plugin that adds inspections, templates and other stuff to support the Spock framework.
The plugin operates over Groovy files as Spock specifications are Groovy classes that extend the spock.lang.Specification
class.
I wanted to change the standard Groovy file icons in the Project view to my plugin's icon only in case a Groovy class extends the spock.lang.Specification
.
Is there a way to achieve that? A similar thing works for XML files where a Maven
icon and validation rules are used for pom.xml
. Another example is yaml
files vs. application.yml
that gets a Spring
icon.
Registering a new fileType
in the plugin.xml
overrides icons for all Groovy files. Registering a fileTypeDetector
did nothing - the type detector was only called for gradlew
and a few other files, but never for a *.groovy
file.
I am out of ideas :( Any help would be greatly appreciated.
Please sign in to leave a comment.
Hej Pavel,
I think the IconProvider extension point (com.intellij.iconProvider) might be what you are looking for.
Hey Marco. Oh My God, you're a lifesaver.
This was literally a one-liner Kotlin function since there is a function to detect Spock Specifications in the Groovy plugin. Thanks so much!!
For future reference, this is how it looks:
Don't you, by any chance, know if I can do something similar with File templates?
For instance, I have a
Spock Specification.groovy.ft
defined, but the template uses the Groovy icon in the Settings.The only way I've found is to register my own
spock
fileType
. This seems like an overkill though, since the plugin does not need its own type. Moreover, any file with aspock
extension would get the Spock icon, which I do not want because such files are not valid Specifications anyway and the Spock framework will fail to execute them.Hej Pavel,
great, I am glad that it works for you and that I could help.
I am not sure about the file template icon issue. My assumption is that it is simply derived from the ‘base type’ (inferred from the file extension specified for the file template). Thus, I too would think it would need a dedicated file type.
Thanks anyway, Marco. Will stick with the custom file type workaround for now.
Have a wonderful Christmas!
You are welcome, Pavel.
Have a wonderful Christmas too and a good start into 2024 (it can only get better, I guess ;-).
Hi Pavel,
Marco is right. The icon is determined based on the file type.
I think that changing the file type is an overkill in your case, and I suggest requesting a File Templates improvement that allows for defining custom icons: https://youtrack.jetbrains.com/issues/IDEA
Hi Karol,
Thanks for confirming.
I too think the custom type is an overkill. However, it is the only option so I have used it for now as a workaround. Anyway, will request an improvement as per your suggestion. Thanks!
Just for the record, this is the issue I created: https://youtrack.jetbrains.com/issue/IDEA-342024/Custom-icons-for-File-templates-in-plugins