now we can rename collections (still needs cleanup)...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2017-12-04 19:17:42 +03:00
parent 5264e5cd3a
commit fddb35b9c7
2 changed files with 95 additions and 10 deletions

View File

@ -1924,6 +1924,8 @@ module.AutoCollections = core.ImageGridFeatures.Feature({
// XXX show collections in image metadata... (???) // XXX show collections in image metadata... (???)
// XXX might be nice to indicate if a collection is loaded -- has .data... // XXX might be nice to indicate if a collection is loaded -- has .data...
// XXX rename collection ui... // XXX rename collection ui...
// XXX might be nice to add collection previews to the collection list...
// ...show the base ribbon from collection as background
var UICollectionActions = actions.Actions({ var UICollectionActions = actions.Actions({
config: { config: {
// Global default collections... // Global default collections...
@ -1948,7 +1950,7 @@ var UICollectionActions = actions.Actions({
&& title != MAIN_COLLECTION_TITLE }, && title != MAIN_COLLECTION_TITLE },
})], })],
// XXX edit collection title here??? // XXX edit collection title here??? (on menu)
// ...also might need a collection editor dialog... // ...also might need a collection editor dialog...
// XXX would be nice to make this nested (i.e. path list)... // XXX would be nice to make this nested (i.e. path list)...
browseCollections: ['Collections/$Collec$tions...', browseCollections: ['Collections/$Collec$tions...',
@ -1963,7 +1965,7 @@ var UICollectionActions = actions.Actions({
var collections = that.collection_order = var collections = that.collection_order =
(that.collection_order || []).slice() (that.collection_order || []).slice()
var defaults = this.config['default-collections'] var defaults = that.config['default-collections']
if(defaults){ if(defaults){
collections = collections.concat(defaults).unique() collections = collections.concat(defaults).unique()
} }
@ -2024,10 +2026,9 @@ var UICollectionActions = actions.Actions({
} }
// update collection list if changed externally... // update collection list if changed externally...
// XXX do we need this???
collections.splice.apply(collections, [0, collections.length].concat( collections.splice.apply(collections, [0, collections.length].concat(
collections collections
.concat(this.collection_order || []) .concat(that.collection_order || [])
.unique())) .unique()))
// main collection... // main collection...
@ -2074,6 +2075,43 @@ var UICollectionActions = actions.Actions({
: that.saveCollection(title) }, : that.saveCollection(title) },
disabled: action ? [MAIN_COLLECTION_TITLE] : false, disabled: action ? [MAIN_COLLECTION_TITLE] : false,
update_merge: 'merge',
// element edit...
// XXX should this be generic???
menu: function(_, from){
var f = $(this).find('.text').last().attr('text') || from
$(this).find('.text').last()
.html(f)
.makeEditable({
activate: true,
clear_on_edit: false,
abort_keys: [
'Esc',
],
})
.on('edit-commit', function(_, to){
// check if name unique... (???)
if(to in that.collections){
// XXX ???
return
}
// XXX need to get the real from...
that.renameCollection(f, to)
if(to in that.collections){
collections[collections.indexOf(f)] = to
}
})
.on('edit-abort edit-commit', function(_, title){
make.dialog.update()
.then(function(){
make.dialog.select(title) })
})
},
}) })
}, { }, {
cls: 'collection-list', cls: 'collection-list',
@ -2083,6 +2121,10 @@ var UICollectionActions = actions.Actions({
// XXX not sure it is good that we have to do this... // XXX not sure it is good that we have to do this...
.replace(/\$/g, '')), .replace(/\$/g, '')),
}) })
// keyboard...
.run(function(){
this.keyboard
.handler('General', 'F2', 'Menu') })
.close(function(){ .close(function(){
that.collection_order = collections that.collection_order = collections

View File

@ -734,17 +734,60 @@ function(list, options){
} }
options = opts options = opts
/* XXX
var merge_strategies = {
custom: function(stored, input){
},
}
//*/
var lst = var lst =
// load dialog state...
(options.update_merge != 'drop_changes' && dialog.__list[id]) ?
dialog.__list[id]
// merge states...
: (options.update_merge instanceof Function && dialog.__list[id]) ?
options.update_merge(dialog.__list[id])
// initial state... // initial state...
!dialog.__list[id] ?
(list instanceof Function ? list() : list)
/*/ custom...
: (options.update_merge in merge_strategies && dialog.__list[id]) ?
merge_strategies[options.update_merge].call(this,
dialog.__list[id],
list instanceof Function ? list() : list)
//*/
// load dialog state...
: (options.update_merge == null || options.update_merge == 'keep_changes') ?
dialog.__list[id]
// load input/external state...
: (options.update_merge == 'drop_changes') ?
(list instanceof Function ? list() : list)
// merge local and external states...
: (options.update_merge == 'merge') ?
(function(local, input){
return input
.sort(function(a, b){
// get base order from input...
var i = local.indexOf(a)
var j = local.indexOf(b)
// order items not in input (added/renamed)
// via their position in local...
i = i == -1 ? input.indexOf(a) : i
j = j == -1 ? input.indexOf(b) : j
return i - j
})
})(dialog.__list[id] || [], list instanceof Function ? list() : list)
// user merge...
: options.update_merge instanceof Function ?
//options.update_merge(dialog.__list[id])
options.update_merge(
dialog.__list[id],
list instanceof Function ? list() : list)
: list instanceof Function ? : list instanceof Function ?
list() list()
: list : list
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...