mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 10:20:08 +00:00
updating journal code...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
de7c09f377
commit
48551ba39a
@ -1889,7 +1889,7 @@ module.Timers = ImageGridFeatures.Feature({
|
|||||||
// This feature logs actions that either have the journal attribute set
|
// This feature logs actions that either have the journal attribute set
|
||||||
// to true or have an undo method/alias...
|
// to true or have an undo method/alias...
|
||||||
//
|
//
|
||||||
// Example:
|
// Example:
|
||||||
// someAction: ['Path/to/Some action',
|
// someAction: ['Path/to/Some action',
|
||||||
// // just journal the action, but it can't be undone...
|
// // just journal the action, but it can't be undone...
|
||||||
// {journal: true},
|
// {journal: true},
|
||||||
@ -1908,7 +1908,21 @@ module.Timers = ImageGridFeatures.Feature({
|
|||||||
//
|
//
|
||||||
// someOtherAction: ['Path/to/Some other action',
|
// someOtherAction: ['Path/to/Some other action',
|
||||||
// // use .otherAction(..) to undo...
|
// // use .otherAction(..) to undo...
|
||||||
// {undo: 'otherAction'},
|
// {undo: 'otherAction'
|
||||||
|
//
|
||||||
|
// // test if action can be undone (returns bool)...
|
||||||
|
// // NOTE: this is called before the <action>...
|
||||||
|
// // NOTE: this can be an alias...
|
||||||
|
// undoable: function(data){
|
||||||
|
// ...
|
||||||
|
// },
|
||||||
|
//
|
||||||
|
// // store aditional undo state in the data, to be used by <action>.undo(..)...
|
||||||
|
// // NOTE: this is called after the <action>...
|
||||||
|
// // NOTE: this can be an alias...
|
||||||
|
// getUndoState: function(data){
|
||||||
|
// ...
|
||||||
|
// }},
|
||||||
// function(){
|
// function(){
|
||||||
// ...
|
// ...
|
||||||
// }],
|
// }],
|
||||||
@ -1918,10 +1932,6 @@ module.Timers = ImageGridFeatures.Feature({
|
|||||||
// enough.
|
// enough.
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// Protocol:
|
|
||||||
// XXX
|
|
||||||
//
|
|
||||||
//
|
|
||||||
|
|
||||||
// XXX would be great to add a mechanism define how to reverse actions...
|
// XXX would be great to add a mechanism define how to reverse actions...
|
||||||
// ...one way to do this at this point is to revert to last state
|
// ...one way to do this at this point is to revert to last state
|
||||||
@ -1947,19 +1957,39 @@ var JournalActions = actions.Actions({
|
|||||||
}
|
}
|
||||||
}],
|
}],
|
||||||
|
|
||||||
|
// Format:
|
||||||
|
// [
|
||||||
|
// {
|
||||||
|
// type: 'basic' | ...,
|
||||||
|
//
|
||||||
|
// action: <action-name>,
|
||||||
|
// args: [ ... ],
|
||||||
|
//
|
||||||
|
// the current image before the action...
|
||||||
|
// current: undefined | <gid>
|
||||||
|
//
|
||||||
|
// the target (current) image after action...
|
||||||
|
// target: undefined | <gid>
|
||||||
|
//
|
||||||
|
// // additional data, can be set via:
|
||||||
|
// // <action>.getUndoState(<data>)...
|
||||||
|
// ...
|
||||||
|
// },
|
||||||
|
// ...
|
||||||
|
// ]
|
||||||
|
//
|
||||||
journal: null,
|
journal: null,
|
||||||
rjournal: null,
|
rjournal: null,
|
||||||
|
|
||||||
journalable: null,
|
journalable: null,
|
||||||
|
|
||||||
// XXX doc supported attrs:
|
// XXX should aliases support explicit undo??? (test)
|
||||||
// undo
|
|
||||||
// undoable
|
|
||||||
// getUndoState
|
|
||||||
// XXX should the action have control over what gets journaled and how???
|
|
||||||
// XXX should aliases support explicit undo???
|
|
||||||
updateJournalableActions: ['System/Update list of journalable actions',
|
updateJournalableActions: ['System/Update list of journalable actions',
|
||||||
doc`
|
doc`
|
||||||
|
|
||||||
|
This will setup the action journal handler as a .pre handler
|
||||||
|
(tagged: 'journal-handler'), calling this again will reset the existing
|
||||||
|
handlers and add new ones.
|
||||||
|
|
||||||
NOTE: action aliases can not handle undo.
|
NOTE: action aliases can not handle undo.
|
||||||
`,
|
`,
|
||||||
@ -1968,55 +1998,49 @@ var JournalActions = actions.Actions({
|
|||||||
|
|
||||||
var handler = function(action){
|
var handler = function(action){
|
||||||
return function(){
|
return function(){
|
||||||
var cur = this.current
|
|
||||||
var args = [...arguments]
|
|
||||||
|
|
||||||
var data = {
|
var data = {
|
||||||
type: 'basic',
|
type: 'basic',
|
||||||
|
|
||||||
action: action,
|
action: action,
|
||||||
args: args,
|
args: [...arguments],
|
||||||
// the current image before the action...
|
current: this.current,
|
||||||
current: cur,
|
// set in the post handler...
|
||||||
// the target (current) image after action...
|
target: undefined,
|
||||||
target: this.current,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get action method handling aliases...
|
||||||
|
var _getActionMethod = function(action, attr){
|
||||||
|
var meth = that.getActionAttr(action, attr)
|
||||||
|
while(typeof(meth) == typeof('str')){
|
||||||
|
meth = that.getActionAttr(meth, attr) }
|
||||||
|
return meth }
|
||||||
|
|
||||||
// test if we need to journal this action signature...
|
// test if we need to journal this action signature...
|
||||||
var test = that.getActionAttr(action, 'undoable')
|
var test = _getActionMethod(action, 'undoable')
|
||||||
if(test && !test.call(that, data)){
|
if(test && !test.call(that, data)){
|
||||||
return
|
return }
|
||||||
}
|
// prep to get additional undo state...
|
||||||
|
var update = _getActionMethod(action, 'getUndoState')
|
||||||
// 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)
|
|
||||||
|
|
||||||
// journal after the action is done...
|
// journal after the action is done...
|
||||||
return function(){ this.journalPush(data) }
|
return function(){
|
||||||
}
|
data.target = this.current
|
||||||
}
|
update
|
||||||
|
&& update instanceof Function
|
||||||
|
&& update.call(that, data)
|
||||||
|
this.journalPush(data) } } }
|
||||||
|
|
||||||
this.journalable = this.actions
|
this.journalable = this.actions
|
||||||
.filter(function(action){
|
.filter(function(action){
|
||||||
|
// remove all existing journal handlers before we setup again...
|
||||||
|
that.off(action+'.pre', 'journal-handler')
|
||||||
// skip aliases...
|
// skip aliases...
|
||||||
return !(that[action] instanceof actions.Alias)
|
return !(that[action] instanceof actions.Alias)
|
||||||
&& (!!that.getActionAttr(action, 'undo')
|
&& (!!that.getActionAttr(action, 'undo')
|
||||||
|| !!that.getActionAttr(action, 'journal'))
|
|| !!that.getActionAttr(action, 'journal')) })
|
||||||
})
|
// set the handler
|
||||||
// reset the handler
|
|
||||||
.map(function(action){
|
.map(function(action){
|
||||||
that
|
that.on(action+'.pre', 'journal-handler', handler(action))
|
||||||
.off(action+'.pre', 'journal-handler')
|
return action }) }],
|
||||||
.on(action+'.pre', 'journal-handler', handler(action))
|
|
||||||
return action
|
|
||||||
})
|
|
||||||
}],
|
|
||||||
|
|
||||||
journalPush: ['- System/Journal/Add an item to journal',
|
journalPush: ['- System/Journal/Add an item to journal',
|
||||||
function(data){
|
function(data){
|
||||||
@ -2027,8 +2051,7 @@ var JournalActions = actions.Actions({
|
|||||||
this.journal = (this.hasOwnProperty('journal') || this.journal) ?
|
this.journal = (this.hasOwnProperty('journal') || this.journal) ?
|
||||||
this.journal || []
|
this.journal || []
|
||||||
: []
|
: []
|
||||||
this.journal.push(data)
|
this.journal.push(data) }],
|
||||||
}],
|
|
||||||
clearJournal: ['System/Journal/Clear the action journal',
|
clearJournal: ['System/Journal/Clear the action journal',
|
||||||
function(){
|
function(){
|
||||||
// NOTE: overwriting here is better as it will keep
|
// NOTE: overwriting here is better as it will keep
|
||||||
@ -2041,8 +2064,7 @@ var JournalActions = actions.Actions({
|
|||||||
this.journal
|
this.journal
|
||||||
&& (this.journal = null)
|
&& (this.journal = null)
|
||||||
this.rjournal
|
this.rjournal
|
||||||
&& (this.rjournal = null)
|
&& (this.rjournal = null) }],
|
||||||
}],
|
|
||||||
runJournal: ['- System/Journal/Run journal',
|
runJournal: ['- System/Journal/Run journal',
|
||||||
//{journal: true},
|
//{journal: true},
|
||||||
function(journal){
|
function(journal){
|
||||||
@ -2052,9 +2074,7 @@ var JournalActions = actions.Actions({
|
|||||||
that
|
that
|
||||||
.focusImage(e.current)
|
.focusImage(e.current)
|
||||||
// run action...
|
// run action...
|
||||||
[e.action].apply(that, e.args)
|
[e.action].apply(that, e.args) }) }],
|
||||||
})
|
|
||||||
}],
|
|
||||||
|
|
||||||
// XXX needs very careful revision...
|
// XXX needs very careful revision...
|
||||||
// - should this be thread safe??? (likely not)
|
// - should this be thread safe??? (likely not)
|
||||||
@ -2121,10 +2141,7 @@ var JournalActions = actions.Actions({
|
|||||||
this.journal = journal
|
this.journal = journal
|
||||||
this.rjournal = rjournal
|
this.rjournal = rjournal
|
||||||
|
|
||||||
break
|
break } } }],
|
||||||
}
|
|
||||||
}
|
|
||||||
}],
|
|
||||||
redo: ['Edit/Redo',
|
redo: ['Edit/Redo',
|
||||||
doc`Redo an action from .rjournal
|
doc`Redo an action from .rjournal
|
||||||
|
|
||||||
@ -2136,11 +2153,8 @@ var JournalActions = actions.Actions({
|
|||||||
return (this.rjournal && this.rjournal.length > 0) || 'disabled' }},
|
return (this.rjournal && this.rjournal.length > 0) || 'disabled' }},
|
||||||
function(){
|
function(){
|
||||||
if(!this.rjournal || this.rjournal.length == 0){
|
if(!this.rjournal || this.rjournal.length == 0){
|
||||||
return
|
return }
|
||||||
}
|
this.runJournal([this.rjournal.pop()]) }],
|
||||||
|
|
||||||
this.runJournal([this.rjournal.pop()])
|
|
||||||
}],
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user