From 804fe63040980aaf9c8164199fdea6eef276fe11 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Thu, 30 Mar 2017 14:07:50 +0300 Subject: [PATCH] added undo to marks/bookmarks... Signed-off-by: Alex A. Naanou --- ui (gen4)/features/core.js | 27 +++++++++++++++++---------- ui (gen4)/features/keyboard.js | 3 +++ ui (gen4)/features/ui-marks.js | 21 +++++++++++++++++++++ 3 files changed, 41 insertions(+), 10 deletions(-) diff --git a/ui (gen4)/features/core.js b/ui (gen4)/features/core.js index 2c27dcea..e4ddb5e1 100755 --- a/ui (gen4)/features/core.js +++ b/ui (gen4)/features/core.js @@ -631,18 +631,25 @@ var JournalActions = actions.Actions({ var cur = this.current var args = args2array(arguments) - return function(){ - this.journalPush({ - type: 'basic', + var data = { + type: 'basic', - action: action, - args: args, - // the current image before the action... - current: cur, - // the target (current) image after action... - target: this.current, - }) + action: action, + args: args, + // the current image before the action... + current: cur, + // the target (current) image after action... + target: this.current, } + + // test if we need to journal this action signature... + var test = that.getActionAttr(action, 'undoable') + if(test && !test.call(that, data)){ + return + } + + // journal after the action is done... + return function(){ this.journalPush(data) } } } diff --git a/ui (gen4)/features/keyboard.js b/ui (gen4)/features/keyboard.js index 43a23ba7..81058138 100755 --- a/ui (gen4)/features/keyboard.js +++ b/ui (gen4)/features/keyboard.js @@ -278,10 +278,12 @@ module.GLOBAL_KEYBOARD = { shift_Up: 'shiftImageUp', alt_shift_Up: 'travelImageUp', ctrl_shift_Up: 'shiftImageUpNewRibbon', + ctrl_Up: 'shiftMarkedUp', shift_Down: 'shiftImageDown', alt_shift_Down: 'travelImageDown', ctrl_shift_Down: 'shiftImageDownNewRibbon', + ctrl_Down: 'shiftMarkedDown', alt_Left: 'shiftImageLeft!', alt_Right: 'shiftImageRight!', @@ -351,6 +353,7 @@ module.GLOBAL_KEYBOARD = { // marking... M: 'toggleMark', ctrl_A: 'toggleMark!: "ribbon" "on" -- Mark all images in ribbon', + ctrl_shift_A: 'toggleMarkBlock!', ctrl_D: 'toggleMark!: "ribbon" "off" -- Unmark all images in ribbon', ctrl_I: 'toggleMark!: "ribbon" -- Invert marks in ribbon', ',': 'prevMarked', diff --git a/ui (gen4)/features/ui-marks.js b/ui (gen4)/features/ui-marks.js index 544f0c96..fd4a64f6 100755 --- a/ui (gen4)/features/ui-marks.js +++ b/ui (gen4)/features/ui-marks.js @@ -104,6 +104,24 @@ function makeTagTogglerAction(tag){ } +var undoTag = function(action){ + return { + // do not journal calls that have no side-effects, e.g. toggler + // introspection... + // XXX should this be a generic predicate??? + undoable: function(a){ + return a.args.indexOf('?') < 0 + && a.args.indexOf('??') < 0 }, + undo: function(a){ + this[action].apply(this, + // XXX is argument handling here too optimistic??? + a.args.map(function(e){ + return e == 'on' ? 'off' + : e == 'off' ? 'on' + : e })) }, + } } + + // // Direction can be: // - 'up' @@ -190,7 +208,9 @@ var ImageMarkActions = actions.Actions({ // Invert marks on current ribbon // .toggleMark('ribbon') // + // toggleMark: ['Mark|Image/Image $mark', + undoTag('toggleMark'), makeTagTogglerAction('selected')], toggleMarkBlock: ['Mark/Mark $block', core.doc`A block is a set of adjacent images either marked on unmarked @@ -329,6 +349,7 @@ var ImageBookmarkActions = actions.Actions({ }, toggleBookmark: ['Bookmark|Image/Image $bookmark', + undoTag('toggleBookmark'), makeTagTogglerAction('bookmark')], // action can be: // 'on' - toggle all on