blob: 3d36b6827c9ea856ced6acbb6f9dd43f6d771d0d [file] [log] [blame]
//
// 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.
//
= DevFaqHowToDefineTheKeyMapCategoryForAnAction
:jbake-type: wiki
:jbake-tags: wiki, devfaq, needsreview
:jbake-status: published
:keywords: Apache NetBeans wiki DevFaqHowToDefineTheKeyMapCategoryForAnAction
:description: Apache NetBeans wiki DevFaqHowToDefineTheKeyMapCategoryForAnAction
:toc: left
:toc-title:
:syntax: true
= 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 `@ActionID(category = "MyOwnLabel", id = "com.sample.MyAction")` the following layer.xml content is generated
[source,xml]
----
<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.
image:keymapshinynewcategory.png[]
[source,java]
----
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:
[source,xml]
----
<filesystem>
<folder name="Actions">
<folder name="MyOwnLabel">
<attr name="SystemFileSystem.localizingBundle" stringvalue="com.sample.Bundle"/>
</folder>
</folder>
</filesystem>
----
Bundle:
[source,java]
----
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".
[source,java]
----
@EditorActionRegistrations({
@EditorActionRegistration(name = "add-caret-up", category = "edit.multicaret")
})
public class AddCaretAction extends ... {
}
----
Excerpt of layer.xml:
[source,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:
[source,java]
----
OptionsDialog/Actions/edit.multicaret=Edit (Multicaret)
----
image:EditorActionRegistrationKeymapCategory.png[]
== Other resources
* link:http://blogs.kiyut.com/tonny/2007/08/04/netbeans-platform-i18n-and-localization/[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 link:http://wiki.netbeans.org/DevFaqHowToDefineTheKeyMapCategoryForAnAction[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-02-07, and needs to be reviewed.