more refactoring and tweaking...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2013-12-16 01:49:47 +04:00
parent 5603fed36b
commit 798a433ab1
5 changed files with 96 additions and 46 deletions

View File

@ -22,32 +22,10 @@ var BOOKMARKS_FILE_PATTERN = /^[0-9]*-bookmarked.json$/
* Helpers * Helpers
*/ */
// This is the same as getGIDBefore(..) but will return the currently var getBookmarkedGIDBefore = makeGIDBeforeGetterFromList(
// loaded and bookmarked image before current. function(){
// return BOOKMARKS
// for exact protocol see: getGIDBefore(..) })
//
// XXX argument processing...
function getBookmarkedGIDBefore(gid){
if(BOOKMARKS.length == 0){
return null
}
gid = gid == null ? getImageGID() : gid
var prev
// need to account for cropping here...
do {
prev = getGIDBefore(gid, BOOKMARKS)
gid = getGIDBefore(prev)
} while(prev != gid && prev != null)
// no bookmarks before current image...
if(prev == null){
return prev
}
return prev
}
@ -101,18 +79,9 @@ var toggleBookmark = makeMarkToggler(
// focus next bookmark... // focus next bookmark...
// //
// NOTE: this will not jump to bookmarks on other ribbons... // NOTE: this will not jump to bookmarks on other ribbons...
//
// XXX make a generic next/prev marked function...
var nextBookmark = makeNextFromListAction( var nextBookmark = makeNextFromListAction(
getBookmarkedGIDBefore, getBookmarkedGIDBefore,
function(){ return BOOKMARKS }) function(){ return BOOKMARKS })
// focus previous bookmark...
//
// NOTE: this will not jump to bookmarks on other ribbons...
//
// XXX make a generic next/prev marked function...
var prevBookmark = makePrevFromListAction( var prevBookmark = makePrevFromListAction(
getBookmarkedGIDBefore, getBookmarkedGIDBefore,
function(){ return BOOKMARKS }) function(){ return BOOKMARKS })

View File

@ -629,6 +629,46 @@ function getGIDBefore(gid, ribbon, search, data){
} }
// Construct a function similar to getGIDBefore(..) that will get the
// closest gid from a list...
//
// for exact protocol see: getGIDBefore(..)
//
// NOTE: this will consider only loaded images...
// NOTE: this needs the list sorted in the same order as the ribbons
// i.e. via DATA.order...
// NOTE: passing a ribbon number or setting restrict_to_ribbon to true
// will restrict the search to a specific ribbon only...
function makeGIDBeforeGetterFromList(get_list, restrict_to_ribbon){
return function(gid, ribbon){
ribbon = ribbon == null && restrict_to_ribbon == true
? getGIDRibbonIndex(gid)
: ribbon
var list = get_list()
if(list.length == 0){
return null
}
console.log('>>>>', ribbon)
gid = gid == null ? getImageGID(null, ribbon) : gid
var prev
// need to account for cropping here...
// skip until we find a match from the list...
do {
prev = getGIDBefore(gid, list)
gid = getGIDBefore(prev, ribbon)
} while(prev != gid && prev != null)
// nothing found before current image...
if(prev == null){
return prev
}
return prev
}
}
// Get "count" of GIDs starting with a given gid ("from") // Get "count" of GIDs starting with a given gid ("from")
// //
// count can be either negative or positive, this will indicate load // count can be either negative or positive, this will indicate load
@ -966,6 +1006,8 @@ function imageUpdated(gid){
// Key differences: // Key differences:
// - nextImage(..) uses DOM to get the next image which is simpler // - nextImage(..) uses DOM to get the next image which is simpler
// - nextImage(..) accepts an offset argument // - nextImage(..) accepts an offset argument
// NOTE: passing a ribbon number or setting restrict_to_ribbon to true
// will restrict the search to a specific ribbon only...
// //
// XXX not sure if we need the offset argument here... // XXX not sure if we need the offset argument here...
// a-la nextImage(n) / prevImage(n) // a-la nextImage(n) / prevImage(n)
@ -973,19 +1015,22 @@ function imageUpdated(gid){
// loaded gids? // loaded gids?
// (i.e. filter it first and then get the needed gid rather // (i.e. filter it first and then get the needed gid rather
// iterating...) // iterating...)
function makeNextFromListAction(get_closest, get_list){ function makeNextFromListAction(get_closest, get_list, restrict_to_ribbon){
get_closest = get_closest == null ? getGIDBefore : get_closest get_closest = get_closest == null ? getGIDBefore : get_closest
get_list = get_list == null ? getRibbonGIDs : get_list get_list = get_list == null ? getRibbonGIDs : get_list
return function(){ return function(ribbon){
var list = get_list() var list = get_list()
if(list.length == 0){ if(list.length == 0){
flashIndicator('end') flashIndicator('end')
return getImage() return getImage()
} }
var cur = getImageGID() var cur = getImageGID()
ribbon = ribbon == null && restrict_to_ribbon == true
? getGIDRibbonIndex(cur)
: ribbon
var o = getGIDOrder(cur) var o = getGIDOrder(cur)
var next = get_closest(cur) var next = get_closest(cur, ribbon)
var i = list.indexOf(next)+1 var i = list.indexOf(next)+1
// we are before the first loaded bookmark, find the first... // we are before the first loaded bookmark, find the first...
@ -994,7 +1039,7 @@ function makeNextFromListAction(get_closest, get_list){
|| getGIDOrder(next) < o) || getGIDOrder(next) < o)
&& i < list.length){ && i < list.length){
next = list[i] next = list[i]
next = get_closest(next) next = get_closest(next, ribbon)
i++ i++
} }
@ -1013,18 +1058,21 @@ function makeNextFromListAction(get_closest, get_list){
// see makeNextFromListAction(..) above for documentation... // see makeNextFromListAction(..) above for documentation...
function makePrevFromListAction(get_closest, get_list){ function makePrevFromListAction(get_closest, get_list, restrict_to_ribbon){
get_closest = get_closest == null ? getGIDBefore : get_closest get_closest = get_closest == null ? getGIDBefore : get_closest
get_list = get_list == null ? getRibbonGIDs : get_list get_list = get_list == null ? getRibbonGIDs : get_list
return function(){ return function(ribbon){
var list = get_list() var list = get_list()
if(list.length == 0){ if(list.length == 0){
flashIndicator('start') flashIndicator('start')
return getImage(cur) return getImage(cur)
} }
var cur = getImageGID() var cur = getImageGID()
var prev = get_closest(cur) ribbon = ribbon == null && restrict_to_ribbon == true
? getGIDRibbonIndex(cur)
: ribbon
var prev = get_closest(cur, ribbon)
// nothing bookmarked before us... // nothing bookmarked before us...
if(prev == null){ if(prev == null){
@ -1035,7 +1083,7 @@ function makePrevFromListAction(get_closest, get_list){
// current image is bookmarked, get the bookmark before it... // current image is bookmarked, get the bookmark before it...
if(prev == cur){ if(prev == cur){
prev = list[list.indexOf(prev)-1] prev = list[list.indexOf(prev)-1]
prev = prev != null ? get_closest(prev) : prev prev = prev != null ? get_closest(prev, ribbon) : prev
// no loaded (crop mode?) bookmark before us... // no loaded (crop mode?) bookmark before us...
if(prev == null){ if(prev == null){
flashIndicator('start') flashIndicator('start')

View File

@ -584,8 +584,10 @@ var KEYBOARD_CONFIG = {
ctrl: doc('Toggle bookmark', ctrl: doc('Toggle bookmark',
function(){ toggleBookmark() }), function(){ toggleBookmark() }),
}, },
'[': doc('Previous bookmarked image', prevBookmark), '[': doc('Previous bookmarked image',
']': doc('Next bookmarked image', nextBookmark), function(){ prevBookmark() }),
']': doc('Next bookmarked image',
function(){ nextBookmark() }),
S: { S: {
default: doc('Start slideshow', default: doc('Start slideshow',

View File

@ -54,6 +54,12 @@ function _removeMark(cls, gid, image){
} }
var getMarkedGIDBefore = makeGIDBeforeGetterFromList(
function(){
return MARKED
})
// Make a mark toggler // Make a mark toggler
// //
// The toggler will: // The toggler will:
@ -378,6 +384,20 @@ function shiftMarkedImagesRight(){
} }
// focus next/prev mark...
//
// NOTE: these will not jump to marks on other ribbons... to prevent this
// add true as the final argument (see restrict_to_ribbon argument
// of makeNextFromListAction(..) for more info)
var nextMark = makeNextFromListAction(
getMarkedGIDBefore,
function(){ return MARKED })
var prevMark = makePrevFromListAction(
getMarkedGIDBefore,
function(){ return MARKED })
/********************************************************************** /**********************************************************************
* Dialogs... * Dialogs...
@ -501,7 +521,10 @@ function setupMarks(viewer){
.on('togglingMark', function(evt, gid, action){ .on('togglingMark', function(evt, gid, action){
// add marked image to list... // add marked image to list...
if(action == 'on'){ if(action == 'on'){
MARKED.indexOf(gid) == -1 && MARKED.push(gid) if(MARKED.indexOf(gid) == -1){
MARKED.push(gid)
MARKED.sort(imageOrderCmp)
}
// remove marked image from list... // remove marked image from list...
} else { } else {
@ -526,6 +549,7 @@ function setupMarks(viewer){
// do the toggle... // do the toggle...
if(state){ if(state){
MARKED.push(e) MARKED.push(e)
MARKED.sort(imageOrderCmp)
} else { } else {
MARKED.splice(MARKED.indexOf(e), 1) MARKED.splice(MARKED.indexOf(e), 1)
} }
@ -562,6 +586,7 @@ function setupMarks(viewer){
var i = MARKED.indexOf(e) var i = MARKED.indexOf(e)
if(i == -1){ if(i == -1){
MARKED.push(e) MARKED.push(e)
MARKED.sort(imageOrderCmp)
} }
}) })
}) })
@ -574,6 +599,7 @@ function setupMarks(viewer){
var i = MARKED.indexOf(e) var i = MARKED.indexOf(e)
if(i == -1){ if(i == -1){
MARKED.push(e) MARKED.push(e)
MARKED.sort(imageOrderCmp)
} else { } else {
MARKED.splice(i, 1) MARKED.splice(i, 1)
} }

View File

@ -4,6 +4,10 @@
* *
**********************************************************************/ **********************************************************************/
// Tag index
//
// This can be constructed from tags in IMAGES with buildTagsFromImages(..)
//
// format: // format:
// { // {
// tag: [ gid, ... ], // tag: [ gid, ... ],
@ -314,5 +318,6 @@ function setupTags(viewer){
SETUP_BINDINGS.push(setupTags) SETUP_BINDINGS.push(setupTags)
/********************************************************************** /**********************************************************************
* vim:set ts=4 sw=4 : */ * vim:set ts=4 sw=4 : */