lots of minor tweaks and some refactoring...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2017-11-19 01:01:44 +03:00
parent 5b4c7353ef
commit 924f88fdae
8 changed files with 695 additions and 395 deletions

View File

@ -1030,20 +1030,24 @@ actions.Actions({
} }
if(target == 'cw' || target == 'ccw'){ if(target == 'cw' || target == 'ccw'){
direction = target direction = target
target = null target = this.data.getImage()
} else {
target = this.data.getImages(target instanceof Array ? target : [target])
} }
this.images this.images
&& this.images.rotateImage(this.data.getImage(target), direction || 'cw') && this.images.rotateImage(target, direction || 'cw')
}], }],
flip: ['- Image|Edit/Flip image', flip: ['- Image|Edit/Flip image',
{journal: true}, {journal: true},
function(target, direction){ function(target, direction){
if(target == 'vertical' || target == 'horizontal'){ if(target == 'vertical' || target == 'horizontal'){
direction = target direction = target
target = null target = this.data.getImage()
} else {
target = this.data.getImages(target instanceof Array ? target : [target])
} }
this.images this.images
&& this.images.flipImage(this.data.getImage(target), direction || 'horizontal') && this.images.flipImage(target, direction || 'horizontal')
}], }],
// shorthands... // shorthands...

View File

@ -513,7 +513,7 @@ var KeyboardActions = actions.Actions({
return return
} }
var a = keyboard.parseActionCall(code) var a = keyboard.parseActionCall(code, that)
var doc = a.doc || that.getDocTitle(a.action) || null var doc = a.doc || that.getDocTitle(a.action) || null
// check if we have no doc... // check if we have no doc...
@ -667,7 +667,7 @@ var KeyboardActions = actions.Actions({
// - .no_default // - .no_default
// - .stop_propagation // - .stop_propagation
var normalizeHandler = function(action){ var normalizeHandler = function(action){
var a = keyboard.parseActionCall(action.doc || action) var a = keyboard.parseActionCall(action.doc || action, that)
return a.action in that ? return a.action in that ?
a.action a.action
+(a.arguments.length > 0 ? +(a.arguments.length > 0 ?
@ -991,7 +991,7 @@ var KeyboardUIActions = actions.Actions({
var c = 0 var c = 0
Object.keys(keys[mode] || {}).forEach(function(action){ Object.keys(keys[mode] || {}).forEach(function(action){
var o = keyboard.parseActionCall(action) var o = keyboard.parseActionCall(action, that)
if(getKeyText){ if(getKeyText){
var doc = '' var doc = ''
@ -1325,7 +1325,7 @@ var KeyboardUIActions = actions.Actions({
['&ctdot;', function(evt, elem){ ['&ctdot;', function(evt, elem){
code = code || '' code = code || ''
// highlight the current action... // highlight the current action...
var a = keyboard.parseActionCall(code) var a = keyboard.parseActionCall(code, that)
var p = a.action in that ? var p = a.action in that ?
that.getDocPath(a.action) that.getDocPath(a.action)
: '' : ''

View File

@ -244,7 +244,20 @@ var ImageMarkActions = actions.Actions({
removeMarkedFromCrop: ['Mark|Crop/Remove marked from crop', removeMarkedFromCrop: ['Mark|Crop/Remove marked from crop',
{browseMode: function(target){ {browseMode: function(target){
return (this.marked.length == 0 || !this.cropped) && 'disabled' }}, return (this.marked.length == 0 || !this.cropped) && 'disabled' }},
function(){ this.removeFromCrop(this.marked) }], 'removeFromCrop: marked'],
rotateMarkedCW: ['Mark/Rotate marked clockwise',
{browseMode: 'cropMarked'},
'rotateCW: marked'],
rotateMarkedCCW: ['Mark/Rotate marked counterclockwise',
{browseMode: 'cropMarked'},
'rotateCCW: marked'],
flipMarkedVertical: ['Mark/Flip marked vertically',
{browseMode: 'cropMarked'},
'flipVertical: marked'],
flipMarkedHorizontal: ['Mark/Flip marked horizontally',
{browseMode: 'cropMarked'},
'flipHorizontal: marked'],
}) })

View File

@ -93,11 +93,11 @@ function(context, cls, data){
primary.pop() primary.pop()
: null : null
secondary = typeof(secondary) == typeof('str') ? secondary = typeof(secondary) == typeof('str') ?
keyboard.parseActionCall(secondary) keyboard.parseActionCall(secondary, context)
: secondary : secondary
primary = primary instanceof Array ? primary.shift() : primary primary = primary instanceof Array ? primary.shift() : primary
primary = typeof(primary) == typeof('str') ? primary = typeof(primary) == typeof('str') ?
keyboard.parseActionCall(primary) keyboard.parseActionCall(primary, context)
: primary : primary
var click = primary instanceof Function ? var click = primary instanceof Function ?
@ -785,7 +785,7 @@ var DialogsActions = actions.Actions({
var loaders = {} var loaders = {}
list.forEach(function(m){ list.forEach(function(m){
var a = keyboard.parseActionCall(m) var a = keyboard.parseActionCall(m, that)
if(a.action in that){ if(a.action in that){
var args = a.arguments var args = a.arguments

View File

@ -1073,6 +1073,7 @@ var DataPrototype = {
// NOTE: this is a partial rewrite avoiding .compact() as much as // NOTE: this is a partial rewrite avoiding .compact() as much as
// possible and restricting it to as small a subset as possible // possible and restricting it to as small a subset as possible
getImages: function(target, count, mode){ getImages: function(target, count, mode){
var that = this
target = (target == null && count == null) ? 'loaded' : target target = (target == null && count == null) ? 'loaded' : target
mode = mode == null ? 'around' : mode mode = mode == null ? 'around' : mode
var list var list
@ -1106,9 +1107,11 @@ var DataPrototype = {
: this.getImages('loaded') : this.getImages('loaded')
count = null count = null
list = target.filter(function(e){ list = target
return loaded.indexOf(e) >= 0 .map(function(e){
}) return that.getImage(e) })
.filter(function(e){
return loaded.indexOf(e) >= 0 })
target = null target = null

View File

@ -154,6 +154,9 @@ function doc(text, func){
// - numbers // - numbers
// - strings // - strings
// - non-nested arrays or objects // - non-nested arrays or objects
//
// XXX EXPERIMENTAL...
// This will resolve names to context attributes
// //
// XXX should this be here??? // XXX should this be here???
// XXX add support for suffix to return false / stop_propagation... // XXX add support for suffix to return false / stop_propagation...
@ -162,7 +165,8 @@ function doc(text, func){
// XXX this is the same as actions.parseStringAction(..), reuse in a logical manner... // XXX this is the same as actions.parseStringAction(..), reuse in a logical manner...
var parseActionCall = var parseActionCall =
module.parseActionCall = module.parseActionCall =
function parseActionCall(txt){ function parseActionCall(txt, context){
context = context || this
// split off the doc... // split off the doc...
var c = txt.split('--') var c = txt.split('--')
var doc = (c[1] || '').trim() var doc = (c[1] || '').trim()
@ -175,11 +179,35 @@ function parseActionCall(txt){
action = no_default ? action.slice(0, -1) : action action = no_default ? action.slice(0, -1) : action
// parse arguments... // parse arguments...
/*
var args = JSON.parse('['+( var args = JSON.parse('['+(
((c[1] || '') ((c[1] || '')
.match(/"[^"]*"|'[^']*'|\{[^\}]*\}|\[[^\]]*\]|\d+|\d+\.\d*|null/gm) .match(/"[^"]*"|'[^']*'|\{[^\}]*\}|\[[^\]]*\]|\d+|\d+\.\d*|null/gm)
|| []) || [])
.join(','))+']') .join(','))+']')
//*/
// XXX EXPERIMENTAL -- is this safe???
var args = ((c[1] || '')
.match(RegExp([
'"[^"]*"',
"'[^']*",
'`[^`]*`',
'\\{[^\\}]*\\}',
'\\[[^\\]]*\\]',
'\\d+|\\d+\\.\\d*',
'[a-zA-Z$@#_][0-9a-zA-Z$@#_]*',
'null',
].join('|'), 'gm'))
|| [])
.map(function(e){
// resolve vars to context attrs...
return /^[a-zA-Z$@#_][0-9a-zA-Z$@#_]*$/.test(e) ?
(context || {})[e]
: JSON.parse(e) })
return { return {
action: action, action: action,
@ -1159,7 +1187,7 @@ function makeKeyboardHandler(keyboard, unhandled, actions){
// XXX should this be a Keyboard thing or a context thing??? // XXX should this be a Keyboard thing or a context thing???
} else if(actions.parseStringHandler || kb.parseStringHandler){ } else if(actions.parseStringHandler || kb.parseStringHandler){
//} else if(kb.parseStringHandler){ //} else if(kb.parseStringHandler){
var h = (actions.parseStringHandler || kb.parseStringHandler)(handler) var h = (actions.parseStringHandler || kb.parseStringHandler)(handler, actions)
//var h = kb.parseStringHandler(handler) //var h = kb.parseStringHandler(handler)
if(h && h.action in actions){ if(h && h.action in actions){

File diff suppressed because it is too large Load Diff

View File

@ -22,7 +22,7 @@
"fs-walk": "^0.0.1", "fs-walk": "^0.0.1",
"glob": "^4.0.6", "glob": "^4.0.6",
"guarantee-events": "^1.0.0", "guarantee-events": "^1.0.0",
"ig-actions": "^3.9.0", "ig-actions": "^3.10.0",
"ig-features": "^3.3.2", "ig-features": "^3.3.2",
"ig-object": "^1.0.2", "ig-object": "^1.0.2",
"openseadragon": "^2.3.1", "openseadragon": "^2.3.1",
@ -41,7 +41,7 @@
"devDependencies": { "devDependencies": {
"less": "*", "less": "*",
"nwjs": "*", "nwjs": "*",
"webdriverio": "^4.0.4", "webdriverio": "^4.9.8",
"webpack": "^2.7.0" "webpack": "^2.7.0"
}, },
"bin": { "bin": {