From c6257a335a4a00b16e0cb470bdb6e3adb9e31d9f Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sun, 2 Jun 2013 23:57:30 +0400 Subject: [PATCH] added mark-based shifting up/down... Signed-off-by: Alex A. Naanou --- ui/data.js | 77 ++++++++++++++++++++++++++++++++++++++++++++++- ui/keybindings.js | 10 +++--- 2 files changed, 80 insertions(+), 7 deletions(-) diff --git a/ui/data.js b/ui/data.js index a2b069f8..cc03a84c 100755 --- a/ui/data.js +++ b/ui/data.js @@ -1433,7 +1433,7 @@ function sortImagesByName(reverse){ } -// shifting images... +// Ordering images... // NOTE: this a bit more complicated than simply shifting an image // left/right the DATA.order, we have to put it before or after // the prev/next image... @@ -1481,6 +1481,81 @@ function shiftImageRight(image){ } +// XXX move to marks.js + +// XXX need to account for empty ribbons... +function shiftMarkedImages(direction, mode, new_ribbon){ + mode = mode == null ? 'ribbon' : mode + var cur = getRibbonIndex() + + // ribbon only... + if(mode == 'ribbon'){ + var ribbon = DATA.ribbons[cur] + // remove all the marked images form current ribbon... + var marked = $.map(MARKED, function(e){ + var i = ribbon.indexOf(e) + if(i >= 0){ + ribbon.splice(i, 1) + return e + } + return null + }) + + // shift all marked images... + } else { + var marked = MARKED.slice() + // remove all the marked images form all the ribbons... + $.each(DATA.ribbons, function(ribbon){ + $.each(marked, function(e){ + var i = ribbon.indexOf(e) + i >= 0 ? ribbon.splice(i, 1) : null + }) + }) + } + + // if we are at the top or bottom ribbons we need to create a new + // ribbon regardless... + if((cur == 0 && direction == 'prev') + || (cur == DATA.ribbons.length-1 && direction == 'next')){ + new_ribbon = true + } + + // add marked to new ribbon... + if(new_ribbon){ + cur += direction == 'next' ? 1 : 0 + DATA.ribbons.splice(cur, 0, marked) + + // add marked to existing ribbon... + } else { + cur += direction == 'next' ? 1 : -1 + DATA.ribbons[cur] = DATA.ribbons[cur].concat(marked).sort(cmp) + } + + // remove empty ribbons... + DATA.ribbons = DATA.ribbons.filter(function(e){ return e.length > 0 ? true : false }) + + updateRibbonOrder() +} +function shiftMarkedImagesUp(mode, new_ribbon){ + return shiftMarkedImages('prev', mode, new_ribbon) +} +function shiftMarkedImagesDown(mode, new_ribbon){ + return shiftMarkedImages('next', mode, new_ribbon) +} + + +// XXX these are ribbon wise only (???) +// XXX this on first step this must pack all marked images +function horizontalShiftMarkedImages(direction){ +} +function shiftMarkedImagesLeft(){ + return shiftMarkedImages('prev') +} +function shiftMarkedImagesRight(){ + return shiftMarkedImages('next') +} + + /********************************************************************** * vim:set ts=4 sw=4 spell : */ diff --git a/ui/keybindings.js b/ui/keybindings.js index ed7d89ab..80d6fb72 100755 --- a/ui/keybindings.js +++ b/ui/keybindings.js @@ -305,11 +305,10 @@ var KEYBOARD_CONFIG = { shiftImageUpNewRibbon(null, DIRECTION) centerRibbons() }), - - // XXX alt: doc('Shift marked images up', function(){ - // XXX + toggleMarkesView('on') + shiftMarkedImagesUp() }), 'alt+shift': doc('Shift marked images up to empty ribbon', function(){ @@ -335,11 +334,10 @@ var KEYBOARD_CONFIG = { shiftImageDownNewRibbon(null, DIRECTION) centerRibbons() }), - - // XXX alt: doc('Shift marked images down', function(){ - // XXX + toggleMarkesView('on') + shiftMarkedImagesDown() }), 'alt+shift': doc('Shift marked images down to empty ribbon', function(){