more cleanup...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2017-01-11 01:46:47 +03:00
parent 664743a975
commit 17f4b7c448
2 changed files with 36 additions and 220 deletions

View File

@ -435,6 +435,7 @@ var KeyboardActions = actions.Actions({
get keyboard(){ get keyboard(){
return this.__keyboard_object }, return this.__keyboard_object },
pauseKeyboardRepeat: ['- Interface/', pauseKeyboardRepeat: ['- Interface/',
function(){ function(){
this.__keyboard_repeat_paused = true }], this.__keyboard_repeat_paused = true }],
@ -558,6 +559,7 @@ var KeyboardActions = actions.Actions({
// } // }
// //
// XXX this does not check overloading between modes... // XXX this does not check overloading between modes...
// XXX do we need this???
getKeysForAction: ['- Interface/', getKeysForAction: ['- Interface/',
function(actions, modes){ function(actions, modes){
var that = this var that = this
@ -601,26 +603,6 @@ var KeyboardActions = actions.Actions({
}], }],
// XXX move to gen2
// XXX need to pre-process the docs...
// - remove the path component...
// - insert the action name where not doc present...
// XXX cleanup CSS
showKeyboardBindings: ['Interface/Show keyboard bindings...',
widgets.makeUIDialog('Drawer',
function(){
return keyboard.buildKeybindingsHelpHTML(
this.__keyboard_config,
this,
function(action){
return Object.keys(this.getPath(action))[0] })
},
{
background: 'white',
focusable: true,
})],
// XXX Things not to forget: // XXX Things not to forget:
// * sort modes // * sort modes
// * sort actions // * sort actions
@ -805,203 +787,30 @@ var KeyboardActions = actions.Actions({
function(){ function(){
thiis.__keyboard_config = GLOBAL_KEYBOARD }], thiis.__keyboard_config = GLOBAL_KEYBOARD }],
// XXX do we look for aliases in this mode only or in all modes? keyHandler: ['- Interface/',
getKeyHandler: ['- Interface/', function(mode, key, action){
function(modes, key, action){ return this.keyboard.handler(mode, key, action) }],
var that = this
// XXX normalize key...
var full_key = key
var modifiers = key.split('+')
key = modifiers.pop()
var code = keyboard.toKeyCode(key)
var args = [].slice.call(arguments).slice(3)
// set handler...
if(action){
modes = modes instanceof Array ? modes : [modes]
// ignore all but the first mode...
modes = modes.slice(0, 1)
// get handler...
} else {
var shift_key = (modifiers.indexOf('shift') >= 0 ?
keyboard._SHIFT_KEYS[key]
: keyboard._UNSHIFT_KEYS[key])
|| ''
var shift_modifiers = shift_key != ''
&& (((modifiers.indexOf('shift') >= 0 ?
modifiers.filter(function(k){ return k != 'shift' })
: modifiers.concat(['shift'])))
|| modifiers).join('+')
var full_shift_key = shift_modifiers == '' ?
shift_key
: shift_modifiers +'+'+ shift_key
var any = modes == 'any'
modes = any ? this.keyboard.modes()
: modes == '*' ? Object.keys(this.keybindigs)
: modes
modes = modes instanceof Array ? modes : [modes]
// filter modes...
var ignore = false
modes = any ?
modes
.filter(function(mode){
if(ignore){
return false
}
var i = that.keybindigs[mode].ignore || []
ignore = i.indexOf(full_key) >= 0
|| i.indexOf(key) >= 0
|| i.indexOf(shift_key) >= 0
|| i.indexOf(full_shift_key) >= 0
|| i.indexOf(code) >= 0
return true
})
: modes
}
modifiers = modifiers.join('+')
// search modes...
var res = {}
ignore = false
modes
.forEach(function(mode){
if(ignore){
return false
}
var bindings = that.keybindigs[mode] // XXX move to gen2
// XXX need to pre-process the docs...
if(action){ // - remove the path component...
var match = 'direct' // - insert the action name where not doc present...
var alias = code in bindings ? code : key // XXX cleanup CSS
showKeyboardBindings: ['Interface/Show keyboard bindings...',
} else { widgets.makeUIDialog('Drawer',
// direct match... function(){
var match = 'direct' return keyboard.buildKeybindingsHelpHTML(
var alias = full_key in bindings ? full_key this.__keyboard_config,
: key in bindings ? key this,
: null function(action){
// shift key match... return Object.keys(this.getPath(action))[0] })
match = alias == null ? 'shifted' : match },
alias = alias == null ? {
(full_shift_key in bindings ? full_shift_key background: 'white',
: shift_key in bindings ? shift_key focusable: true,
: null) })],
: alias
// code match...
match = alias == null ? 'code' : match
alias = alias == null ?
(code in bindings ? code : null)
: alias
}
var mod = (match == 'code' || match == 'direct') ?
modifiers
: shift_modifiers
mod = mod == '' ? 'default' : mod
var handler = alias
// spin through aliases...
// XXX do we look for aliases in this mode only or in all modes?
var seen = []
while(handler in bindings){
// handler loop...
if(seen.indexOf(handler) >= 0){
return null
}
alias = handler
handler = bindings[alias]
seen.push(alias)
// go into the map structure...
if(!action && typeof(handler) != typeof('str')){
handler = handler[mod]
}
}
// set the action...
if(action){
if(handler == null || typeof(handler) == typeof('str')){
bindings[alias] = modifiers.length == 0 ?
action
: { modifiers : action }
} else if(modifiers.length == 0){
handler['default'] = action
} else {
handler[modifiers] = action
}
// get the action...
} else {
if(handler){
res[mode] = handler
}
ignore = any && handler == 'DROP'
}
})
return !action ?
(modes.length == 1 ? res[modes[0]] : res) || null
: undefined
}],
// XXX move this to lib/keyboard.js
// XXX not done yet...
bindKey: ['- Interface/',
function(mode, key, action){
var modifiers = key.split('+')
key = modifiers.pop()
modifiers = modifiers.join('+')
var code = keyboard.toKeyCode(key)
var args = [].slice.call(arguments).slice(3)
action = action
+ (args.length > 0 ?
': '+ args.map(JSON.stringify).join(' ')
: '')
var bindings = this.keybindigs[mode]
var alias = code in bindings ? code : key
var handler = bindings[key] || bindings[code]
// spin through aliases...
var seen = []
while(handler in bindings){
// handler loop...
if(seen.indexOf(handler) >= 0){
return null
}
alias = handler
handler = bindings[alias]
seen.push(alias)
}
if(handler == null || typeof(handler) == typeof('str')){
bindings[alias] = modifiers.length == 0 ?
action
: { modifiers : action }
} else if(modifiers.length == 0){
handler['default'] = action
} else {
handler[modifiers] = action
}
}],
}) })
var Keyboard = var Keyboard =

View File

@ -106,7 +106,7 @@ for(var k in SPECIAL_KEYS){
/*********************************************************************/ /*********************************************************************/
// documentation wrapper... // Documentation wrapper...
var doc = var doc =
module.doc = module.doc =
function doc(text, func){ function doc(text, func){
@ -116,7 +116,9 @@ function doc(text, func){
} }
// supported action format: // Parse action call format...
//
// supported format:
// <actio-name>[!][: <args>][-- <doc>] // <actio-name>[!][: <args>][-- <doc>]
// //
// <args> can contain space seporated: // <args> can contain space seporated:
@ -126,6 +128,8 @@ function doc(text, func){
// //
// XXX should this be here??? // XXX should this be here???
// XXX add support for suffix to return false / stop_propagation... // XXX add support for suffix to return false / stop_propagation...
// XXX should this handle calls???
// i.e. have .call(..) / .apply(..) methods???
var parseActionCall = var parseActionCall =
module.parseActionCall = module.parseActionCall =
function parseActionCall(txt){ function parseActionCall(txt){
@ -596,17 +600,15 @@ var KeyboardHandlerPrototype = {
// - search for key code without modifiers // - search for key code without modifiers
// - if an alias is found it is first checked with and then // - if an alias is found it is first checked with and then
// without modifiers // without modifiers
//
// XXX getting '(' yields a different result from 'shift-#9'
handler: function(mode, key, handler){ handler: function(mode, key, handler){
var that = this var that = this
var keyboard = this.keyboard var keyboard = this.keyboard
var key_separators = KEY_SEPARATORS var key_separators = KEY_SEPARATORS
if(arguments.length == 0){ if(mode == null){
return null return null
} }
if(arguments.length == 1 && this.isKey(mode)){ if(key == null && this.isKey(mode)){
key = mode key = mode
mode = '*' mode = '*'
} }
@ -753,6 +755,7 @@ var KeyboardHandlerPrototype = {
: Object.keys(this.keyboard) }, : Object.keys(this.keyboard) },
// init base data...
__init__: function(keyboard, is_mode_applicable){ __init__: function(keyboard, is_mode_applicable){
this.keyboard = keyboard this.keyboard = keyboard
@ -770,8 +773,11 @@ object.makeConstructor('Keyboard',
/*********************************************************************/ /*********************************************************************/
// Base event handler wrapper of Keyboard...
//
var makeKeyboardHandler = var makeKeyboardHandler =
module.makeKeyboardHandler = module.makeKeyboardHandler =
function makeKeyboardHandler(keyboard, unhandled, actions){ function makeKeyboardHandler(keyboard, unhandled, actions){
@ -835,6 +841,7 @@ function makeKeyboardHandler(keyboard, unhandled, actions){
// Event handler wrapper to stop handling keys if check callback does // Event handler wrapper to stop handling keys if check callback does
// not pass (returns false)... // not pass (returns false)...
//
var stoppableKeyboardRepeat = var stoppableKeyboardRepeat =
module.stoppableKeyboardRepeat = module.stoppableKeyboardRepeat =
function(handler, check){ function(handler, check){