--- openide.awt/apichanges.xml +++ openide.awt/apichanges.xml @@ -50,6 +50,21 @@ AWT API + + + New attributes (popupText, menuText) in @ActionRegistration annotation + + + + + +

+ New annotation to register references to actions from layer. +

+
+ + +
New @ActionReference annotations --- openide.awt/src/org/netbeans/modules/openide/awt/ActionProcessor.java +++ openide.awt/src/org/netbeans/modules/openide/awt/ActionProcessor.java @@ -191,6 +191,16 @@ File f = layer(e).file("Actions/" + aid.category() + "/" + id + ".instance"); f.bundlevalue("displayName", ar.displayName()); + String menuText = ar.menuText(); + if(!menuText.isEmpty()) { + f.bundlevalue("menuText", menuText); + } + + String popupText = ar.popupText(); + if (!popupText.isEmpty()) { + f.bundlevalue("popupText", popupText); + } + String key; boolean createDelegate = true; if (e.getKind() == ElementKind.FIELD) { --- openide.awt/src/org/openide/awt/ActionRegistration.java +++ openide.awt/src/org/openide/awt/ActionRegistration.java @@ -65,6 +65,30 @@ * @return display name for the action */ String displayName(); + + /** + * Provides the text if one wants to use other text in a JMenuItem than + * the name of the action taken from Action.NAME. Takes precedence + * over standard Action.NAME. + * + * @return display name for the action + * + * @see Actions#connect(javax.swing.JMenuItem, javax.swing.Action, boolean) + * @since 7.29 + */ + String menuText() default ""; + + /** + * Provides the text if one wants to use other text in a JMenuItem popup + * than the name of the action taken from Action.NAME. + * + * @return display name for the action in a popup menu + * + * @see Actions#connect(javax.swing.JMenuItem, javax.swing.Action, boolean) + * @since 7.29 + */ + String popupText() default ""; + /** Path to image representing the action's icon. * @return "org/myproject/mypkg/Icon.png" */ --- openide.awt/test/unit/src/org/netbeans/modules/openide/awt/ActionProcessorTest.java +++ openide.awt/test/unit/src/org/netbeans/modules/openide/awt/ActionProcessorTest.java @@ -58,11 +58,13 @@ import javax.swing.AbstractAction; import javax.swing.Action; import javax.swing.ActionMap; +import javax.swing.JButton; import javax.swing.JSeparator; import org.netbeans.junit.NbTestCase; import org.openide.awt.ActionReference; import org.openide.awt.ActionReferences; import org.openide.awt.ActionRegistration; +import org.openide.awt.Actions; import org.openide.awt.DynamicMenuContent; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; @@ -594,6 +596,37 @@ return null; } } + + @ActionID(category="menutext", id="namedaction") + @ActionRegistration(displayName="This is an Action", menuText="This is a Menu Action", popupText="This is a Popup Action") + public static class NamedAction extends AbstractAction { + public NamedAction() { } + @Override + public void actionPerformed(ActionEvent e) { } + } + + public void testPopupText() throws Exception { + FileObject fo = FileUtil.getConfigFile("Actions/menutext/namedaction.instance"); + assertNotNull("Instance found", fo); + Object obj = fo.getAttribute("instanceCreate"); + assertNotNull("Action created", obj); + + JMenuItem item = new JMenuItem(); + Actions.connect(item, (Action) obj, true ); + assertEquals( "This is a Popup Action", item.getText() ); + } + + public void testMenuText() throws Exception { + FileObject fo = FileUtil.getConfigFile("Actions/menutext/namedaction.instance"); + assertNotNull("Instance found", fo); + Object obj = fo.getAttribute("instanceCreate"); + assertNotNull("Action created", obj); + + JMenuItem item = new JMenuItem(); + Actions.connect(item, (Action) obj, false ); + assertEquals( "This is a Menu Action", item.getText() ); + } + public void testDirectInstanceIfImplementsMenuPresenter() throws Exception { FileObject fo = FileUtil.getConfigFile("Actions/eager/direct-one.instance"); assertNotNull("Instance found", fo);