reworked hidden/disabled items + action attrs now get searched correctly...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2016-12-30 03:21:09 +03:00
parent fdb280d519
commit ff8ca76a3d
5 changed files with 98 additions and 48 deletions

View File

@ -890,6 +890,8 @@ module.CropActions = actions.Actions({
} }
}], }],
uncrop: ['Crop/Uncrop', uncrop: ['Crop/Uncrop',
{browseMode: function(){
return (this.crop_stack && this.crop_stack.length > 0) || 'disabled' }},
function(level, restore_current, keep_crop_order){ function(level, restore_current, keep_crop_order){
level = level || 1 level = level || 1
@ -927,16 +929,22 @@ module.CropActions = actions.Actions({
} }
}], }],
uncropAll: ['Crop/Uncrop all', uncropAll: ['Crop/Uncrop all',
{browseMode: function(){
return (this.crop_stack && this.crop_stack.length > 0) || 'disabled' }},
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: ['Crop|Edit/Uncrop and keep crop image order', uncropAndKeepOrder: ['Crop|Edit/Uncrop and keep crop image order',
{browseMode: function(){
return (this.crop_stack && this.crop_stack.length > 0) || 'disabled' }},
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: ['- Crop|Edit/Merge crop', mergeCrop: ['- Crop|Edit/Merge crop',
{browseMode: function(){
return (this.crop_stack && this.crop_stack.length > 0) || 'disabled' }},
function(){ function(){
// XXX // XXX
}], }],

View File

@ -100,9 +100,8 @@ var RangeActions = actions.Actions({
} }
}], }],
clearRange: ['Range/Clear range', clearRange: ['Range/Clear range',
// XXX not sure if it is best to hide things or make them do a // XXX not sure if this is the right way to go...
// sensible default thing... {browseMode: function(){ return !this.data.__range && 'disabled' }},
//{isDisabled: function(){ return !this.data.__range }},
function(image){ function(image){
var r = this.ribbons.viewer.find('.ribbon') var r = this.ribbons.viewer.find('.ribbon')
@ -162,9 +161,8 @@ var RangeActions = actions.Actions({
function(image){ this.setRangeBorder(image, 'close') }], function(image){ this.setRangeBorder(image, 'close') }],
cropRange: ['Range|Crop/Crop range', cropRange: ['Range|Crop/Crop range',
// XXX not sure if it is best to hide things or make them do a // XXX not sure if this is the right way to go...
// sensible default thing... {browseMode: function(){ return !this.data.__range && 'disabled' }},
//{isDisabled: function(){ return !this.data.__range }},
function(){ function(){
var range = this.data.__range var range = this.data.__range
var order = this.data.order var order = this.data.order
@ -176,9 +174,8 @@ var RangeActions = actions.Actions({
: this.crop([]) : this.crop([])
}], }],
cropRangeOut: ['Range|Crop/Crop out range', cropRangeOut: ['Range|Crop/Crop out range',
// XXX not sure if it is best to hide things or make them do a // XXX not sure if this is the right way to go...
// sensible default thing... {browseMode: function(){ return !this.data.__range && 'disabled' }},
//{isDisabled: function(){ return !this.data.__range }},
function(){ function(){
var range = this.data.__range var range = this.data.__range
var order = this.data.order var order = this.data.order
@ -189,6 +186,8 @@ var RangeActions = actions.Actions({
.concat(order.slice(order.indexOf(range[1])+1))) .concat(order.slice(order.indexOf(range[1])+1)))
: this.crop() : this.crop()
}], }],
uncrop: [function(){}],
}) })

View File

@ -780,7 +780,8 @@ var BrowseActionsActions = actions.Actions({
], ],
'browse-actions-settings': { 'browse-actions-settings': {
showDisabled: false, showDisabled: true,
showHidden: false,
showEmpty: false, showEmpty: false,
}, },
}, },
@ -790,9 +791,9 @@ var BrowseActionsActions = actions.Actions({
// This uses action definition to build and present an action tree. // This uses action definition to build and present an action tree.
// //
// This supports the following element syntax: // This supports the following element syntax:
// - leading '- ' in path to indicate disabled element. // - leading '- ' in path to indicate a hidden/disabled element.
// Example: // Example:
// '- Path/To/Element' (disabled) // '- Path/To/Element' (disabled/hidden)
// 'Path/To/Other element' (enabled) // 'Path/To/Other element' (enabled)
// //
// - leading path element number followed by colon to indicate // - leading path element number followed by colon to indicate
@ -806,18 +807,23 @@ var BrowseActionsActions = actions.Actions({
// with greater or no priority. // with greater or no priority.
// //
// //
// An action can also be disabled dynamically: // Action mode (disabled/hidden) and also be controlled dynamically:
// - .isDisabled() action method is called with actions as base if // - .browseMode() action method is called with actions as base.
// action is not disabled.
// Example: // Example:
// someAction: ['Path/To/Some action', // someAction: ['Path/To/Some action',
// {isDisabled: function(){ ... }}, // {browseMode: function(){ ... }},
// function(){ // function(){
// ... // ...
// }], // }],
// .browseMode() can return:
// 'disabled' - item will be disabled.
// 'hidden' - item will be both hidden and disabled.
// //
// NOTE: disabling an action path has priority over the action // NOTE: disabling in path has priority over .browseMode(), thus
// .isDisabled() predicate... // it is possible to hide/disable an enabled item but not
// possible to enable a disabled by default path.
// NOTE: .browseMode() can be defined in any action in chain,
// though only the last one is called...
// //
// //
// NOTE: if the action returns an instance of overlay.Overlay this // NOTE: if the action returns an instance of overlay.Overlay this
@ -883,14 +889,14 @@ var BrowseActionsActions = actions.Actions({
}).bind(this) }).bind(this)
// Tree builder... // Tree builder...
var buildTree = function(path, leaf, action, disabled, tree){ var buildTree = function(path, leaf, action, mode, tree){
path = path.slice() path = path.slice()
// build leaf... // build leaf...
if(path.length == 0){ if(path.length == 0){
leaf.split(/\|/g) leaf.split(/\|/g)
.forEach(function(leaf){ .forEach(function(leaf){
var l = getItem(tree, leaf)[0] var l = getItem(tree, leaf)[0]
tree[l || leaf] = action != null ? [action, disabled] : action tree[l || leaf] = action != null ? [action, mode] : action
}) })
return return
} }
@ -903,7 +909,7 @@ var BrowseActionsActions = actions.Actions({
branch = tree[branch[0] || e] = branch[1] || {} branch = tree[branch[0] || e] = branch[1] || {}
// build sub-branch... // build sub-branch...
buildTree(path, leaf, action, disabled, branch) buildTree(path, leaf, action, mode, branch)
}) })
} }
@ -915,7 +921,8 @@ var BrowseActionsActions = actions.Actions({
// //
// <name>: [ // <name>: [
// <action-name>, // <action-name>,
// <disabled>, // // mode...
// 'disabled' | 'hidden',
// ], // ],
// //
// ... // ...
@ -938,22 +945,16 @@ var BrowseActionsActions = actions.Actions({
// build the tree... // build the tree...
var paths = this.getPath() var paths = this.getPath()
Object.keys(paths).forEach(function(key){ Object.keys(paths).forEach(function(key){
// handle disabled flag... // handle mode flag...
var action = paths[key][0] var action = paths[key][0]
var disabled = key.split(/^- /) var mode = key.split(/^- /)
var path = disabled.pop() var path = mode.pop()
disabled = disabled.length > 0 mode = mode.length > 0 ? 'hidden' : null
// prepare to handle disabled action predicate...
disabled = (!disabled && actions[action].isDisabled) ?
actions[action].isDisabled
: disabled
path = path.split(/[\\\/]/g) path = path.split(/[\\\/]/g)
var leaf = path.pop() var leaf = path.pop()
buildTree(path, leaf, action, disabled, tree) buildTree(path, leaf, action, mode, tree)
}) })
//console.log('!!!!', tree) //console.log('!!!!', tree)
@ -980,12 +981,13 @@ var BrowseActionsActions = actions.Actions({
if(cur instanceof Array if(cur instanceof Array
&& actions.isToggler && actions.isToggler(cur[0])){ && actions.isToggler && actions.isToggler(cur[0])){
var action = cur[0] var action = cur[0]
var disabled = cur[1] var mode = cur[1]
// handle disabled predicate... // handle live modes...
disabled = disabled instanceof Function ? if(mode == null){
disabled.call(actions) var m = actions.getAttr(action, 'browseMode')
: disabled mode = m ? m.call(actions) : mode
}
var cur_state = actions[action]('?') var cur_state = actions[action]('?')
var states = actions[action]('??') var states = actions[action]('??')
@ -1000,12 +1002,19 @@ var BrowseActionsActions = actions.Actions({
// build states... // build states...
states.forEach(function(state){ states.forEach(function(state){
make(state, { disabled: disabled }) make(state, {
// NOTE: if something is hidden
// it is also disabled...
// ...this is by design.
disabled: mode == 'hidden' || mode == 'disabled',
hidden: mode == 'hidden',
})
.addClass(state == cur_state ? 'selected highlighted' : '') .addClass(state == cur_state ? 'selected highlighted' : '')
.on('open', function(){ .on('open', function(){
actions[action](state) actions[action](state)
that.pop() that.pop()
}) })
.addClass(mode == 'hidden' ? mode : '')
}) })
// Level: lister -- hand control to lister... // Level: lister -- hand control to lister...
@ -1048,17 +1057,22 @@ var BrowseActionsActions = actions.Actions({
// Item: action... // Item: action...
if(cur[key] instanceof Array){ if(cur[key] instanceof Array){
var action = cur[key][0] var action = cur[key][0]
var disabled = cur[key][1] var mode = cur[key][1]
// handle disabled predicate... // handle live modes...
disabled = disabled instanceof Function ? if(mode == null){
disabled.call(actions) var m = actions.getAttr(action, 'browseMode')
: disabled mode = m ? m.call(actions) : mode
}
// Action: toggler -> add toggle button... // Action: toggler -> add toggle button...
if(actions.isToggler && actions.isToggler(action)){ if(actions.isToggler && actions.isToggler(action)){
make(text + '/', { make(text + '/', {
disabled: disabled, // NOTE: if something is hidden
// it is also disabled...
// ...this is by design.
disabled: mode == 'hidden' || mode == 'disabled',
hidden: mode == 'hidden',
buttons: [ buttons: [
[actions[action]('?'), [actions[action]('?'),
function(){ function(){
@ -1067,6 +1081,7 @@ var BrowseActionsActions = actions.Actions({
that.select('"'+ text +'"') that.select('"'+ text +'"')
}] }]
]}) ]})
.addClass(mode == 'hidden' ? mode : '')
.on('open', function(){ .on('open', function(){
// XXX can this open a dialog??? // XXX can this open a dialog???
actions[action]() actions[action]()
@ -1077,7 +1092,13 @@ var BrowseActionsActions = actions.Actions({
// Action: normal... // Action: normal...
} else { } else {
make(text, { disabled: disabled }) make(text, {
// NOTE: if something is hidden
// it is also disabled...
// ...this is by design.
disabled: mode == 'hidden' || mode == 'disabled',
hidden: mode == 'hidden',
})
.on('open', function(){ .on('open', function(){
waitFor(actions[action]()) waitFor(actions[action]())
}) })
@ -1100,12 +1121,14 @@ var BrowseActionsActions = actions.Actions({
fullPathEdit: true, fullPathEdit: true,
showDisabled: actions.config['browse-actions-settings'].showDisabled, showDisabled: actions.config['browse-actions-settings'].showDisabled,
showHidden: actions.config['browse-actions-settings'].showHidden,
}) })
// save show disabled state to .config... // save show disabled state to .config...
.on('close', function(){ .on('close', function(){
var config = actions.config['browse-actions-settings'] var config = actions.config['browse-actions-settings']
config.showDisabled = dialog.options.showDisabled config.showDisabled = dialog.options.showDisabled
config.showHidden = dialog.options.showHidden
}) })
return dialog return dialog

View File

@ -233,6 +233,9 @@ var BrowserPrototype = {
// affected... // affected...
showDisabled: true, showDisabled: true,
// XXX
showHidden: false,
// Enable/disable disabled drawing... // Enable/disable disabled drawing...
// //
// If false these will disable the corresponding methods. // If false these will disable the corresponding methods.
@ -246,6 +249,9 @@ var BrowserPrototype = {
// affected... // affected...
toggleDisabledDrawing: true, toggleDisabledDrawing: true,
// XXX
toggleHiddenDrawing: true,
// Group traversable elements... // Group traversable elements...
// //
// Possible values: // Possible values:
@ -469,6 +475,7 @@ var BrowserPrototype = {
}, },
D: 'toggleDisabledDrawing', D: 'toggleDisabledDrawing',
H: 'toggleHiddenDrawing',
T: 'toggleNonTraversableDrawing', T: 'toggleNonTraversableDrawing',
// XXX should these use .select(..)??? // XXX should these use .select(..)???
@ -666,6 +673,16 @@ var BrowserPrototype = {
cur && this.select(cur) cur && this.select(cur)
return this return this
}, },
toggleHiddenDrawing: function(){
var cur = this.selected
if(this.options.toggleHiddenDrawing == false){
return this
}
this.options.showHidden = !this.options.showHidden
this.update()
cur && this.select(cur)
return this
},
/* /*
@ -929,12 +946,14 @@ var BrowserPrototype = {
// XXX revise signature... // XXX revise signature...
var make = function(p, traversable, disabled, buttons){ var make = function(p, traversable, disabled, buttons){
var hidden = false
// options passed as an object... // options passed as an object...
if(traversable != null && typeof(traversable) == typeof({})){ if(traversable != null && typeof(traversable) == typeof({})){
var opts = traversable var opts = traversable
traversable = opts.traversable traversable = opts.traversable
disabled = opts.disabled disabled = opts.disabled
buttons = opts.buttons buttons = opts.buttons
hidden = opts.hidden
} }
buttons = buttons buttons = buttons
@ -1000,7 +1019,8 @@ var BrowserPrototype = {
// skip drawing of non-traversable or disabled elements if // skip drawing of non-traversable or disabled elements if
// .showNonTraversable or .showDisabled are false respectively... // .showNonTraversable or .showDisabled are false respectively...
if((!traversable && !that.options.showNonTraversable) if((!traversable && !that.options.showNonTraversable)
|| (disabled && !that.options.showDisabled)){ || (disabled && !that.options.showDisabled)
|| (hidden && !that.options.showHidden)){
return $() return $()
} }

View File

@ -23,7 +23,7 @@
"glob": "^4.0.6", "glob": "^4.0.6",
"guarantee-events": "^1.0.0", "guarantee-events": "^1.0.0",
"ig-features": "^2.0.0", "ig-features": "^2.0.0",
"ig-actions": "^1.8.0", "ig-actions": "^1.9.0",
"ig-object": "^1.0.1", "ig-object": "^1.0.1",
"openseadragon": "^2.1.0", "openseadragon": "^2.1.0",
"requirejs": "^2.1.23", "requirejs": "^2.1.23",