mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-30 02:40:08 +00:00
split sort to a seporate feature + sdded manual sort order (not yet sure how to store it)...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
02dfeb1285
commit
5a557e7f11
@ -80,7 +80,6 @@ actions.Actions({
|
|||||||
],
|
],
|
||||||
'ribbon-focus-mode': 'order',
|
'ribbon-focus-mode': 'order',
|
||||||
|
|
||||||
'defeault-sort': 'birthtime ctime',
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
@ -514,6 +513,64 @@ actions.Actions({
|
|||||||
|
|
||||||
// XXX align to ribbon...
|
// XXX align to ribbon...
|
||||||
|
|
||||||
|
// basic image editing...
|
||||||
|
//
|
||||||
|
// XXX should we have .rotate(..) and .flip(..) generic actions???
|
||||||
|
rotateCW: ['Image|Edit/',
|
||||||
|
function(target){
|
||||||
|
this.images
|
||||||
|
&& this.images.rotateImage(this.data.getImage(target), 'cw') }],
|
||||||
|
rotateCCW: ['Image|Edit/',
|
||||||
|
function(target){
|
||||||
|
this.images
|
||||||
|
&& this.images.rotateImage(this.data.getImage(target), 'ccw') }],
|
||||||
|
flipVertical: ['Image|Edit/',
|
||||||
|
function(target){
|
||||||
|
this.images
|
||||||
|
&& this.images.flipImage(this.data.getImage(target), 'vertical') }],
|
||||||
|
flipHorizontal: ['Image|Edit/',
|
||||||
|
function(target){
|
||||||
|
this.images
|
||||||
|
&& this.images.flipImage(this.data.getImage(target), 'horizontal') }],
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
var Base =
|
||||||
|
module.Base = core.ImageGridFeatures.Feature({
|
||||||
|
title: 'ImageGrid base',
|
||||||
|
|
||||||
|
tag: 'base',
|
||||||
|
/* XXX ???
|
||||||
|
suggested: [
|
||||||
|
'tags',
|
||||||
|
'sort',
|
||||||
|
],
|
||||||
|
*/
|
||||||
|
|
||||||
|
actions: BaseActions,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------
|
||||||
|
// Sort...
|
||||||
|
|
||||||
|
var SortActions =
|
||||||
|
module.SortActions = actions.Actions({
|
||||||
|
config: {
|
||||||
|
'default-sort': 'Date',
|
||||||
|
|
||||||
|
'sort-modes': {
|
||||||
|
'none': '',
|
||||||
|
'Date': 'metadata.createDate birthtime',
|
||||||
|
'Name': 'name path',
|
||||||
|
'Name (XP-style)': 'name-leading-sequence name path',
|
||||||
|
'File sequence number': 'name-leading-sequence name path',
|
||||||
|
// XXX sequence number with overflow...
|
||||||
|
// XXX manual...
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
// Custom sort modes...
|
// Custom sort modes...
|
||||||
//
|
//
|
||||||
// Format:
|
// Format:
|
||||||
@ -541,6 +598,16 @@ actions.Actions({
|
|||||||
return a - b
|
return a - b
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
// Sort using the default sort method
|
||||||
|
// .sortImages()
|
||||||
|
//
|
||||||
|
// Sort using a specific method(s):
|
||||||
|
// .sortImages(<method>)
|
||||||
|
// .sortImages([<method>, ..])
|
||||||
|
//
|
||||||
|
// Update current sort order:
|
||||||
|
// .sortImages('update')
|
||||||
|
//
|
||||||
// XXX this also requires images...
|
// XXX this also requires images...
|
||||||
// XXX cache order???
|
// XXX cache order???
|
||||||
sortImages: ['- Edit|Sort/Sort images',
|
sortImages: ['- Edit|Sort/Sort images',
|
||||||
@ -556,14 +623,25 @@ actions.Actions({
|
|||||||
|| reverse == 'reverse'
|
|| reverse == 'reverse'
|
||||||
|| reverse
|
|| reverse
|
||||||
|
|
||||||
|
method = method == 'update' ? [] : method
|
||||||
method = method
|
method = method
|
||||||
|| this.config['defeault-sort']
|
|| this.config['sort-modes'][this.config['default-sort']]
|
||||||
|
|| this.config['default-sort']
|
||||||
|| 'birthtime'
|
|| 'birthtime'
|
||||||
// handle multiple methods....
|
// handle multiple methods....
|
||||||
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...
|
||||||
|
var i = method.indexOf('reverse')
|
||||||
|
if(i >=0){
|
||||||
|
reverse = true
|
||||||
|
method.splice(i, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// build the compare routine...
|
||||||
method = method.map(function(m){
|
method = method.map(function(m){
|
||||||
return BaseActions.__sort_modes__[m]
|
return SortActions.__sort_modes__[m]
|
||||||
|| (that.__sort_modes__ && that.__sort_modes__[m])
|
|| (that.__sort_modes__ && that.__sort_modes__[m])
|
||||||
// sort by attr path...
|
// sort by attr path...
|
||||||
|| (function(){
|
|| (function(){
|
||||||
@ -607,44 +685,97 @@ actions.Actions({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// do the sort (in place)...
|
// do the sort (in place)...
|
||||||
if(method && this.images){
|
if(method && method.length > 0 && this.images){
|
||||||
this.data.order = this.data.order.slice()
|
this.data.order = this.data.order.slice()
|
||||||
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))
|
||||||
this.data.updateImagePositions()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.data.updateImagePositions()
|
||||||
}],
|
}],
|
||||||
|
|
||||||
// basic image editing...
|
// XXX should this be a dialog with ability to edit modes???
|
||||||
//
|
// - toggle reverse sort
|
||||||
// XXX should we have .rotate(..) and .flip(..) generic actions???
|
// XXX should this store state???
|
||||||
rotateCW: ['Image|Edit/',
|
// XXX handle manual...
|
||||||
function(target){
|
// ...set manual on shiftImageLeft/shiftImageRight
|
||||||
this.images
|
toggleImageSort: ['Edit|Sort/Sort images by',
|
||||||
&& this.images.rotateImage(this.data.getImage(target), 'cw') }],
|
toggler.Toggler(null,
|
||||||
rotateCCW: ['Image|Edit/',
|
function(){ return this.data.sort_mode || 'none' },
|
||||||
function(target){
|
function(){
|
||||||
this.images
|
return Object.keys(this.config['sort-modes'])
|
||||||
&& this.images.rotateImage(this.data.getImage(target), 'ccw') }],
|
.concat(this.data.manual_order ? ['Manual'] : [])},
|
||||||
flipVertical: ['Image|Edit/',
|
// prevent setting 'none' as mode...
|
||||||
function(target){
|
function(mode){
|
||||||
this.images
|
return mode != 'none'
|
||||||
&& this.images.flipImage(this.data.getImage(target), 'vertical') }],
|
|| (mode == 'Manual' && this.data.manual_order) },
|
||||||
flipHorizontal: ['Image|Edit/',
|
function(mode){
|
||||||
function(target){
|
// save manual order...
|
||||||
this.images
|
if(this.data.sort_mode == 'Manual'){
|
||||||
&& this.images.flipImage(this.data.getImage(target), 'horizontal') }],
|
this.data.manual_order = this.data.order.slice()
|
||||||
|
}
|
||||||
|
|
||||||
|
// special case: manual order...
|
||||||
|
// XXX this does not use .sortImages(..) thus this does not update...
|
||||||
|
if(mode == 'Manual'){
|
||||||
|
this.data.order = this.data.manual_order.slice()
|
||||||
|
this.sortImages('update')
|
||||||
|
|
||||||
|
} else {
|
||||||
|
this.sortImages(this.config['sort-modes'][mode])
|
||||||
|
}
|
||||||
|
|
||||||
|
this.data.sort_mode = mode
|
||||||
|
})],
|
||||||
|
|
||||||
|
// Store/load:
|
||||||
|
// .sort_mode
|
||||||
|
// .manual_order
|
||||||
|
load: [function(data){
|
||||||
|
return function(){
|
||||||
|
if(data.data && data.data.sort_mode){
|
||||||
|
this.data.sort_mode = data.data.sort_mode
|
||||||
|
}
|
||||||
|
|
||||||
|
if(data.data && data.data.manual_order){
|
||||||
|
this.data.manual_order = data.data.manual_order
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
json: [function(){
|
||||||
|
return function(res){
|
||||||
|
if(this.data.sort_mode){
|
||||||
|
res.data.sort_mode = this.data.sort_mode
|
||||||
|
}
|
||||||
|
|
||||||
|
if(this.data.manual_order){
|
||||||
|
res.data.manual_order = this.data.manual_order
|
||||||
|
|
||||||
|
} else if(this.toggleImageSort('?') == 'Manual'){
|
||||||
|
res.data.manual_order = this.data.order
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}],
|
||||||
})
|
})
|
||||||
|
|
||||||
|
var Sort =
|
||||||
|
module.Sort = core.ImageGridFeatures.Feature({
|
||||||
|
title: '',
|
||||||
|
|
||||||
var Base =
|
tag: 'sort',
|
||||||
module.Base = core.ImageGridFeatures.Feature({
|
depends: [
|
||||||
title: 'ImageGrid base',
|
'base',
|
||||||
|
],
|
||||||
|
|
||||||
tag: 'base',
|
actions: SortActions,
|
||||||
|
|
||||||
actions: BaseActions,
|
handlers: [
|
||||||
|
['shiftImageRight shiftImageLeft',
|
||||||
|
function(){
|
||||||
|
this.data.sort_mode = 'Manual'
|
||||||
|
}],
|
||||||
|
],
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@ -1026,6 +1157,7 @@ module.ImageGroup = core.ImageGridFeatures.Feature({
|
|||||||
core.ImageGridFeatures.Feature('base-full', [
|
core.ImageGridFeatures.Feature('base-full', [
|
||||||
'base',
|
'base',
|
||||||
'tags',
|
'tags',
|
||||||
|
'sort',
|
||||||
'crop',
|
'crop',
|
||||||
'image-group',
|
'image-group',
|
||||||
])
|
])
|
||||||
|
|||||||
@ -22,7 +22,11 @@ var toggler = require('lib/toggler')
|
|||||||
// default...
|
// default...
|
||||||
var makeConfigToggler =
|
var makeConfigToggler =
|
||||||
module.makeConfigToggler =
|
module.makeConfigToggler =
|
||||||
function(attr, states, callback){
|
function(attr, states, a, b){
|
||||||
|
|
||||||
|
var pre = a
|
||||||
|
var post = b || function(action){ action != null && this.focusImage() }
|
||||||
|
|
||||||
return toggler.Toggler(null,
|
return toggler.Toggler(null,
|
||||||
function(_, action){
|
function(_, action){
|
||||||
var lst = states.constructor === Array ? states : states.call(this)
|
var lst = states.constructor === Array ? states : states.call(this)
|
||||||
@ -37,9 +41,7 @@ function(attr, states, callback){
|
|||||||
//this.focusImage()
|
//this.focusImage()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
states,
|
states, pre, post)
|
||||||
// XXX should we focus image by default here???
|
|
||||||
callback || function(action){ action != null && this.focusImage() })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -166,13 +166,6 @@ module.ViewerActions = actions.Actions({
|
|||||||
'last', // select last image
|
'last', // select last image
|
||||||
],
|
],
|
||||||
'ribbon-focus-mode': 'visual',
|
'ribbon-focus-mode': 'visual',
|
||||||
|
|
||||||
'sort-modes': {
|
|
||||||
'Sort by date': 'metadata.createDate birthtime',
|
|
||||||
'Sort by name': 'name path',
|
|
||||||
'Sort by name (XP-style)': 'name-leading-sequence name path',
|
|
||||||
'Sort by file sequence number': 'name-leading-sequence name path',
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Images...
|
// Images...
|
||||||
@ -634,15 +627,6 @@ module.ViewerActions = actions.Actions({
|
|||||||
reverseRibbons: [ reloadAfter() ],
|
reverseRibbons: [ reloadAfter() ],
|
||||||
sortImages: [ reloadAfter(true) ],
|
sortImages: [ reloadAfter(true) ],
|
||||||
|
|
||||||
// XXX should this be a dialog with ability to edit modes???
|
|
||||||
// XXX should this store state???
|
|
||||||
toggleImageSort: ['Edit|Sort/Sort images by',
|
|
||||||
core.makeConfigToggler(
|
|
||||||
function(){ return Object.keys(this.config['sort-modes'])[0]},
|
|
||||||
function(){ return Object.keys(this.config['sort-modes']) },
|
|
||||||
function(mode){ this.sortImages(this.config['sort-modes'][mode]) })],
|
|
||||||
|
|
||||||
|
|
||||||
// basic image editing...
|
// basic image editing...
|
||||||
//
|
//
|
||||||
// XXX should we have .rotate(..) and .flip(..) generic actions???
|
// XXX should we have .rotate(..) and .flip(..) generic actions???
|
||||||
@ -786,7 +770,6 @@ module.Viewer = core.ImageGridFeatures.Feature({
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*********************************************************************/
|
/*********************************************************************/
|
||||||
// Utilities and Services...
|
// Utilities and Services...
|
||||||
|
|
||||||
|
|||||||
@ -243,7 +243,7 @@ function(elem, state_accessor, states, callback_a, callback_b){
|
|||||||
if(callback_pre != null){
|
if(callback_pre != null){
|
||||||
if(callback_pre.apply(this, [action, e].concat(args)) === false){
|
if(callback_pre.apply(this, [action, e].concat(args)) === false){
|
||||||
//return
|
//return
|
||||||
return func('?')
|
return func.call(this, '?')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user