started preparing actions for browse widget integration...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2015-09-05 16:07:35 +03:00
parent 65eb5b4ac4
commit 1081699919
2 changed files with 71 additions and 67 deletions

View File

@ -52,6 +52,10 @@ var viewer = require('viewer')
//var promise = require('promise') //var promise = require('promise')
// widgets...
var browse = require('lib/widget/browse')
/*********************************************************************/ /*********************************************************************/

View File

@ -257,8 +257,8 @@ actions.Actions({
// adding new items to the resulting structure... // adding new items to the resulting structure...
// XXX is this the correct way to go??? // XXX is this the correct way to go???
// ...can we save simple attribute values??? // ...can we save simple attribute values???
json: ['Dump state as JSOM object', json: ['Serialize/Dump state as JSOM object',
'This will collect JSON data from every afailable attribute ' 'This will collect JSON data from every available attribute '
+'supporting the .dumpJSON() method.', +'supporting the .dumpJSON() method.',
function(){ function(){
var res = {} var res = {}
@ -304,19 +304,19 @@ actions.Actions({
// shorthands... // shorthands...
// XXX do we reset direction on these??? // XXX do we reset direction on these???
firstImage: ['Focus first image in current ribbon', firstImage: ['Navigate/Focus first image in current ribbon',
function(all){ this.focusImage(all == null ? 'first' : 0) }], function(all){ this.focusImage(all == null ? 'first' : 0) }],
lastImage: ['Focus last image in current ribbon', lastImage: ['Navigate/Focus last image in current ribbon',
function(all){ this.focusImage(all == null ? 'last' : -1) }], function(all){ this.focusImage(all == null ? 'last' : -1) }],
// XXX these break if image at first/last position are not loaded (crop, group, ...) // XXX these break if image at first/last position are not loaded (crop, group, ...)
// XXX do we actually need these??? // XXX do we actually need these???
firstGlobalImage: ['Get first globally image', firstGlobalImage: ['Navigate/Get first globally image',
function(){ this.firstImage(true) }], function(){ this.firstImage(true) }],
lastGlobalImage: ['Get last globally image', lastGlobalImage: ['Navigate/Get last globally image',
function(){ this.lastImage(true) }], function(){ this.lastImage(true) }],
// XXX skip unloaded images... // XXX skip unloaded images...
prevImage: ['Focus previous image', prevImage: ['Navigate/Focus previous image',
function(a){ function(a){
// keep track of traverse direction... // keep track of traverse direction...
this.direction = 'left' this.direction = 'left'
@ -331,7 +331,7 @@ actions.Actions({
this.focusImage('prev', a) this.focusImage('prev', a)
} }
}], }],
nextImage: ['Focus next image', nextImage: ['Navigate/Focus next image',
function(a){ function(a){
// keep track of traverse direction... // keep track of traverse direction...
this.direction = 'right' this.direction = 'right'
@ -348,24 +348,24 @@ actions.Actions({
}], }],
// XXX skip unloaded images... // XXX skip unloaded images...
prevImageInOrder: ['Focus previous image in order', prevImageInOrder: ['Navigate/Focus previous image in order',
function(){ this.prevImage(this.data.getImages(this.data.order)) }], function(){ this.prevImage(this.data.getImages(this.data.order)) }],
nextImageInOrder: ['Focus next image in order', nextImageInOrder: ['Navigate/Focus next image in order',
function(){ this.nextImage(this.data.getImages(this.data.order)) }], function(){ this.nextImage(this.data.getImages(this.data.order)) }],
// XXX should these be here??? // XXX should these be here???
prevTagged: ['Focus previous image tagged with tag', prevTagged: ['Navigate/Focus previous image tagged with tag',
makeTagWalker('prev')], makeTagWalker('prev')],
nextTagged: ['Focus next image tagged with tag', nextTagged: ['Navigate/Focus next image tagged with tag',
makeTagWalker('next')], makeTagWalker('next')],
firstRibbon: ['Focus previous ribbon', firstRibbon: ['Navigate/Focus previous ribbon',
function(){ this.focusRibbon('first') }], function(){ this.focusRibbon('first') }],
lastRibbon: ['Focus next ribbon', lastRibbon: ['Navigate/Focus next ribbon',
function(){ this.focusRibbon('last') }], function(){ this.focusRibbon('last') }],
prevRibbon: ['Focus previous ribbon', prevRibbon: ['Navigate/Focus previous ribbon',
function(){ this.focusRibbon('before') }], function(){ this.focusRibbon('before') }],
nextRibbon: ['Focus next ribbon', nextRibbon: ['Navigate/Focus next ribbon',
function(){ this.focusRibbon('after') }], function(){ this.focusRibbon('after') }],
@ -379,7 +379,7 @@ actions.Actions({
// XXX // XXX
}], }],
shiftImageUp: ['Shift image up', shiftImageUp: ['Edit/Shift image up',
'If implicitly shifting current image (i.e. no arguments), focus ' 'If implicitly shifting current image (i.e. no arguments), focus '
+'will shift to the next or previous image in the current ' +'will shift to the next or previous image in the current '
+'ribbon depending on current direction.', +'ribbon depending on current direction.',
@ -402,7 +402,7 @@ actions.Actions({
this.data.shiftImageUp(target) this.data.shiftImageUp(target)
} }
}], }],
shiftImageDown: ['Shift image down', shiftImageDown: ['Edit/Shift image down',
'If implicitly shifting current image (i.e. no arguments), focus ' 'If implicitly shifting current image (i.e. no arguments), focus '
+'will shift to the next or previous image in the current ' +'will shift to the next or previous image in the current '
+'ribbon depending on current direction.', +'ribbon depending on current direction.',
@ -425,17 +425,17 @@ actions.Actions({
this.data.shiftImageDown(target) this.data.shiftImageDown(target)
} }
}], }],
shiftImageUpNewRibbon: ['Shift image up to a new empty ribbon', shiftImageUpNewRibbon: ['Edit/Shift image up to a new empty ribbon',
function(target){ function(target){
this.data.newRibbon(target) this.data.newRibbon(target)
this.shiftImageUp(target) this.shiftImageUp(target)
}], }],
shiftImageDownNewRibbon: ['Shift image down to a new empty ribbon', shiftImageDownNewRibbon: ['Edit/Shift image down to a new empty ribbon',
function(target){ function(target){
this.data.newRibbon(target, 'below') this.data.newRibbon(target, 'below')
this.shiftImageDown(target) this.shiftImageDown(target)
}], }],
shiftImageLeft: ['Shift image left', shiftImageLeft: ['Edit/Shift image left',
function(target){ function(target){
if(target == null){ if(target == null){
this.direction = 'left' this.direction = 'left'
@ -443,7 +443,7 @@ actions.Actions({
this.data.shiftImageLeft(target) this.data.shiftImageLeft(target)
this.focusImage() this.focusImage()
}], }],
shiftImageRight: ['Shift image right', shiftImageRight: ['Edit/Shift image right',
function(target){ function(target){
if(target == null){ if(target == null){
this.direction = 'right' this.direction = 'right'
@ -452,13 +452,13 @@ actions.Actions({
this.focusImage() this.focusImage()
}], }],
shiftRibbonUp: ['Shift ribbon up', shiftRibbonUp: ['Edit/Shift ribbon up',
function(target){ function(target){
this.data.shiftRibbonUp(target) this.data.shiftRibbonUp(target)
// XXX is this the right way to go/??? // XXX is this the right way to go/???
this.focusImage() this.focusImage()
}], }],
shiftRibbonDown: ['Shift ribbon down', shiftRibbonDown: ['Edit/Shift ribbon down',
function(target){ function(target){
this.data.shiftRibbonDown(target) this.data.shiftRibbonDown(target)
// XXX is this the right way to go/??? // XXX is this the right way to go/???
@ -466,13 +466,13 @@ actions.Actions({
}], }],
// these operate on the current image... // these operate on the current image...
travelImageUp: ['Travel with the current image up (Shift up and keep focus)', travelImageUp: ['Edit/Travel with the current image up (Shift up and keep focus)',
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: ['Travel with the current image down (Shift down and keep focus)', travelImageDown: ['Edit/Travel with the current image down (Shift down and keep focus)',
function(target){ function(target){
target = target || this.current target = target || this.current
this.shiftImageDown(target) this.shiftImageDown(target)
@ -480,9 +480,9 @@ actions.Actions({
}], }],
reverseImages: ['Reverse image order', reverseImages: ['Edit/Reverse image order',
function(){ this.data.reverseImages() }], function(){ this.data.reverseImages() }],
reverseRibbons: ['Reverse ribbon order', reverseRibbons: ['Edit/Reverse ribbon order',
function(){ this.data.reverseRibbons() }], function(){ this.data.reverseRibbons() }],
// XXX align to ribbon... // XXX align to ribbon...
@ -623,7 +623,7 @@ actions.Actions({
// crop... // crop...
// //
crop: [ crop: ['Crop/Crop image list',
function(list, flatten){ function(list, flatten){
list = list || this.data.order list = list || this.data.order
if(this.crop_stack == null){ if(this.crop_stack == null){
@ -638,7 +638,7 @@ actions.Actions({
this.data = this.data.crop(list, flatten) this.data = this.data.crop(list, flatten)
} }
}], }],
uncrop: ['Uncrop ribbons', uncrop: ['Crop/Uncrop ribbons',
function(level, restore_current, keep_crop_order){ function(level, restore_current, keep_crop_order){
level = level || 1 level = level || 1
@ -675,17 +675,17 @@ actions.Actions({
delete this.crop_stack delete this.crop_stack
} }
}], }],
uncropAll: ['', uncropAll: ['Crop/Uncrop all',
function(restore_current){ this.uncrop('all', restore_current) }], function(restore_current){ this.uncrop('all', restore_current) }],
// XXX see if we need to do this on this level?? // XXX see if we need to do this on this level??
// ...might be a good idea to do this in data... // ...might be a good idea to do this in data...
uncropAndKeepOrder: ['Uncrop and keep crop image order', uncropAndKeepOrder: ['Crop/Uncrop and keep crop image order',
function(level, restore_current){ this.uncrop(level, restore_current, true) }], function(level, restore_current){ this.uncrop(level, restore_current, true) }],
// XXX same as uncrop but will also try and merge changes... // XXX same as uncrop but will also try and merge changes...
// - the order is simple and already done above... // - the order is simple and already done above...
// - I think that levels should be relative to images, the // - I think that levels should be relative to images, the
// only problem here is how to deal with new ribbons... // only problem here is how to deal with new ribbons...
mergeCrop: ['', mergeCrop: ['Crop/Merge crop',
function(){ function(){
// XXX // XXX
}], }],
@ -693,7 +693,7 @@ actions.Actions({
// XXX save a crop (catalog)... // XXX save a crop (catalog)...
// XXX // XXX
cropRibbon: ['Crop current ribbon', cropRibbon: ['Crop/Crop current ribbon',
function(ribbon, flatten){ function(ribbon, flatten){
if(typeof(ribbon) == typeof(true)){ if(typeof(ribbon) == typeof(true)){
flatten = ribbon flatten = ribbon
@ -702,7 +702,7 @@ actions.Actions({
ribbon = ribbon || 'current' ribbon = ribbon || 'current'
this.crop(this.data.getImages(ribbon), flatten) this.crop(this.data.getImages(ribbon), flatten)
}], }],
cropRibbonAndAbove: ['Crop current and above ribbons', cropRibbonAndAbove: ['Crop/Crop current and above ribbons',
function(ribbon, flatten){ function(ribbon, flatten){
if(typeof(ribbon) == typeof(true)){ if(typeof(ribbon) == typeof(true)){
flatten = ribbon flatten = ribbon
@ -725,7 +725,7 @@ actions.Actions({
}], }],
// XXX should this be here??? // XXX should this be here???
cropTagged: ['', cropTagged: ['Crop/Crop tagged images',
function(tags, mode, flatten){ function(tags, mode, flatten){
var selector = mode == 'any' ? 'getTaggedByAny' : 'getTaggedByAll' var selector = mode == 'any' ? 'getTaggedByAny' : 'getTaggedByAll'
this.crop(this.data[selector](tags), flatten) this.crop(this.data[selector](tags), flatten)
@ -734,15 +734,15 @@ actions.Actions({
// grouping... // grouping...
// XXX need to tell .images about this... // XXX need to tell .images about this...
group: ['Group images', group: ['Group/Group images',
function(gids, group){ this.data.group(gids, group) }], function(gids, group){ this.data.group(gids, group) }],
ungroup: ['Ungroup images', ungroup: ['Group/Ungroup images',
function(gids, group){ this.data.ungroup(gids, group) }], function(gids, group){ this.data.ungroup(gids, group) }],
// direction can be: // direction can be:
// 'next' // 'next'
// 'prev' // 'prev'
groupTo: ['', groupTo: ['Group/Group to',
function(target, direction){ function(target, direction){
target = this.data.getImage(target) target = this.data.getImage(target)
var other = this.data.getImage(target, direction == 'next' ? 1 : -1) var other = this.data.getImage(target, direction == 'next' ? 1 : -1)
@ -762,21 +762,21 @@ actions.Actions({
} }
}], }],
// shorthands to .groupTo(..) // shorthands to .groupTo(..)
groupBack: ['Group target image with the image/group before it', groupBack: ['Group/Group target image with the image/group before it',
function(target){ this.groupTo(target, 'prev') }], function(target){ this.groupTo(target, 'prev') }],
groupForward: ['Group target image with the image/group after it', groupForward: ['Group/Group target image with the image/group after it',
function(target){ this.groupTo(target, 'next') }], function(target){ this.groupTo(target, 'next') }],
// NOTE: this will only group loaded images... // NOTE: this will only group loaded images...
groupMarked: ['Group loaded marked images', groupMarked: ['Group/Group loaded marked images',
function(){ this.group(this.data.getImages(this.data.getTaggedByAny('marked'))) }], function(){ this.group(this.data.getImages(this.data.getTaggedByAny('marked'))) }],
expandGroup: ['', expandGroup: ['Group/Expand group',
function(target){ this.data.expandGroup(target || this.current) }], function(target){ this.data.expandGroup(target || this.current) }],
collapseGroup: ['', collapseGroup: ['Group/Collapse group',
function(target){ this.data.collapseGroup(target || this.current) }], function(target){ this.data.collapseGroup(target || this.current) }],
cropGroup: ['', cropGroup: ['Crop/Crop group',
function(target){ this.crop(this.data.cropGroup(target || this.current)) }], function(target){ this.crop(this.data.cropGroup(target || this.current)) }],
}) })
@ -933,7 +933,7 @@ actions.Actions(Client, {
// General UI stuff... // General UI stuff...
// NOTE: this is applicable to all uses... // NOTE: this is applicable to all uses...
toggleTheme: ['Toggle viewer theme', toggleTheme: ['Interface/Toggle viewer theme',
CSSClassToggler( CSSClassToggler(
function(){ return this.ribbons.viewer }, function(){ return this.ribbons.viewer },
[ [
@ -941,7 +941,7 @@ actions.Actions(Client, {
'dark', 'dark',
'light' 'light'
]) ], ]) ],
setEmptyMsg: ['Set message to be displayed when nothing is loaded.', setEmptyMsg: ['Interface/Set message to be displayed when nothing is loaded.',
function(msg, help){ this.ribbons.setEmptyMsg(msg, help) }], function(msg, help){ this.ribbons.setEmptyMsg(msg, help) }],
@ -1095,7 +1095,7 @@ actions.Actions(Client, {
// NOTE: these prioritize whole images, i.e. each image will at least // NOTE: these prioritize whole images, i.e. each image will at least
// once be fully shown. // once be fully shown.
prevScreen: ['Focus previous image one screen width away', prevScreen: ['Navigate/Focus previous image one screen width away',
function(){ function(){
// NOTE: the 0.2 is added to compensate for alignment/scaling // NOTE: the 0.2 is added to compensate for alignment/scaling
// errors -- 2.99 images wide counts as 3 while 2.5 as 2. // errors -- 2.99 images wide counts as 3 while 2.5 as 2.
@ -1103,7 +1103,7 @@ actions.Actions(Client, {
w += (w % 2) - 1 w += (w % 2) - 1
this.prevImage(w) this.prevImage(w)
}], }],
nextScreen: ['Focus next image one screen width away', nextScreen: ['Navigate/Focus next image one screen width away',
function(){ function(){
var w = Math.floor(this.ribbons.getScreenWidthImages() + 0.2) var w = Math.floor(this.ribbons.getScreenWidthImages() + 0.2)
w += (w % 2) - 1 w += (w % 2) - 1
@ -1114,7 +1114,7 @@ actions.Actions(Client, {
// //
// Zooming is done by multiplying the current scale by config['zoom-step'] // Zooming is done by multiplying the current scale by config['zoom-step']
// and rounding to nearest discrete number of images to fit on screen. // and rounding to nearest discrete number of images to fit on screen.
zoomIn: ['Zoom in', zoomIn: ['Zoom/Zoom in',
function(){ function(){
this.ribbons.setOrigin() this.ribbons.setOrigin()
@ -1125,7 +1125,7 @@ actions.Actions(Client, {
this.fitImage(n <= 0 ? 1 : n) this.fitImage(n <= 0 ? 1 : n)
}], }],
zoomOut: ['Zoom out', zoomOut: ['Zoom/Zoom out',
function(){ function(){
this.ribbons.setOrigin() this.ribbons.setOrigin()
@ -1138,7 +1138,7 @@ actions.Actions(Client, {
this.fitImage(n > max ? max : n) this.fitImage(n > max ? max : n)
}], }],
fitOrig: ['Fit to original scale', fitOrig: ['Zoom/Fit to original scale',
function(){ function(){
this.ribbons.setScale(1) this.ribbons.setScale(1)
this.refresh() this.refresh()
@ -1148,7 +1148,7 @@ actions.Actions(Client, {
// NOTE: this will add .config['fit-overflow'] to odd counts if no // NOTE: this will add .config['fit-overflow'] to odd counts if no
// overflow if passed. // overflow if passed.
// ...this is done to add ability to control scroll indication. // ...this is done to add ability to control scroll indication.
fitImage: ['Fit image', fitImage: ['Zoom/Fit image',
function(count, overflow){ function(count, overflow){
if(count != null){ if(count != null){
overflow = overflow == false ? 0 : overflow overflow = overflow == false ? 0 : overflow
@ -1167,15 +1167,15 @@ actions.Actions(Client, {
// XXX the question with these is how to make these relatively // XXX the question with these is how to make these relatively
// similar across platforms... // similar across platforms...
// ...for this we need to get display dpi... // ...for this we need to get display dpi...
fitSmall: ['Show small image', fitSmall: ['Zoom/Show small image',
function(){ }], function(){ }],
fitNormal: ['Show normal image', fitNormal: ['Zoom/Show normal image',
function(){ }], function(){ }],
fitScreen: ['Fit image to screen', fitScreen: ['Zoom/Fit image to screen',
function(){ }], function(){ }],
fitRibbon: ['Fit ribbon vertically', fitRibbon: ['Zoom/Fit ribbon vertically',
function(count){ function(count){
this.ribbons.fitRibbon(count) this.ribbons.fitRibbon(count)
this.refresh() this.refresh()
@ -1409,7 +1409,7 @@ var PartialRibbonsActions = actions.Actions({
// - we are less than screen width from the edge // - we are less than screen width from the edge
// - threshold is set to 0 // - threshold is set to 0
// XXX this is not signature compatible with data.updateRibbon(..) // XXX this is not signature compatible with data.updateRibbon(..)
updateRibbon: ['Update partial ribbon size', updateRibbon: ['Interface/Update partial ribbon size',
function(target, w, size, threshold){ function(target, w, size, threshold){
target = target instanceof jQuery target = target instanceof jQuery
? this.ribbons.getElemGID(target) ? this.ribbons.getElemGID(target)
@ -1487,7 +1487,7 @@ var PartialRibbonsActions = actions.Actions({
} }
}], }],
// XXX do we handle off-screen ribbons here??? // XXX do we handle off-screen ribbons here???
resizeRibbon: ['Resize ribbon to n images', resizeRibbon: ['Interface/Resize ribbon to n images',
function(target, size){ function(target, size){
size = size size = size
|| (this.config['ribbon-size-screens'] * this.screenwidth) || (this.config['ribbon-size-screens'] * this.screenwidth)
@ -1784,7 +1784,7 @@ module.ShiftAnimation = features.Feature(ImageGridFeatures, {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
var BoundsIndicatorsActions = actions.Actions({ var BoundsIndicatorsActions = actions.Actions({
flashIndicator: ['Flash an indicator', flashIndicator: ['Interface/Flash an indicator',
function(direction){ function(direction){
if(this.ribbons.getRibbonSet().length == 0){ if(this.ribbons.getRibbonSet().length == 0){
return return
@ -1906,7 +1906,7 @@ module.BoundsIndicators = features.Feature(ImageGridFeatures, {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
var CurrentImageIndicatorActions = actions.Actions({ var CurrentImageIndicatorActions = actions.Actions({
updateCurrentImageIndicator: ['Update current image indicator', updateCurrentImageIndicator: ['Interface/Update current image indicator',
function(target, update_border){ function(target, update_border){
var ribbon_set = this.ribbons.getRibbonSet() var ribbon_set = this.ribbons.getRibbonSet()
@ -2346,10 +2346,10 @@ var ImageMarkActions = actions.Actions({
// Invert marks on current ribbon // Invert marks on current ribbon
// .toggleMark('ribbon') // .toggleMark('ribbon')
// //
toggleMark: ['Toggle image mark', toggleMark: ['Mark/Toggle image mark',
makeTagTogglerAction('selected')], makeTagTogglerAction('selected')],
// XXX // XXX
toggleMarkBlock: ['Toggle block marks', toggleMarkBlock: ['Mark/Toggle block marks',
'A block is a set of adjacent images either marked on unmarked ' 'A block is a set of adjacent images either marked on unmarked '
+'in the same way', +'in the same way',
function(target){ function(target){
@ -2359,7 +2359,7 @@ var ImageMarkActions = actions.Actions({
// XXX // XXX
}], }],
markTagged: ['Mark images by tags', markTagged: ['Mark/Mark images by tags',
function(tags, mode){ function(tags, mode){
var selector = mode == 'any' ? 'getTaggedByAny' : 'getTaggedByAll' var selector = mode == 'any' ? 'getTaggedByAny' : 'getTaggedByAll'
@ -2370,12 +2370,12 @@ var ImageMarkActions = actions.Actions({
}], }],
// XXX do we need first/last marked??? // XXX do we need first/last marked???
prevMarked: ['Focus previous marked image', prevMarked: ['Mark|Navigate/Focus previous marked image',
function(mode){ this.prevTagged('selected', mode) }], function(mode){ this.prevTagged('selected', mode) }],
nextMarked: ['Focus next marked image', nextMarked: ['Mark|Navigate/Focus next marked image',
function(mode){ this.nextTagged('selected', mode) }], function(mode){ this.nextTagged('selected', mode) }],
cropMarked: ['Crop marked images', cropMarked: ['Mark|Crop/Crop marked images',
function(flatten){ this.cropTagged('selected', 'any', flatten) }], function(flatten){ this.cropTagged('selected', 'any', flatten) }],
}) })