From d0f0356edcf80b3d255667f4b3efb73e26bfa0a1 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Tue, 31 Jan 2017 02:51:06 +0300 Subject: [PATCH] refactoring... Signed-off-by: Alex A. Naanou --- ui (gen4)/features/filesystem.js | 49 +++++------------------- ui (gen4)/features/ui-widgets.js | 65 ++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 39 deletions(-) diff --git a/ui (gen4)/features/filesystem.js b/ui (gen4)/features/filesystem.js index c00ca7ad..30d07ed0 100755 --- a/ui (gen4)/features/filesystem.js +++ b/ui (gen4)/features/filesystem.js @@ -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() diff --git a/ui (gen4)/features/ui-widgets.js b/ui (gen4)/features/ui-widgets.js index be75fa94..00bc7d7a 100755 --- a/ui (gen4)/features/ui-widgets.js +++ b/ui (gen4)/features/ui-widgets.js @@ -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(, ) + -> 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(, ) + -> 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: { + : , + ... + }, + + // 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...