working on .uncollect(..) undo...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2017-12-30 05:44:50 +03:00
parent c428d9c4dc
commit 8a6659383d
3 changed files with 33 additions and 5 deletions

View File

@ -1895,6 +1895,8 @@ module.CropActions = actions.Actions({
: this.data.ribbons[g] ? this.data.getImages(g) : g,
// get ribbon and ribbon order...
[this.data.getRibbon(g), this.data.getRibbonOrder(g)],
// XXX this is not needed here but is used by .uncollect.undo(..)
this.data.order.indexOf(g),
] }.bind(this)) },
undo: function(d){
(d.placements || [])

View File

@ -976,10 +976,33 @@ var CollectionActions = actions.Actions({
NOTE: this will remove any gid, be it image or ribbon.
`,
{
browseMode: function(){ return !this.collection && 'disabled' }
/* XXX
getUndoState: function(d){},
undo: function(d){},
browseMode: function(){ return !this.collection && 'disabled' },
/*/ XXX two ways to go:
// - .collect(..) + .data.placeImage(..)
// - rewrite .collect(..) to use .data.placeImage(..) (like: .addToCrop(..))
//getUndoState: 'removeFromCrop',
getUndoState: function(d){
var base = this.getActionAttr('removeFromCrop', 'getUndoState')
base && base.call(this, d)
d.collection = d.args[1] || this.collection
},
// XXX this does not work yet...
// XXX this use
undo: function(d){
var that = this
var gids = d.args[0] || [d.current]
gids = gids instanceof Array ? gids : [gids]
var collection = d.collection
this
.collect(gids, collection)
.ensureCollection(collection)
.then(function(){
d.placements.forEach(function(e){
// XXX does not place correctly...
that.data.placeImage(e[0], e[1], that.data.order[e[2]])
that.reload(true)
}) })
},
//*/
},
function(gids, collection){

View File

@ -681,6 +681,9 @@ var JournalActions = actions.Actions({
// get additional undo state...
var update = that.getActionAttr(action, 'getUndoState')
while(typeof(update) == typeof('str')){
update = that.getActionAttr(update, 'getUndoState')
}
update
&& update instanceof Function
&& update.call(that, data)
@ -795,7 +798,7 @@ var JournalActions = actions.Actions({
// pass the action name...
undo.call(this, a)
: typeof(undo) == typeof('str') ?
// pass journal structure as-is...
// XXX pass journal structure as-is... (???)
this[undo].apply(this, a.args)
: null