mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 10:20:08 +00:00
reworking undo/redo and parts of journalling...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
4cfd21c4a3
commit
3c2106b8e8
@ -2078,11 +2078,11 @@ var JournalActions = actions.Actions({
|
|||||||
// run action...
|
// run action...
|
||||||
[e.action].apply(that, e.args) }) }],
|
[e.action].apply(that, e.args) }) }],
|
||||||
|
|
||||||
// XXX would be a good idea to add arguments this this:
|
// XXX might be a good idea to add support for:
|
||||||
// <count> - number of actions to undo (DONE)
|
// - time-periods
|
||||||
// 'unsaved' - all actions till last save marker
|
// - specific times
|
||||||
// XXX need to add generic handlers for:
|
// XXX need to add generic handlers for:
|
||||||
// - save actions... (XXX)
|
// - save actions... DONE
|
||||||
// - load/unload...
|
// - 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)
|
||||||
@ -2092,6 +2092,7 @@ var JournalActions = actions.Actions({
|
|||||||
// XXX should we run undo of every action that supports it in the chain???
|
// XXX should we run undo of every action that supports it in the chain???
|
||||||
// ...i.e. multiple extending actions can support undo
|
// ...i.e. multiple extending actions can support undo
|
||||||
// XXX will also need to handle other methods + aliases in chain...
|
// XXX will also need to handle other methods + aliases in chain...
|
||||||
|
// XXX in mode method count the undoable actions...
|
||||||
// XXX EXPERIMENTAL...
|
// XXX EXPERIMENTAL...
|
||||||
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
|
||||||
@ -2102,6 +2103,8 @@ var JournalActions = actions.Actions({
|
|||||||
|
|
||||||
.undo('unsaved')
|
.undo('unsaved')
|
||||||
|
|
||||||
|
.undo('all')
|
||||||
|
|
||||||
|
|
||||||
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()
|
||||||
@ -2117,15 +2120,22 @@ var JournalActions = actions.Actions({
|
|||||||
(this.hasOwnProperty('rjournal') || this.rjournal) ?
|
(this.hasOwnProperty('rjournal') || this.rjournal) ?
|
||||||
this.rjournal || []
|
this.rjournal || []
|
||||||
: []
|
: []
|
||||||
|
count = count == 'all' ?
|
||||||
|
Infinity
|
||||||
|
: count
|
||||||
|
|
||||||
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...
|
// stop at save point...
|
||||||
if(count == 'unsaved'
|
if(count == 'unsaved'
|
||||||
&& (a.type == 'save'
|
&& (a == 'SAVED'
|
||||||
|| a == 'SAVED')){
|
|| a.type == 'save')){
|
||||||
break }
|
break }
|
||||||
|
// stop at load...
|
||||||
|
// XXX not sure if this is correct....
|
||||||
|
if(a.action == 'load'){
|
||||||
|
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')
|
||||||
@ -2163,19 +2173,32 @@ 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 }],
|
||||||
|
// XXX add arg:
|
||||||
|
// - count - DONE
|
||||||
|
// - 'unsaved' / 'all'
|
||||||
|
// XXX REVISE...
|
||||||
redo: ['Edit/Redo',
|
redo: ['Edit/Redo',
|
||||||
doc`Redo an action from .rjournal
|
doc`Redo an action from .rjournal
|
||||||
|
|
||||||
.redo()
|
.redo()
|
||||||
|
.redo(<count>)
|
||||||
|
.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
|
||||||
`,
|
`,
|
||||||
{mode: function(){
|
{mode: function(){
|
||||||
return (this.rjournal && this.rjournal.length > 0) || 'disabled' }},
|
return (this.rjournal && this.rjournal.length > 0) || 'disabled' }},
|
||||||
function(){
|
function(count=1){
|
||||||
if(!this.rjournal || this.rjournal.length == 0){
|
count = count == 'all' ?
|
||||||
return }
|
Infinity
|
||||||
|
: count
|
||||||
|
while(count-- > 0
|
||||||
|
&& (this.rjournal || []).length > 0){
|
||||||
|
// XXX only run undoable actions... (???)
|
||||||
this.runJournal([this.rjournal.pop()]) }],
|
this.runJournal([this.rjournal.pop()]) }],
|
||||||
|
|
||||||
|
//undoUnsaved: ['Edit/Undo unsaved',
|
||||||
|
// 'undo: "unsaved"'],
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@ -2199,6 +2222,14 @@ module.Journal = ImageGridFeatures.Feature({
|
|||||||
// log state, action and its args...
|
// log state, action and its args...
|
||||||
['start',
|
['start',
|
||||||
function(){ this.updateJournalableActions() }],
|
function(){ this.updateJournalableActions() }],
|
||||||
|
|
||||||
|
// clear journal when clearing...
|
||||||
|
// XXX we should be loading new journal instead...
|
||||||
|
// XXX is this a good idea???
|
||||||
|
['load clear',
|
||||||
|
function(){
|
||||||
|
delete this.journal
|
||||||
|
delete this.rjournal }],
|
||||||
// log saved event to journal...
|
// log saved event to journal...
|
||||||
['saved',
|
['saved',
|
||||||
function(res, ...args){
|
function(res, ...args){
|
||||||
@ -2206,16 +2237,11 @@ module.Journal = ImageGridFeatures.Feature({
|
|||||||
//this.journal.push('SAVED')
|
//this.journal.push('SAVED')
|
||||||
this.journalPush({
|
this.journalPush({
|
||||||
type: 'save',
|
type: 'save',
|
||||||
|
// XXX should use the actual save timestamp...
|
||||||
date: Date.now(),
|
date: Date.now(),
|
||||||
|
|
||||||
// XXX do we need this???
|
|
||||||
//action: action,
|
|
||||||
//args: [...args],
|
|
||||||
|
|
||||||
current: this.current,
|
current: this.current,
|
||||||
target: this.current,
|
target: this.current,
|
||||||
})
|
}) }],
|
||||||
}],
|
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user