mirror of
				https://github.com/flynx/ImageGrid.git
				synced 2025-10-31 03:10:07 +00:00 
			
		
		
		
	cleanup, tweaking and refactoring...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									4d169b91b4
								
							
						
					
					
						commit
						6f388e30df
					
				| @ -211,16 +211,18 @@ actions.Actions({ | |||||||
| 		`,
 | 		`,
 | ||||||
| 		{journal: true}, | 		{journal: true}, | ||||||
| 		function(d){ | 		function(d){ | ||||||
| 			this.clear() |  | ||||||
| 
 |  | ||||||
| 			return function(){ | 			return function(){ | ||||||
|  | 				if(d.images){ | ||||||
| 					this.images = d.images instanceof images.Images ?  | 					this.images = d.images instanceof images.Images ?  | ||||||
| 						d.images  | 						d.images  | ||||||
| 						: images.Images(d.images) | 						: images.Images(d.images) | ||||||
|  | 				} | ||||||
|  | 				if(d.data){ | ||||||
| 					this.data = d.data instanceof data.Data ?  | 					this.data = d.data instanceof data.Data ?  | ||||||
| 						d.data  | 						d.data  | ||||||
| 						: data.Data(d.data) | 						: data.Data(d.data) | ||||||
| 				} | 				} | ||||||
|  | 			} | ||||||
| 		}], | 		}], | ||||||
| 	// XXX should this clear or load empty???
 | 	// XXX should this clear or load empty???
 | ||||||
| 	clear: ['File/Clear', | 	clear: ['File/Clear', | ||||||
| @ -271,7 +273,7 @@ actions.Actions({ | |||||||
| 		NOTE: this will ignore attributes starting with '__'. | 		NOTE: this will ignore attributes starting with '__'. | ||||||
| 		`,
 | 		`,
 | ||||||
| 		function(mode){ | 		function(mode){ | ||||||
| 			var res = {} | 			return function(res){ | ||||||
| 				for(var k in this){ | 				for(var k in this){ | ||||||
| 					if(!k.startsWith('__')  | 					if(!k.startsWith('__')  | ||||||
| 							&& this[k] != null  | 							&& this[k] != null  | ||||||
| @ -279,7 +281,7 @@ actions.Actions({ | |||||||
| 						res[k] = this[k].dumpJSON() | 						res[k] = this[k].dumpJSON() | ||||||
| 					} | 					} | ||||||
| 				} | 				} | ||||||
| 			return res | 			} | ||||||
| 		}], | 		}], | ||||||
| 
 | 
 | ||||||
| 	getImagePath: ['- System/', | 	getImagePath: ['- System/', | ||||||
|  | |||||||
| @ -50,6 +50,13 @@ var MAIN_COLLECTION_TITLE = 'All' | |||||||
| // XXX undo...
 | // XXX undo...
 | ||||||
| var CollectionActions = actions.Actions({ | var CollectionActions = actions.Actions({ | ||||||
| 	config: { | 	config: { | ||||||
|  | 		// can be:
 | ||||||
|  | 		// 	'all'		- save crop state for all collections (default)
 | ||||||
|  | 		// 	'main'		- save crop state for main state only
 | ||||||
|  | 		// 	'none'		- do not save crop state
 | ||||||
|  | 		'collection-save-crop-state': 'all', | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| 		// XXX add default collection list to config...
 | 		// XXX add default collection list to config...
 | ||||||
| 		'default-collections': [ | 		'default-collections': [ | ||||||
| 		], | 		], | ||||||
| @ -153,10 +160,6 @@ var CollectionActions = actions.Actions({ | |||||||
| 		function(title, data){  | 		function(title, data){  | ||||||
| 			return new Promise(function(resolve){ resolve(data.data) }) }], | 			return new Promise(function(resolve){ resolve(data.data) }) }], | ||||||
| 
 | 
 | ||||||
| 	// XXX should a collection have its own crop stack???
 |  | ||||||
| 	// 		...this would be logical as the base collection is persistent
 |  | ||||||
| 	// 		and crop state indicates that uncropping will lose the state...
 |  | ||||||
| 	// XXX should this be a crop or just use the same mechanic as crops???
 |  | ||||||
| 	loadCollection: ['- Collections/', | 	loadCollection: ['- Collections/', | ||||||
| 		core.doc`Load collection...
 | 		core.doc`Load collection...
 | ||||||
| 
 | 
 | ||||||
| @ -195,38 +198,38 @@ var CollectionActions = actions.Actions({ | |||||||
| 					|| !(collection in this.collections)){ | 					|| !(collection in this.collections)){ | ||||||
| 				return | 				return | ||||||
| 			} | 			} | ||||||
|  | 			var crop_mode = this.config['collection-save-crop-state'] || 'all' | ||||||
| 
 | 
 | ||||||
| 			var current = this.current | 			var current = this.current | ||||||
| 			var ribbon = this.current_ribbon | 			var ribbon = this.current_ribbon | ||||||
| 
 | 
 | ||||||
|  | 			var prev = this.collection | ||||||
| 			var collection_data = this.collections[collection] | 			var collection_data = this.collections[collection] | ||||||
| 			var handlers = this.collection_handlers | 			var handlers = this.collection_handlers | ||||||
| 
 | 
 | ||||||
|  | 			// save current collection state...
 | ||||||
| 			// main view -> save it...
 | 			// main view -> save it...
 | ||||||
| 			if(this.collection == null){ | 			if(this.collection == null){ | ||||||
| 				this.collections[MAIN_COLLECTION_TITLE] = { | 				var main = this.collections[MAIN_COLLECTION_TITLE] = { | ||||||
| 					title: MAIN_COLLECTION_TITLE, | 					title: MAIN_COLLECTION_TITLE, | ||||||
| 					data: this.data, |  | ||||||
| 					crop_stack: this.crop_stack, |  | ||||||
| 				} |  | ||||||
| 				} | 				} | ||||||
| 
 | 
 | ||||||
| 			// load main collection...
 | 				// mode 'none' -> do not save crop state...
 | ||||||
| 			if(collection == MAIN_COLLECTION_TITLE){ | 				if(crop_mode == 'none'){ | ||||||
| 				var state = this.collections[MAIN_COLLECTION_TITLE] | 					//this.saveCollection(this.collection, 'base')
 | ||||||
|  | 					main.data = (this.crop_stack || [])[0] || this.data | ||||||
| 
 | 
 | ||||||
| 				this.load({ | 				// modes 'all' and 'main' -> save crop state...
 | ||||||
| 					data: state.data, | 				} else { | ||||||
| 					crop_stack: state.crop_stack, | 					//this.saveCollection(this.collection, 'crop')
 | ||||||
|  | 					main.data = this.data | ||||||
|  | 					main.crop_stack = this.crop_stack | ||||||
|  | 				} | ||||||
| 
 | 
 | ||||||
| 					// keep the collections...
 | 			} else if(crop_mode == 'all'){ | ||||||
| 					collections: this.collections, | 				this.saveCollection(this.collection, 'crop') | ||||||
| 					collection_order: this.collection_order, | 				//this.collections[this.collection].data = this.data
 | ||||||
| 				}) | 				//this.collections[this.collection].crop_stack = this.crop_stack
 | ||||||
| 
 |  | ||||||
| 				delete this.collections[MAIN_COLLECTION_TITLE] |  | ||||||
| 
 |  | ||||||
| 				return new Promise(function(resolve){ resolve(data) }) |  | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
| 			// load collection...
 | 			// load collection...
 | ||||||
| @ -240,25 +243,51 @@ var CollectionActions = actions.Actions({ | |||||||
| 
 | 
 | ||||||
| 							// current...
 | 							// current...
 | ||||||
| 							data.current = data.getImage(current)  | 							data.current = data.getImage(current)  | ||||||
| 								// current is not in collection -> try and keep the ribbon context...
 | 								// current is not in collection -> try and keep 
 | ||||||
| 								|| that.data.getImage(current, data.getImages(that.data.getImages(ribbon))) | 								// the ribbon context...
 | ||||||
|  | 								|| that.data.getImage( | ||||||
|  | 									current,  | ||||||
|  | 									data.getImages(that.data.getImages(ribbon))) | ||||||
| 								// get closest image from collection...
 | 								// get closest image from collection...
 | ||||||
| 								|| that.data.getImage(current, data.order) | 								|| that.data.getImage(current, data.order) | ||||||
| 								|| data.current | 								|| data.current | ||||||
| 
 | 
 | ||||||
| 							// XXX
 | 							data.tags = that.data.tags | ||||||
| 							//data.tags = that.data.tags
 | 
 | ||||||
|  | 							// NOTE: tags and other position dependant 
 | ||||||
|  | 							// 		data needs to be updated as collections
 | ||||||
|  | 							// 		may contain different numbers/orders of
 | ||||||
|  | 							// 		images...
 | ||||||
|  | 							data.updateImagePositions() | ||||||
| 
 | 
 | ||||||
| 							that.load({ | 							that.load({ | ||||||
| 								data: data, | 								data: data, | ||||||
| 
 | 
 | ||||||
|  | 								crop_stack: collection_data.crop_stack, | ||||||
|  | 
 | ||||||
| 								collections: that.collections, | 								collections: that.collections, | ||||||
| 								collection_order: that.collection_order, | 								collection_order: that.collection_order, | ||||||
| 							}) | 							}, true) | ||||||
| 
 | 
 | ||||||
| 							// NOTE: we need this to sync the possible different 
 | 							// maintain the .collection state...
 | ||||||
| 							// 		states (order, ...) of the collection and .data...
 | 							if(collection == MAIN_COLLECTION_TITLE){ | ||||||
| 							that.collectionLoaded(collection)	 | 								// no need to maintain the main data in two 
 | ||||||
|  | 								// locations...
 | ||||||
|  | 								delete that.collections[MAIN_COLLECTION_TITLE] | ||||||
|  | 								delete this.location.collection | ||||||
|  | 
 | ||||||
|  | 							} else { | ||||||
|  | 								that.data.collection = that.location.collection = collection | ||||||
|  | 								// cleanup...
 | ||||||
|  | 								if(collection == null){ | ||||||
|  | 									delete this.location.collection | ||||||
|  | 								} | ||||||
|  | 							} | ||||||
|  | 
 | ||||||
|  | 							// collection events...
 | ||||||
|  | 							that | ||||||
|  | 								.collectionUnloaded(prev || MAIN_COLLECTION_TITLE) | ||||||
|  | 								.collectionLoaded(collection)	 | ||||||
| 						}) | 						}) | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| @ -274,7 +303,6 @@ var CollectionActions = actions.Actions({ | |||||||
| 			// This is the window resize event...
 | 			// This is the window resize event...
 | ||||||
| 			//
 | 			//
 | ||||||
| 			// Not for direct use.
 | 			// Not for direct use.
 | ||||||
| 			this.data.collection = this.location.collection = collection |  | ||||||
| 		})], | 		})], | ||||||
| 	collectionUnloaded: ['- Collections/', | 	collectionUnloaded: ['- Collections/', | ||||||
| 		core.doc`This is called when unloading a collection.
 | 		core.doc`This is called when unloading a collection.
 | ||||||
| @ -285,48 +313,89 @@ var CollectionActions = actions.Actions({ | |||||||
| 			// Not for direct use.
 | 			// Not for direct use.
 | ||||||
| 		})], | 		})], | ||||||
| 
 | 
 | ||||||
|  | 	// XXX saving into current collection will leave the viewer in an 
 | ||||||
|  | 	// 		inconsistent state:
 | ||||||
|  | 	// 			- collection X is indicated as loaded
 | ||||||
|  | 	// 			- collection X has different state than what is loaded
 | ||||||
|  | 	// 		...not sure how to deal with this yet...
 | ||||||
| 	saveCollection: ['- Collections/', | 	saveCollection: ['- Collections/', | ||||||
| 		core.doc`Save current state to collection
 | 		core.doc`Save current state to collection
 | ||||||
| 
 | 
 | ||||||
|  | 			Save Current state to current collection | ||||||
|  | 			.saveCollection() | ||||||
|  | 			.saveCollection('current') | ||||||
|  | 				-> this | ||||||
|  | 				NOTE: this will do nothing if no collection is loaded. | ||||||
|  | 
 | ||||||
| 			Save Current state as collection | 			Save Current state as collection | ||||||
| 			.saveCollection(collection) | 			.saveCollection(collection) | ||||||
| 				-> this | 				-> this | ||||||
| 
 | 
 | ||||||
| 			Save new empty collection | 			Save new empty collection | ||||||
| 			.saveCollection(collection, true) | 			.saveCollection(collection, 'empty') | ||||||
| 				-> this | 				-> this | ||||||
|  | 
 | ||||||
|  | 			Save current crop state to collection | ||||||
|  | 			.saveCollection(collection, 'crop') | ||||||
|  | 				-> this | ||||||
|  | 
 | ||||||
|  | 			Save top depth crops from current crop stack to collection | ||||||
|  | 			.saveCollection(collection, depth) | ||||||
|  | 				-> this | ||||||
|  | 
 | ||||||
|  | 			Save base crop state to collection | ||||||
|  | 			.saveCollection(collection, 'base') | ||||||
|  | 				-> this | ||||||
|  | 
 | ||||||
| 		`,
 | 		`,
 | ||||||
| 		function(collection, empty){ | 		function(collection, mode){ | ||||||
| 			var that = this | 			var that = this | ||||||
| 			collection = collection || this.collection | 			collection = collection || this.collection | ||||||
|  | 			collection = collection == 'current' ? this.collection : collection | ||||||
| 
 | 
 | ||||||
| 			if(collection == null || collection == MAIN_COLLECTION_TITLE){ | 			if(collection == null || collection == MAIN_COLLECTION_TITLE){ | ||||||
| 				return | 				return | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
|  | 			var depth = typeof(mode) == typeof(123) ? mode : null | ||||||
|  | 			mode = depth == 0 ? null  | ||||||
|  | 				: depth ? 'crop'  | ||||||
|  | 				: mode | ||||||
|  | 
 | ||||||
| 			var collections = this.collections = this.collections || {} | 			var collections = this.collections = this.collections || {} | ||||||
| 
 | 
 | ||||||
| 			collections[collection] = { | 			var state = collections[collection] = { | ||||||
| 				title: collection, | 				title: collection, | ||||||
| 
 | 
 | ||||||
| 				// NOTE: we do not need to care about tags here as they 
 | 				// NOTE: we do not need to care about tags here as they 
 | ||||||
| 				// 		will get overwritten on load...
 | 				// 		will get overwritten on load...
 | ||||||
| 				data: (empty ?  | 				data: (mode == 'empty' ?  | ||||||
| 							(new this.data.constructor()) | 							(new this.data.constructor()) | ||||||
| 						: this.data | 						: mode == 'base' && this.crop_stack ?  | ||||||
| 							.clone() | 							(this.crop_stack[0] || this.data.clone()) | ||||||
|  | 						: mode == 'crop' ?  | ||||||
|  | 							this.data.clone() | ||||||
|  | 						: this.data.clone() | ||||||
| 							.removeUnloadedGIDs()) | 							.removeUnloadedGIDs()) | ||||||
| 					.run(function(){ | 					.run(function(){ | ||||||
| 						this.collection = collection | 						this.collection = collection | ||||||
|  | 
 | ||||||
| 						// NOTE: we are doing this manually after .removeUnloadedGIDs(..)
 | 						// NOTE: we are doing this manually after .removeUnloadedGIDs(..)
 | ||||||
| 						// 		as the later will mess-up the structures 
 | 						// 		as the later will mess-up the structures 
 | ||||||
| 						// 		inherited from the main .data, namely tags...
 | 						// 		inherited from the main .data, namely tags...
 | ||||||
| 						this.tags = that.data.tags | 						//this.tags = that.data.tags
 | ||||||
| 					}), | 					}), | ||||||
| 			} | 			} | ||||||
|  | 
 | ||||||
|  | 			if(mode == 'crop' && this.crop_stack && depth != 0){ | ||||||
|  | 				depth = depth || this.crop_stack.length | ||||||
|  | 				depth = this.crop_stack.length - Math.min(depth, this.crop_stack.length) | ||||||
|  | 
 | ||||||
|  | 				state.crop_stack = this.crop_stack.slice(depth) | ||||||
|  | 			} | ||||||
| 		}], | 		}], | ||||||
| 	newCollection: ['- Collections/', | 	newCollection: ['- Collections/', | ||||||
| 		function(collection){ return this.saveCollection(collection, true) }], | 		function(collection){ return this.saveCollection(collection, 'empty') }], | ||||||
| 	// XXX should we do anything special if collection is loaded???
 | 	// XXX should we do anything special if collection is loaded???
 | ||||||
| 	removeCollection: ['- Collections/', | 	removeCollection: ['- Collections/', | ||||||
| 		function(collection){ | 		function(collection){ | ||||||
| @ -633,27 +702,6 @@ module.Collection = core.ImageGridFeatures.Feature({ | |||||||
| 	actions: CollectionActions,  | 	actions: CollectionActions,  | ||||||
| 
 | 
 | ||||||
| 	handlers: [ | 	handlers: [ | ||||||
| 		// maintain the .collection state...
 |  | ||||||
| 		['uncrop.pre', |  | ||||||
| 			function(){ |  | ||||||
| 				var collection = this.collection |  | ||||||
| 				return function(){ |  | ||||||
| 					collection != null  |  | ||||||
| 						&& collection != this.data.collection |  | ||||||
| 						&& this.collectionUnloaded(collection) } |  | ||||||
| 			}], |  | ||||||
| 		['collectionUnloaded', |  | ||||||
| 			function(_, collection){ |  | ||||||
| 				var collection = this.location.collection = this.data.collection |  | ||||||
| 
 |  | ||||||
| 				// cleanup...
 |  | ||||||
| 				if(collection == null){ |  | ||||||
| 					delete this.location.collection |  | ||||||
| 				} |  | ||||||
| 
 |  | ||||||
| 				this.data.updateImagePositions() |  | ||||||
| 			}], |  | ||||||
| 
 |  | ||||||
| 		// XXX maintain changes...
 | 		// XXX maintain changes...
 | ||||||
| 		// 		- collection-level: mark collections as changed...
 | 		// 		- collection-level: mark collections as changed...
 | ||||||
| 		// 		- in-collection:
 | 		// 		- in-collection:
 | ||||||
| @ -867,11 +915,24 @@ module.UICollection = core.ImageGridFeatures.Feature({ | |||||||
| 	actions: UICollectionActions,  | 	actions: UICollectionActions,  | ||||||
| 
 | 
 | ||||||
| 	handlers: [ | 	handlers: [ | ||||||
|  | 		// update view when removing from current collection...
 | ||||||
| 		['uncollect', | 		['uncollect', | ||||||
| 			function(_, gids, collection){ | 			function(_, gids, collection){ | ||||||
| 				(collection == null || this.collection == collection) | 				(collection == null || this.collection == collection) | ||||||
| 					&& this.reload(true) | 					&& this.reload(true) | ||||||
| 			}], | 			}], | ||||||
|  | 
 | ||||||
|  | 		// maintain crop viewer state when loading/unloading collections...
 | ||||||
|  | 		['collectionLoaded collectionUnloaded', | ||||||
|  | 			function(){ | ||||||
|  | 				this.dom[this.collection ?  | ||||||
|  | 					'addClass'  | ||||||
|  | 					: 'removeClass']('collection-mode') | ||||||
|  | 
 | ||||||
|  | 				this.dom[this.cropped ?  | ||||||
|  | 					'addClass'  | ||||||
|  | 					: 'removeClass']('crop-mode') | ||||||
|  | 			}], | ||||||
| 	], | 	], | ||||||
| }) | }) | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -547,7 +547,7 @@ var SerializationActions = actions.Actions({ | |||||||
| 	json: ['- System/', | 	json: ['- System/', | ||||||
| 		function(){ return {} }], | 		function(){ return {} }], | ||||||
| 	load: ['- System/', | 	load: ['- System/', | ||||||
| 		function(){ }], | 		function(data, merge){ !merge && this.clear() }], | ||||||
| 	clear: ['- Sustem/', | 	clear: ['- Sustem/', | ||||||
| 		function(){ }], | 		function(){ }], | ||||||
| }) | }) | ||||||
|  | |||||||
| @ -119,16 +119,28 @@ module.GLOBAL_KEYBOARD = { | |||||||
| 		shift_S: 'DROP', | 		shift_S: 'DROP', | ||||||
| 	}, | 	}, | ||||||
| 
 | 
 | ||||||
| 	// XXX add "save as collection..."
 |  | ||||||
| 	'Crop': { | 	'Crop': { | ||||||
| 		pattern: '.crop-mode', | 		pattern: '.crop-mode', | ||||||
| 
 | 
 | ||||||
|  | 		drop: [ | ||||||
|  | 			'Esc', | ||||||
|  | 		], | ||||||
|  | 
 | ||||||
| 		Esc: 'uncrop', | 		Esc: 'uncrop', | ||||||
| 		ctrl_Esc: 'uncropAll', | 		shift_Esc: 'uncropAll', | ||||||
|  | 
 | ||||||
|  | 		// XXX
 | ||||||
|  | 		//ctrl_S: 'saveAsCollection',
 | ||||||
| 
 | 
 | ||||||
| 		W: 'testAction2 -- XXX DEBUG: remove when done...', | 		W: 'testAction2 -- XXX DEBUG: remove when done...', | ||||||
| 	}, | 	}, | ||||||
| 
 | 
 | ||||||
|  | 	'Collection': { | ||||||
|  | 		pattern: '.collection-mode', | ||||||
|  | 
 | ||||||
|  | 		Esc: 'loadCollection: "All"', | ||||||
|  | 	}, | ||||||
|  | 
 | ||||||
| 	'Range': { | 	'Range': { | ||||||
| 		doc: 'Range editing', | 		doc: 'Range editing', | ||||||
| 		pattern: '.brace', | 		pattern: '.brace', | ||||||
|  | |||||||
| @ -549,15 +549,6 @@ core.ImageGridFeatures.Feature({ | |||||||
| 			function(target){  | 			function(target){  | ||||||
| 				return updateImagePosition(this, target) }], | 				return updateImagePosition(this, target) }], | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| 		// manage the .crop-mode css class...
 |  | ||||||
| 		['crop uncrop', |  | ||||||
| 			function(){ |  | ||||||
| 				this.dom[this.cropped ?  |  | ||||||
| 					'addClass'  |  | ||||||
| 					: 'removeClass']('crop-mode') |  | ||||||
| 			}], |  | ||||||
| 
 |  | ||||||
| 		// reloading and updating...
 | 		// reloading and updating...
 | ||||||
| 		[[ | 		[[ | ||||||
| 			'sortImages', | 			'sortImages', | ||||||
|  | |||||||
| @ -746,6 +746,17 @@ module.Viewer = core.ImageGridFeatures.Feature({ | |||||||
| 
 | 
 | ||||||
| 		['focusImage.post',  | 		['focusImage.post',  | ||||||
| 			function(){ this.alignRibbons() }], | 			function(){ this.alignRibbons() }], | ||||||
|  | 
 | ||||||
|  | 		// manage the .crop-mode css class...
 | ||||||
|  | 		// XXX this is not the right spot for this...
 | ||||||
|  | 		// 		...but this is a bit too small for a stand-alone feature...
 | ||||||
|  | 		['crop uncrop', | ||||||
|  | 			function(){ | ||||||
|  | 				this.dom[this.cropped ?  | ||||||
|  | 					'addClass'  | ||||||
|  | 					: 'removeClass']('crop-mode') | ||||||
|  | 			}], | ||||||
|  | 
 | ||||||
| 	], | 	], | ||||||
| }) | }) | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user