mirror of
				https://github.com/flynx/ImageGrid.git
				synced 2025-10-31 19:30:07 +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...
 | 	// Current ribbon...
 | ||||||
| 	get currentRibbon(){ | 	get current_ribbon(){ | ||||||
| 		return this.data.getRibbon() | 		return this.data.getRibbon() | ||||||
| 	}, | 	}, | ||||||
| 	set currentRibbon(value){ | 	set current_ribbon(value){ | ||||||
| 		this.focusRibbon(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 a key binding list UI...
 | ||||||
| // XXX add loading/storing of kb bindings...
 | // 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.
 | 		// Set this to -1 or null to run keys without any limitations.
 | ||||||
| 		'max-key-repeat-rate': 0, | 		'max-key-repeat-rate': 0, | ||||||
|  | 
 | ||||||
|  | 		'keyboard-repeat-pause-check': 100, | ||||||
| 	}, | 	}, | ||||||
| 
 | 
 | ||||||
| 	get keyboard(){ | 	get keyboard(){ | ||||||
| 		return this.__keyboard_config | 		return this.__keyboard_config | ||||||
| 	}, | 	}, | ||||||
| 
 | 
 | ||||||
|  | 	pauseKeyboardRepeat: ['- Interface/', | ||||||
|  | 		function(){ | ||||||
|  | 			this.__keyboard_repeat_paused = true | ||||||
|  | 		}], | ||||||
|  | 
 | ||||||
| 	toggleKeyboardHandling: ['- Interface/Toggle keyboard handling', | 	toggleKeyboardHandling: ['- Interface/Toggle keyboard handling', | ||||||
| 		toggler.Toggler(null, function(_, state){  | 		toggler.Toggler(null, function(_, state){  | ||||||
| 			if(state == null){ | 			if(state == null){ | ||||||
| 				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) | ||||||
|  | 
 | ||||||
| 			// XXX this does not work yet...
 | 			// XXX this does not work yet...
 | ||||||
| 			//var target = this.ribbons.viewer
 | 			//var target = this.ribbons.viewer
 | ||||||
| 			var target = $(document) | 			var target = $(document) | ||||||
| @ -420,24 +455,28 @@ var KeyboardActions = actions.Actions({ | |||||||
| 					//this.ribbons.viewer
 | 					//this.ribbons.viewer
 | ||||||
| 					var handler =  | 					var handler =  | ||||||
| 					this.__keyboard_handler = | 					this.__keyboard_handler = | ||||||
| 						keyboard.makeKeyboardHandler( | 						stoppableKeyboardRepeat( | ||||||
| 							function(){ return that.__keyboard_config }, | 							keyboard.makeKeyboardHandler( | ||||||
| 							function(k){ window.DEBUG && console.log('KEY:', k) },  | 								function(){ return that.__keyboard_config }, | ||||||
| 							this) | 								function(k){ window.DEBUG && console.log('KEY:', k) },  | ||||||
|  | 								this), | ||||||
|  | 							check) | ||||||
| 
 | 
 | ||||||
| 				// drop keys if repeating too fast...
 | 				// drop keys if repeating too fast...
 | ||||||
| 				// NOTE: this is done for smoother animations...
 | 				// NOTE: this is done for smoother animations...
 | ||||||
| 				} else { | 				} else { | ||||||
| 					var handler =  | 					var handler =  | ||||||
| 					this.__keyboard_handler = | 					this.__keyboard_handler = | ||||||
| 						keyboard.dropRepeatingkeys( | 						stoppableKeyboardRepeat( | ||||||
| 							keyboard.makeKeyboardHandler( | 							keyboard.dropRepeatingkeys( | ||||||
| 								function(){ return that.__keyboard_config }, | 								keyboard.makeKeyboardHandler( | ||||||
| 								function(k){ window.DEBUG && console.log(k) }, | 									function(){ return that.__keyboard_config }, | ||||||
| 								this),  | 									function(k){ window.DEBUG && console.log(k) }, | ||||||
| 							function(){  | 									this),  | ||||||
| 								return that.config['max-key-repeat-rate'] | 								function(){  | ||||||
| 							}) | 									return that.config['max-key-repeat-rate'] | ||||||
|  | 								}), | ||||||
|  | 							check) | ||||||
| 				} | 				} | ||||||
| 
 | 
 | ||||||
| 				target.keydown(handler) | 				target.keydown(handler) | ||||||
| @ -484,7 +523,21 @@ module.Keyboard = core.ImageGridFeatures.Feature({ | |||||||
| 				this.__keyboard_config = this.keyboard || GLOBAL_KEYBOARD | 				this.__keyboard_config = this.keyboard || GLOBAL_KEYBOARD | ||||||
| 
 | 
 | ||||||
| 				this.toggleKeyboardHandling('on') | 				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