cleanup and refactoring...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2017-09-08 21:32:52 +03:00
parent 4a77371662
commit 2a22cd975c
3 changed files with 35 additions and 88 deletions

View File

@ -826,13 +826,13 @@ actions.Actions({
// corresponding normal shift operations... // corresponding normal shift operations...
// XXX .undoLast(..) on these for some reason skips... // XXX .undoLast(..) on these for some reason skips...
// ...e.g. two shifts are undone with three calls to .undoLast()... // ...e.g. two shifts are undone with three calls to .undoLast()...
shiftImageUpNewRibbon: ['Edit|Ribbon/Shift image up to a new empty ribbon', shiftImageUpNewRibbon: ['Edit|Image/Shift image up to a new empty ribbon',
{journal: true}, {journal: true},
function(target){ function(target){
this.data.newRibbon(target) this.data.newRibbon(target)
this.shiftImageUp(target) this.shiftImageUp(target)
}], }],
shiftImageDownNewRibbon: ['Edit|Ribbon/Shift image down to a new empty ribbon', shiftImageDownNewRibbon: ['Edit|Image/Shift image down to a new empty ribbon',
{journal: true}, {journal: true},
function(target){ function(target){
this.data.newRibbon(target, 'below') this.data.newRibbon(target, 'below')
@ -877,14 +877,14 @@ actions.Actions({
}], }],
// these operate on the current image... // these operate on the current image...
travelImageUp: ['Edit/Travel with the current image up (Shift up and keep focus)', travelImageUp: ['Edit|Image/Travel with the current image up (Shift up and keep focus)',
{undo: undoShift('travelImageDown')}, {undo: undoShift('travelImageDown')},
function(target){ function(target){
target = target || this.current target = target || this.current
this.shiftImageUp(target) this.shiftImageUp(target)
this.focusImage(target) this.focusImage(target)
}], }],
travelImageDown: ['Edit/Travel with the current image down (Shift down and keep focus)', travelImageDown: ['Edit|Image/Travel with the current image down (Shift down and keep focus)',
{undo: undoShift('travelImageUp')}, {undo: undoShift('travelImageUp')},
function(target){ function(target){
target = target || this.current target = target || this.current

View File

@ -338,22 +338,22 @@ var ImageMarkEditActions = actions.Actions({
}) })
}], }],
shiftMarkedUp: ['Mark|Ribbon/Shift marked $up', shiftMarkedUp: ['Mark/Shift marked $up',
{undo: undoShift('shiftMarkedDown'), {undo: undoShift('shiftMarkedDown'),
browseMode: 'cropMarked'}, browseMode: 'cropMarked'},
shiftMarked('up')], shiftMarked('up')],
shiftMarkedDown: ['Mark|Ribbon/Shift marked $down', shiftMarkedDown: ['Mark/Shift marked $down',
{undo: undoShift('shiftMarkedUp'), {undo: undoShift('shiftMarkedUp'),
browseMode: 'cropMarked'}, browseMode: 'cropMarked'},
shiftMarked('down')], shiftMarked('down')],
// XXX undo... // XXX undo...
shiftMarkedAfter: ['Mark|Ribbon|Image/Shift marked after', shiftMarkedAfter: ['Mark|Image/Shift marked after',
{browseMode: 'cropMarked'}, {browseMode: 'cropMarked'},
function(target){ function(target){
this.shiftImageTo(this.marked, target || 'current', 'after') }], this.shiftImageTo(this.marked, target || 'current', 'after') }],
// XXX undo... // XXX undo...
shiftMarkedBefore: ['Mark|Ribbon|Image/Shift marked before', shiftMarkedBefore: ['Mark|Image/Shift marked before',
{browseMode: 'cropMarked'}, {browseMode: 'cropMarked'},
function(target){ function(target){
this.shiftImageTo(this.marked, target || 'current', 'before') }], this.shiftImageTo(this.marked, target || 'current', 'before') }],

View File

@ -1576,70 +1576,6 @@ var DataPrototype = {
this.ribbon_order.reverse() }, this.ribbon_order.reverse() },
// Gather gids into a connected section...
//
// The section is positioned relative to a reference gid, which also
// determines the ribbon.
//
// Gather images relative to current image
// .gatherImages(images)
// .gatherImages(images, 'current')
// -> data
//
// Gather images relative to image/ribbon
// .gatherImages(images, image|ribbon)
// -> data
//
// Gather images relative to first/last image in given images
// .gatherImages(images, 'first')
// .gatherImages(images, 'last')
// -> data
//
// Gather images relative to image/ribbon and place them strictly
// after (default) or before it...
// .gatherImages(images, 'auto')
// .gatherImages(images, 'after')
// .gatherImages(images, 'before')
// .gatherImages(images, image|ribbon, 'auto')
// .gatherImages(images, image|ribbon, 'after')
// .gatherImages(images, image|ribbon, 'before')
// -> data
//
// Gather images only in one explicit dimension...
// .gatherImages(.., 'horizontal')
// .gatherImages(.., 'vertical')
// -> data
//
// NOTE: if mode is 'vertical' then place is ignored...
// NOTE: this is a different interface to .placeImage(..)
gatherImages: function(images, reference, place, mode){
var that = this
var args = [].slice.call(arguments)
var modes = /vertical|horizontal|both/
var placements = /before|after|auto/
// get trailing args first, if given...
mode = modes.test(args.slice(-1)[0]) ? args.pop() : mode
place = placements.test(args.slice(-1)[0]) ? args.pop() : place
place = place || 'after'
reference = args[1] || 'current'
reference = (reference == 'first' || reference == 'last') ?
this.makeSparseImages(images).compact()[reference == 'first' ? 0 : images.length-1]
: this.getImage(reference)
return this.placeImage(
images,
mode == 'horizontal' ?
'keep' :
this.getRibbon(reference),
mode == 'vertical' ?
'keep'
: reference,
place)
},
// Place image at position... // Place image at position...
// //
// Place images at order into ribbon... // Place images at order into ribbon...
@ -1742,15 +1678,24 @@ var DataPrototype = {
// Shift image... // Shift image...
// //
// Shift image to target position: // Shift image(s) to after target position:
// .shiftImage(from, gid|order|ribbon) // .shiftImage(from, gid|order|ribbon)
// .shiftImage(from, gid|order|ribbon, 'before')
// .shiftImage(from, gid|order|ribbon, 'after') // .shiftImage(from, gid|order|ribbon, 'after')
// -> data
// //
// Shift image by offset: // Shift image(s) to before target position:
// .shiftImage(from, gid|order|ribbon, 'before')
// -> this
//
// Shift vertically only -- keep image order...
// .shiftImage(from, gid|order|ribbon, 'vertical')
//
// Shift horizontally only -- keep image(s) in same ribbons...
// .shiftImage(from, gid|order|ribbon, 'horizontal')
//
//
// Shift image(s) by offset:
// .shiftImage(from, offset, 'offset') // .shiftImage(from, offset, 'offset')
// -> data // -> this
// //
// //
// order is expected to be ribbon order. // order is expected to be ribbon order.
@ -1765,29 +1710,27 @@ var DataPrototype = {
// //
// //
// NOTE: this will not create new ribbons. // NOTE: this will not create new ribbons.
// NOTE: .getImage(..) defaults to 'before' thus this to defaults // NOTE: this is a different interface to .placeImage(..)
// to 'after'
// //
// XXX needs better docs... // XXX should we use .placeImage(..) instead???
shiftImage: function(from, target, mode, direction){ shiftImage: function(from, target, mode){
from = from == null || from == 'current' ? this.current : from from = from == null || from == 'current' ? this.current : from
if(from == null){ if(from == null){
return return
} }
from = from instanceof Array ? from : [from] from = from instanceof Array ? from : [from]
var place
// target is an offset... // target is an offset...
if(mode == 'offset'){ if(mode == 'offset'){
if(target > 0){ if(target > 0){
var t = this.getImage(from.slice(-1)[0], target) var t = this.getImage(from.slice(-1)[0], target)
|| this.getImage('last', from.slice(-1)[0]) || this.getImage('last', from.slice(-1)[0])
place = from.indexOf(t) >= 0 ? null : 'after' var direction = from.indexOf(t) >= 0 ? null : 'after'
} else { } else {
var t = this.getImage(from[0], target) var t = this.getImage(from[0], target)
|| this.getImage('first', from[0]) || this.getImage('first', from[0])
place = from.indexOf(t) >= 0 ? null : 'before' var direction = from.indexOf(t) >= 0 ? null : 'before'
} }
// target is ribbon index... // target is ribbon index...
@ -1795,15 +1738,19 @@ var DataPrototype = {
var t = this.getImage(this.getRibbon(target)) var t = this.getImage(this.getRibbon(target))
// in case of an empty ribbon... // in case of an empty ribbon...
|| this.getRibbon(target) || this.getRibbon(target)
place = mode || 'after' var direction = mode == 'before' || mode == 'after' ? mode : 'after'
// target is an image... // target is an image...
} else { } else {
var t = this.getImage(target) var t = this.getImage(target)
place = mode || 'after' var direction = mode == 'before' || mode == 'after' ? mode : 'after'
} }
return this.gatherImages(from, t, place, direction) return this.placeImage(
from,
mode == 'horizontal' ? 'keep' : t,
mode == 'vertical' ? 'keep' : t,
direction)
}, },
// Shorthand actions... // Shorthand actions...