added save points to journal...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-02-17 00:13:41 +03:00
parent bc25606027
commit 4cfd21c4a3

View File

@ -2097,14 +2097,16 @@ var JournalActions = actions.Actions({
doc`Undo last action(s) from .journal that can be undone doc`Undo last action(s) from .journal that can be undone
.undo() .undo()
.undo(<count>) .undo(<count>)
.undo('unsaved')
This will shift the action from .journal to .rjournal preparing This will shift the action from .journal to .rjournal preparing
it for .redo() it for .redo()
NOTE: this will remove all the non undoable actions from the NOTE: this counts undoable actions only.
.journal up until and including the undone action.
NOTE: only the undone action is pushed to .rjournal
`, `,
{mode: function(){ {mode: function(){
return (this.journal && this.journal.length > 0) || 'disabled' }}, return (this.journal && this.journal.length > 0) || 'disabled' }},
@ -2116,13 +2118,15 @@ var JournalActions = actions.Actions({
this.rjournal || [] this.rjournal || []
: [] : []
// XXX add test for save point -- 'unsaved' keyword...
// XXX this counts undoable actions only -- is this correct...
while(count-- > 0
&& journal.length > 1){
for(var i = journal.length-1; i >= 0; i--){ for(var i = journal.length-1; i >= 0; i--){
var a = journal[i] var a = journal[i]
// stop at save point...
if(count == 'unsaved'
&& (a.type == 'save'
|| a == 'SAVED')){
break }
// see if the action has an explicit undo attr... // see if the action has an explicit undo attr...
var undo = this.getActionAttr(a.action, 'undo') var undo = this.getActionAttr(a.action, 'undo')
@ -2136,25 +2140,29 @@ var JournalActions = actions.Actions({
// NOTE: this is likely to have side-effect on the // NOTE: this is likely to have side-effect on the
// journal and maybe even rjournal... // journal and maybe even rjournal...
// NOTE: these side-effects are cleaned out later. // NOTE: these side-effects are cleaned out later.
var undo = undo instanceof Function ? undo instanceof Function ?
// pass the action name... // pass the action name...
undo.call(this, a) undo.call(this, a)
: typeof(undo) == typeof('str') ? : typeof(undo) == typeof('str') ?
// XXX pass journal structure as-is... (???) // XXX pass journal structure as-is... (???)
this[undo].apply(this, a.args) this[undo].apply(this, a.args)
: null : null }
// push the undone command to the reverse journal... // push the action to the reverse journal...
rjournal.push(journal.splice(i, 1)[0]) rjournal.push(journal.splice(i, 1)[0])
// stop when done...
if(undo
&& count != 'unsaved'
&& --count <= 0){
break } }
// restore journal state... // restore journal state...
// NOTE: calling the undo action would have cleared // NOTE: calling the undo action would have cleared
// the rjournal and added stuff to the journal // the rjournal and added stuff to the journal
// so we will need to restore things... // so we will need to restore things...
this.journal = journal this.journal = journal
this.rjournal = rjournal this.rjournal = rjournal }],
break } } } }],
redo: ['Edit/Redo', redo: ['Edit/Redo',
doc`Redo an action from .rjournal doc`Redo an action from .rjournal
@ -2193,9 +2201,20 @@ module.Journal = ImageGridFeatures.Feature({
function(){ this.updateJournalableActions() }], function(){ this.updateJournalableActions() }],
// log saved event to journal... // log saved event to journal...
['saved', ['saved',
function(){ function(res, ...args){
// XXX // XXX
this.journal.push('SAVED') //this.journal.push('SAVED')
this.journalPush({
type: 'save',
date: Date.now(),
// XXX do we need this???
//action: action,
//args: [...args],
current: this.current,
target: this.current,
})
}], }],
], ],
}) })