PDA

View Full Version : Accelerators for NativeMenuItem



iDave
17 Jul 2008, 12:34 PM
Since, the Ext air api, doesn't allow to set an accelerator or "keyEquivalent" (in air language), I've added just a line of code in ext.air.js, after line 1630:


nativeItem.keyEquivalent = cfg.key;


so, now I'm able to set my accelerators in this way:



var appMenu = Ext.air.SystemMenu;

appMenu.add("File", [
{text: "New foo", handler: myHandler, key: "n"}
]);


...nothing of special, but I hope is helpful for someone ;)

Adversus
17 Oct 2008, 4:50 AM
Ok, one more thing about accelerators in AIR. By replacing the code from iDave with:



if (!Ext.isEmpty(cfg.key)) {
nativeItem.keyEquivalent = cfg.key;
if (!Ext.isEmpty(cfg.modifier)) {
nativeItem.keyEquivalentModifiers = cfg.modifier;
}
}


...you can use modifiers for the key like:


var appMenu = Ext.air.SystemMenu;

appMenu.add("File", [
{text: "New foo", handler: myHandler, key: "n", modifier: [air.Keyboard.CONTROL,air.Keyboard.ALTERNATE],}
]);

Modifiers supported by AIR: CONTROL, ALTERNATE, SHIFT, COMMAND (Mac)

Have fun!

RobSmith
17 Oct 2008, 5:11 AM
Thanks for sharing, guys!