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

View File

@ -1107,7 +1107,7 @@ var RibbonsPrototype = {
} }
} }
} }
// remove all images that we do not need... // remove all images that we do not need...
var unloaded = $() var unloaded = $()
loaded = loaded loaded = loaded

View File

@ -121,6 +121,8 @@ module.GLOBAL_KEYBOARD = {
}, },
'(': 'prevImageInOrder', '(': 'prevImageInOrder',
')': 'nextImageInOrder', ')': 'nextImageInOrder',
',': 'prevMarked',
'.': 'nextMarked',
Up: { Up: {
default: 'prevRibbon', default: 'prevRibbon',
shift: 'shiftImageUp', 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', lastGlobalImage: ['Get last globally image',
function(){ this.lastImage(true) }], function(){ this.lastImage(true) }],
// XXX skip unloaded images...
prevImage: ['Focus previous image', prevImage: ['Focus previous image',
function(a){ function(a){
// keep track of traverse direction... // keep track of traverse direction...
@ -305,10 +332,17 @@ actions.Actions({
} }
}], }],
// XXX skip unloaded images...
prevImageInOrder: ['Focus previous image in order', 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', 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', firstRibbon: ['Focus previous ribbon',
function(){ this.focusRibbon('first') }], function(){ this.focusRibbon('first') }],
@ -543,6 +577,13 @@ actions.Actions({
this.crop(data.getImages(images), flatten) 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... // do the update...
// the target is not loaded... // loaded more than we need (crop?)...
if(this.ribbons.getImage(target).length == 0 if(na + pa < nl + pl
// the target is not loaded...
|| this.ribbons.getImage(target).length == 0
// passed threshold on the right... // passed threshold on the right...
|| (nl < threshold && na > nl) || (nl < threshold && na > nl)
// passed threshold on the left... // passed threshold on the left...
@ -1723,6 +1766,7 @@ module.GlobalStateIndicator = Feature({
//--------------------------------------------------------------------- //---------------------------------------------------------------------
var ImageMarkActions = actions.Actions({ var ImageMarkActions = actions.Actions({
toggleMark: ['', toggleMark: ['',
// XXX make this a real toggler... // XXX make this a real toggler...
@ -1736,41 +1780,14 @@ var ImageMarkActions = actions.Actions({
return action return action
}], }],
// mode can be: // XXX do we need first/last marked???
// "ribbon" - next marked in current ribbon (default)
// "all" - next marked in sequence
nextMarked: ['',
function(mode){
mode = mode == null ? 'ribbon' : mode
// XXX
}],
prevMarked: ['', prevMarked: ['',
function(mode){ function(mode){ this.prevTagged('selected', mode) }],
mode = mode == null ? 'ribbon' : mode nextMarked: ['',
function(mode){ this.nextTagged('selected', mode) }],
// XXX
}],
firstMarked: ['',
function(mode){
mode = mode == null ? 'ribbon' : mode
// XXX
}],
lastMarked: ['',
function(mode){
mode = mode == null ? 'ribbon' : mode
// XXX
}],
cropMarked: ['', cropMarked: ['',
function(mode){ function(flatten){ this.cropTagged('selected', 'any', flatten) }],
mode = mode == null ? 'ribbon' : mode
// XXX
}],
}) })
@ -1799,6 +1816,14 @@ module.ImageBookmarks = Feature({
tag: 'image-bookmarks', tag: 'image-bookmarks',
actions: ImageBookmarkActions, actions: ImageBookmarkActions,
prevBookmarked: ['',
function(mode){ this.prevTagged('bookmarked', mode) }],
nextBookmarked: ['',
function(mode){ this.nextTagged('bookmarked', mode) }],
cropBookmarked: ['',
function(flatten){ this.cropTagged('bookmarked', 'any', flatten) }],
}) })