making add/remove from crop equally expressive for undo...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2017-12-28 05:02:13 +03:00
parent d28401a2ec
commit e854c49741
2 changed files with 25 additions and 8 deletions

View File

@ -1808,6 +1808,7 @@ module.CropActions = actions.Actions({
// ...add a way to store additional info in the journal...
// XXX undo -- .removeFromCrop(..) but only the gids that were
// actually added... (???)
// XXX BUG order does odd things...
addToCrop: ['- Crop/',
core.doc`Add gids to current crop...
@ -1873,14 +1874,18 @@ module.CropActions = actions.Actions({
`,
{
browseMode: 'uncrop',
// XXX group gid - ribbon
//getUndoState: function(data){ },
// XXX this does not account for:
// - location (order, ribbon, ribbon order) of removed images
// XXX these does not account for:
// - ribbon_order
// ...ribbon order is important when a ribbon got cleared...
// - keyword and ribbon gids
//undo: function(d){
// this.addToCrop(d.args.length > 0 ? d.args : d.current) },
// XXX group gid - ribbon
getUndoState: function(d){
d.placements = (d.args[0] || [d.current])
.map(function(g){ return [ g, this.data.getRibbon(g) ] }.bind(this)) },
undo: function(d){
(d.placements || [])
.forEach(function(e){
this.addToCrop(e[0], e[1], 'keep') }.bind(this)) },
},
function(gids){
var that = this
@ -1933,7 +1938,7 @@ module.CropActions = actions.Actions({
NOTE: this is a shorthand for .removeFromCrop(..) but only supports
ribbon removal.`,
{browseMode: 'uncrop'},
{browseMode: 'uncrop',},
function(gids){
var that = this
gids = gids || this.current_ribbon

View File

@ -1619,7 +1619,10 @@ var DataPrototype = {
// -> data
//
// images is .getImage(..) compatible or a list of compatibles.
// ribbon is .getRibbon(..) compatible or 'keep'.
// ribbon is:
// - .getRibbon(..) compatible or 'keep'
// - a new ribbon gid (appended to .ribbon_order)
// - [gid, order] where gid will be placed at order in .ribbon_order
// order is .getImageOrder(..) compatible or 'keep'.
//
// This will not change the relative order of input images unless
@ -1648,6 +1651,15 @@ var DataPrototype = {
// vertical shift -- gather images to the target ribbon...
if(ribbon != 'keep'){
var to = this.getRibbon(ribbon)
// create ribbon...
if(to == null){
var i = ribbon instanceof Array ? ribbon[1] : null
to = ribbon instanceof Array ? ribbon[0] : ribbon
this.ribbons[to] = []
i == null ?
this.ribbon_order.push(to)
: this.ribbon_order.splice(i, 0, to)
}
this.makeSparseImages(images)
.forEach(function(img, f){
var from = that.getRibbon(img)