mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 02:10:08 +00:00
refactoring -- now pausing of repeating key handling is a keyboard feature...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
6a8c5fb561
commit
852769acea
@ -673,10 +673,16 @@ var KeyboardActions = actions.Actions({
|
|||||||
`,
|
`,
|
||||||
{ keepDialogTitle: true },
|
{ keepDialogTitle: true },
|
||||||
function(key, no_match){
|
function(key, no_match){
|
||||||
|
var that = this
|
||||||
// get/set the handler...
|
// get/set the handler...
|
||||||
var handler = this.__key_press_handler =
|
var handler = this.__key_press_handler =
|
||||||
this.__key_press_handler
|
this.__key_press_handler
|
||||||
|| keyboard.makeKeyboardHandler(this.keyboard, null, this)
|
//|| keyboard.makeKeyboardHandler(this.keyboard, null, this)
|
||||||
|
|| keyboard.makePausableKeyboardHandler(
|
||||||
|
this.keyboard,
|
||||||
|
null,
|
||||||
|
this,
|
||||||
|
function(){ return that.config['keyboard-repeat-pause-check'] })
|
||||||
// do the call...
|
// do the call...
|
||||||
return handler(key, no_match)
|
return handler(key, no_match)
|
||||||
}],
|
}],
|
||||||
@ -689,24 +695,6 @@ var KeyboardActions = actions.Actions({
|
|||||||
return this.__keyboard_handler ? 'on' : 'off'
|
return this.__keyboard_handler ? 'on' : 'off'
|
||||||
}
|
}
|
||||||
|
|
||||||
// repeat stop checker...
|
|
||||||
var check = (function(){
|
|
||||||
if(this.config['keyboard-repeat-pause-check'] > 0
|
|
||||||
&& this.__keyboard_repeat_paused){
|
|
||||||
var that = this
|
|
||||||
this.__keyboard_repeat_pause_timeout
|
|
||||||
&& clearTimeout(this.__keyboard_repeat_pause_timeout)
|
|
||||||
|
|
||||||
this.__keyboard_repeat_pause_timeout = setTimeout(function(){
|
|
||||||
delete that.__keyboard_repeat_paused
|
|
||||||
delete that.__keyboard_repeat_pause_timeout
|
|
||||||
}, this.config['keyboard-repeat-pause-check'] || 100)
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}).bind(this)
|
|
||||||
|
|
||||||
var kb = this.keyboard
|
var kb = this.keyboard
|
||||||
|
|
||||||
// start/reset keyboard handling...
|
// start/reset keyboard handling...
|
||||||
@ -725,15 +713,7 @@ var KeyboardActions = actions.Actions({
|
|||||||
&& target.off('keydown', this.__keyboard_handler)
|
&& target.off('keydown', this.__keyboard_handler)
|
||||||
|
|
||||||
// make the base handler...
|
// make the base handler...
|
||||||
var handler =
|
var handler = this.keyPress.bind(this)
|
||||||
keyboard.stoppableKeyboardRepeat(
|
|
||||||
this.keyPress.bind(this),
|
|
||||||
/*/ log unbound keys...
|
|
||||||
function(evt){
|
|
||||||
return that.keyPress(evt, function(evt, k){
|
|
||||||
window.DEBUG && console.log('KEY:', k) }) },
|
|
||||||
//*/
|
|
||||||
check)
|
|
||||||
|
|
||||||
// setup base keyboard for devel, in case something breaks...
|
// setup base keyboard for devel, in case something breaks...
|
||||||
// This branch does not drop keys...
|
// This branch does not drop keys...
|
||||||
@ -771,7 +751,10 @@ var KeyboardActions = actions.Actions({
|
|||||||
|
|
||||||
This is useful for stopping repeating (held down) keys after some
|
This is useful for stopping repeating (held down) keys after some
|
||||||
event.`,
|
event.`,
|
||||||
function(){ this.__keyboard_repeat_paused = true }],
|
function(){
|
||||||
|
this.config['keyboard-repeat-pause-check'] > 0
|
||||||
|
&& this.keyboard.pauseRepeat
|
||||||
|
&& this.keyboard.pauseRepeat() }],
|
||||||
})
|
})
|
||||||
|
|
||||||
var Keyboard =
|
var Keyboard =
|
||||||
|
|||||||
@ -1049,6 +1049,48 @@ function makeKeyboardHandler(keyboard, unhandled, actions){
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------
|
||||||
|
// Pausable base event handler wrapper of Keyboard...
|
||||||
|
//
|
||||||
|
// This is the same as .makeKeyboardHandler(..) but adds ability to
|
||||||
|
// pause repeating key handling...
|
||||||
|
//
|
||||||
|
// This will extend the keyboard object by adding:
|
||||||
|
// .pauseRepeat() - will pause repeating keys...
|
||||||
|
//
|
||||||
|
var makePausableKeyboardHandler =
|
||||||
|
module.makePausableKeyboardHandler =
|
||||||
|
function makePausableKeyboardHandler(keyboard, unhandled, actions, check_interval){
|
||||||
|
|
||||||
|
var kb = keyboard instanceof Keyboard ?
|
||||||
|
keyboard
|
||||||
|
//: Keyboard(keyboard, checkGlobalMode)
|
||||||
|
: Keyboard(keyboard)
|
||||||
|
|
||||||
|
kb.pauseRepeat = function(){ this.__repeat_paused = true }
|
||||||
|
|
||||||
|
return stoppableKeyboardRepeat(
|
||||||
|
makeKeyboardHandler(kb, unhandled, actions),
|
||||||
|
function(){
|
||||||
|
if(kb.__repeat_paused){
|
||||||
|
var that = this
|
||||||
|
kb.__repeat_pause_timeout
|
||||||
|
&& clearTimeout(kb.__repeat_pause_timeout)
|
||||||
|
|
||||||
|
kb.__repeat_pause_timeout = setTimeout(function(){
|
||||||
|
delete kb.__repeat_paused
|
||||||
|
delete kb.__repeat_pause_timeout
|
||||||
|
}, (check_interval instanceof Function ?
|
||||||
|
check_interval.call(actions)
|
||||||
|
: (check_interval || 100)))
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
// handler wrappers...
|
// handler wrappers...
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user