added tagged/marked/bookmarked navigation + several fixes + some refactoring...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2014-11-19 19:30:38 +03:00
parent 2f15a08003
commit 22f90336ee
4 changed files with 83 additions and 38 deletions

View File

@ -668,6 +668,11 @@ var DataPrototype = {
//
// Filter the list and return only loaded images from it:
// .getImages(list)
// .getImages(list, 'loaded')
// -> list
//
// .getImages(list, 'current')
// .getImages(list, order|ribbon)
// -> list
//
// Get loaded images from ribbon:
@ -726,10 +731,17 @@ var DataPrototype = {
// filter out the unloaded gids from given list...
} else if(target != null && target.constructor === Array){
var loaded = this.getImages('loaded')
var loaded = count == 'current' ? this.getImages('current')
: count in this.ribbons ? this.ribbons[count].compact()
: typeof(count) == typeof(123) ?
this.ribbons[this.getRibbon(count)].compact()
: this.getImages('loaded')
count = null
list = target.filter(function(e){
return loaded.indexOf(e) >= 0
})
target = null
// target is ribbon gid...
@ -820,6 +832,7 @@ var DataPrototype = {
//
//
// NOTE: this expects ribbon order and not image order.
// NOTE: negative ribbon order is relative to list tail.
getRibbon: function(target, offset){
target = target == null ? this.current : target
@ -873,7 +886,12 @@ var DataPrototype = {
}
if(o != null){
// negative indexes are relative to list tail...
o = o < 0 ? o + this.ribbon_order.length : o
o += offset
if(o < 0 || o > this.ribbon_order.length){
// ERROR: offset out of bounds...
return null

View File

@ -121,6 +121,8 @@ module.GLOBAL_KEYBOARD = {
},
'(': 'prevImageInOrder',
')': 'nextImageInOrder',
',': 'prevMarked',
'.': 'nextMarked',
Up: {
default: 'prevRibbon',
shift: 'shiftImageUp',

View File

@ -99,6 +99,32 @@ function updateImagePosition(actions, target){
}
// mode can be:
// "ribbon" - next marked in current ribbon (default)
// "all" - next marked in sequence
//
// XXX add support for tag lists...
function makeTagWalker(direction, dfl_tag){
var meth = direction == 'next' ? 'nextImage' : 'prevImage'
return function(tag, mode){
mode = mode == null ? 'all' : mode
tag = tag || dfl_tag
// account for no tags or no images tagged...
var lst = this.data.tags != null ? this.data.tags[tag] : []
lst = lst || []
if(mode == 'ribbon'){
this[meth](this.data.getImages(lst, 'current'))
} else {
this[meth](lst)
}
}
}
/*********************************************************************/
//
@ -274,6 +300,7 @@ actions.Actions({
lastGlobalImage: ['Get last globally image',
function(){ this.lastImage(true) }],
// XXX skip unloaded images...
prevImage: ['Focus previous image',
function(a){
// keep track of traverse direction...
@ -305,10 +332,17 @@ actions.Actions({
}
}],
// XXX skip unloaded images...
prevImageInOrder: ['Focus previous image in order',
function(){ this.prevImage(this.data.order) }],
function(){ this.prevImage(this.data.getImages(this.data.order)) }],
nextImageInOrder: ['Focus next image in order',
function(){ this.nextImage(this.data.order) }],
function(){ this.nextImage(this.data.getImages(this.data.order)) }],
// XXX should these be here???
prevTagged: ['',
makeTagWalker('prev')],
nextTagged: ['',
makeTagWalker('next')],
firstRibbon: ['Focus previous ribbon',
function(){ this.focusRibbon('first') }],
@ -543,6 +577,13 @@ actions.Actions({
this.crop(data.getImages(images), flatten)
}],
// XXX should this be here???
cropTagged: ['',
function(tags, mode, flatten){
var selector = mode == 'any' ? 'getTaggedByAny' : 'getTaggedByAll'
this.crop(this.data[selector](tags), flatten)
}],
})
@ -1127,8 +1168,10 @@ var PartialRibbonsActions = actions.Actions({
// do the update...
// the target is not loaded...
if(this.ribbons.getImage(target).length == 0
// loaded more than we need (crop?)...
if(na + pa < nl + pl
// the target is not loaded...
|| this.ribbons.getImage(target).length == 0
// passed threshold on the right...
|| (nl < threshold && na > nl)
// passed threshold on the left...
@ -1723,6 +1766,7 @@ module.GlobalStateIndicator = Feature({
//---------------------------------------------------------------------
var ImageMarkActions = actions.Actions({
toggleMark: ['',
// XXX make this a real toggler...
@ -1736,41 +1780,14 @@ var ImageMarkActions = actions.Actions({
return action
}],
// mode can be:
// "ribbon" - next marked in current ribbon (default)
// "all" - next marked in sequence
nextMarked: ['',
function(mode){
mode = mode == null ? 'ribbon' : mode
// XXX
}],
// XXX do we need first/last marked???
prevMarked: ['',
function(mode){
mode = mode == null ? 'ribbon' : mode
// XXX
}],
firstMarked: ['',
function(mode){
mode = mode == null ? 'ribbon' : mode
// XXX
}],
lastMarked: ['',
function(mode){
mode = mode == null ? 'ribbon' : mode
// XXX
}],
function(mode){ this.prevTagged('selected', mode) }],
nextMarked: ['',
function(mode){ this.nextTagged('selected', mode) }],
cropMarked: ['',
function(mode){
mode = mode == null ? 'ribbon' : mode
// XXX
}],
function(flatten){ this.cropTagged('selected', 'any', flatten) }],
})
@ -1799,6 +1816,14 @@ module.ImageBookmarks = Feature({
tag: 'image-bookmarks',
actions: ImageBookmarkActions,
prevBookmarked: ['',
function(mode){ this.prevTagged('bookmarked', mode) }],
nextBookmarked: ['',
function(mode){ this.nextTagged('bookmarked', mode) }],
cropBookmarked: ['',
function(flatten){ this.cropTagged('bookmarked', 'any', flatten) }],
})