shifting marked up/down no works + added undo...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2017-03-29 18:55:02 +03:00
parent ed68854c80
commit 45515c2e34

View File

@ -110,17 +110,47 @@ function makeTagTogglerAction(tag){
// - 'down' // - 'down'
var shiftMarked = function(direction){ var shiftMarked = function(direction){
return function(ribbon){ return function(ribbon){
var that = this
var marked = this.markedInRibbon(ribbon) var marked = this.markedInRibbon(ribbon)
var next
this['shiftImage'+ direction.capitalize()](marked) // need to shift focus...
if(marked.indexOf(this.current) >= 0){
var d = this.direction == 'right' ? 'next' : 'prev'
var getNext = function(direction){
var next = that.data.getImage(direction)
while(next != null && marked.indexOf(next) >= 0){
next = that.data.getImage(next, direction)
}
return next
}
next = getNext(d)
|| getNext(d == 'next' ? 'prev' : 'next')
next != null
&& this.data.focusImage(next)
}
// shift the image...
this.data['shiftImage'+ direction.capitalize()](marked)
// obey the shiftImage protocol... // obey the shiftImage protocol...
// XXX should this be in handlers???
this.shiftImage.apply(this, marked) this.shiftImage.apply(this, marked)
} }
} }
// NOTE: this is specific to shiftMarkedUp/shiftMarkedDown...
var undoShift = function(undo){
return function(a){
this[undo](this.data.getRibbon(
undo == 'shiftMarkedUp' ? 'next' : 'prev',
a.args.length == 0 ? a.current : a.args[0])) }}
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// XXX .toggleMarkBlock(..) not done yet... // XXX .toggleMarkBlock(..) not done yet...
@ -192,9 +222,12 @@ var ImageMarkActions = actions.Actions({
cropMarked: ['Mark|Crop/Crop $marked images', cropMarked: ['Mark|Crop/Crop $marked images',
function(flatten){ this.cropTagged('selected', 'any', flatten) }], function(flatten){ this.cropTagged('selected', 'any', flatten) }],
// XXX add undo...
shiftMarkedUp: ['Mark|Ribbon/Shift marked up', shiftMarkedUp: ['Mark|Ribbon/Shift marked up',
{undo: undoShift('shiftMarkedDown')},
shiftMarked('up')], shiftMarked('up')],
shiftMarkedDown: ['Mark|Ribbon/Shift marked down', shiftMarkedDown: ['Mark|Ribbon/Shift marked down',
{undo: undoShift('shiftMarkedUp')},
shiftMarked('down')], shiftMarked('down')],
}) })
@ -217,7 +250,6 @@ module.ImageMarks = core.ImageGridFeatures.Feature({
actions: ImageMarkActions, actions: ImageMarkActions,
}) })
var ImageMarksUI = var ImageMarksUI =
module.ImageMarksUI = core.ImageGridFeatures.Feature({ module.ImageMarksUI = core.ImageGridFeatures.Feature({
title: '', title: '',
@ -226,43 +258,17 @@ module.ImageMarksUI = core.ImageGridFeatures.Feature({
tag: 'ui-image-marks', tag: 'ui-image-marks',
depends: [ depends: [
'ui' 'ui',
'image-marks',
], ],
handlers: [ handlers: [
// XXX is a full reload a good thing here???
[[ [[
'shiftMarkedUp.pre', 'shiftMarkedUp',
'shiftMarkedDown.pre', 'shiftMarkedDown',
], ],
function(ribbon){ function(ribbon){ this.reload(true) }],
var that = this
var marked = this.markedInRibbon(ribbon)
// need to shift focus...
// XXX this still results in odd alignment problems in some cases...
if(marked.indexOf(this.current) >= 0){
var direction = this.direction == 'right' ? 'next' : 'prev'
var getNext = function(direction){
var next = that.data.getImage(direction)
while(next != null && marked.indexOf(next) >= 0){
next = that.data.getImage(next, direction)
}
return next
}
var next = getNext(direction)
|| getNext(direction == 'next' ? 'prev' : 'next')
var l = this.ribbons.getRibbonLocator()
next != null
&& this.ribbons.preventTransitions(l)
&& this.focusImage(next)
&& this.ribbons.restoreTransitions(l)
}
return ui.updateImagePosition(this, marked)
}],
// XXX is this the right way to go??? // XXX is this the right way to go???
['updateImage', function(_, gid, img){ ['updateImage', function(_, gid, img){
@ -322,10 +328,29 @@ module.ImageBookmarks = core.ImageGridFeatures.Feature({
tag: 'image-bookmarks', tag: 'image-bookmarks',
depends: ['base'], depends: [
'base'
],
suggested: [
'ui-image-bookmarks',
],
actions: ImageBookmarkActions, actions: ImageBookmarkActions,
})
var ImageBookmarksUI =
module.ImageBookmarksUI = core.ImageGridFeatures.Feature({
title: '',
doc: '',
tag: 'ui-image-bookmarks',
depends: [
'ui',
'image-bookmarks',
],
handlers: [ handlers: [
// XXX is this the right way to go??? // XXX is this the right way to go???
['updateImage', function(_, gid, img){ ['updateImage', function(_, gid, img){
@ -342,7 +367,6 @@ module.ImageBookmarks = core.ImageGridFeatures.Feature({
}) })
//--------------------------------------------------------------------- //---------------------------------------------------------------------
core.ImageGridFeatures.Feature('marks', [ core.ImageGridFeatures.Feature('marks', [