-
Notifications
You must be signed in to change notification settings - Fork 1
DevFaqHowToDefineTheKeyMapCategoryForAnAction
-
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.
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
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)
The content in this page was kindly donated by Oracle Corp. to the Apache Software Foundation.
This page was exported from http://wiki.netbeans.org/DevFaqHowToDefineTheKeyMapCategoryForAnAction , that was last modified by NetBeans user Markiewb on 2016-07-21T20:58:18Z.
NOTE: This document was automatically converted to the AsciiDoc format on 2018-01-26, and needs to be reviewed.
Apache NetBeans is an effort undergoing incubation at The Apache Software Foundation (ASF).
Incubation is required of all newly accepted projects until a further review indicates that the infrastructure, communications, and decision making process have stabilized in a manner consistent with other successful ASF projects.
While incubation status is not necessarily a reflection of the completeness or stability of the code, it does indicate that the project has yet to be fully endorsed by the ASF.
This wiki is an experiment pending Apache NetBeans Community approval.