How to optionally add an action to a group?

Hi all,

I need to add my action to a group which is not available all the time (some IDEA installations define this group; some don't).

If I define action this way

<action id="MyAction" text="...">
    <add-to-group group-id="MainToolBar" anchor="last"/>
    <add-to-group group-id="AnotherGroup" anchor="last"/>
    ...
</action>

then, if the group is not defined, IDEA dumps exception (ERROR - nSystem.impl.ActionManagerImpl - ... group with id "AnotherGroup" isn't registered; action will be added to the "Other" group..." + the stacktrace.


How can I specify that this "add-to-group" is optional (suppress the error; and only add the action to existing groups)?



Or, is there a way to create optional sections in the plugin.xml file, e.g.

<if configuration1>
    <action id="MyAction" text="...">
        <add-to-group group-id="MainToolBar" anchor="last"/>
        <add-to-group group-id="AnotherGroup" anchor="last"/>
    </action>
</if>
<if configuration2>
    <action id="MyAction" text="...">
        <add-to-group group-id="MainToolBar" anchor="last"/>
    </action>
</if>

where "configuration1" = some predicate to check idea version, Ultimate/Community, or the fact that specific plugin has specific version.


thanks
Sergey

7 comments
Comment actions Permalink

"some IDEA installations define this group; some don't)"

What exactly is the criteria whether this group is available or not?

a) Community vs ultimate edition?
b) installed plugin?

These criteria could be matched for a) providing two versions of plugin  b) registering action in additional plugin descriptor referenced via <depends optional="true" ... /> in your plugin.xml with ID of required (additional) plugin

0
Comment actions Permalink

One of such groups is "NavToolBarOthers" which ~replaces "MainToolBar" in IDEA 13. I.e. when plugin is installed into IDEA 12, action should be added into "MainToolBar", but if it's IDEA 13, action should be added to "NavToolBarOthers" as well.

Is there a way to specify IDEA version in "depends" condition; somehow like this:

<depends optional="true" config-file="myextraconfig.xml">IDEA 13+</depends>

thanks.

0
Comment actions Permalink

Perhaps one of new IDEA plugins can be used as a guard, e.g.

<depends ...>org.jetbrains.plugins.terminal</depends>;

but it looks like a dirty hack.

0
Comment actions Permalink

The correct way is to provide two distinct versions (read: just "patched" plugin.xml) of your plugin with corresponding build number ranges targeting the major versions, see http://confluence.jetbrains.com/display/IDEADEV/Build+Number+Ranges

0
Comment actions Permalink

Thanks for the link and for the advice.

Is there a way to keep two "patched" plugin.xml files within one plugin jar?

Or, is it possible to provide two jar files with plugin.xml inside:

idea/plugins/
   MyPlugin/
       lib/
           pluginjar1.jar (with plugin.xml #1 - <idea-version since-build="0" until-build="132.999999"/>)
           pluginjar2.jar (with plugin.xml #2 - <idea-version since-build="133.0"/>)
           lib.jar
           lib2.jar,...

0
Comment actions Permalink

No and No (AFAIK)


0

Please sign in to leave a comment.