mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 02:10:08 +00:00
added ability to pause keyboard repeat...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
9b84b686ab
commit
0deba5d277
@ -122,10 +122,10 @@ actions.Actions({
|
||||
},
|
||||
|
||||
// Current ribbon...
|
||||
get currentRibbon(){
|
||||
get current_ribbon(){
|
||||
return this.data.getRibbon()
|
||||
},
|
||||
set currentRibbon(value){
|
||||
set current_ribbon(value){
|
||||
this.focusRibbon(value)
|
||||
},
|
||||
|
||||
|
||||
@ -377,6 +377,16 @@ module.GLOBAL_KEYBOARD = {
|
||||
|
||||
|
||||
|
||||
/*********************************************************************/
|
||||
|
||||
var stoppableKeyboardRepeat = function(handler, check){
|
||||
return function(evt){
|
||||
return check() && handler(evt)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*********************************************************************/
|
||||
// XXX add a key binding list UI...
|
||||
// XXX add loading/storing of kb bindings...
|
||||
@ -388,18 +398,43 @@ var KeyboardActions = actions.Actions({
|
||||
//
|
||||
// Set this to -1 or null to run keys without any limitations.
|
||||
'max-key-repeat-rate': 0,
|
||||
|
||||
'keyboard-repeat-pause-check': 100,
|
||||
},
|
||||
|
||||
get keyboard(){
|
||||
return this.__keyboard_config
|
||||
},
|
||||
|
||||
pauseKeyboardRepeat: ['- Interface/',
|
||||
function(){
|
||||
this.__keyboard_repeat_paused = true
|
||||
}],
|
||||
|
||||
toggleKeyboardHandling: ['- Interface/Toggle keyboard handling',
|
||||
toggler.Toggler(null, function(_, state){
|
||||
if(state == null){
|
||||
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)
|
||||
|
||||
// XXX this does not work yet...
|
||||
//var target = this.ribbons.viewer
|
||||
var target = $(document)
|
||||
@ -420,16 +455,19 @@ var KeyboardActions = actions.Actions({
|
||||
//this.ribbons.viewer
|
||||
var handler =
|
||||
this.__keyboard_handler =
|
||||
stoppableKeyboardRepeat(
|
||||
keyboard.makeKeyboardHandler(
|
||||
function(){ return that.__keyboard_config },
|
||||
function(k){ window.DEBUG && console.log('KEY:', k) },
|
||||
this)
|
||||
this),
|
||||
check)
|
||||
|
||||
// drop keys if repeating too fast...
|
||||
// NOTE: this is done for smoother animations...
|
||||
} else {
|
||||
var handler =
|
||||
this.__keyboard_handler =
|
||||
stoppableKeyboardRepeat(
|
||||
keyboard.dropRepeatingkeys(
|
||||
keyboard.makeKeyboardHandler(
|
||||
function(){ return that.__keyboard_config },
|
||||
@ -437,7 +475,8 @@ var KeyboardActions = actions.Actions({
|
||||
this),
|
||||
function(){
|
||||
return that.config['max-key-repeat-rate']
|
||||
})
|
||||
}),
|
||||
check)
|
||||
}
|
||||
|
||||
target.keydown(handler)
|
||||
@ -484,7 +523,21 @@ module.Keyboard = core.ImageGridFeatures.Feature({
|
||||
this.__keyboard_config = this.keyboard || GLOBAL_KEYBOARD
|
||||
|
||||
this.toggleKeyboardHandling('on')
|
||||
}]
|
||||
}],
|
||||
|
||||
// pause keyboard repeat...
|
||||
['shiftImageUp.pre shiftImageDown.pre',
|
||||
function(){
|
||||
var r = this.current_ribbon
|
||||
|
||||
return function(){
|
||||
// pause repeat if shifting last image out of the ribbon...
|
||||
if(this.data.ribbons[r] == null
|
||||
|| this.data.ribbons[r].len == 0){
|
||||
this.pauseKeyboardRepeat()
|
||||
}
|
||||
}
|
||||
}],
|
||||
],
|
||||
})
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user