Download NetBeans!

20050602 Thursday June 02, 2005

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>

Jun 02 2005, 01:14:40 AM PDT Permalink

Trackback URL: http://blogs.sun.com/geertjan/entry/adding_items_to_existing_popup
Comments:

Post a Comment:

Name:
E-Mail:
URL:

Your Comment:

HTML Syntax: NOT allowed