From 1adf3d60b30b1a7d07b2cf07fa9a1c5fad873726 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Mon, 13 Jan 2014 02:18:32 +0400 Subject: [PATCH] now date sorting (dialog) falls back to file sequence and then file name when the earlier is equal + added cmp chaining... Signed-off-by: Alex A. Naanou --- buildcache.py | 8 ++++++-- ui/sort.js | 28 ++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/buildcache.py b/buildcache.py index 9226bf1d..943cfd26 100755 --- a/buildcache.py +++ b/buildcache.py @@ -2,7 +2,7 @@ #======================================================================= __version__ = '''0.0.01''' -__sub_version__ = '''20140102083502''' +__sub_version__ = '''20140112165326''' __copyright__ = '''(c) Alex A. Naanou 2011''' @@ -527,6 +527,7 @@ def build_images(path, config=CONFIG, gid_generator=hash_gid, dry_run=False, ver if orientation not in range(0, 9): orientation = 0 + p = pathjoin(path, name) img = { 'id': gid_generator(source_path), 'name': name, @@ -556,7 +557,10 @@ def build_images(path, config=CONFIG, gid_generator=hash_gid, dry_run=False, ver 8: None, }[orientation], 'path': getpath(path, source_path, absolute_path), - 'ctime': os.path.getctime(pathjoin(path, name)), + 'ctime': min( + # to compensate for touch updating mtime by default... + os.path.getmtime(p), + os.path.getctime(p)), 'preview': {}, } diff --git a/ui/sort.js b/ui/sort.js index 932ba32c..1e495bfd 100755 --- a/ui/sort.js +++ b/ui/sort.js @@ -159,6 +159,26 @@ function imageXPStyleFileNameCmp(a, b, get, data){ } +function chainCmp(a, b, cmp_chain, get, data){ + var res + for(var i=0; i < cmp_chain.length; i++){ + res = cmp_chain[i](a, b, get, data) + if(res != 0){ + return res + } + } + return res +} + + +function imageDateOrSeqOrNameCmp(a, b, get, data){ + return chainCmp(a, b, [ + imageDateCmp, + imageSeqOrNameCmp + ], get, data) +} + + // Get list of gids sorted by proximity to current gid // // NOTE: the distance used is the actual 2D distance... @@ -207,6 +227,9 @@ function sortImages(cmp, reverse){ function sortImagesByDate(reverse){ return sortImages(imageDateCmp, reverse) } +function sortImagesByDateOrSeqOrName(reverse){ + return sortImages(imageDateOrSeqOrNameCmp, reverse) +} function sortImagesByFileName(reverse){ return sortImages(imageNameCmp, reverse) } @@ -390,7 +413,7 @@ function sortImagesDialog(){ cfg = {} cfg[alg] = [ - 'Date', + 'Date | this will fall back to file sequence and file name.', 'Sequence number', 'Sequence number with overflow', 'File name' @@ -406,7 +429,8 @@ function sortImagesDialog(){ res = res[alg] if(/Date/i.test(res)){ - var method = sortImagesByDate + //var method = sortImagesByDate + var method = sortImagesByDateOrSeqOrName } else if(/File name/i.test(res)){ var method = sortImagesByFileNameXPStyle