From 4f8ebda91ccf1982812fbd906115ce9aa5a4544a Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Mon, 10 Sep 2012 04:23:48 +0400 Subject: [PATCH] reworked the key handler a bit... Signed-off-by: Alex A. Naanou --- ui/gallery-prototype.js | 26 ++++++++++---- ui/keybindings.js | 77 ++++++++++++++++++++++------------------- 2 files changed, 60 insertions(+), 43 deletions(-) diff --git a/ui/gallery-prototype.js b/ui/gallery-prototype.js index 873352cd..f0b2223f 100755 --- a/ui/gallery-prototype.js +++ b/ui/gallery-prototype.js @@ -1483,13 +1483,17 @@ function makeKeyboardHandler(keybindings, unhandled){ unhandled = function(){return false} } return function(evt){ + var did_handling = false + var res = null for(var mode in keybindings){ if($(mode).length > 0){ var bindings = keybindings[mode] var key = evt.keyCode if(bindings.ignore != null && bindings.ignore.indexOf(key) != -1){ - return true + // return true + did_handling = true + continue } // XXX ugly... var modifers = evt.ctrlKey ? 'ctrl' : '' @@ -1504,7 +1508,7 @@ function makeKeyboardHandler(keybindings, unhandled){ } // no handler... if(handler == null){ - return unhandled(key) + continue } // Array, lisp style with docs... // XXX for some odd reason in chrome typeof([]) == typeof({})!!! @@ -1519,17 +1523,25 @@ function makeKeyboardHandler(keybindings, unhandled){ callback = handler['default'] } if(callback != null){ - var res = callback() - return KEYBOARD_HANDLER_PROPAGATE&&res?true:false + res = callback() + did_handling = true + continue } } else { // simple callback... - var res = handler() - return KEYBOARD_HANDLER_PROPAGATE&&res?true:false + res = handler() + did_handling = true + continue } - return unhandled(key) } } + if(!did_handling){ + // key is unhandled by any modes... + return unhandled(key) + } else { + // XXX should we handle multiple hits??? + return KEYBOARD_HANDLER_PROPAGATE&&res?true:false + } } } diff --git a/ui/keybindings.js b/ui/keybindings.js index 23fe8387..b8b6e559 100755 --- a/ui/keybindings.js +++ b/ui/keybindings.js @@ -2,31 +2,11 @@ // NOTE: use String.fromCharCode(code)... // list of keys to be ignored by handler but still handled by the browser... - var keybindings = { - '.overlay-mode': { - title: 'Overlay mode', - doc: 'overlay mode key bindings.', - - ignore: [ - 37, // Left - 39, // Right - 36, // Home - 32, // Space - 35, // End - 38, // Up - 40, // Down - ], - - 27: ImageGrid.closeOverlay, // Esc - }, - - - //'*': { - // everything except overlays... - '.viewer *:not(.overlay-mode *)': { - title: 'ALL', - doc: 'global key bindings.', + // global bindings... + '*': { + title: 'Global', + doc: '', ignore: [ 116, // F5 @@ -53,6 +33,43 @@ var keybindings = { 27: ImageGrid.closeOverlay, // Esc + // ignore the modifiers (shift, alt, ctrl, caps)... + 16: function(){}, + 17: 16, + 18: 16, + 20: 16, // Caps Lock + + // refresh... + // XXX make this into a real action... + 116: function(){ return DEBUG?true:false }, // F5 + 112: 116, // F12 + }, + + + // overlay... + '.overlay-mode': { + title: 'Overlay mode', + doc: 'Overlay mode key bindings.', + + ignore: [ + 33, // PgUp + 34, // PgDown + 37, // Left + 39, // Right + 36, // Home + 32, // Space + 35, // End + 38, // Up + 40, // Down + ], + }, + + + // everything except overlays... + '.viewer *:not(.overlay-mode *)': { + title: 'Ribbon and Viewer', + doc: '', + // zooming... 187: ImageGrid.scaleContainerUp, // + 189: ImageGrid.scaleContainerDown, // - @@ -118,18 +135,6 @@ var keybindings = { // misc actions... 82: ImageGrid.reverseImageOrder, // r - - - // ignore the modifiers (shift, alt, ctrl, caps)... - 16: function(){}, - 17: 16, - 18: 16, - 20: 16, // Caps Lock - - // refresh... - // XXX make this into a real action... - 116: function(){ return DEBUG?true:false }, // F5 - 112: 116, // F12 } }