How do I define and localise the keymap category of an action?

Apache NetBeans Wiki Index

Note: These pages are being reviewed.

Keymap category for @ActionID

  • The category of the @ActionID-annotation of the action defines the keymap category, which is shown in the keymap options. The category is the name of the "Actions"-subfolder within the layer.xml, which is generated from the annotations. From @ActionID(category = "MyOwnLabel", id = "com.sample.MyAction") the following layer.xml content is generated

<filesystem>
    <folder name="Actions">
        <folder name="MyOwnLabel">
            <!-- action registration follows -->
        </folder>
    </folder>
</filesystem>
  • If you want to localise the category (or include a '/' in its name), then you have to use the attribute “SystemFileSystem.localizingBundle” for the folder. Create a layer.xml (via wizard), duplicate the folder structure and add the attribute for localisation. This explicit layer.xml file and the autogenerated layer.xml-file will be merged automatically. The referred bundle key is an absolute path based on the folder structure. For example: Actions/MyOwnLabel=Shiny new category

Example The following action is shown in the localised "Shiny new category" category.

keymapshinynewcategory

package com.sample;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import org.openide.awt.ActionID;
import org.openide.awt.ActionRegistration;
import org.openide.util.NbBundle.Messages;

@ActionID(
        category = "MyOwnLabel",
        id = "com.sample.MyAction"
)
@ActionRegistration(
        displayName = "#CTL_MyAction"
)
@Messages("CTL_MyAction=Execute xyz")
public final class MyAction implements ActionListener {

    @Override
    public void actionPerformed(ActionEvent e) {
        // TODO implement action body
    }
}

Excerpt of layer.xml:

<filesystem>
    <folder name="Actions">
        <folder name="MyOwnLabel">
            <attr name="SystemFileSystem.localizingBundle" stringvalue="com.sample.Bundle"/>
        </folder>
    </folder>
</filesystem>

Bundle:

Actions/MyOwnLabel=Shiny new category

Keymap category for @EditorActionRegistration

The category of the @EditorActionRegistration-annotation of the action defines the keymap category (since NB 8.2 )

The category is defined the subfolder in "OptionsDialog/Actions".

@EditorActionRegistrations({
    @EditorActionRegistration(name = "add-caret-up", category = "edit.multicaret")
})
public class AddCaretAction extends ... {
}

Excerpt of layer.xml:

<filesystem>
    <folder name="OptionsDialog">
        <folder name="Actions">
            <folder name="edit.multicaret">
                <attr name="SystemFileSystem.localizingBundle" stringvalue="org.netbeans.modules.editor.actions.Bundle"/>

                <file name="add-caret-up">
                    <!--org.netbeans.modules.editor.actions.AddCaretAction-->
                </file>
            </folder>
        </folder>
    </folder>
</filesystem>

Bundle:

OptionsDialog/Actions/edit.multicaret=Edit (Multicaret)

EditorActionRegistrationKeymapCategory