refactoring...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2017-01-31 02:51:06 +03:00
parent 0aeb494a6b
commit d0f0356edc
2 changed files with 75 additions and 39 deletions

View File

@ -925,9 +925,9 @@ var FileSystemLoaderUIActions = actions.Actions({
// in the list.
// NOTE: the first one is auto-selected.
'path-loaders': [
'loadIndex',
'loadImages',
//'loadPath',
'loadIndex: "$PATH"',
'loadImages: "$PATH"',
//'loadPath: "$PATH"',
'---',
'loadImagesAsRibbon: "$PATH" "above" -- Load images to new ribbon above',
'loadImagesAsRibbon: "$PATH" "below" -- Load images to new ribbon below',
@ -981,43 +981,14 @@ var FileSystemLoaderUIActions = actions.Actions({
// list of loaders...
} else {
// user-provided list...
if(callback){
var loaders = callback
// build the loaders list from .config...
} else {
var loaders = {}
that.config['path-loaders'].forEach(function(m){
var a = keyboard.parseActionCall(m)
if(a.action in that){
var args = a.arguments
// empty args...
args = args.length == 0 ?
[path]
: args
// replace the path placeholder...
var i = args.indexOf('$PATH')
i >= 0
&& args.splice(i, 1, path)
// the callback...
loaders[a.doc != '' ?
a.doc
: that.getDocTitle(a.action)] =
function(){
return that[a.action].apply(that, args) }
// non-actions...
} else {
loaders[m] = null
}
})
}
// show user the loader list...
var so = that.showList(loaders, { path: 0 })
var so = that.showActionList(
callback
|| that.config['path-loaders'],
{
path: 0,
args_dict: { '$PATH': path },
})
// close self and parent...
.open(function(){
so.close()

View File

@ -287,6 +287,8 @@ function(actions, list, list_key, value_key, options){
/*********************************************************************/
// Dialogs and containers...
@ -575,8 +577,71 @@ var DialogsActions = actions.Actions({
// Helper for creating lists fast...
showList: ['- Interface/',
core.doc`Show list dialog...
.showList(<list>, <options>)
-> dialog
See browse.makeList(..) / browse.Items.List(..) for more info.
`,
makeUIDialog(function(list, options){
return browse.makeList(null, list, options) })],
showActionList: ['- Interface/',
core.doc`Show list of actions dialog...
.showActionList(<list>, <options>)
-> dialog
Like .showList(..) but understands keyboard.parseActionCall(..) syntax,
Options format:
{
// arguments and what to replace them with, this is used
// to define templates in the list and pass real values
// via the dict.
args_dict: {
<arg>: <value>,
...
},
// Same format .showList(..) understands...
...
}
`,
makeUIDialog(function(list, options){
var that = this
list = list instanceof Function ? list.call(this) : list
options = options || {}
var args_dict = options.args_dict || {}
var loaders = {}
list.forEach(function(m){
var a = keyboard.parseActionCall(m)
if(a.action in that){
var args = a.arguments
.map(function(a){
return args_dict[a] !== undefined ?
args_dict[a]
: a })
// the callback...
loaders[a.doc != '' ?
a.doc
: that.getDocTitle(a.action)] =
function(){
return that[a.action].apply(that, args) }
// non-actions...
} else {
loaders[m] = null
}
})
return browse.makeList(null, loaders, options)
})],
// Show doc for action...