mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-30 02:40:08 +00:00
added nested undo... (experimental)
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
af109c13f8
commit
71849ae9b3
@ -2007,6 +2007,9 @@ var JournalActions = actions.Actions({
|
|||||||
data.slice()
|
data.slice()
|
||||||
: this.updateJournalableActions() }) },
|
: this.updateJournalableActions() }) },
|
||||||
|
|
||||||
|
// XXX can things get on the journal while an action is running??? (race)
|
||||||
|
// ...if yes, this would make the way nested actions are collected
|
||||||
|
// wrong...
|
||||||
// XXX <action>.getUndoState(..) should be called for every action
|
// XXX <action>.getUndoState(..) should be called for every action
|
||||||
// in chain...
|
// in chain...
|
||||||
// XXX should aliases support explicit undo??? (test)
|
// XXX should aliases support explicit undo??? (test)
|
||||||
@ -2041,6 +2044,11 @@ var JournalActions = actions.Actions({
|
|||||||
// action state, only set on undoable actions when undone.
|
// action state, only set on undoable actions when undone.
|
||||||
undone: true | false,
|
undone: true | false,
|
||||||
|
|
||||||
|
// nested action journal (optional)
|
||||||
|
// this contains actions called from within the current
|
||||||
|
// action that can be undone.
|
||||||
|
nested: [ ... ],
|
||||||
|
|
||||||
// additional data, can be set via:
|
// additional data, can be set via:
|
||||||
// <action>.getUndoState(<data>)...
|
// <action>.getUndoState(<data>)...
|
||||||
...
|
...
|
||||||
@ -2055,6 +2063,7 @@ var JournalActions = actions.Actions({
|
|||||||
var that = this
|
var that = this
|
||||||
var handler = function(action){
|
var handler = function(action){
|
||||||
return function(){
|
return function(){
|
||||||
|
var len = (this.journal || []).length
|
||||||
var data = {
|
var data = {
|
||||||
type: 'basic',
|
type: 'basic',
|
||||||
date: Date.now(),
|
date: Date.now(),
|
||||||
@ -2076,6 +2085,9 @@ var JournalActions = actions.Actions({
|
|||||||
// journal after the action is done...
|
// journal after the action is done...
|
||||||
return function(){
|
return function(){
|
||||||
data.target = this.current
|
data.target = this.current
|
||||||
|
// collect nested journal data...
|
||||||
|
if((this.journal || []).length > len){
|
||||||
|
data.nested = (this.journal || []).splice(len) }
|
||||||
// prep to get additional undo state...
|
// prep to get additional undo state...
|
||||||
// XXX this should be called for all actions in chain...
|
// XXX this should be called for all actions in chain...
|
||||||
var update = that.getActionAttrAliased(action, 'getUndoState')
|
var update = that.getActionAttrAliased(action, 'getUndoState')
|
||||||
@ -2140,21 +2152,23 @@ var JournalActions = actions.Actions({
|
|||||||
// run action...
|
// run action...
|
||||||
[e.action].apply(that, e.args) }) }],
|
[e.action].apply(that, e.args) }) }],
|
||||||
|
|
||||||
// XXX might be a good idea to add support for:
|
// XXX handle .nested undo actions...
|
||||||
// - time-periods - DONE
|
// ...either automatically or allow the client to recursively
|
||||||
// - specific times - DONE
|
// call the undo handler for them...
|
||||||
// ...might be a good idea to support date strings directly...
|
|
||||||
// XXX needs very careful revision...
|
|
||||||
// - should this be thread safe??? (likely not)
|
|
||||||
// - revise actions...
|
|
||||||
// XXX how do we handle nested action calls??
|
// XXX how do we handle nested action calls??
|
||||||
// Example:
|
// Example:
|
||||||
// .toggleMark(..) -> .tag(..)
|
// .toggleMark(..) -> .tag(..)
|
||||||
|
// ...one way to do this is to group all the nested calls and
|
||||||
|
// undo them as one unit, this should also be controllable by
|
||||||
|
// the root action...
|
||||||
|
// XXX needs very careful revision...
|
||||||
|
// - should this be thread safe??? (likely not)
|
||||||
|
// - revise 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...
|
||||||
// XXX should we implement redo as an undo of undo?
|
// XXX should we implement redo as an undo of undo?
|
||||||
// XXX use .journalUnsaved...
|
// XXX use .journalUnsaved???
|
||||||
undo: ['Edit/Undo',
|
undo: ['Edit/Undo',
|
||||||
doc`Undo last action(s) from .journal that can be undone
|
doc`Undo last action(s) from .journal that can be undone
|
||||||
|
|
||||||
@ -2253,6 +2267,8 @@ var JournalActions = actions.Actions({
|
|||||||
// 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 }],
|
||||||
|
// NOTE: we do not have to care about .nested actions on the redo
|
||||||
|
// level as they will be nested again by the root action...
|
||||||
redo: ['Edit/Redo',
|
redo: ['Edit/Redo',
|
||||||
doc`Redo an action from .rjournal
|
doc`Redo an action from .rjournal
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user