mirror of
				https://github.com/flynx/ImageGrid.git
				synced 2025-10-31 03:10:07 +00:00 
			
		
		
		
	fixed a bug in keyboard.js and made the introspection better...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									57e922c59c
								
							
						
					
					
						commit
						6ffd4e1e84
					
				| @ -39,7 +39,8 @@ function directionImage(reverse){ | |||||||
| // XXX this is experimental...
 | // XXX this is experimental...
 | ||||||
| // 		...not sure yet how to go about this...
 | // 		...not sure yet how to go about this...
 | ||||||
| function Action(text, func){ | function Action(text, func){ | ||||||
| 	func = func == null ? function(){return true}: func | 	var not_action = func === false ? true : false | ||||||
|  | 	func = !func ? function(){return true}: func | ||||||
| 	func.doc = text | 	func.doc = text | ||||||
| 
 | 
 | ||||||
| 	var name = text.split('\n')[0].trim() | 	var name = text.split('\n')[0].trim() | ||||||
| @ -48,12 +49,17 @@ function Action(text, func){ | |||||||
| 		console.warn('Action: "'+name+'" is defined more than once.') | 		console.warn('Action: "'+name+'" is defined more than once.') | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	ACTIONS[name] = func | 	if(!not_action){ | ||||||
|  | 		ACTIONS[name] = func | ||||||
|  | 	} | ||||||
| 
 | 
 | ||||||
| 	return func | 	return func | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| doc = Action | 
 | ||||||
|  | var _doc = doc | ||||||
|  | var doc = Action | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| /*********************************************************************/ | /*********************************************************************/ | ||||||
| @ -119,17 +125,21 @@ var KEYBOARD_CONFIG = { | |||||||
| 			'image selection/marks.', | 			'image selection/marks.', | ||||||
| 		pattern: '.overlay-info:hover', | 		pattern: '.overlay-info:hover', | ||||||
| 
 | 
 | ||||||
| 		ignore: [ 'A' ], | 		ignore: [ 'A', 'C', 'D' ], | ||||||
| 
 | 
 | ||||||
|  | 		// NOTE: these are here only for documentation...
 | ||||||
| 		A: { | 		A: { | ||||||
| 			// NOTE: this is here only for documentation...
 | 			ctrl: doc('Select all', false), | ||||||
| 			ctrl: doc('Select all'), |  | ||||||
| 		}, | 		}, | ||||||
|  | 		C: { | ||||||
|  | 			ctrl: doc('Copy selection', false) | ||||||
|  | 		}, | ||||||
|  | 
 | ||||||
| 		D: { | 		D: { | ||||||
| 			ctrl: doc('Clear selection',  | 			ctrl: doc('Clear selection',  | ||||||
| 				function(){ | 				function(){ | ||||||
|  | 					console.log('!!!') | ||||||
| 					document.getSelection().empty() | 					document.getSelection().empty() | ||||||
| 					return false |  | ||||||
| 				}) | 				}) | ||||||
| 		} | 		} | ||||||
| 	}, | 	}, | ||||||
| @ -145,7 +155,7 @@ var KEYBOARD_CONFIG = { | |||||||
| 
 | 
 | ||||||
| 		ignore: '*', | 		ignore: '*', | ||||||
| 
 | 
 | ||||||
| 		'insert-return': doc('Insert return'), | 		'insert-return': doc('Insert return', false), | ||||||
| 
 | 
 | ||||||
| 		Enter: { | 		Enter: { | ||||||
| 				default: doc('Accept dialog', | 				default: doc('Accept dialog', | ||||||
| @ -387,16 +397,16 @@ var KEYBOARD_CONFIG = { | |||||||
| 			}, | 			}, | ||||||
| 
 | 
 | ||||||
| 		// zooming...
 | 		// zooming...
 | ||||||
| 		'#1': doc('Fit one image', function(){ fitNImages(1) }), | 		'#1': doc('Fit one image', function(){ return !fitNImages(1) }), | ||||||
| 		'#2': doc('Fit two images', function(){ fitNImages(2) }), | 		'#2': doc('Fit two images', function(){ return !fitNImages(2) }), | ||||||
| 		'#3': doc('Fit three images', function(){ fitNImages(3) }), | 		'#3': doc('Fit three images', function(){ return !fitNImages(3) }), | ||||||
| 		'#4': doc('Fit four images', function(){ fitNImages(4) }), | 		'#4': doc('Fit four images', function(){ return !fitNImages(4) }), | ||||||
| 		'#5': doc('Fit five images', function(){ fitNImages(5) }), | 		'#5': doc('Fit five images', function(){ return !fitNImages(5) }), | ||||||
| 		'#6': doc('Fit six images', function(){ fitNImages(6) }), | 		'#6': doc('Fit six images', function(){ return !fitNImages(6) }), | ||||||
| 		'#7': doc('Fit seven images', function(){ fitNImages(7) }), | 		'#7': doc('Fit seven images', function(){ return !fitNImages(7) }), | ||||||
| 		'#8': doc('Fit eight images', function(){ fitNImages(8) }), | 		'#8': doc('Fit eight images', function(){ return !fitNImages(8) }), | ||||||
| 		'#9': doc('Fit nine images', function(){ fitNImages(9) }), | 		'#9': doc('Fit nine images', function(){ return !fitNImages(9) }), | ||||||
| 		'#0': doc('Fit maximum images', function(){ fitNImages(getScreenWidthInImages(CONFIG.min_image_size)) }), | 		'#0': doc('Fit maximum images', function(){ return !fitNImages(getScreenWidthInImages(CONFIG.min_image_size)) }), | ||||||
| 
 | 
 | ||||||
| 		// cropping...
 | 		// cropping...
 | ||||||
| 		C: doc('Show ribbon crop dialog', cropImagesDialog), | 		C: doc('Show ribbon crop dialog', cropImagesDialog), | ||||||
| @ -866,6 +876,10 @@ var KEYBOARD_CONFIG = { | |||||||
| 			'ctrl+alt': function(){ alert('ctrl-alt-`') }, | 			'ctrl+alt': function(){ alert('ctrl-alt-`') }, | ||||||
| 		}, | 		}, | ||||||
| 		*/ | 		*/ | ||||||
|  | 	}, | ||||||
|  | 
 | ||||||
|  | 	'.image': { | ||||||
|  | 		'#1': doc('mooo!') | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -10,6 +10,17 @@ | |||||||
| 
 | 
 | ||||||
| /*********************************************************************/ | /*********************************************************************/ | ||||||
| 
 | 
 | ||||||
|  | // Attributes to be ignored my the key handler...
 | ||||||
|  | //
 | ||||||
|  | // These are used for system tasks.
 | ||||||
|  | var KEYBOARD_SYSTEM_ATTRS = [ | ||||||
|  | 	'doc', | ||||||
|  | 	'title', | ||||||
|  | 	'ignore', | ||||||
|  | 	'pattern' | ||||||
|  | ] | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| // Neither _SPECIAL_KEYS nor _KEY_CODES are meant for direct access, use
 | // Neither _SPECIAL_KEYS nor _KEY_CODES are meant for direct access, use
 | ||||||
| // toKeyName(<code>) and toKeyCode(<name>) for a more uniform access.
 | // toKeyName(<code>) and toKeyCode(<name>) for a more uniform access.
 | ||||||
| //
 | //
 | ||||||
| @ -109,7 +120,7 @@ function toKeyCode(c){ | |||||||
| 
 | 
 | ||||||
| // documentation wrapper...
 | // documentation wrapper...
 | ||||||
| function doc(text, func){ | function doc(text, func){ | ||||||
| 	func = func == null ? function(){return true}: func | 	func = !func ? function(){return true}: func | ||||||
| 	func.doc = text | 	func.doc = text | ||||||
| 	return func | 	return func | ||||||
| } | } | ||||||
| @ -152,12 +163,6 @@ function normalizeModifiers(c, a, s){ | |||||||
|  * |  * | ||||||
|  * For doc on format see makeKeyboardHandler(...) |  * For doc on format see makeKeyboardHandler(...) | ||||||
|  * |  * | ||||||
|  * modes can be: |  | ||||||
|  * 	- 'any'	(default)	- Get list of all applicable handlers up until |  | ||||||
|  * 							the first applicable ignore. |  | ||||||
|  * 	- 'all'				- Get ALL handlers, including ignores |  | ||||||
|  * 	- <mode>			- Get handlers for an explicit mode |  | ||||||
|  * |  | ||||||
|  * modifiers can be: |  * modifiers can be: | ||||||
|  * 	- '' (default)		- No modifiers |  * 	- '' (default)		- No modifiers | ||||||
|  * 	- '?'				- Return list of applicable modifiers per mode |  * 	- '?'				- Return list of applicable modifiers per mode | ||||||
| @ -171,6 +176,13 @@ function normalizeModifiers(c, a, s){ | |||||||
|  * 							NOTE: normalizeModifiers(...) can be used as |  * 							NOTE: normalizeModifiers(...) can be used as | ||||||
|  * 								a reference, if in doubt. |  * 								a reference, if in doubt. | ||||||
|  * |  * | ||||||
|  |  * modes can be: | ||||||
|  |  * 	- 'any'	(default)	- Get list of all applicable handlers up until | ||||||
|  |  * 							the first applicable ignore. | ||||||
|  |  * 	- 'all'				- Get ALL handlers, including ignores | ||||||
|  |  * 	- <mode>			- Get handlers for an explicit mode | ||||||
|  |  * | ||||||
|  |  * | ||||||
|  * This will also resolve several shifted keys by name, for example: |  * This will also resolve several shifted keys by name, for example: | ||||||
|  * 'shift-/' is the same as '?', and either can be used, but the shorter  |  * 'shift-/' is the same as '?', and either can be used, but the shorter  | ||||||
|  * direct notation has priority (see _SHIFT_KEYS for supported keys). |  * direct notation has priority (see _SHIFT_KEYS for supported keys). | ||||||
| @ -183,6 +195,19 @@ function normalizeModifiers(c, a, s){ | |||||||
|  * 	} |  * 	} | ||||||
|  * |  * | ||||||
|  * |  * | ||||||
|  |  * <handler> can be: | ||||||
|  |  * 	- <function>		- handler | ||||||
|  |  * 	- [<doc>, <function>] | ||||||
|  |  * 						- lisp-style handler | ||||||
|  |  * 	- 'IGNORE'			- if mode is 'all' and key is in .ignore | ||||||
|  |  * 	- [<function>, 'IGNORE NEXT'] | ||||||
|  |  * 						- if mode is 'all' and the key is both in .ignore | ||||||
|  |  * 						  and a handler is defined in the current section | ||||||
|  |  * 						  NOTE: in this case if this mode matches, all | ||||||
|  |  * 						  		the subsequent handlers will get ignored | ||||||
|  |  * 						  		in normal modes... | ||||||
|  |  * | ||||||
|  |  * | ||||||
|  * NOTE: it is not possible to do a shift-? as it is already shifted. |  * NOTE: it is not possible to do a shift-? as it is already shifted. | ||||||
|  * NOTE: if a key is not handled in a mode, that mode will not be  |  * NOTE: if a key is not handled in a mode, that mode will not be  | ||||||
|  * 		present in the resulting object. |  * 		present in the resulting object. | ||||||
| @ -191,17 +216,16 @@ function normalizeModifiers(c, a, s){ | |||||||
|  * NOTE: modifiers can be a list of three bools... |  * NOTE: modifiers can be a list of three bools... | ||||||
|  * 		(see: normalizeModifiers(...) for further information) |  * 		(see: normalizeModifiers(...) for further information) | ||||||
|  * |  * | ||||||
|  * XXX need an explicit way to prioritize modes, avoiding object attr  |  | ||||||
|  * 		ordering... |  | ||||||
|  * XXX check do we need did_handling here... |  * XXX check do we need did_handling here... | ||||||
|  * |  | ||||||
|  * XXX BUG explicitly given modes do not yield results if the pattern  |  * XXX BUG explicitly given modes do not yield results if the pattern  | ||||||
|  * 		does not match... |  * 		does not match... | ||||||
|  */ |  */ | ||||||
| function getKeyHandlers(key, modifiers, keybindings, modes, shifted_keys){ | function getKeyHandlers(key, modifiers, keybindings, modes, shifted_keys){ | ||||||
| 	var chr = null | 	var chr = null | ||||||
| 	var s_chr = null | 	var s_chr = null | ||||||
|  | 	// XXX I do not understand why this is here...
 | ||||||
| 	var did_handling = false | 	var did_handling = false | ||||||
|  | 	var did_ignore = false | ||||||
| 	modifiers = modifiers == null ? '' : modifiers | 	modifiers = modifiers == null ? '' : modifiers | ||||||
| 	modifiers = modifiers != '?' ? normalizeModifiers(modifiers) : modifiers | 	modifiers = modifiers != '?' ? normalizeModifiers(modifiers) : modifiers | ||||||
| 	modes = modes == null ? 'any' : modes | 	modes = modes == null ? 'any' : modes | ||||||
| @ -224,6 +248,24 @@ function getKeyHandlers(key, modifiers, keybindings, modes, shifted_keys){ | |||||||
| 
 | 
 | ||||||
| 	for(var title in keybindings){ | 	for(var title in keybindings){ | ||||||
| 
 | 
 | ||||||
|  | 		// If a key is ignored then look no further...
 | ||||||
|  | 		/* | ||||||
|  | 		if(did_ignore && modes != 'all'){ | ||||||
|  | 			break | ||||||
|  | 		} | ||||||
|  | 		*/ | ||||||
|  | 		if(did_ignore){ | ||||||
|  | 			if(modes != 'all'){ | ||||||
|  | 				break | ||||||
|  | 			} else { | ||||||
|  | 				did_ignore = false | ||||||
|  | 				// XXX do we actually need this???
 | ||||||
|  | 				if(modifiers != '?' && res[mode] != 'IGNORE'){ | ||||||
|  | 					res[mode] = [ res[mode], 'IGNORE NEXT'] | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
| 		// older version compatibility...
 | 		// older version compatibility...
 | ||||||
| 		if(keybindings[title].pattern != null){ | 		if(keybindings[title].pattern != null){ | ||||||
| 			var mode = keybindings[title].pattern | 			var mode = keybindings[title].pattern | ||||||
| @ -237,7 +279,7 @@ function getKeyHandlers(key, modifiers, keybindings, modes, shifted_keys){ | |||||||
| 			|| modes == mode | 			|| modes == mode | ||||||
| 			// 'any' means we need to check the mode...
 | 			// 'any' means we need to check the mode...
 | ||||||
| 			|| (modes == 'any' | 			|| (modes == 'any' | ||||||
| 				// '*' allways matches...
 | 				// '*' always matches...
 | ||||||
| 				&& mode == '*' | 				&& mode == '*' | ||||||
| 				// match the mode...
 | 				// match the mode...
 | ||||||
| 				|| $(mode).length != 0))){ | 				|| $(mode).length != 0))){ | ||||||
| @ -257,6 +299,7 @@ function getKeyHandlers(key, modifiers, keybindings, modes, shifted_keys){ | |||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		// alias...
 | 		// alias...
 | ||||||
|  | 		// XXX should this be before after or combined with ignore handling...
 | ||||||
| 		while( handler != null  | 		while( handler != null  | ||||||
| 				&& (typeof(handler) == typeof(123)  | 				&& (typeof(handler) == typeof(123)  | ||||||
| 					|| typeof(handler) == typeof('str') | 					|| typeof(handler) == typeof('str') | ||||||
| @ -293,21 +336,24 @@ function getKeyHandlers(key, modifiers, keybindings, modes, shifted_keys){ | |||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|  | 		// if something is ignored then just breakout and stop handling...
 | ||||||
|  | 		if(bindings.ignore == '*'  | ||||||
|  | 				|| bindings.ignore != null  | ||||||
|  | 					&& (bindings.ignore.indexOf(key) != -1  | ||||||
|  | 						|| bindings.ignore.indexOf(chr) != -1)){ | ||||||
|  | 			did_handling = true | ||||||
|  | 			// ignoring a key will stop processing it...
 | ||||||
|  | 			if(modes == 'all' || mode == modes){ | ||||||
|  | 				// NOTE: if a handler is defined in this section, this 
 | ||||||
|  | 				// 		will be overwritten...
 | ||||||
|  | 				// XXX need to add the handler to this if it's defined...
 | ||||||
|  | 				res[mode] = 'IGNORE' | ||||||
|  | 			} | ||||||
|  | 			did_ignore = true | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
| 		// no handler...
 | 		// no handler...
 | ||||||
| 		if(handler == null){ | 		if(handler == null){ | ||||||
| 			// if something is ignored then just breakout and stop handling...
 |  | ||||||
| 			if(bindings.ignore == '*'  |  | ||||||
| 					|| bindings.ignore != null  |  | ||||||
| 						&& (bindings.ignore.indexOf(key) != -1  |  | ||||||
| 							|| bindings.ignore.indexOf(chr) != -1)){ |  | ||||||
| 				did_handling = true |  | ||||||
| 				// ignoring a key will stop processing it...
 |  | ||||||
| 				if(modes == 'all' || mode == modes){ |  | ||||||
| 					res[mode] = 'IGNORE' |  | ||||||
| 				} else { |  | ||||||
| 					break |  | ||||||
| 				} |  | ||||||
| 			} |  | ||||||
| 			continue | 			continue | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| @ -531,7 +577,7 @@ function buildKeybindingsHelp(keybindings, shifted_keys){ | |||||||
| 
 | 
 | ||||||
| 		// handlers...
 | 		// handlers...
 | ||||||
| 		for(var key in mode){ | 		for(var key in mode){ | ||||||
| 			if(key == 'doc' || key == 'title' || key == 'ignore' || key == 'pattern'){ | 			if(KEYBOARD_SYSTEM_ATTRS.indexOf(key) >= 0){ | ||||||
| 				continue | 				continue | ||||||
| 			} | 			} | ||||||
| 			var modifiers = getKeyHandlers(key, '?', keybindings, 'all')[pattern] | 			var modifiers = getKeyHandlers(key, '?', keybindings, 'all')[pattern] | ||||||
| @ -542,12 +588,16 @@ function buildKeybindingsHelp(keybindings, shifted_keys){ | |||||||
| 
 | 
 | ||||||
| 				var handler = getKeyHandlers(key, mod, keybindings, 'all')[pattern] | 				var handler = getKeyHandlers(key, mod, keybindings, 'all')[pattern] | ||||||
| 
 | 
 | ||||||
|  | 				if(handler.constructor.name == 'Array' && handler[1] == 'IGNORE NEXT'){ | ||||||
|  | 					handler = handler[0] | ||||||
|  | 				} | ||||||
|  | 
 | ||||||
| 				// standard object doc...
 | 				// standard object doc...
 | ||||||
| 				if('doc' in handler){ | 				if('doc' in handler){ | ||||||
| 					var doc = handler.doc | 					var doc = handler.doc | ||||||
| 
 | 
 | ||||||
| 				// lisp style...
 | 				// lisp style...
 | ||||||
| 				} else if(typeof(handler) == typeof([]) && handler.constructor.name == 'Array'){ | 				} else if(handler.constructor.name == 'Array'){ | ||||||
| 					var doc = handler[1] | 					var doc = handler[1] | ||||||
| 
 | 
 | ||||||
| 				// no doc...
 | 				// no doc...
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user