cleanup and minor tweaking...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2018-03-25 00:14:01 +03:00
parent 97f0cd3b1a
commit 29ed4a312d

View File

@ -1387,20 +1387,18 @@ var BrowseActionsActions = actions.Actions({
// XXX this should also (optionally?): // XXX this should also (optionally?):
// - sort levels - DONE // - sort levels - DONE
// ...remove sorting from .browseActions(..) // - expand path patterns - DONE
// - expand path patterns (???)
// - handle "*" listing (???) // - handle "*" listing (???)
// - handle visibility checks (???) // - handle visibility checks (???)
// XXX add option to run checks... getActions: ['- System/',
listActions: ['- System/',
core.doc`List actions in action tree... core.doc`List actions in action tree...
Build tree and return it... Build tree and return it...
.listActions('raw'[, tree]) .getActions('raw'[, tree])
-> tree -> tree
Get sup-tree/action at path... Get sup-tree/action at path...
.listActions(path[, tree]) .getActions(path[, tree])
-> sub-tree -> sub-tree
-> action -> action
@ -1434,7 +1432,6 @@ var BrowseActionsActions = actions.Actions({
// Sort tree level in-place... // Sort tree level in-place...
// //
// NOTE: this will remove the priority // NOTE: this will remove the priority
// XXX should this also handle path patterns...
var sortTree = function(tree, raw_keys, shallow){ var sortTree = function(tree, raw_keys, shallow){
var level = Object.keys(tree) var level = Object.keys(tree)
level level
@ -1469,9 +1466,16 @@ var BrowseActionsActions = actions.Actions({
key.replace(PRIORITY, '').trim() key.replace(PRIORITY, '').trim()
: key : key
// replace keys in order... // remove the key form old position...
var value = tree[key] var value = tree[key]
delete tree[key] delete tree[key]
// skip patterns...
if(!raw_keys && /\.\*/.test(key)){
return
}
// place the key in correct order...
tree[text] = value tree[text] = value
// go down the tree... // go down the tree...
@ -1488,9 +1492,6 @@ var BrowseActionsActions = actions.Actions({
// //
// returns: // returns:
// [<existing-text>, <new-level>] // [<existing-text>, <new-level>]
//
// XXX this may mess up the ordering of items when using
// item patterns...
var getItem = function(level, text){ var getItem = function(level, text){
// direct match... // direct match...
if(text in level){ if(text in level){
@ -1526,8 +1527,6 @@ var BrowseActionsActions = actions.Actions({
// Tree builder... // Tree builder...
// //
// XXX normalize actions -- whitespace, '!', args...
// XXX should this do level sorting???
var buildTree = function(path, leaf, action, mode, tree){ var buildTree = function(path, leaf, action, mode, tree){
path = path.slice() path = path.slice()
// build leaf... // build leaf...
@ -1593,7 +1592,6 @@ var BrowseActionsActions = actions.Actions({
}) })
// sort the tree... // sort the tree...
// XXX still needs to handle path patterns...
sortTree(tree, path == 'raw') sortTree(tree, path == 'raw')
} }
@ -1622,7 +1620,7 @@ var BrowseActionsActions = actions.Actions({
// XXX can this also do a flat mode??? // XXX can this also do a flat mode???
// ...this would help with the (global) search -- switch to // ...this would help with the (global) search -- switch to
// flat if searching in root mode... // flat if searching in root mode...
// XXX should this be live (options.live) or not??? (currently not) // XXX should this be live (options.live_tree) or not??? (currently not)
browseActions: ['Interface|System/Dialog/Actions...', browseActions: ['Interface|System/Dialog/Actions...',
core.doc`Browse actions dialog... core.doc`Browse actions dialog...
@ -1686,6 +1684,10 @@ var BrowseActionsActions = actions.Actions({
callback: <function>, callback: <function>,
no_disabled: false, no_disabled: false,
no_hidden: false, no_hidden: false,
// if true then the action tree will get rebuilt live on
// each list navigation...
live_tree: false,
} }
@ -1722,8 +1724,6 @@ var BrowseActionsActions = actions.Actions({
fullPathEdit: true, fullPathEdit: true,
item_shortcut_marker: MARKER, item_shortcut_marker: MARKER,
live: true,
} }
cfg.__proto__ = this.config['browse-actions-settings'] cfg.__proto__ = this.config['browse-actions-settings']
@ -1770,14 +1770,14 @@ var BrowseActionsActions = actions.Actions({
}.bind(this) }.bind(this)
// pre-cache the action tree... // pre-cache the action tree...
var tree = cfg.live ? var tree = !options.live_tree ?
null actions.getActions('raw')
: actions.listActions('raw') : null
// now for the dialog... // now for the dialog...
return browse.makeLister(null, function(path, make){ return browse.makeLister(null, function(path, make){
var that = this var that = this
var cur = actions.listActions(path.slice(), tree) var cur = actions.getActions(path.slice(), tree)
// render current level... // render current level...
// NOTE: we can be at one of several level types, each // NOTE: we can be at one of several level types, each
@ -1845,43 +1845,8 @@ var BrowseActionsActions = actions.Actions({
// Level: normal -- list actions... // Level: normal -- list actions...
} else { } else {
var level = Object.keys(cur) Object.keys(cur)
level
/*/ XXX
.slice()
// sort according to item priority: 'NN: <text>'
// NN > 0 - is sorted above the non-prioritized
// elements, the greater the number
// the higher the element
// NN < 0 - is sorted below the non-prioritized
// elements, the lower the number
// the lower the element
// other - keep order
.sort(function(a, b){
var ai = PRIORITY.exec(a)
ai = ai ? ai.pop()*1 : null
ai = ai > 0 ? -ai
: ai < 0 ? -ai + level.length
: 0
var bi = PRIORITY.exec(b)
bi = bi ? bi.pop()*1 : null
bi = bi > 0 ? -bi
: bi < 0 ? -bi + level.length
: 0
return ai == bi ?
level.indexOf(a) - level.indexOf(b)
: ai - bi
})
//*/
.forEach(function(key){ .forEach(function(key){
// remove the order...
// XXX remove this...
// ...this is done by .listActions(..)
//var text = key.replace(PRIORITY, '').trim()
var text = key
// Item: action... // Item: action...
if(cur[key] instanceof Array){ if(cur[key] instanceof Array){
var action = cur[key][0] var action = cur[key][0]
@ -1892,7 +1857,7 @@ var BrowseActionsActions = actions.Actions({
// 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(key + '/', {
cls: mode == 'hidden' ? mode : '', cls: mode == 'hidden' ? mode : '',
// NOTE: if something is hidden // NOTE: if something is hidden
// it is also disabled... // it is also disabled...
@ -1912,7 +1877,7 @@ var BrowseActionsActions = actions.Actions({
function(){ function(){
actions[action]() actions[action]()
that.update() that.update()
that.select('"'+ text +'"') that.select('"'+ key +'"')
}], }],
//[getKeys(action)], //[getKeys(action)],
], ],
@ -1922,13 +1887,13 @@ var BrowseActionsActions = actions.Actions({
: actions[action]() : actions[action]()
that.update() that.update()
that.select('"'+ text +'"') that.select('"'+ key +'"')
}, },
}) })
// Action: normal... // Action: normal...
} else { } else {
make(text, { make(key, {
// NOTE: if something is hidden // NOTE: if something is hidden
// it is also disabled... // it is also disabled...
// ...this is by design. // ...this is by design.
@ -1954,9 +1919,9 @@ var BrowseActionsActions = actions.Actions({
} else if(actions.config['browse-actions-settings'].showEmpty } else if(actions.config['browse-actions-settings'].showEmpty
|| (cur[key] != null || (cur[key] != null
&& Object.keys(cur[key]).length > 0)){ && Object.keys(cur[key]).length > 0)){
var p = '/'+ path.concat([text]).join('/') +'/' var p = '/'+ path.concat([key]).join('/') +'/'
p = MARKER ? p.replace(MARKER, '$1') : p p = MARKER ? p.replace(MARKER, '$1') : p
make(text + '/', { make(key + '/', {
push_on_open: true, push_on_open: true,
attrs: { attrs: {
keys: [ keys: [
@ -1967,7 +1932,7 @@ var BrowseActionsActions = actions.Actions({
}) })
// item: line... // item: line...
} else if(/---+/.test(text)){ } else if(/---+/.test(key)){
make('---') make('---')
} }
}) })