mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 10:20:08 +00:00
added save points to journal...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
bc25606027
commit
4cfd21c4a3
@ -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,45 +2118,51 @@ var JournalActions = actions.Actions({
|
|||||||
this.rjournal || []
|
this.rjournal || []
|
||||||
: []
|
: []
|
||||||
|
|
||||||
// XXX add test for save point -- 'unsaved' keyword...
|
for(var i = journal.length-1; i >= 0; i--){
|
||||||
// XXX this counts undoable actions only -- is this correct...
|
var a = journal[i]
|
||||||
while(count-- > 0
|
|
||||||
&& journal.length > 1){
|
|
||||||
for(var i = journal.length-1; i >= 0; i--){
|
|
||||||
var a = journal[i]
|
|
||||||
|
|
||||||
// see if the action has an explicit undo attr...
|
// stop at save point...
|
||||||
var undo = this.getActionAttr(a.action, 'undo')
|
if(count == 'unsaved'
|
||||||
|
&& (a.type == 'save'
|
||||||
|
|| a == 'SAVED')){
|
||||||
|
break }
|
||||||
|
|
||||||
// general undo...
|
// see if the action has an explicit undo attr...
|
||||||
if(undo){
|
var undo = this.getActionAttr(a.action, 'undo')
|
||||||
// restore focus to where it was when the action
|
|
||||||
// was called...
|
|
||||||
this.focusImage(a.current)
|
|
||||||
|
|
||||||
// call the undo method/action...
|
// general undo...
|
||||||
// NOTE: this is likely to have side-effect on the
|
if(undo){
|
||||||
// journal and maybe even rjournal...
|
// restore focus to where it was when the action
|
||||||
// NOTE: these side-effects are cleaned out later.
|
// was called...
|
||||||
var undo = undo instanceof Function ?
|
this.focusImage(a.current)
|
||||||
// pass the action name...
|
|
||||||
undo.call(this, a)
|
|
||||||
: typeof(undo) == typeof('str') ?
|
|
||||||
// XXX pass journal structure as-is... (???)
|
|
||||||
this[undo].apply(this, a.args)
|
|
||||||
: null
|
|
||||||
|
|
||||||
// push the undone command to the reverse journal...
|
// call the undo method/action...
|
||||||
rjournal.push(journal.splice(i, 1)[0])
|
// NOTE: this is likely to have side-effect on the
|
||||||
|
// journal and maybe even rjournal...
|
||||||
|
// NOTE: these side-effects are cleaned out later.
|
||||||
|
undo instanceof Function ?
|
||||||
|
// pass the action name...
|
||||||
|
undo.call(this, a)
|
||||||
|
: typeof(undo) == typeof('str') ?
|
||||||
|
// XXX pass journal structure as-is... (???)
|
||||||
|
this[undo].apply(this, a.args)
|
||||||
|
: null }
|
||||||
|
|
||||||
// restore journal state...
|
// push the action to the reverse journal...
|
||||||
// NOTE: calling the undo action would have cleared
|
rjournal.push(journal.splice(i, 1)[0])
|
||||||
// the rjournal and added stuff to the journal
|
|
||||||
// so we will need to restore things...
|
// stop when done...
|
||||||
this.journal = journal
|
if(undo
|
||||||
this.rjournal = rjournal
|
&& count != 'unsaved'
|
||||||
|
&& --count <= 0){
|
||||||
|
break } }
|
||||||
|
|
||||||
break } } } }],
|
// restore journal state...
|
||||||
|
// NOTE: calling the undo action would have cleared
|
||||||
|
// the rjournal and added stuff to the journal
|
||||||
|
// so we will need to restore things...
|
||||||
|
this.journal = journal
|
||||||
|
this.rjournal = rjournal }],
|
||||||
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,
|
||||||
|
})
|
||||||
}],
|
}],
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user