| <!-- |
| |
| Licensed to the Apache Software Foundation (ASF) under one |
| or more contributor license agreements. See the NOTICE file |
| distributed with this work for additional information |
| regarding copyright ownership. The ASF licenses this file |
| to you under the Apache License, Version 2.0 (the |
| "License"); you may not use this file except in compliance |
| with the License. You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, |
| software distributed under the License is distributed on an |
| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| KIND, either express or implied. See the License for the |
| specific language governing permissions and limitations |
| under the License. |
| |
| --> |
| =How do I define and localise the keymap category of an action?= |
| |
| ==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 <code>@ActionID(category = "MyOwnLabel", id = "com.sample.MyAction")</code> the following layer.xml content is generated |
| <pre> |
| <filesystem> |
| <folder name="Actions"> |
| <folder name="MyOwnLabel"> |
| <!-- action registration follows --> |
| </folder> |
| </folder> |
| </filesystem> |
| </pre> |
| |
| |
| |
| * If you want to localise the category (or include a '/' in its name), then you have to use the attribute "<code>SystemFileSystem.localizingBundle</code>" 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: <code>Actions/MyOwnLabel=Shiny new category</code> |
| |
| '''Example''' |
| The following action is shown in the localised "Shiny new category" category. |
| |
| [[image:keymapshinynewcategory.png]] |
| |
| <pre> |
| 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 |
| } |
| } |
| </pre> |
| Excerpt of layer.xml: |
| <pre> |
| <filesystem> |
| <folder name="Actions"> |
| <folder name="MyOwnLabel"> |
| <attr name="SystemFileSystem.localizingBundle" stringvalue="com.sample.Bundle"/> |
| </folder> |
| </folder> |
| </filesystem> |
| </pre> |
| Bundle: |
| <pre> |
| Actions/MyOwnLabel=Shiny new category |
| </pre> |
| |
| ==Keymap category for @EditorActionRegistration== |
| The category of the @EditorActionRegistration-annotation of the action defines the keymap category (since NB 8.2 {{iz|171261}}) |
| |
| The category is defined the subfolder in "OptionsDialog/Actions". |
| |
| <pre> |
| @EditorActionRegistrations({ |
| @EditorActionRegistration(name = "add-caret-up", category = "edit.multicaret") |
| }) |
| public class AddCaretAction extends ... { |
| } |
| </pre> |
| Excerpt of layer.xml: |
| <pre> |
| <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> |
| </pre> |
| Bundle: |
| <pre> |
| OptionsDialog/Actions/edit.multicaret=Edit (Multicaret) |
| </pre> |
| |
| [[File:EditorActionRegistrationKeymapCategory.png]] |
| |
| ==Other resources== |
| * http://blogs.kiyut.com/tonny/2007/08/04/netbeans-platform-i18n-and-localization/ |
| |
| ===Apache Migration Information=== |
| |
| 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. |
| |