cleanup, refactoring and added marking of virtual blocks...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2019-10-24 04:40:45 +03:00
parent 568757f9f1
commit 59d28d01ac
3 changed files with 59 additions and 40 deletions

View File

@ -1401,6 +1401,14 @@ module.CropActions = actions.Actions({
.crop(data, false) .crop(data, false)
-> this -> 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 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 there is no need to bind to anything but this to handle a
@ -1412,6 +1420,16 @@ module.CropActions = actions.Actions({
{undo: 'uncrop'}, {undo: 'uncrop'},
function(list, flatten){ function(list, flatten){
list = list || this.data.getImages() 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 = this.crop_stack || []
this.crop_stack.push(this.data) this.crop_stack.push(this.data)

View File

@ -30,6 +30,8 @@ var ui = require('features/ui')
// 'ribbon' - current ribbon // 'ribbon' - current ribbon
// ribbon - specific ribbon (gid) // ribbon - specific ribbon (gid)
// Array // Array
// attr
// !attr
// //
// NOTE: of no data is defined this will not have any effect... // 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 // NOTE: we are not using the vanilla toggler here as it can't handle
@ -74,6 +76,17 @@ function makeTagTogglerAction(tag){
// the action... // the action...
var action = function(target, 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... // special case: no data...
if(this.data == null){ if(this.data == null){
return action == '??' ? ['off', 'on'] : 'off' return action == '??' ? ['off', 'on'] : 'off'
@ -255,7 +268,8 @@ var ImageMarkActions = actions.Actions({
cropMarked: ['Mark|Crop/Crop $marked images', cropMarked: ['Mark|Crop/Crop $marked images',
{browseMode: function(target){ {browseMode: function(target){
return this.marked.length == 0 && 'disabled' }}, 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) }], //function(flatten){ this.cropTagged('marked', 'any', flatten) }],
removeMarkedFromCrop: ['Mark|Crop/Remove marked from crop', removeMarkedFromCrop: ['Mark|Crop/Remove marked from crop',
@ -302,20 +316,23 @@ module.ImageMarks = core.ImageGridFeatures.Feature({
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
var ImageMarkEditActions = actions.Actions({ var ImageMarkEditActions = actions.Actions({
// Common use-cases: // XXX should this be like .crop(..) and accept attr name???
// 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')
//
toggleMark: ['Mark|Image/Image $mark', 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'), undoTag('toggleMark'),
makeTagTogglerAction('marked')], makeTagTogglerAction('marked')],
toggleMarkBlock: ['Mark/Invert $block marks', toggleMarkBlock: ['Mark/Invert $block marks',
@ -518,8 +535,9 @@ var ImageBookmarkActions = actions.Actions({
cropBookmarked: ['Bookmark|Crop/Crop $bookmarked images', cropBookmarked: ['Bookmark|Crop/Crop $bookmarked images',
{browseMode: function(target){ {browseMode: function(target){
return this.bookmarked.length == 0 && 'disabled' }}, return this.bookmarked.length == 0 && 'disabled' }},
'crop: "bookmarked" ...'],
//function(flatten){ this.cropTagged('bookmark', 'any', flatten) }], //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... // NOTE: this is usable without ribbons...

View File

@ -46,12 +46,6 @@ var VirtualBlocksActions = actions.Actions({
.filter(function(gid){ .filter(function(gid){
img = that.images[gid] || {} img = that.images[gid] || {}
return img.type == 'virtual' }) }, 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"... // construction of new "virtual images"...
// //
@ -169,29 +163,18 @@ var VirtualBlocksActions = actions.Actions({
this.makeVirtualBlock(ref, offset, img) }], this.makeVirtualBlock(ref, offset, img) }],
// crop... // crop...
// XXX would be nice to avoid these and just register a list and context...
cropVirtualBlocks: ['Virtual block|Crop/$Crop $virtual blocks', 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' }, { browseMode: 'makeVirtualBlock' },
function(mode){ 'crop: "virtual" ...'],
mode = mode || 'keep'
return this.crop(
mode == 'keep' ?
this.virtual
: this.nonVirtual) }],
cropVirtualBlocksOut: ['Virtual block|Crop/Crop virtual blocks out', cropVirtualBlocksOut: ['Virtual block|Crop/Crop virtual blocks out',
{ browseMode: 'cropVirtualBlocks' }, { browseMode: 'cropVirtualBlocks' },
'cropVirtualBlocks: "skip"'], 'crop: "!virtual" ...'],
// marks...
toggleMarkVirtualBlocks: ['Virtual block|Mark/-50:Toggle $mark on $virtual blocks',
{ browseMode: 'makeVirtualBlock' },
'toggleMark: "virtual"'],
}) })
var VirtualBlocks = var VirtualBlocks =