mirror of
				https://github.com/flynx/ImageGrid.git
				synced 2025-10-31 03:10:07 +00:00 
			
		
		
		
	preset list mostly done, getting ready to add presets and preset history...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									23a1b3818d
								
							
						
					
					
						commit
						8b5a3aee83
					
				| @ -3095,15 +3095,28 @@ var FileSystemWriterUIActions = actions.Actions({ | |||||||
| 		'exportDialog: "images"'], | 		'exportDialog: "images"'], | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 	// XXX export using a preset...
 |  | ||||||
| 	// XXX TODO:
 | 	// XXX TODO:
 | ||||||
| 	// 		- format the element into: title (optional) + info
 | 	// 		- format the element into: title (optional) + info
 | ||||||
|  | 	// XXX add a 'name' field to the exportDialog(..)???
 | ||||||
|  | 	// XXX button icons... 
 | ||||||
|  | 	// XXX button shortcuts...
 | ||||||
| 	exportPresets: ['- File/Export history...', | 	exportPresets: ['- File/Export history...', | ||||||
| 		widgets.makeUIDialog(function(mode){ | 		widgets.makeUIDialog(function(mode){ | ||||||
| 			var that = this | 			var that = this | ||||||
|  | 			var logger = this.logger && this.logger.push('exportPresets') | ||||||
|  | 
 | ||||||
|  | 			// XXX these should be type-specific...
 | ||||||
|  | 			var getName = function(preset){ | ||||||
|  | 				return preset.name | ||||||
|  | 					|| `${ preset.mode }: "${ preset.path }"` } | ||||||
| 
 | 
 | ||||||
| 			// presets...
 | 			// presets...
 | ||||||
| 			var presets = that.config['export-presets'] || [] | 			var presets = that.config['export-presets'] || [] | ||||||
|  | 			var index = presets | ||||||
|  | 				.reduce(function(res, e, i){ | ||||||
|  | 					res[getName(e)] = i  | ||||||
|  | 					return res }, {}) | ||||||
|  | 			var keys = Object.keys(index) | ||||||
| 
 | 
 | ||||||
| 			// history...
 | 			// history...
 | ||||||
| 			// XXX
 | 			// XXX
 | ||||||
| @ -3111,56 +3124,73 @@ var FileSystemWriterUIActions = actions.Actions({ | |||||||
| 			var history_index = {} | 			var history_index = {} | ||||||
| 			var history_keys = Object.keys(history_index) | 			var history_keys = Object.keys(history_index) | ||||||
| 
 | 
 | ||||||
| 			// XXX
 |  | ||||||
| 			var getPreset = function(title, presets, index){ | 			var getPreset = function(title, presets, index){ | ||||||
| 				return presets[index[title]] } | 				return presets[index[title]] } | ||||||
| 
 | 
 | ||||||
| 			return browse.makeLister(null, function(path, make){ | 			return browse.makeLister(null, function(path, make){ | ||||||
| 
 | 				// preset list...
 | ||||||
| 				var index = presets |  | ||||||
| 					.reduce(function(res, e, i){ |  | ||||||
| 						name = e.name |  | ||||||
| 							// XXX these should be type-specific...
 |  | ||||||
| 							|| `${ e.mode }: "${ e.path }"` |  | ||||||
| 						res[name] = i  |  | ||||||
| 						return res }, {}) |  | ||||||
| 				var keys = Object.keys(index) |  | ||||||
| 
 |  | ||||||
| 				// presets...
 |  | ||||||
| 				//make.Separator()
 |  | ||||||
| 				keys.length == 0 ? | 				keys.length == 0 ? | ||||||
| 					make.Empty('No presets...') | 					make.Empty('No presets...') | ||||||
| 					: make.EditableList(keys, { | 					: make.EditableList(keys, { | ||||||
| 						list_id: 'presets', | 						list_id: 'presets', | ||||||
| 						sortable: true, | 						sortable: true, | ||||||
|  | 						update_merge: 'live', | ||||||
| 						new_item: false, | 						new_item: false, | ||||||
|  | 						// NOTE: we use empty to restore the automatic value...
 | ||||||
|  | 						allow_empty: true, | ||||||
|  | 						itemedit: function(evt, from, to){ | ||||||
|  | 							var preset = getPreset(from, presets, index) | ||||||
|  | 							// clear...
 | ||||||
|  | 							if(to.trim() == ''){ | ||||||
|  | 								delete preset.name | ||||||
|  | 								to = keys[keys.indexOf(from)] = getName(preset) | ||||||
|  | 							// set...
 | ||||||
|  | 							} else { | ||||||
|  | 								to = preset.name = to.trim() } | ||||||
|  | 							// update index...
 | ||||||
|  | 							index[to] = index[from] | ||||||
|  | 							delete index[from]  | ||||||
|  | 							// select item...
 | ||||||
|  | 							// NOTE: this is not done automatically because 
 | ||||||
|  | 							// 		we are changing the title .EditableList(..)
 | ||||||
|  | 							// 		is expecting...
 | ||||||
|  | 							make.dialog.one('update',  | ||||||
|  | 								function(){ | ||||||
|  | 									make.dialog.select(to) }) }, | ||||||
| 						buttons: [ | 						buttons: [ | ||||||
| 							// XXX new export or should this be edit???
 | 							['<small>edit</small>', function(title){ | ||||||
| 							['E', function(title){ | 								var preset = getPreset(title, presets, index) | ||||||
| 								that.exportDialog(getPreset(title, presets, index)) | 								that.exportDialog(preset) | ||||||
| 						   			.close(function(){ | 						   			.close(function(){ | ||||||
| 										// XXX for some reason on update when 
 | 										var n = getName(preset) | ||||||
| 										// 		name affected the item does not 
 | 										// update the list if name is affected...
 | ||||||
| 										// 		get updated...
 | 										if(n != title){ | ||||||
| 										make.dialog.update() })}], | 											keys[keys.indexOf(title)] = n | ||||||
| 							// XXX not sure about the default icon...
 | 											index[n] = index[title] | ||||||
| 							['T', 'TO_TOP'], | 											delete index[title] | ||||||
| 							'REMOVE', | 											make.dialog.select(n)  | ||||||
| 						], | 											make.dialog.update() } })}], | ||||||
| 						// XXX export...
 | 							['♦', 'TO_TOP'], | ||||||
|  | 							'REMOVE'], | ||||||
|  | 						// export...
 | ||||||
| 						open: function(evt, title){ | 						open: function(evt, title){ | ||||||
| 							that.exportAs(getPreset(title, presets, index)) | 							var preset = getPreset(title, presets, index) | ||||||
| 							make.dialog.close() }, | 							// export only if we get a good preset...
 | ||||||
| 						// XXX handle rename -> update index...
 | 							if(preset && getName(preset) == title){ | ||||||
| 						// XXX
 | 								that.exportAs(preset) | ||||||
| 					}) | 								return make.dialog.close() } | ||||||
|  | 							// error...
 | ||||||
|  | 							logger  | ||||||
|  | 								&& logger.emit('error', 'preset not found.') }, }) | ||||||
| 
 | 
 | ||||||
| 				// export dialog...
 | 				// export dialog...
 | ||||||
| 				make.Separator({ style: { opacity: '0.1' } }) | 				make.Separator({ style: { opacity: '0.1' } }) | ||||||
| 				make('E$xport...', { | 				make('E$xport...', { | ||||||
| 					open: function(){ | 					open: function(){ | ||||||
| 						that.exportDialog() | 						that.exportDialog() | ||||||
| 						make.dialog.close() }, }) | 							.close(function(evt, reason){ | ||||||
|  | 								reason != 'reject' | ||||||
|  | 									&& make.dialog.close() }) }, }) | ||||||
| 
 | 
 | ||||||
| 				// history...
 | 				// history...
 | ||||||
| 				make.Separator() | 				make.Separator() | ||||||
| @ -3186,30 +3216,49 @@ var FileSystemWriterUIActions = actions.Actions({ | |||||||
| 			}) | 			}) | ||||||
| 			.run(function(){ | 			.run(function(){ | ||||||
| 				var that = this | 				var that = this | ||||||
| 				// XXX
 | 				// XXX this does not work yet...
 | ||||||
| 				this.keyboard.on('E', function(){ | 				this.keyboard.on('E', function(){ | ||||||
| 					console.log('!!!!!!!!!!!!!', that.selected) | 					console.log('!!!!!!!!!!!!!', that.selected) | ||||||
| 				}) | 				}) | ||||||
| 			}) |  | ||||||
| 	   		.close(function(){ |  | ||||||
| 
 |  | ||||||
| 				// XXX need to merge history/presets back when dialog closes...
 |  | ||||||
| 				// XXX
 |  | ||||||
| 
 |  | ||||||
| 			}) })], | 			}) })], | ||||||
| 
 | 
 | ||||||
| 	// XXX these do note need the ui -- move to a separate feature...
 | 	// XXX these do note need the ui -- move to a separate feature...
 | ||||||
| 	// XXX these are essentially the same as the history API, make a 
 | 	// XXX these are essentially the same as the history API, make a 
 | ||||||
| 	// 		generic list manager???
 | 	// 		generic list manager???
 | ||||||
|  | 	// XXX need to check preset uniqueness...
 | ||||||
| 	exportPresetSave: ['- File/',  | 	exportPresetSave: ['- File/',  | ||||||
| 		function(){}], | 		function(settings){ | ||||||
|  | 			settings = settings  | ||||||
|  | 				|| this.config['export-settings'] | ||||||
|  | 			// XXX need to check preset uniqueness...
 | ||||||
|  | 			settings  | ||||||
|  | 				&& (this.config['export-presets'] =  | ||||||
|  | 						this.config['export-presets']  | ||||||
|  | 						|| []) | ||||||
|  | 					.push(settings) }], | ||||||
|  | 
 | ||||||
|  | 	// XXX need a way to reference a preset...
 | ||||||
| 	exportPresetDelete: ['- File/',  | 	exportPresetDelete: ['- File/',  | ||||||
| 		function(){}], | 		function(){}], | ||||||
| 	exportPresetRun: ['- File/',  | 	exportPresetRun: ['- File/',  | ||||||
| 		function(){}], | 		function(){}], | ||||||
| 
 | 
 | ||||||
|  | 	// XXX need to check item uniqueness...
 | ||||||
| 	exportHistoryPush: ['- File/',  | 	exportHistoryPush: ['- File/',  | ||||||
| 		function(){}], | 		function(settings){ | ||||||
|  | 			settings = settings  | ||||||
|  | 				|| this.config['export-settings'] | ||||||
|  | 			var l = this.config['export-history-length'] || 50 | ||||||
|  | 			var history =  | ||||||
|  | 				this.config['export-history'] =  | ||||||
|  | 					this.config['export-history'] || [] | ||||||
|  | 			// add...
 | ||||||
|  | 			// XXX need to check item uniqueness...
 | ||||||
|  | 			settings  | ||||||
|  | 				&& history.push(settings)  | ||||||
|  | 			// trim the history...
 | ||||||
|  | 			history.length > l | ||||||
|  | 				&& history.splice(0, history.length - l) }], | ||||||
| }) | }) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @ -3226,6 +3275,13 @@ module.FileSystemWriterUI = core.ImageGridFeatures.Feature({ | |||||||
| 	], | 	], | ||||||
| 
 | 
 | ||||||
| 	actions: FileSystemWriterUIActions, | 	actions: FileSystemWriterUIActions, | ||||||
|  | 
 | ||||||
|  | 	handlers: [ | ||||||
|  | 		[[ | ||||||
|  | 			'exportIndex', | ||||||
|  | 			'exportDirs', | ||||||
|  | 		], function(_, settings){}] | ||||||
|  | 	], | ||||||
| }) | }) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -842,8 +842,7 @@ var DialogsActions = actions.Actions({ | |||||||
| 				: options.sortable | 				: options.sortable | ||||||
| 			return browse.makeLister(null,  | 			return browse.makeLister(null,  | ||||||
| 				function(path, make){ | 				function(path, make){ | ||||||
| 					make.EditableList(list, options) | 					make.EditableList(list, options) },  | ||||||
| 				},  |  | ||||||
| 				options) })], | 				options) })], | ||||||
| 	showActionList: ['- Interface/',  | 	showActionList: ['- Interface/',  | ||||||
| 		core.doc`Show list of actions dialog...
 | 		core.doc`Show list of actions dialog...
 | ||||||
|  | |||||||
| @ -600,7 +600,14 @@ function(data, options){ | |||||||
| //
 | //
 | ||||||
| // 		// Item edit event handler...
 | // 		// Item edit event handler...
 | ||||||
| // 		//
 | // 		//
 | ||||||
| // 		itemedit: function(from, to){ ... },
 | // 		itemedit: function(evt, from, to){ ... },
 | ||||||
|  | //
 | ||||||
|  | // 		// If true allow saving and triggering options.itemedit(..) on an
 | ||||||
|  | // 		// empty value after editing the item... (default: null)
 | ||||||
|  | // 		//
 | ||||||
|  | // 		// NOTE: this will not save the empty value (see .Editable(..))
 | ||||||
|  | // 		//		this will only trigger the handler on an empty value...
 | ||||||
|  | // 		allow_empty: null | <bool>,
 | ||||||
| //
 | //
 | ||||||
| //		// Item open event handler...
 | //		// Item open event handler...
 | ||||||
| //		//
 | //		//
 | ||||||
| @ -659,10 +666,11 @@ function(data, options){ | |||||||
| // 		// Merge list state and external list mode on update...
 | // 		// Merge list state and external list mode on update...
 | ||||||
| // 		//
 | // 		//
 | ||||||
| // 		// This can be:
 | // 		// This can be:
 | ||||||
| // 		//	null			- keep dialog state, ignore external state (default)
 | // 		//	'keep_changes'	- keep dialog state, ignore external state (default)
 | ||||||
|  | // 		//	null			- same as 'keep_changes'
 | ||||||
| // 		//	'drop_changes'	- replace dialog state with input state
 | // 		//	'drop_changes'	- replace dialog state with input state
 | ||||||
| // 		//	'keep_changes'	- keep dialog state (ignoring input)
 |  | ||||||
| // 		//	'merge'			- merge dialog state and input state
 | // 		//	'merge'			- merge dialog state and input state
 | ||||||
|  | // 		//	'live'			- live edit
 | ||||||
| // 		//	<function>		- merge the changes
 | // 		//	<function>		- merge the changes
 | ||||||
| //		//
 | //		//
 | ||||||
| // 		update_merge: null | 'drop_changes' | 'keep_changes' | 'merge' | <function>,
 | // 		update_merge: null | 'drop_changes' | 'keep_changes' | 'merge' | <function>,
 | ||||||
| @ -861,19 +869,15 @@ function(list, options){ | |||||||
| 				], | 				], | ||||||
| 			}) | 			}) | ||||||
| 			.on('edit-commit', function(evt, to){ | 			.on('edit-commit', function(evt, to){ | ||||||
| 				if(to.trim() != ''){ | 				if(options.allow_empty || to.trim() != ''){ | ||||||
| 					to = saveItem(to, from) | 					to = saveItem(to, from) | ||||||
| 
 |  | ||||||
| 					options.itemedit  | 					options.itemedit  | ||||||
| 						&& options.itemedit.call(elem, evt, from, to) | 						&& options.itemedit.call(elem, evt, from, to) } }) | ||||||
| 				} |  | ||||||
| 			}) |  | ||||||
| 			.on('edit-abort edit-commit', function(_, title){ | 			.on('edit-abort edit-commit', function(_, title){ | ||||||
| 				title = title.trim() == '' ? from : title | 				title = title.trim() == '' ? from : title | ||||||
| 				title = title.replace(/\$/g, '') | 				title = title.replace(/\$/g, '') | ||||||
| 				dialog.update() | 				dialog.update() | ||||||
| 					.then(function(){ dialog.select(`"${title}"`) }) | 					.then(function(){ dialog.select(`"${title}"`) }) }) } | ||||||
| 			}) } |  | ||||||
| 
 | 
 | ||||||
| 	dialog.__list = dialog.__list || {} | 	dialog.__list = dialog.__list || {} | ||||||
| 	dialog.__editable = dialog.__editable || {} | 	dialog.__editable = dialog.__editable || {} | ||||||
| @ -893,8 +897,7 @@ function(list, options){ | |||||||
| 	options = options || {} | 	options = options || {} | ||||||
| 	var opts = {} | 	var opts = {} | ||||||
| 	for(var k in options){ | 	for(var k in options){ | ||||||
| 		opts[k] = options[k] | 		opts[k] = options[k] } | ||||||
| 	} |  | ||||||
| 	options = opts | 	options = opts | ||||||
| 
 | 
 | ||||||
| 	var lst =  | 	var lst =  | ||||||
| @ -903,7 +906,9 @@ function(list, options){ | |||||||
| 			(list instanceof Function ? list() : list) | 			(list instanceof Function ? list() : list) | ||||||
| 
 | 
 | ||||||
| 		// load dialog state (ignore input)...
 | 		// load dialog state (ignore input)...
 | ||||||
| 		: (options.update_merge == null || options.update_merge == 'keep_changes') ?  | 		: (options.update_merge == null  | ||||||
|  | 				|| options.update_merge == 'keep_changes' | ||||||
|  | 				|| options.update_merge == 'live') ?  | ||||||
| 			dialog.__list[id] | 			dialog.__list[id] | ||||||
| 
 | 
 | ||||||
| 		// load input/external state (ignore dialog state)...
 | 		// load input/external state (ignore dialog state)...
 | ||||||
| @ -922,8 +927,7 @@ function(list, options){ | |||||||
| 						// via their position in local...
 | 						// via their position in local...
 | ||||||
| 						i = i == -1 ? input.indexOf(a) : i | 						i = i == -1 ? input.indexOf(a) : i | ||||||
| 						j = j == -1 ? input.indexOf(b) : j | 						j = j == -1 ? input.indexOf(b) : j | ||||||
| 						return i - j | 						return i - j }) | ||||||
| 					}) |  | ||||||
| 			})(dialog.__list[id] || [], list instanceof Function ? list() : list) | 			})(dialog.__list[id] || [], list instanceof Function ? list() : list) | ||||||
| 
 | 
 | ||||||
| 		// user merge...
 | 		// user merge...
 | ||||||
| @ -940,7 +944,11 @@ function(list, options){ | |||||||
| 	var editable = dialog.__editable[id] = lst instanceof Array | 	var editable = dialog.__editable[id] = lst instanceof Array | ||||||
| 	// NOTE: we .slice() here to make the changes a bit better packaged
 | 	// NOTE: we .slice() here to make the changes a bit better packaged
 | ||||||
| 	// 		or discrete and not done as they come in...
 | 	// 		or discrete and not done as they come in...
 | ||||||
| 	lst = lst instanceof Array ? lst.slice() : Object.keys(lst) | 	lst = lst instanceof Array ?  | ||||||
|  | 		(options.update_merge == 'live' ? | ||||||
|  | 			lst | ||||||
|  | 			: lst.slice()) | ||||||
|  | 		: Object.keys(lst) | ||||||
| 
 | 
 | ||||||
| 	dialog.__list[id] = lst | 	dialog.__list[id] = lst | ||||||
| 
 | 
 | ||||||
| @ -959,8 +967,7 @@ function(list, options){ | |||||||
| 		options.to_top_button | 		options.to_top_button | ||||||
| 			&& buttons.push('TO_TOP') | 			&& buttons.push('TO_TOP') | ||||||
| 		options.to_bottom_button | 		options.to_bottom_button | ||||||
| 			&& buttons.push('TO_BOTTOM') | 			&& buttons.push('TO_BOTTOM') } | ||||||
| 	} |  | ||||||
| 	// remove...
 | 	// remove...
 | ||||||
| 	editable  | 	editable  | ||||||
| 		&& options.delete_button !== false | 		&& options.delete_button !== false | ||||||
| @ -1055,8 +1062,7 @@ function(list, options){ | |||||||
| 				var key = button instanceof Array ? button[1] : button | 				var key = button instanceof Array ? button[1] : button | ||||||
| 				// skip seen buttons...
 | 				// skip seen buttons...
 | ||||||
| 				if(seen.indexOf(key) >= 0){ | 				if(seen.indexOf(key) >= 0){ | ||||||
| 					return key | 					return key } | ||||||
| 				} |  | ||||||
| 				var res = button in __buttons ?  | 				var res = button in __buttons ?  | ||||||
| 						__buttons[button] | 						__buttons[button] | ||||||
| 					: button[1] in __buttons ?  | 					: button[1] in __buttons ?  | ||||||
| @ -1065,12 +1071,9 @@ function(list, options){ | |||||||
| 				// group if at least one sort button is present...
 | 				// group if at least one sort button is present...
 | ||||||
| 				if(res !== button){ | 				if(res !== button){ | ||||||
| 					options.groupList = true | 					options.groupList = true | ||||||
| 
 |  | ||||||
| 					// avoid duplicates...
 | 					// avoid duplicates...
 | ||||||
| 					seen.push(key) | 					seen.push(key) } | ||||||
| 				} | 				return res.slice() }) | ||||||
| 				return res.slice() |  | ||||||
| 			}) |  | ||||||
| 			// clear out the unused button placeholders...
 | 			// clear out the unused button placeholders...
 | ||||||
| 			.filter(function(b){  | 			.filter(function(b){  | ||||||
| 				return ['UP', 'DOWN', 'TO_TOP', 'TO_BOTTOM', 'REMOVE'].indexOf(b) < 0 }) | 				return ['UP', 'DOWN', 'TO_TOP', 'TO_BOTTOM', 'REMOVE'].indexOf(b) < 0 }) | ||||||
| @ -1260,8 +1263,8 @@ function(list, pins, options){ | |||||||
| 	// link the to_remove lists of pins and the main list...
 | 	// link the to_remove lists of pins and the main list...
 | ||||||
| 	dialog.__to_remove = dialog.__to_remove || {} | 	dialog.__to_remove = dialog.__to_remove || {} | ||||||
| 	if(dialog.__to_remove[id] == null){ | 	if(dialog.__to_remove[id] == null){ | ||||||
| 		dialog.__to_remove[id] = dialog.__to_remove[pins_id] = [] | 		dialog.__to_remove[id] =  | ||||||
| 	} | 			dialog.__to_remove[pins_id] = [] } | ||||||
| 
 | 
 | ||||||
| 	// XXX redraw....
 | 	// XXX redraw....
 | ||||||
| 	// 		- sort			- within one list this is trivial (history.js)
 | 	// 		- sort			- within one list this is trivial (history.js)
 | ||||||
| @ -2027,8 +2030,7 @@ var BrowserPrototype = { | |||||||
| 		if(e.length <= 0){ | 		if(e.length <= 0){ | ||||||
| 			return null | 			return null | ||||||
| 		} | 		} | ||||||
| 		return e.find('.text').text() | 		return e.find('.text').text() }, | ||||||
| 	}, |  | ||||||
| 	set selected(value){ | 	set selected(value){ | ||||||
| 		return this.select(value) }, | 		return this.select(value) }, | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user