Adding an menu item in the context menu when right clicked on a file

Answered

Hi ,

We are working on an internal plugin in which i would like to add a menu item to the context menu that get populated when you right click on the file.  Below is the snapshot when i right clicked on a file. I was able to add it in the Popup menu when you click within the editor but was not able to get it on the popup menu that gets created on right click of a file. Any help would be deeply appreciated 

 

0
4 comments

Hi Vikram,

Add your action to the ProjectViewPopupMenu, e.g.:

<action class="com.example.MyAction">
      <add-to-group group-id="ProjectViewPopupMenu"/>
</action>
2

Hi,

It can be done:

  • programmatically - you can extend com.intellij.openapi.actionSystem.DefaultActionGroup and use addSeparator().

  • in plugin.xml by creating a wrapper group:
<group id="my_group" popup="true" text="MyGroup"></group>

<action id="a" class="A">
    <add-to-group group-id="my_group"/>
</action>

<action id="B" class="B">
    <add-to-group group-id="my_group"/>
</action>

<group id="wrapper">
    <reference ref="my_group"/>
    <separator/>
    <add-to-group group-id="ProjectViewPopupMenu" anchor="..." relative-to-action="..."/>
</group>
1

Karol Lewandowski Thanks for the help i was able to add a group to "ProjectViewPopupMenu", I needed one more help I needed to add a Separator between my group ie "Polaris Help" and Create Gist. I was able to add the separator between action that are present in the group but i am not sure how to add a Separator between my group and other groups

Need Separator after polaris help

 

My group section in pulgin.xml

<group text="Polaris Help" id="Polaris.HELP" icon="CVEIcons.POLARIS_ICON" popup="true">
<add-to-group group-id="EditorPopupMenu"/>
<add-to-group group-id="ProjectViewPopupMenu"/>
<separator/>
</group>

<action id="some id"
class="Some class"
text="Action 1">
<add-to-group group-id="Polaris.HELP" anchor="last"/>
</action>
<action id="some other id"
class="Some other class"
text="Action 2">
<add-to-group group-id="Polaris.HELP" anchor="first"/>
</action>
0

Karol Lewandowski Useful, but the <separator/> should in my_group, or it will not appear in ProjectViewPopupMenu.

0

Please sign in to leave a comment.