some minor fixes, docs and cleanup...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2016-04-22 18:11:22 +03:00
parent de55a50e12
commit 121d9d7e8c
4 changed files with 64 additions and 60 deletions

View File

@ -624,12 +624,20 @@ module.SortActions = actions.Actions({
// //
// Sort using a specific method(s): // Sort using a specific method(s):
// .sortImages(<method>) // .sortImages(<method>)
// .sortImages(<method>, <reverse>)
//
// .sortImages('<method> ..')
// .sortImages('<method> ..', <reverse>)
//
// .sortImages([<method>, ..]) // .sortImages([<method>, ..])
// .sortImages([<method>, ..], <reverse>)
// NOTE: <method> can either be one of: // NOTE: <method> can either be one of:
// 1) method name (key) from .config['sort-methods'] // 1) method name (key) from .config['sort-methods']
// 2) a space separated string of methods or attribute paths // 2) a space separated string of methods or attribute paths
// as in .config['sort-methods']'s values. // as in .config['sort-methods']'s values.
// for more info se doc for: .config['sort-methods'] // for more info se doc for: .config['sort-methods']
// NOTE: if it is needed to reverse the method by default just
// add 'reverse' to it's string.
// //
// Update current sort order: // Update current sort order:
// .sortImages('update') // .sortImages('update')
@ -638,6 +646,9 @@ module.SortActions = actions.Actions({
// NOTE: this is designed to facilitate manual sorting of // NOTE: this is designed to facilitate manual sorting of
// .data.order // .data.order
// //
// Reverse image order:
// .sortImages('reverse')
//
// //
// NOTE: reverse is calculated by oddity -- if an odd number indicated // NOTE: reverse is calculated by oddity -- if an odd number indicated
// then the result is reversed, otherwise it is not. // then the result is reversed, otherwise it is not.
@ -654,7 +665,7 @@ module.SortActions = actions.Actions({
var that = this var that = this
if(method == 'reverse'){ if(method == 'reverse'){
method = null method = []
reverse = true reverse = true
} }
@ -662,54 +673,68 @@ module.SortActions = actions.Actions({
: reverse == 'reverse' : reverse == 'reverse'
|| reverse || reverse
// special case: 'update'
method = method == 'update' ? [] : method method = method == 'update' ? [] : method
// defaults...
method = method method = method
|| this.config['sort-methods'][this.config['default-sort']] || this.config['sort-methods'][this.config['default-sort']]
|| this.config['default-sort'] || this.config['default-sort']
|| 'birthtime' || 'birthtime'
method = this.config['sort-methods'][method] || method
// handle multiple methods.... // expand method names...
// XXX should this be recursive???
method = typeof(method) == typeof('str') ?
method
.split(/ +/g)
.map(function(m){
return that.config['sort-methods'][m] || m })
.join(' ')
: method
method = typeof(method) == typeof('str') ? method.split(/ +/g) : method method = typeof(method) == typeof('str') ? method.split(/ +/g) : method
method = method instanceof Array ? method : [method] method = method instanceof Array ? method : [method]
// get the reverse... // get the reverse arity...
var i = method.indexOf('reverse') var i = method.indexOf('reverse')
while(i >=0){ while(i >=0){
reverse = !reverse reverse = !reverse
method.splice(i, 1)
method.splice(i, 1)
i = method.indexOf('reverse') i = method.indexOf('reverse')
} }
// build the compare routine... // build the compare routine...
method = method.map(function(m){ method = method
return SortActions.__sort_methods__[m] // remove duplicate methods...
|| (that.__sort_methods__ && that.__sort_methods__[m]) .unique()
// sort by attr path... .map(function(m){
|| (function(){ return SortActions.__sort_methods__[m]
var p = m.split(/\./g) || (that.__sort_methods__ && that.__sort_methods__[m])
var _get = function(obj){ // sort by attr path...
for(var i=0; i<p.length; i++){ || (function(){
obj = obj[p[i]] var p = m.split(/\./g)
if(obj === undefined){ var _get = function(obj){
return null for(var i=0; i<p.length; i++){
obj = obj[p[i]]
if(obj === undefined){
return null
}
} }
return obj
} }
return obj return function(a, b){
} a = _get(this.images[a])
return function(a, b){ b = _get(this.images[b])
a = _get(this.images[a])
b = _get(this.images[b])
if(a == b){ if(a == b){
return 0 return 0
} else if(a < b){ } else if(a < b){
return -1 return -1
} else { } else {
return +1 return +1
} }
}})() }})()
}) })
// prepare the cmp function... // prepare the cmp function...
var cmp = method.length == 1 ? var cmp = method.length == 1 ?
@ -732,6 +757,10 @@ module.SortActions = actions.Actions({
reverse ? reverse ?
this.data.order.sort(cmp.bind(this)).reverse() this.data.order.sort(cmp.bind(this)).reverse()
: this.data.order.sort(cmp.bind(this)) : this.data.order.sort(cmp.bind(this))
// just reverse...
} else if(method.length <= 0 && reverse) {
this.data.order.reverse()
} }
this.data.updateImagePositions() this.data.updateImagePositions()
@ -740,7 +769,7 @@ module.SortActions = actions.Actions({
// XXX should this be a dialog with ability to edit modes??? // XXX should this be a dialog with ability to edit modes???
// - toggle reverse sort // - toggle reverse sort
// XXX currently this will not toggle past 'none' // XXX currently this will not toggle past 'none'
toggleImageSort: ['Edit|Sort/Sort images by', toggleImageSort: ['Edit|Sort/Toggle image sort method',
toggler.Toggler(null, toggler.Toggler(null,
function(){ return this.data.sort_method || 'none' }, function(){ return this.data.sort_method || 'none' },
function(){ function(){
@ -763,7 +792,7 @@ module.SortActions = actions.Actions({
this.sortImages('update') this.sortImages('update')
} else { } else {
this.sortImages(this.config['sort-methods'][mode]) this.sortImages(mode)
} }
this.data.sort_method = mode this.data.sort_method = mode

View File

@ -263,7 +263,8 @@ module.GLOBAL_KEYBOARD = {
O: 'browsePath', O: 'browsePath',
S: { S: {
default: 'slideshowDialog', default: 'slideshowDialog',
shift: 'sortImages: "birthtime ctime" -- Sort images by date', //shift: 'sortImages: "Date" -- Sort images by date',
shift: 'sortImages -- Sort images',
alt: 'browseActions: "/Sort/"', alt: 'browseActions: "/Sort/"',
// XXX need to make this save to base_path if it exists and // XXX need to make this save to base_path if it exists and
// ask the user if it does not... now it always asks. // ask the user if it does not... now it always asks.

View File

@ -564,32 +564,6 @@ module.ImagesPrototype = {
return gids return gids
}, },
// Shorthands... // Shorthands...
// XXX default gids may include stray attributes...
sortByDate: function(gids, reverse){
gids = gids == null ? Object.keys(this) : gids
return this.sortImages(gids, null, reverse)
},
sortByName: function(gids, reverse){
gids = gids == null ? Object.keys(this) : gids
return this.sortImages(gids, module.makeImageNameCmp(this), reverse)
},
sortBySeqOrName: function(gids, reverse){
gids = gids == null ? Object.keys(this) : gids
return this.sortImages(gids, module.makeImageSeqOrNameCmp(this), reverse)
},
sortByNameXPStyle: function(gids, reverse){
gids = gids == null ? Object.keys(this) : gids
return this.sortImages(gids,
module.makeImageSeqOrNameCmp(this, null, this.getImageNameLeadingSeq),
reverse)
},
sortByDateOrSeqOrName: function(gids, reverse){
gids = gids == null ? Object.keys(this) : gids
return this.sortImages(gids, [
module.makeImageDateCmp(this),
module.makeImageSeqOrNameCmp(this)
], reverse)
},
// XXX // XXX
sortedImagesByFileNameSeqWithOverflow: function(gids, reverse){ sortedImagesByFileNameSeqWithOverflow: function(gids, reverse){
gids = gids == null ? Object.keys(this) : gids gids = gids == null ? Object.keys(this) : gids

View File

@ -457,7 +457,7 @@ function getKeyHandlers(key, modifiers, keybindings, modes, shifted_keys, action
// actions... // actions...
} else if(handler in actions } else if(handler in actions
|| handler.split(/!?\s*:\s*|!/)[0].trim() in actions){ || handler.split(/!?\s*:\s*|!|--/)[0].trim() in actions){
var c = parseActionCall(handler) var c = parseActionCall(handler)