summaryrefslogtreecommitdiff
path: root/swat2/style/qooxdoo/widgets/core/QxCommand.js
blob: 488de0dd34a4bda9c8a3aa4c77d9e04fcc75a991 (plain)
1
2
/* Copyright (c): 2002-2005 (Germany): United Internet, 1&1, GMX, Schlund+Partner, Alturo */
function QxCommand(vShortcut,vKeyCode,vManager){QxTarget.call(this);if(isValid(vShortcut)){this.setShortcut(vShortcut);};if(isValid(vKeyCode)){this.setKeyCode(vKeyCode);};this.setManager(isValid(vManager)?vManager:window.application.getClientWindow().getEventManager());};QxCommand.extend(QxTarget,"QxCommand");QxCommand.addProperty({name:"checked",type:Boolean,defaultValue:false});QxCommand.addProperty({name:"shortcut",type:String});QxCommand.addProperty({name:"keyCode",type:Number});QxCommand.addProperty({name:"manager",type:Object});proto.execute=function(vTarget){this.dispatchEvent(new QxDataEvent("execute",vTarget));return false;};proto._shortcutParts={};proto._modifyShortcut=function(_b1,_b2,_b3,_b4){if(_b1){var a = _b1.toLowerCase().split(/[-+\s]+/);var al=a.length;this._shortcutParts={};for(var i=0;i<al;i++){this._shortcutParts[a[i]]=true;};}else {this._shortcutParts=null;};return true;};proto._modifyManager=function(_b1,_b2,_b3,_b4){if(_b2){_b2.removeCommand(this);};if(_b1){_b1.addCommand(this);};return true;};proto._matchesKeyEvent=function(e){if(!(isValid(this.getShortcut())||isValid(this.getKeyCode()))){return false;};if((this._shortcutParts.shift&&!e.getShiftKey())||(this._shortcutParts.ctrl&&!e.getCtrlKey())||(this._shortcutParts.alt&&!e.getAltKey())){return false;};var vEventCode=e.getKeyCode();var vSelfCode=this.getKeyCode();switch(vSelfCode){case null:break;case vEventCode:return true;};var c=String.fromCharCode(vEventCode).toLowerCase();if(this._shortcutParts[c]){return true;};if(vSelfCode==null){for(var vPart in this._shortcutParts){switch(vPart){case "ctrl":case "shift":case "alt":case "control":break;default:if(vEventCode==QxKeyEvent.keys[vPart]){return true;};};};};return false;};proto.toString=function(){var vShortcut=this.getShortcut();var vKeyCode=this.getKeyCode();var vString="";if(isValidString(vShortcut)){vString=vShortcut;if(isValidNumber(vKeyCode)){var vTemp=QxKeyEvent.codes[vKeyCode];vString+="+"+(vTemp?vTemp.toFirstUp():String(vKeyCode));};}else if(isValidNumber(vKeyCode)){var vTemp=QxKeyEvent.codes[vKeyCode];vString=vTemp?vTemp.toFirstUp():String(vKeyCode);};return vString;};proto.dispose=function(){if(this.getDisposed()){return;};this._ownerWindow=null;return QxTarget.prototype.dispose.call(this);};