How to add items to a tab context menu?

Hi all,

I want to add a menu item to the context path of specific files (in this case, Markdown files). How can I do this? Any samples available?

Thanks,

Erik

7 comments
Comment actions Permalink

There are a lot of examples in IntelliJ IDEA Community source code and opensource plugins.
For example actions from the Dart plugin that work only for files named pubspec.yaml:

<group>
  <action id="Dart.pub.get" class="com.jetbrains.lang.dart.ide.actions.DartPubGetAction" text="Pub: Get Dependencies" description="Run 'pub get'"/>
  <action id="Dart.pub.upgrade" class="com.jetbrains.lang.dart.ide.actions.DartPubUpgradeAction" text="Pub: Upgrade Dependencies" description="Run 'pub upgrade'"/>
  <action id="Dart.pub.build" class="com.jetbrains.lang.dart.ide.actions.DartPubBuildAction" text="Pub: Build..." description="Run 'pub build'"/>
  <separator/>
  <add-to-group group-id="EditorPopupMenu" anchor="first"/>
  <add-to-group group-id="ProjectViewPopupMenu" relative-to-action="CutCopyPasteGroup" anchor="before"/>
</group>


Make sure to make the action invisible for all files except the ones the action is valid for: implement updateAction() in your action class accordingly

0
Comment actions Permalink

Hi Alexander, thanks for the reply.

For sure there plugins which do it, but how do I find these plugins? Eg, I've never installed the Dart plugin before, I didn't know it had this menu.

Question: why are there 3 actions, then a separator, and then add-to-groups? I only want to display it when right-clicking on a file. Do I only need an action for that, or do I also need it to some group?

0
Comment actions Permalink

You'll probably have only one action. Separator - as you like. Add to group - yes, you need it. One adds to editor popup, the other one - to the context menu in Project View. Skip the latter if you want.

0
Comment actions Permalink

Yes, follow 'IntelliJ IDEA Action System' link on the first page that you mentioned.

0
Comment actions Permalink

You even can do without parent group tag, just add add-to-group tag as action tag child.

0
Comment actions Permalink

Ah, thanks. I actually read that page, but it wasn't clear to me how I could add context menu items based on that information. After re-reading it, it's still not clear to me, but your example is, so I'm sure I'll work something out. Thanks for the pointer!

0

Please sign in to leave a comment.