* isSpecialKeyMapped() renamed to isKeyMapped()
* Functional HorizontalMenuView * Minor updates
This commit is contained in:
parent
a1b87c7a60
commit
c1469a1f9c
|
@ -32,7 +32,7 @@ require('util').inherits(EditTextView, TextView);
|
|||
|
||||
EditTextView.prototype.onKeyPress = function(ch, key) {
|
||||
if(key) {
|
||||
if(this.isSpecialKeyMapped('backspace', key.name)) {
|
||||
if(this.isKeyMapped('backspace', key.name)) {
|
||||
if(this.text.length > 0) {
|
||||
this.text = this.text.substr(0, this.text.length - 1);
|
||||
|
||||
|
@ -47,7 +47,7 @@ EditTextView.prototype.onKeyPress = function(ch, key) {
|
|||
}
|
||||
|
||||
return;
|
||||
} else if(this.isSpecialKeyMapped('clearLine', key.name)) {
|
||||
} else if(this.isKeyMapped('clearLine', key.name)) {
|
||||
this.text = '';
|
||||
this.cursorPos.col = 0;
|
||||
this.setFocus(true); // resetting focus will redraw & adjust cursor
|
||||
|
|
|
@ -10,6 +10,8 @@ var _ = require('lodash');
|
|||
|
||||
exports.HorizontalMenuView = HorizontalMenuView;
|
||||
|
||||
// :TODO: Update this to allow scrolling if number of items cannot fit in width (similar to VerticalMenuView)
|
||||
|
||||
function HorizontalMenuView(options) {
|
||||
options.cursor = options.cursor || 'hide';
|
||||
|
||||
|
@ -107,4 +109,46 @@ HorizontalMenuView.prototype.setItems = function(items) {
|
|||
HorizontalMenuView.super_.prototype.setItems.call(this, items);
|
||||
|
||||
this.positionCacheExpired = true;
|
||||
};
|
||||
|
||||
HorizontalMenuView.prototype.onKeyPress = function(ch, key) {
|
||||
if(key) {
|
||||
var prevFocusedItemIndex = this.focusedItemIndex;
|
||||
|
||||
if(this.isKeyMapped('left', key.name)) {
|
||||
if(0 === this.focusedItemIndex) {
|
||||
this.focusedItemIndex = this.items.length - 1;
|
||||
} else {
|
||||
this.focusedItemIndex--;
|
||||
}
|
||||
|
||||
} else if(this.isKeyMapped('right', key.name)) {
|
||||
if(this.items.length - 1 === this.focusedItemIndex) {
|
||||
this.focusedItemIndex = 0;
|
||||
} else {
|
||||
this.focusedItemIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
if(prevFocusedItemIndex !== this.focusedItemIndex) {
|
||||
// :TODO: Optimize this in cases where we only need to redraw two items. Always the case now, somtimes
|
||||
// if this is changed to allow scrolling
|
||||
this.redraw();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(ch && this.hotKeys) {
|
||||
var keyIndex = this.hotKeys[this.caseInsensitiveHotKeys ? ch.toLowerCase() : ch];
|
||||
if(_.isNumber(keyIndex)) {
|
||||
this.focusedItemIndex = keyIndex;
|
||||
this.redraw();
|
||||
}
|
||||
}
|
||||
|
||||
HorizontalMenuView.super_.prototype.onKeyPress.call(this, ch, key);
|
||||
};
|
||||
|
||||
HorizontalMenuView.prototype.getData = function() {
|
||||
return this.focusedItemIndex;
|
||||
};
|
|
@ -106,7 +106,7 @@ MaskEditTextView.prototype.setMaskPattern = function(pattern) {
|
|||
|
||||
MaskEditTextView.prototype.onKeyPress = function(ch, key) {
|
||||
if(key) {
|
||||
if(this.isSpecialKeyMapped('backspace', key.name)) {
|
||||
if(this.isKeyMapped('backspace', key.name)) {
|
||||
if(this.text.length > 0) {
|
||||
this.patternArrayPos--;
|
||||
assert(this.patternArrayPos >= 0);
|
||||
|
@ -128,7 +128,7 @@ MaskEditTextView.prototype.onKeyPress = function(ch, key) {
|
|||
}
|
||||
|
||||
return;
|
||||
} else if(this.isSpecialKeyMapped('clearLine', key.name)) {
|
||||
} else if(this.isKeyMapped('clearLine', key.name)) {
|
||||
this.text = '';
|
||||
this.patternArrayPos = 0;
|
||||
this.setFocus(true); // redraw + adjust cursor
|
||||
|
|
|
@ -499,13 +499,13 @@ MultiLineEditTextView.prototype.onKeyPress = function(key, isSpecial) {
|
|||
};
|
||||
|
||||
MultiLineEditTextView.prototype.onSpecialKeyPress = function(keyName) {
|
||||
if(this.isSpecialKeyMapped('up', keyName)) {
|
||||
if(this.isKeyMapped('up', keyName)) {
|
||||
this.cursorUp();
|
||||
} else if(this.isSpecialKeyMapped('down', keyName)) {
|
||||
} else if(this.isKeyMapped('down', keyName)) {
|
||||
this.cursorDown();
|
||||
} else if(this.isSpecialKeyMapped('left', keyName)) {
|
||||
} else if(this.isKeyMapped('left', keyName)) {
|
||||
this.cursorLeft();
|
||||
} else if(this.isSpecialKeyMapped('right', keyName)) {
|
||||
} else if(this.isKeyMapped('right', keyName)) {
|
||||
this.cursorRight();
|
||||
}
|
||||
|
||||
|
|
|
@ -1036,7 +1036,7 @@ MultiLineEditTextView2.prototype.onKeyPress = function(ch, key) {
|
|||
|
||||
if(key) {
|
||||
HANDLED_SPECIAL_KEYS.forEach(function aKey(specialKey) {
|
||||
if(self.isSpecialKeyMapped(specialKey, key.name)) {
|
||||
if(self.isKeyMapped(specialKey, key.name)) {
|
||||
self[_.camelCase('keyPress ' + specialKey)]();
|
||||
handled = true;
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ function SpinnerMenuView(options) {
|
|||
*/
|
||||
|
||||
this.updateSelection = function() {
|
||||
assert(!self.positionCacheExpired);
|
||||
//assert(!self.positionCacheExpired);
|
||||
|
||||
assert(this.focusedItemIndex >= 0 && this.focusedItemIndex <= self.items.length);
|
||||
|
||||
|
@ -66,7 +66,7 @@ SpinnerMenuView.prototype.setFocus = function(focused) {
|
|||
|
||||
SpinnerMenuView.prototype.onKeyPress = function(ch, key) {
|
||||
if(key) {
|
||||
if(this.isSpecialKeyMapped('up', key.name)) {
|
||||
if(this.isKeyMapped('up', key.name)) {
|
||||
if(0 === this.focusedItemIndex) {
|
||||
this.focusedItemIndex = this.items.length - 1;
|
||||
} else {
|
||||
|
@ -75,7 +75,7 @@ SpinnerMenuView.prototype.onKeyPress = function(ch, key) {
|
|||
|
||||
this.updateSelection();
|
||||
return;
|
||||
} else if(this.isSpecialKeyMapped('down', key.name)) {
|
||||
} else if(this.isKeyMapped('down', key.name)) {
|
||||
if(this.items.length - 1 === this.focusedItemIndex) {
|
||||
this.focusedItemIndex = 0;
|
||||
} else {
|
||||
|
|
|
@ -25,7 +25,7 @@ function ToggleMenuView (options) {
|
|||
*/
|
||||
|
||||
this.updateSelection = function() {
|
||||
assert(!self.positionCacheExpired);
|
||||
//assert(!self.positionCacheExpired);
|
||||
assert(this.focusedItemIndex >= 0 && this.focusedItemIndex <= self.items.length);
|
||||
|
||||
self.redraw();
|
||||
|
@ -71,14 +71,14 @@ ToggleMenuView.prototype.setFocus = function(focused) {
|
|||
ToggleMenuView.prototype.onKeyPress = function(ch, key) {
|
||||
if(key) {
|
||||
var needsUpdate;
|
||||
if(this.isSpecialKeyMapped('right', key.name) || this.isSpecialKeyMapped('down', key.name)) {
|
||||
if(this.isKeyMapped('right', key.name) || this.isKeyMapped('down', key.name)) {
|
||||
if(this.items.length - 1 === this.focusedItemIndex) {
|
||||
this.focusedItemIndex = 0;
|
||||
} else {
|
||||
this.focusedItemIndex++;
|
||||
}
|
||||
needsUpdate = true;
|
||||
} else if(this.isSpecialKeyMapped('left', key.name) || this.isSpecialKeyMapped('up', key.name)) {
|
||||
} else if(this.isKeyMapped('left', key.name) || this.isKeyMapped('up', key.name)) {
|
||||
if(0 === this.focusedItemIndex) {
|
||||
this.focusedItemIndex = this.items.length - 1;
|
||||
} else {
|
||||
|
@ -95,7 +95,7 @@ ToggleMenuView.prototype.onKeyPress = function(ch, key) {
|
|||
|
||||
if(ch && this.hotKeys) {
|
||||
var keyIndex = this.hotKeys[this.caseInsensitiveHotKeys ? ch.toLowerCase() : ch];
|
||||
if(!_.isUndefined(keyIndex)) {
|
||||
if(_.isNumber(keyIndex)) {
|
||||
this.focusedItemIndex = keyIndex;
|
||||
this.updateSelection();
|
||||
}
|
||||
|
|
|
@ -109,7 +109,7 @@ VerticalMenuView.prototype.onKeyPress = function(ch, key) {
|
|||
if(key) {
|
||||
var prevFocusedItemIndex = this.focusedItemIndex;
|
||||
|
||||
if(this.isSpecialKeyMapped('up', key.name)) {
|
||||
if(this.isKeyMapped('up', key.name)) {
|
||||
if(0 === this.focusedItemIndex) {
|
||||
this.focusedItemIndex = this.items.length - 1;
|
||||
|
||||
|
@ -125,7 +125,7 @@ VerticalMenuView.prototype.onKeyPress = function(ch, key) {
|
|||
this.viewWindow.bottom--;
|
||||
}
|
||||
}
|
||||
} else if(this.isSpecialKeyMapped('down', key.name)) {
|
||||
} else if(this.isKeyMapped('down', key.name)) {
|
||||
if(this.items.length - 1 === this.focusedItemIndex) {
|
||||
this.focusedItemIndex = 0;
|
||||
|
||||
|
@ -144,6 +144,7 @@ VerticalMenuView.prototype.onKeyPress = function(ch, key) {
|
|||
}
|
||||
|
||||
if(prevFocusedItemIndex !== this.focusedItemIndex) {
|
||||
// :TODO: Optimize this for cases where no scrolling occured & only two items need updated
|
||||
this.redraw();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ function View(options) {
|
|||
this.specialKeyMap = options.specialKeyMap || VIEW_SPECIAL_KEY_MAP_DEFAULT;
|
||||
}
|
||||
|
||||
this.isSpecialKeyMapped = function(keySet, keyName) {
|
||||
this.isKeyMapped = function(keySet, keyName) {
|
||||
return _.has(this.specialKeyMap, keySet) && this.specialKeyMap[keySet].indexOf(keyName) > -1;
|
||||
};
|
||||
|
||||
|
@ -241,9 +241,9 @@ View.prototype.onKeyPress = function(ch, key) {
|
|||
if(key) {
|
||||
assert(this.specialKeyMap, 'No special key map defined');
|
||||
|
||||
if(this.isSpecialKeyMapped('accept', key.name)) {
|
||||
if(this.isKeyMapped('accept', key.name)) {
|
||||
this.emit('action', 'accept');
|
||||
} else if(this.isSpecialKeyMapped('next', key.name)) {
|
||||
} else if(this.isKeyMapped('next', key.name)) {
|
||||
this.emit('action', 'next');
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
|
@ -406,15 +406,28 @@
|
|||
"options" : { "cls" : true },
|
||||
"form" : {
|
||||
"0" : {
|
||||
"BT5HM1" : {
|
||||
"BT5HM1HM2" : {
|
||||
"mci" : {
|
||||
"HM1" : {
|
||||
"items" : [ "One", "Two", "Three" ]
|
||||
"items" : [ "One", "Two", "Three" ],
|
||||
"hotKeys" : { "1" : 0, "2" : 1, "3" : 2 }
|
||||
},
|
||||
"HM2" : {
|
||||
"items" : [ "Uno", "Dos", "Tres" ],
|
||||
"hotKeys" : { "U" : 0, "D" : 1, "T" : 2 }
|
||||
},
|
||||
"BT5" : {
|
||||
"text" : "< Back",
|
||||
"submit" : [ "escape" ]
|
||||
}
|
||||
},
|
||||
"submit" : {
|
||||
"*" : [
|
||||
{
|
||||
"value" : 5,
|
||||
"action" : "@menu:demoMain"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue