* Allow hot keys to be case insensitive

* Start of better demo
This commit is contained in:
Bryan Ashby 2015-04-27 17:27:23 -06:00
parent 028c5be418
commit 3e93b5b67d
4 changed files with 52 additions and 7 deletions

View File

@ -25,7 +25,9 @@ function MenuView(options) {
this.items = [];
}
this.setHotKeys(options.hotkeys);
this.caseInsensitiveHotKeys = miscUtil.valueWithDefault(options.caseInsensitiveHotKeys, true);
this.setHotKeys(options.hotKeys);
this.focusedItemIndex = options.focusedItemIndex || 0;
this.focusedItemIndex = this.items.length >= this.focusedItemIndex ? this.focusedItemIndex : 0;
@ -103,9 +105,16 @@ MenuView.prototype.setItems = function(items) {
}
};
MenuView.prototype.setHotKeys = function(hotkeys) {
if(_.isObject(hotkeys)) {
this.hotkeys = hotkeys;
MenuView.prototype.setHotKeys = function(hotKeys) {
if(_.isObject(hotKeys)) {
if(this.caseInsensitiveHotKeys) {
this.hotKeys = {};
for(var key in hotKeys) {
this.hotKeys[key.toLowerCase()] = hotKeys[key];
}
} else {
this.hotKeys = hotKeys;
}
}
}

View File

@ -60,13 +60,13 @@ ToggleMenuView.prototype.setFocus = function(focused) {
};
ToggleMenuView.prototype.onKeyPress = function(key, isSpecial) {
if(isSpecial || !this.hotkeys) {
if(isSpecial || !this.hotKeys) {
return;
}
assert(1 === key.length);
var keyIndex = this.hotkeys[key];
var keyIndex = this.hotKeys[this.caseInsensitiveHotKeys ? key.toLowerCase() : key];
if(!_.isUndefined(keyIndex)) {
this.focusedItemIndex = keyIndex;
this.updateSelection();

Binary file not shown.

View File

@ -199,6 +199,41 @@
}
}
},
"demoEditTextView" : {
"art" : "demo_edit_text_view1.ans",
"options" : { "cls" : true },
"form" : {
"0" : {
"BT4ET1ET2ET3" : {
"mci" : {
"ET1" : {
"maxLength" : 20
},
"ET2" : {
"maxLength" : 20
},
"ET3" : {
"fillChar" : " ",
"maxLength" : 20
},
"BT4" : {
"text" : "Back",
"submit" : true
}
},
"submit" : {
"*" : [
{
"value" : 4,
"action" : "@menu:demoMain"
}
]
}
}
}
}
}
/*
"demoEditTextView" : {
"art" : "demo_edit_text_view.ans",
"options" : { "cls" : true },
@ -219,11 +254,12 @@
},
"TM6" : {
"items" : [ "Yes", "No" ],
"hotkeys" : { "y" : 0, "n" : 1 }
"hotkeys" : { "Y" : 0, "n" : 1 }
}
}
}
}
}
}
*/
}