How to hide/disable menu when the corresponding plugin is not used?
Hi
I have written a plugin for generating KDoc for Kotlin files in IntelliJ IDEA. I have registered actions in plugin.xml.
The actual problem is, this menu will show every NOT KOTLIN projects. I only need it in Kotlin or Kotlin configured projects.
The action is in Code generation menu. But this will show in every file. If I am using a Java project or Flutter project, this menu will show.
How to hide the menu If the project is not configured Kotlin, or selected file is not a Kotlin file?
I will attach the plugin.xml
Thanks in advance
<idea-plugin>
<extensions defaultExtensionNs="com.intellij">
<!-- Add your extensions here -->
<enterHandlerDelegate implementation="com.kdocer.EnterAfterKDocGenHandler" order="first"/>
<applicationService serviceImplementation="com.kdocer.service.KDecerAppService"/>
<applicationService serviceImplementation="com.kdocer.service.KDocerSettings"/>
<applicationConfigurable parentId="tools" instance="com.kdocer.service.KDocerConfigurable"
id="com.kdocer.service.KDocerConfigurable"
displayName="KDoc-er"/>
<enterHandlerDelegate implementation="com.kdocer.EnterAfterKDocGenHandler" order="first"/>
</extensions>
<actions>
<group id="KDo-cer-format-menu" text="_KDoc-er" description="Generate KDocs" popup="true">
<action id="KDo-cer-format-menu-all-add"
class="com.kdocer.action.KDocerAllGenAction"
text="Create KDocs for All Elements"
description="Generate KDocs for all elements in the current Kotlin file.">
</action>
<action id="KDo-cer-format-menu-add"
class="com.kdocer.action.KDocerGenAction"
text="Create KDoc for Element"
description="Generate KDoc for all elements in the current Kotlin file.">
</action>
<action id="KDo-cer-format-menu-remove"
class="com.kdocer.action.KDocerRemoveAction"
text="Remove KDoc for Element"
description="Remove KDoc">
</action>
<action id="KDo-cer-format-menu-all-remove"
class="com.kdocer.action.KDocerAllRemoveAction"
text="Remove KDocs for All Elements"
description="Remove KDocs">
</action>
<add-to-group group-id="CodeFormatGroup" anchor="last"/>
<add-to-group group-id="ProjectViewPopupMenuModifyGroup" anchor="last"/>
</group>
<group id="KDo-cer-menu" text="_KDoc-er" description="Generate KDocs" popup="true">
<action id="KDo-cer-menu-all-add"
class="com.kdocer.action.KDocerAllGenAction"
text="Create KDocs for All Elements"
description="Generate Kdocs for all elements in the current Kotlin file.">
</action>
<action id="KDo-cer-menu-add"
class="com.kdocer.action.KDocerGenAction"
text="Create KDoc for Element"
description="Generate Kdoc for current element.">
</action>
<action id="KDo-cer-menu-remove"
class="com.kdocer.action.KDocerRemoveAction"
text="Remove KDoc for Element"
description="Remove KDoc">
</action>
<action id="KDo-cer-menu-all-remove"
class="com.kdocer.action.KDocerAllRemoveAction"
text="Remove KDocs for All Elements"
description="Remove KDocs">
</action>
<add-to-group group-id="GenerateGroup" anchor="last"/>
<add-to-group group-id="ProjectViewPopupMenuModifyGroup" anchor="last"/>
</group>
</actions>
</idea-plugin>
Please sign in to leave a comment.
1) You can add a required dependency on Kotlin plugin, so it won't be installed "accidentally" by users not having Kotlin plugin enabled at all https://jetbrains.org/intellij/sdk/docs/basics/plugin_structure/plugin_dependencies.html#configuring-pluginxml
2) You need to override update() method to reflect Action's status/visibility https://jetbrains.org/intellij/sdk/docs/tutorials/action_system/working_with_custom_actions.html#extending-the-update-method