Adding Items to Existing Popup Menus and Editors in NetBeans IDE 4.1

There's a great mailing list for anyone interested in learning about and contributing to NetBeans Modules. Its address is dev@openide.netbeans.org. Yesterday I found out two new cool things -- how to add a menu item to an existing popup menu or editor. Previously, I only knew how to create a data loader that recognizes a file object and assigns menu items to it. But what about if your file object is already recognized and you just want to add some menu items to its existing popup menu? Or what if you want to add a menu item to an editor's popup menu? Everything you need to do, apart from actually creating the Action class (subclassing CallableSystemAction) that defines the menu item, is done in the layer.xml file:

<folder name="Editors">
    <folder name="text">
      <folder name="x-java">
         <folder name="Popup">
             <file name="org-netbeans-modules-mymodule-MyAction.instance"/>
         </folder>
      </folder>
    </folder>
</folder>

By the way, even though the documentation always refers to something called the 'Source Editor', there are in fact several editors. The above entry in the layer.xml would only affect the Java editor. For other editors, replace the x-java above with one of the following values:

  • plain
  • html
  • xml
  • x-properties
  • x-jsp

There are also others, the above is just a random subset.

And, to add a menu item to the Java file object's popup menu, add the following to the layer.xml file:

<folder name="Loaders">
    <folder name="text">
      <folder name="x-java">
         <folder name="Actions">
             <file name="org-netbeans-modules-mymodule-MyAction.instance"/>
         </folder>
      </folder>
    </folder>
</folder>

Comments:

Hey Geertjan,awesome article!
I wish to understand more because I am developing an application that will
need to use a Popup menu that is generated by a mouse hover action.
Could you get in touch via email?
Thanks

Posted by Kelvin Nkinyili on July 03, 2011 at 11:54 PM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
24
25
26
27
28
29
30
   
       
Today