From fddb35b9c7e3b63ab1a90847e50aeeb23064d516 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Mon, 4 Dec 2017 19:17:42 +0300 Subject: [PATCH] now we can rename collections (still needs cleanup)... Signed-off-by: Alex A. Naanou --- ui (gen4)/features/collections.js | 50 +++++++++++++++++++++++++--- ui (gen4)/lib/widget/browse.js | 55 +++++++++++++++++++++++++++---- 2 files changed, 95 insertions(+), 10 deletions(-) diff --git a/ui (gen4)/features/collections.js b/ui (gen4)/features/collections.js index 79d9069f..90f36a67 100755 --- a/ui (gen4)/features/collections.js +++ b/ui (gen4)/features/collections.js @@ -1924,6 +1924,8 @@ module.AutoCollections = core.ImageGridFeatures.Feature({ // XXX show collections in image metadata... (???) // XXX might be nice to indicate if a collection is loaded -- has .data... // 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({ config: { // Global default collections... @@ -1948,7 +1950,7 @@ var UICollectionActions = actions.Actions({ && title != MAIN_COLLECTION_TITLE }, })], - // XXX edit collection title here??? + // XXX edit collection title here??? (on menu) // ...also might need a collection editor dialog... // XXX would be nice to make this nested (i.e. path list)... browseCollections: ['Collections/$Collec$tions...', @@ -1963,7 +1965,7 @@ var UICollectionActions = actions.Actions({ var collections = that.collection_order = (that.collection_order || []).slice() - var defaults = this.config['default-collections'] + var defaults = that.config['default-collections'] if(defaults){ collections = collections.concat(defaults).unique() } @@ -2024,10 +2026,9 @@ var UICollectionActions = actions.Actions({ } // update collection list if changed externally... - // XXX do we need this??? collections.splice.apply(collections, [0, collections.length].concat( collections - .concat(this.collection_order || []) + .concat(that.collection_order || []) .unique())) // main collection... @@ -2074,6 +2075,43 @@ var UICollectionActions = actions.Actions({ : that.saveCollection(title) }, 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', @@ -2083,6 +2121,10 @@ var UICollectionActions = actions.Actions({ // XXX not sure it is good that we have to do this... .replace(/\$/g, '')), }) + // keyboard... + .run(function(){ + this.keyboard + .handler('General', 'F2', 'Menu') }) .close(function(){ that.collection_order = collections diff --git a/ui (gen4)/lib/widget/browse.js b/ui (gen4)/lib/widget/browse.js index 97d31da2..b436d97e 100755 --- a/ui (gen4)/lib/widget/browse.js +++ b/ui (gen4)/lib/widget/browse.js @@ -734,17 +734,60 @@ function(list, options){ } options = opts + /* XXX + var merge_strategies = { + custom: function(stored, input){ + }, + } + //*/ + 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... + !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() : list + var editable = dialog.__editable[id] = lst instanceof Array // NOTE: we .slice() here to make the changes a bit better packaged // or discrete and not done as they come in...