PDA

View Full Version : Bind Key Event to an Action



Voyd
30 Mar 2012, 1:34 PM
Is there a way to bind a key event an action? I have a basic menu bar of buttons (that are actually actions) that are shared by a itemcontextmenu with a right click of a node in a tree. Everything works beautifully if I stop there, but now I want to bind a key event with those actions. I have these actions enable and disable based on where a user clicks in my tree, but now when a user clicks a node -- which turns on the addAction per se, I want "ctrl-a" available which will also fire my action. Hopefully this makes sense. I put some dummy code in below to paint a picture.



var addAction = Ext.create('Ext.Action', {
itemId : 'addAction',
text : 'Add',
handler : function() {
// Do something
},
scope : this,
disabled : true
});

var deleteAction = Ext.create('Ext.Action', {
itemId : 'deleteAction',
text : 'Delete',
handler : function() {
// Do something
},
scope : this,
disabled : true
});

// Add the actions into an array
var actions = [addAction, deleteAction];


// Feed the context menu the array of actions
var menu1 = Ext.create('Ext.menu.Menu', {
items : actions
});
var aPanel = Ext.create('Ext.panel.Panel, {
bodyCls : 'panel-default',
layout : {
type : 'border',
align : 'stretch'
},
tbar : actions
});