mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 18:30:09 +00:00
.redo(..) now mostly works... need more testing...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
03abe6c011
commit
eed4f4afdf
@ -1981,6 +1981,9 @@ var JournalActions = actions.Actions({
|
|||||||
|
|
||||||
// the target (current) image after action...
|
// the target (current) image after action...
|
||||||
target: undefined | <gid>
|
target: undefined | <gid>
|
||||||
|
|
||||||
|
// action state, only set on undoable actions when undone.
|
||||||
|
undone: true | false,
|
||||||
|
|
||||||
// additional data, can be set via:
|
// additional data, can be set via:
|
||||||
// <action>.getUndoState(<data>)...
|
// <action>.getUndoState(<data>)...
|
||||||
@ -2039,7 +2042,6 @@ var JournalActions = actions.Actions({
|
|||||||
that.on(action+'.pre', 'journal-handler', handler(action))
|
that.on(action+'.pre', 'journal-handler', handler(action))
|
||||||
return action }) }],
|
return action }) }],
|
||||||
|
|
||||||
// XXX do not clear .rjournal on redo...
|
|
||||||
journalPush: ['- System/Journal/Add an item to journal',
|
journalPush: ['- System/Journal/Add an item to journal',
|
||||||
function(data){
|
function(data){
|
||||||
// clear the reverse journal...
|
// clear the reverse journal...
|
||||||
@ -2065,32 +2067,29 @@ var JournalActions = actions.Actions({
|
|||||||
&& (this.journal = null)
|
&& (this.journal = null)
|
||||||
this.rjournal
|
this.rjournal
|
||||||
&& (this.rjournal = null) }],
|
&& (this.rjournal = null) }],
|
||||||
|
// XXX not sure about the filter arg...
|
||||||
runJournal: ['- System/Journal/Run journal',
|
runJournal: ['- System/Journal/Run journal',
|
||||||
//{journal: true},
|
//{journal: true},
|
||||||
function(journal){
|
function(journal, filter){
|
||||||
var that = this
|
var that = this
|
||||||
journal.forEach(function(e){
|
journal.forEach(function(e){
|
||||||
// load state...
|
;(typeof(filter) == 'function'?
|
||||||
that
|
filter.call(that, e)
|
||||||
.focusImage(e.current)
|
: true)
|
||||||
// run action...
|
&& that
|
||||||
[e.action].apply(that, e.args) }) }],
|
.focusImage(e.current)
|
||||||
|
// run action...
|
||||||
|
[e.action].apply(that, e.args) }) }],
|
||||||
|
|
||||||
// XXX might be a good idea to add support for:
|
// XXX might be a good idea to add support for:
|
||||||
// - time-periods
|
// - time-periods
|
||||||
// - specific times
|
// - specific times
|
||||||
// XXX need to add generic handlers for:
|
|
||||||
// - save actions... DONE
|
|
||||||
// - load/unload...
|
|
||||||
// XXX needs very careful revision...
|
// XXX needs very careful revision...
|
||||||
// - should this be thread safe??? (likely not)
|
// - should this be thread safe??? (likely not)
|
||||||
// - should the undo action have side-effects on the
|
// - should the undo action have side-effects on the
|
||||||
// journal/rjournal or should we clean them out???
|
// journal/rjournal or should we clean them out???
|
||||||
// (currently cleaned)
|
// (currently cleaned)
|
||||||
// XXX should we run undo of every action that supports it in the chain???
|
// XXX how do we handle nested action calls??
|
||||||
// ...i.e. multiple extending actions can support undo
|
|
||||||
// XXX will also need to handle other methods + aliases in chain...
|
|
||||||
// XXX in mode method count the undoable actions...
|
|
||||||
// XXX should we stop at non-undoable actions???
|
// XXX should we stop at non-undoable actions???
|
||||||
// ...intuitively, yes, as undoing past these may result in an
|
// ...intuitively, yes, as undoing past these may result in an
|
||||||
// inconsistent state...
|
// inconsistent state...
|
||||||
@ -2111,6 +2110,8 @@ var JournalActions = actions.Actions({
|
|||||||
it for .redo()
|
it for .redo()
|
||||||
|
|
||||||
NOTE: this counts undoable actions only.
|
NOTE: this counts undoable actions only.
|
||||||
|
NOTE: actions when undone (i.e. undoable) are marked with .undone = true
|
||||||
|
while unundoable actions are simply copied over to .rjournal
|
||||||
`,
|
`,
|
||||||
{mode: function(){
|
{mode: function(){
|
||||||
return (this.journal && this.journal.length > 0) || 'disabled' }},
|
return (this.journal && this.journal.length > 0) || 'disabled' }},
|
||||||
@ -2155,13 +2156,16 @@ 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.
|
||||||
|
// XXX should we cache this???
|
||||||
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
|
||||||
|
|
||||||
|
a.undone = true }
|
||||||
|
|
||||||
// push the action to the reverse journal...
|
// push the action to the reverse journal...
|
||||||
rjournal.push(journal.pop())
|
rjournal.push(journal.pop())
|
||||||
@ -2190,6 +2194,8 @@ var JournalActions = actions.Actions({
|
|||||||
.redo('all')
|
.redo('all')
|
||||||
|
|
||||||
Essentially this will remove and re-run the last action in .rjournal
|
Essentially this will remove and re-run the last action in .rjournal
|
||||||
|
|
||||||
|
NOTE: this will clear the .undone attr of redoable actions
|
||||||
`,
|
`,
|
||||||
{mode: function(){
|
{mode: function(){
|
||||||
return (this.rjournal && this.rjournal.length > 0) || 'disabled' }},
|
return (this.rjournal && this.rjournal.length > 0) || 'disabled' }},
|
||||||
@ -2197,15 +2203,33 @@ var JournalActions = actions.Actions({
|
|||||||
if(!this.rjournal || this.rjournal.length == 0){
|
if(!this.rjournal || this.rjournal.length == 0){
|
||||||
return }
|
return }
|
||||||
|
|
||||||
count = count == 'all' ?
|
var journal = this.journal
|
||||||
Infinity
|
|
||||||
: count
|
|
||||||
var rjournal = this.rjournal
|
var rjournal = this.rjournal
|
||||||
var l = rjournal.length
|
var l = rjournal.length
|
||||||
|
|
||||||
// XXX need to handle un-undoable actions...
|
if(count == 'all'){
|
||||||
// XXX need to count undoable actions instead of all actions (like in .undo(..))...
|
count = Infinity
|
||||||
this.runJournal(rjournal.splice(l-count || 0, count))
|
} else {
|
||||||
|
var t = 0
|
||||||
|
var c = 0
|
||||||
|
// count only undoable actions, i.e. the ones we undid...
|
||||||
|
for(var a of rjournal.slice().reverse()){
|
||||||
|
c++
|
||||||
|
a.undone
|
||||||
|
&& t++
|
||||||
|
if(t >= count){
|
||||||
|
break } }
|
||||||
|
count = c }
|
||||||
|
|
||||||
|
this.runJournal(
|
||||||
|
rjournal.splice(l-count || 0, count),
|
||||||
|
// skip actions not undoable and push them back to the journal...
|
||||||
|
function(e){
|
||||||
|
var redo = e.undone
|
||||||
|
!redo
|
||||||
|
&& journal.push(e)
|
||||||
|
delete e.undone
|
||||||
|
return redo })
|
||||||
|
|
||||||
// restore .rjournal after actions are run...
|
// restore .rjournal after actions are run...
|
||||||
// NOTE: this is done to compensate for .journalPush(..) clearing
|
// NOTE: this is done to compensate for .journalPush(..) clearing
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user