reworked .direction processing fixing a long standing bug + undo for .setBaseRibbon(..)...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2018-12-15 21:50:24 +03:00
parent 59d82686c8
commit 7327520c0f
2 changed files with 83 additions and 65 deletions

View File

@ -35,25 +35,6 @@ var core = require('features/core')
/*********************************************************************/ /*********************************************************************/
// Generate an undo function for shift operations...
//
// NOTE: {undo: 'shiftImageDown'}, will not do here because we need to
// pass an argument to the shift action, as without an argument
// these actions will shift focus to a different image in the same
// ribbon...
// .shiftImageDown(x)
// shift image x without changing focus, i.e. the focused
// image before the action will stay focused after.
// .focusImage(x).shiftImageDown()
// focus image x, then shift it down (current image default)
// this will shift focus to .direction of current image.
var undoShift = function(undo){
return function(a){
this[undo](a.args.length == 0 ? a.current : a.args[0]) }}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// XXX split this into read and write actions... // XXX split this into read and write actions...
var BaseActions = var BaseActions =
module.BaseActions = module.BaseActions =
@ -63,6 +44,8 @@ actions.Actions({
// ...where should this be stored??? // ...where should this be stored???
version: version.version || '4.0.0a', version: version.version || '4.0.0a',
'default-direction': 'right',
// Number of steps to change default direction... // Number of steps to change default direction...
// //
// see .direction for details... // see .direction for details...
@ -138,55 +121,63 @@ actions.Actions({
// Assigning 'left!' or 'right!' ('!' appended) will reset the counter // Assigning 'left!' or 'right!' ('!' appended) will reset the counter
// and force direction change. // and force direction change.
// //
// Configuration (.config): // Configuration:
// 'steps-to-change-direction' // .config['steps-to-change-direction']
// Sets the number of steps to change direction (N) // Sets the number of steps to change direction (N)
// //
// 'shifts-affect-direction' // .config['shifts-affect-direction']
// If 'on', add last direction change before vertical shift to // If 'on', add last direction change before vertical shift to
// direction counter (N) // direction counter (N)
// This makes the direction change after several shifts up/down // This makes the direction change after several shifts up/down
// "backwards" a bit faster. // "backwards" a bit faster.
// //
__direction: null,
__direction_last: null,
get direction(){ get direction(){
return this._direction >= 0 ? 'right' return this.__direction == null ?
: this._direction < 0 ? 'left' (this.config['default-direction'] || 'right')
: 'right' }, : this.__direction[0] },
set direction(value){ set direction(value){
// repeat last direction... value = value.trim()
if(value == '!'){ // test input value...
if(this._direction_last == null){ if(!/^(left!?|right!?|!)$/.test(value)){
return throw new Error('.direction: unexpected value:', value) }
} // value is '!' -> repeat last direction...
this.direction = this._direction_last value = value == '!' ?
// NOTE: this stabilizes the .direction, preventing repeating this.__direction_last
// the last explicitly set value over and over again... || (this.__direction || [])[0]
this._direction_last = this.direction || this.config['default-direction']
|| 'right'
: value
// force direction change... var steps = this.config['steps-to-change-direction']
} else if(typeof(value) == typeof('str') var direction = this.__direction || new Array(steps)
&& value.slice(-1) == '!'){
value = this._direction = value == 'left!' ? -1
: value == 'right!' ? 0
: this._direction
this._direction_last = value >= 0 ? 'right' : 'left'
// 'update' direction... // value ends with '!' -> force direction change...
} else { direction = (value.endsWith('!')
value = value == 'left' ? -1 && direction[0] != value.slice(0, -1)) ?
: value == 'right' ? 1 new Array(steps)
: 0 : direction
this._direction_last = value >= 0 ? 'right' : 'left'
var d = (this._direction || 0) + value // normalize value...
var s = this.config['steps-to-change-direction'] value = this.__direction_last =
s = s < 1 ? 1 : s value.endsWith('!') ? value.slice(0, -1) : value
// cap the direction value between -s and s-1...
// NOTE: we use s-1 instead of s as 0/null is a positive // update direction...
// direction... this.__direction =
d = d >= s ? s-1 : d // fill empty state...
d = d < -s ? -s : d direction[0] == null ?
this._direction = d direction.fill(value)
} // update direction...
: direction[0] == value ?
direction
.concat([value])
.slice(-steps)
// reset direction...
: direction.length == 1 ?
(new Array(steps)).fill(value)
// step in the opposite direction...
: direction.slice(0, -1)
}, },
@ -800,6 +791,25 @@ core.ImageGridFeatures.Feature({
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// Edit... // Edit...
// Generate an undo function for shift operations...
//
// NOTE: {undo: 'shiftImageDown'}, will not do here because we need to
// pass an argument to the shift action, as without an argument
// these actions will shift focus to a different image in the same
// ribbon...
// .shiftImageDown(x)
// shift image x without changing focus, i.e. the focused
// image before the action will stay focused after.
// .focusImage(x).shiftImageDown()
// focus image x, then shift it down (current image default)
// this will shift focus to .direction of current image.
var undoShift = function(undo){
return function(a){
this[undo](a.args.length == 0 ? a.current : a.args[0]) }}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
var BaseEditActions = var BaseEditActions =
module.BaseEditActions = module.BaseEditActions =
actions.Actions({ actions.Actions({
@ -810,9 +820,12 @@ actions.Actions({
// //
// NOTE: for all of these, current/ribbon image is a default... // NOTE: for all of these, current/ribbon image is a default...
// XXX add undo...
setBaseRibbon: ['Edit|Ribbon/Set base ribbon', { setBaseRibbon: ['Edit|Ribbon/Set base ribbon', {
journal: true, journal: true,
getUndoState: function(state){
state.base = this.base },
undo: function(state){
this.setBaseRibbon(state.base) },
browseMode: function(target){ browseMode: function(target){
return this.current_ribbon == this.base && 'disabled' }}, return this.current_ribbon == this.base && 'disabled' }},
function(target){ this.data.setBase(target) }], function(target){ this.data.setBase(target) }],
@ -822,10 +835,8 @@ actions.Actions({
core.makeConfigToggler('shifts-affect-direction', core.makeConfigToggler('shifts-affect-direction',
['off', 'on'], ['off', 'on'],
function(action){ function(action){
if(action == 'on'){ action == 'on'
delete this._direction_last && (delete this.__direction_last) })],
}
})],
// NOTE: this does not retain direction information, handle individual // NOTE: this does not retain direction information, handle individual
@ -874,8 +885,9 @@ actions.Actions({
this.data.shiftImageUp(cur) this.data.shiftImageUp(cur)
this.focusImage(next) this.focusImage(next)
this.config['shifts-affect-direction'] == 'on' this.config['shifts-affect-direction'] == 'on'
&& (this.direction = '!') && (this.direction = this.direction)
// if a specific target is given, just shift it... // if a specific target is given, just shift it...
} else { } else {
@ -903,7 +915,9 @@ actions.Actions({
this.data.shiftImageDown(cur) this.data.shiftImageDown(cur)
this.focusImage(next) this.focusImage(next)
this.config['shifts-affect-direction'] == 'on' && (this.direction = '!')
this.config['shifts-affect-direction'] == 'on'
&& (this.direction = this.direction)
// if a specific target is given, just shift it... // if a specific target is given, just shift it...
} else { } else {

View File

@ -552,7 +552,7 @@ var URLHistoryUIActions = actions.Actions({
// XXX add option to force full update on dialog.update() (???) // XXX add option to force full update on dialog.update() (???)
listURLHistory: ['History|File/Location history...', listURLHistory: ['History|File/Location history...',
widgets.makeUIDialog(function(){ widgets.makeUIDialog(function(mode){
var that = this var that = this
var data var data
var orig_pins var orig_pins
@ -706,6 +706,10 @@ var URLHistoryUIActions = actions.Actions({
return dialog return dialog
})], })],
/*/ XXX
listURLHistoryPinned: ['History|File/Location history (pinned)...',
'listURLHistoryPinned: "pinned"'],
//*/
}) })
var URLHistoryUI = var URLHistoryUI =