Add SwitchKeymapAction

This commit is contained in:
László Monda
2016-03-29 23:02:36 +02:00
parent 1b75c067f4
commit a721dd3212
3 changed files with 45 additions and 9 deletions

View File

@@ -0,0 +1,44 @@
class SwitchKeymapAction extends KeyAction implements Serializable<SwitchKeymapAction> {
static keyActionTypeString = 'switchKeymap';
static keyActionId = 246;
private _keymapId: number;
get keymapId(): number {
return this._keymapId;
}
set keymapId(value) {
if (!SwitchKeymapAction.isKeymapIdValid(value)) {
throw 'Invalid SwitchKeymapAction.keymapId: ${value}';
}
this._keymapId = value;
}
static isKeymapIdValid(keymapId) {
return 0 <= keymapId && keymapId <= 255;
}
fromJsObject(jsObject: any): SwitchKeymapAction {
this.keymapId = jsObject.keymapId;
return this;
}
fromBinary(buffer: UhkBuffer): SwitchKeymapAction {
this.keymapId = buffer.readUInt8();
return this;
}
toJsObject(): any {
return {
keyActionType: SwitchKeymapAction.keyActionTypeString,
keymapId: this.keymapId
};
}
toBinary(buffer: UhkBuffer) {
buffer.writeUInt8(SwitchKeymapAction.keyActionId);
buffer.writeUInt8(this.keymapId);
}
}

View File

@@ -2,4 +2,5 @@
/// <reference path="KeystrokeAction.ts" />
/// <reference path="MouseAction.ts" />
/// <reference path="PlayMacroAction.ts" />
/// <reference path="SwitchKeymapAction.ts" />
/// <reference path="NoneAction.ts" />

View File

@@ -22,7 +22,6 @@ let KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_RIGHT_CTRL = 240;
let KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_RIGHT_SHIFT = 241;
let KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_RIGHT_ALT = 242;
let KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_RIGHT_SUPER = 243;
let KEY_ACTION_ID_SWITCH_KEYMAP = 246;
let KEY_ACTION_ID_NONE = 255;
let SWITCH_LAYER_MOD = 0;
@@ -45,9 +44,6 @@ function serializeKeyAction(keyAction) {
case 'dualRoleKeystroke':
serializeDualRoleKeyAction(keyAction);
break;
case 'switchKeymap':
serializeSwitchKeymapAction(keyAction);
break;
case 'switchLayer':
serializeSwitchLayerAction(keyAction);
break;
@@ -73,11 +69,6 @@ function serializeDualRoleKeyAction(dualRoleKeyAction) {
writer.writeUInt8(dualRoleKeyAction.scancode);
}
function serializeSwitchKeymapAction(switchKeymapAction) {
writer.writeUInt8(KEY_ACTION_ID_SWITCH_KEYMAP);
writer.writeUInt8(switchKeymapAction.keymapId);
}
function serializeSwitchLayerAction(switchLayerAction) {
writer.writeUInt8(KEY_ACTION_ID_SWITCH_LAYER);
writer.writeUInt8({