diff --git a/ui (gen4)/data.js b/ui (gen4)/data.js index 54314489..16238de6 100755 --- a/ui (gen4)/data.js +++ b/ui (gen4)/data.js @@ -355,7 +355,7 @@ var DataPrototype = { // clear empty ribbons only... } else if(gids == 'empty'){ for(var r in this.ribbons){ - if(this.ribbons[r].len() == 0){ + if(this.ribbons[r].len == 0){ this.clear(r) } } @@ -1293,7 +1293,7 @@ var DataPrototype = { var res = this.shiftImage(gid, r-1, 'vertical') // clear empty ribbon... r = r == 0 ? 1 : r - if(this.ribbons[this.ribbon_order[r]].len() == 0){ + if(this.ribbons[this.ribbon_order[r]].len == 0){ var b = this.getRibbonOrder(this.base)-1 r = this.ribbon_order.splice(r, 1)[0] @@ -1315,7 +1315,7 @@ var DataPrototype = { } var res = this.shiftImage(gid, r+1, 'vertical') // clear empty ribbon... - if(this.ribbons[this.ribbon_order[r]].len() == 0){ + if(this.ribbons[this.ribbon_order[r]].len == 0){ var b = this.getRibbonOrder(this.base)-1 r = this.ribbon_order.splice(r, 1)[0] @@ -1858,10 +1858,16 @@ var DataWithTagsPrototype = { if(this.tags != null){ var tags = this.tags - res.tags = {} + var restags = {} Object.keys(tags).forEach(function(tag){ - res.tags[tag] = tags[tag].compact() + var lst = tags[tag].compact() + if(lst.len > 0){ + restags[tag] = lst + } }) + if(Object.keys(restags).length > 0){ + res.tags = restags + } } return res @@ -1896,6 +1902,7 @@ var DataWithTagsPrototype = { var order = this.order tags.forEach(function(tag){ gids.forEach(function(gid){ + gid = that.getImage(gid) if(tagset[tag] == null){ tagset[tag] = [] } @@ -1906,6 +1913,9 @@ var DataWithTagsPrototype = { return this }, untag: function(tags, gids){ + if(this.tags == null){ + return this + } tags = tags.constructor !== Array ? [tags] : tags gids = gids == null ? this.getImage() : gids @@ -1915,19 +1925,69 @@ var DataWithTagsPrototype = { var tagset = this.tags var order = this.order tags.forEach(function(tag){ - gids.forEach(function(gid){ - delete tagset[tag][order.indexOf(gid)] - }) - if(tagset[tag].length == 0){ - delete tagset[tag] + if(tag in tagset){ + gids.forEach(function(gid){ + if(tag in tagset){ + delete tagset[tag][order.indexOf(gid)] + } + }) + if(tagset[tag].len == 0){ + delete tagset[tag] + } } }) return this }, - // XXX - toggleTag: function(tags, gids, action){ + // NOTE: this does not support multiple tags at this point... + toggleTag: function(tag, gids, action){ + gids = gids == null ? this.getImage() : gids + gids = gids.constructor !== Array ? [gids] : gids + + // tag all... + if(action == 'on'){ + this.tag(tag, gids) + return action + + // untag all... + } else if(action == 'off'){ + this.untag(tag, gids) + return action + + // get tag state... + } else if(action == '?'){ + if(this.tags == null){ + return gids.map(function(gid){ return 'off' }) + } + var that = this + var tagset = this.tags + var order = this.order + var res = gids.map(function(gid){ + //return that.getTags(gid).indexOf(tag) != -1 ? 'on' : 'off' + return tagset[tag][order.indexOf(gid)] != null ? 'on' : 'off' + }) + + // toggle each... + } else { + var that = this + var tagset = this.tags + var order = this.order + var res = gids.map(function(gid){ + //var t = that.getTags(gid).indexOf(tag) != -1 ? 'off' : 'on' + var t = tagset == null ? 'on' + : tagset[tag][order.indexOf(gid)] == null ? 'on' + : 'off' + if(t == 'on'){ + that.tag(tag, gid) + } else { + that.untag(tag, gid) + } + return t + }) + } + + return res.length == 1 ? res[0] : res }, getTags: function(gids){ diff --git a/ui (gen4)/lib/jli.js b/ui (gen4)/lib/jli.js index 35e14d25..c74a733d 100755 --- a/ui (gen4)/lib/jli.js +++ b/ui (gen4)/lib/jli.js @@ -1044,21 +1044,21 @@ function makeDeferredPool(size, paused){ // prepare to remove self from pool... var i = pool.indexOf(this) - Pool._event_handlers.progress.fire(pool.length - pool.len(), pool.length + queue.length) + Pool._event_handlers.progress.fire(pool.length - pool.len, pool.length + queue.length) // remove self from queue... delete pool[i] // shrink the pool if it's overfilled... // i.e. do not pop another worker and let the "thread" die. - if(pool.len() > pool_size){ + if(pool.len > pool_size){ // remove self... return } // pause the queue -- do not do anything else... if(that._paused == true){ // if pool is empty fire the pause event... - if(pool.len() == 0){ + if(pool.len == 0){ Pool._event_handlers.pause.fire() } return @@ -1072,7 +1072,7 @@ function makeDeferredPool(size, paused){ run.apply(that, next) // empty queue AND empty pool mean we are done... - } else if(pool.len() == 0){ + } else if(pool.len == 0){ var l = pool.length // NOTE: potential race condition -- something can be // pushed to pool just before it's "compacted"... @@ -1087,7 +1087,7 @@ function makeDeferredPool(size, paused){ that._fill() }) .fail(function(){ - Pool._event_handlers.fail.fire(pool.length - pool.len(), pool.length + queue.length) + Pool._event_handlers.fail.fire(pool.length - pool.len, pool.length + queue.length) deferred.reject.apply(deferred, arguments) }) .progress(function(){ @@ -1106,7 +1106,7 @@ function makeDeferredPool(size, paused){ var that = this var pool_size = this.size var run = this._run - var l = this.pool.len() + var l = this.pool.len if(this._paused != true && l < pool_size @@ -1161,7 +1161,7 @@ function makeDeferredPool(size, paused){ Pool.doneFilling = function(){ delete this._filling // trigger depleted if we are empty... - if(this.pool.len() == 0 && this.queue.length == 0){ + if(this.pool.len == 0 && this.queue.length == 0){ that._event_handlers.deplete.fire(l) } return this @@ -1204,7 +1204,7 @@ function makeDeferredPool(size, paused){ return this._paused } Pool.isRunning = function(){ - return this.pool.len() > 0 + return this.pool.len > 0 } @@ -1337,10 +1337,19 @@ Array.prototype.compact = function(){ // like .length but for sparse arrays will return the element count... // XXX make this a prop... +/* Array.prototype.len = function(){ //return this.compact().length return Object.keys(this).length } +*/ + +Object.defineProperty(Array.prototype, 'len', { + get : function () { + return Object.keys(this).length + }, + set : function(val){}, +}); // convert JS arguments to Array... diff --git a/ui (gen4)/ui.js b/ui (gen4)/ui.js index 56e9dcba..d96f42be 100755 --- a/ui (gen4)/ui.js +++ b/ui (gen4)/ui.js @@ -167,6 +167,17 @@ module.GLOBAL_KEYBOARD = { default: 'uncrop', ctrl: 'uncropAll', }, + + // marking... + A: { + ctrl: 'toggleMark!: "ribbon" "on"', + }, + D: { + ctrl: 'toggleMark!: "ribbon" "off"', + }, + I: { + ctrl: 'toggleMark!: "ribbon"', + }, }, } diff --git a/ui (gen4)/viewer.js b/ui (gen4)/viewer.js index cf4e4c51..dc975dfe 100755 --- a/ui (gen4)/viewer.js +++ b/ui (gen4)/viewer.js @@ -1767,17 +1767,51 @@ module.GlobalStateIndicator = Feature({ //--------------------------------------------------------------------- +// XXX add image updater... var ImageMarkActions = actions.Actions({ + // target can be: + // 'all' + // 'loaded' + // 'ribbon' - current ribbon + // ribbon - specific ribbon (gid) + // Array + // + // XXX make this a real toggler... ??? toggleMark: ['', - // XXX make this a real toggler... function(target, action){ - // XXX do tagging on data and get the correct action if one is not given... + target = target || 'current' + target = target == 'all' + || target == 'loaded' + || target in this.data.ribbons + ? this.data.getImages(target) + : target == 'ribbon' ? this.data.getImages('current') + : target + target = target.constructor !== Array ? [target] : target + + var res = this.data.toggleTag('selected', target, action) if(this.ribbons != null){ - this.ribbons.toggleImageMark(target, 'selected', action) + var that = this + target.forEach(function(t){ + that.ribbons.toggleImageMark(t, 'selected', action) + }) } - return action + return res + }], + toggleMarkBlock: ['', + function(){ + // XXX + }], + + markTagged: ['', + function(tags, mode){ + var selector = mode == 'any' ? 'getTaggedByAny' : 'getTaggedByAll' + + var that = this + this.data[selector](tags).forEach(function(gid){ + that.toggleMark(gid, 'on') + }) }], // XXX do we need first/last marked??? @@ -1805,6 +1839,24 @@ module.ImageMarks = Feature({ //--------------------------------------------------------------------- var ImageBookmarkActions = actions.Actions({ + toggleBookmark: ['', + function(){ + }], + // action can be: + // 'on' - toggle all on + // 'off' - toggle all off + // 'next' - toggle each image to next state + toggleBookmarkOnMarked: ['', + function(action){ + }], + + prevBookmarked: ['', + function(mode){ this.prevTagged('bookmarked', mode) }], + nextBookmarked: ['', + function(mode){ this.nextTagged('bookmarked', mode) }], + + cropBookmarked: ['', + function(flatten){ this.cropTagged('bookmarked', 'any', flatten) }], }) @@ -1817,13 +1869,6 @@ module.ImageBookmarks = Feature({ actions: ImageBookmarkActions, - prevBookmarked: ['', - function(mode){ this.prevTagged('bookmarked', mode) }], - nextBookmarked: ['', - function(mode){ this.nextTagged('bookmarked', mode) }], - - cropBookmarked: ['', - function(flatten){ this.cropTagged('bookmarked', 'any', flatten) }], })