From 59d28d01acc966c1fcf2f795252805795e3ba287 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Thu, 24 Oct 2019 04:40:45 +0300 Subject: [PATCH] cleanup, refactoring and added marking of virtual blocks... Signed-off-by: Alex A. Naanou --- ui (gen4)/features/base.js | 18 +++++++++++ ui (gen4)/features/marks.js | 48 +++++++++++++++++++--------- ui (gen4)/features/virtual-blocks.js | 33 +++++-------------- 3 files changed, 59 insertions(+), 40 deletions(-) diff --git a/ui (gen4)/features/base.js b/ui (gen4)/features/base.js index e51c75a8..232d0084 100755 --- a/ui (gen4)/features/base.js +++ b/ui (gen4)/features/base.js @@ -1401,6 +1401,14 @@ module.CropActions = actions.Actions({ .crop(data, false) -> this + Make a crop of this[attr] gid list... + .crop(attr) + -> this + + Make a crop excluding this[attr] gid list... + .crop(!attr) + -> this + NOTE: this is used as a basis for all the crop operations, so there is no need to bind to anything but this to handle a @@ -1412,6 +1420,16 @@ module.CropActions = actions.Actions({ {undo: 'uncrop'}, function(list, flatten){ list = list || this.data.getImages() + // gid list attr... + list = list in this ? + this[list] + : list + // reverse gid list attr... + if(typeof(list) == typeof('str') && list[0] == '!'){ + var skip = new Set(this[list.slice(1)]) + list = this.data.order + .filter(function(gid){ + return !skip.has(gid) }) } this.crop_stack = this.crop_stack || [] this.crop_stack.push(this.data) diff --git a/ui (gen4)/features/marks.js b/ui (gen4)/features/marks.js index e995ece9..131cab3b 100755 --- a/ui (gen4)/features/marks.js +++ b/ui (gen4)/features/marks.js @@ -30,6 +30,8 @@ var ui = require('features/ui') // 'ribbon' - current ribbon // ribbon - specific ribbon (gid) // Array +// attr +// !attr // // NOTE: of no data is defined this will not have any effect... // NOTE: we are not using the vanilla toggler here as it can't handle @@ -74,6 +76,17 @@ function makeTagTogglerAction(tag){ // the action... var action = function(target, action){ + // gid list attr... + target = target in this ? + this[target] + : target + // reverse gid list attr... + if(typeof(target) == typeof('str') && target[0] == '!'){ + var skip = new Set(this[target.slice(1)]) + target = this.data.order + .filter(function(gid){ + return !skip.has(gid) }) } + // special case: no data... if(this.data == null){ return action == '??' ? ['off', 'on'] : 'off' @@ -255,7 +268,8 @@ var ImageMarkActions = actions.Actions({ cropMarked: ['Mark|Crop/Crop $marked images', {browseMode: function(target){ return this.marked.length == 0 && 'disabled' }}, - function(flatten){ this.cropTagged('marked', flatten) }], + 'crop: "marked" ...'], + //function(flatten){ this.cropTagged('marked', flatten) }], //function(flatten){ this.cropTagged('marked', 'any', flatten) }], removeMarkedFromCrop: ['Mark|Crop/Remove marked from crop', @@ -302,20 +316,23 @@ module.ImageMarks = core.ImageGridFeatures.Feature({ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - var ImageMarkEditActions = actions.Actions({ - // Common use-cases: - // Toggle mark on current image - // .toggleMark() - // - // Mark current ribbon - // .toggleMark('ribbon', 'on') - // - // Unmark all loaded images - // .toggleMark('loaded', 'off') - // - // Invert marks on current ribbon - // .toggleMark('ribbon') - // + // XXX should this be like .crop(..) and accept attr name??? toggleMark: ['Mark|Image/Image $mark', + core.doc` + + Toggle mark on current image + .toggleMark() + + Mark current ribbon + .toggleMark('ribbon', 'on') + + Unmark all loaded images + .toggleMark('loaded', 'off') + + Invert marks on current ribbon + .toggleMark('ribbon') + + `, undoTag('toggleMark'), makeTagTogglerAction('marked')], toggleMarkBlock: ['Mark/Invert $block marks', @@ -518,8 +535,9 @@ var ImageBookmarkActions = actions.Actions({ cropBookmarked: ['Bookmark|Crop/Crop $bookmarked images', {browseMode: function(target){ return this.bookmarked.length == 0 && 'disabled' }}, + 'crop: "bookmarked" ...'], //function(flatten){ this.cropTagged('bookmark', 'any', flatten) }], - function(flatten){ this.cropTagged('bookmark', flatten) }], + //function(flatten){ this.cropTagged('bookmark', flatten) }], }) // NOTE: this is usable without ribbons... diff --git a/ui (gen4)/features/virtual-blocks.js b/ui (gen4)/features/virtual-blocks.js index 74c1b7ab..df7f2ee7 100644 --- a/ui (gen4)/features/virtual-blocks.js +++ b/ui (gen4)/features/virtual-blocks.js @@ -46,12 +46,6 @@ var VirtualBlocksActions = actions.Actions({ .filter(function(gid){ img = that.images[gid] || {} return img.type == 'virtual' }) }, - get nonVirtual(){ - var that = this - return this.data.order - .filter(function(gid){ - img = that.images[gid] || {} - return img.type != 'virtual' }) }, // construction of new "virtual images"... // @@ -169,29 +163,18 @@ var VirtualBlocksActions = actions.Actions({ this.makeVirtualBlock(ref, offset, img) }], // crop... + // XXX would be nice to avoid these and just register a list and context... cropVirtualBlocks: ['Virtual block|Crop/$Crop $virtual blocks', - core.doc`Crop virtual blocks... - - Crop (keep) virtual blocks... - .cropVirtualBlocks() - .cropVirtualBlocks('keep') - -> this - - Crop virtual bloks out... - .cropVirtualBlocks('skip') - -> this - - `, { browseMode: 'makeVirtualBlock' }, - function(mode){ - mode = mode || 'keep' - return this.crop( - mode == 'keep' ? - this.virtual - : this.nonVirtual) }], + 'crop: "virtual" ...'], cropVirtualBlocksOut: ['Virtual block|Crop/Crop virtual blocks out', { browseMode: 'cropVirtualBlocks' }, - 'cropVirtualBlocks: "skip"'], + 'crop: "!virtual" ...'], + + // marks... + toggleMarkVirtualBlocks: ['Virtual block|Mark/-50:Toggle $mark on $virtual blocks', + { browseMode: 'makeVirtualBlock' }, + 'toggleMark: "virtual"'], }) var VirtualBlocks =