From 00ec10a335144c1bb3af7d971d3f41e670ccb47f Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Fri, 4 Aug 2017 04:28:29 +0300 Subject: [PATCH] added persistent aliases... Signed-off-by: Alex A. Naanou --- ui (gen4)/features/alias.js | 57 ++++++++++++++++++++++++++++++++ ui (gen4)/features/all.js | 1 + ui (gen4)/features/keyboard.js | 3 ++ ui (gen4)/features/meta.js | 2 ++ ui (gen4)/features/ui-widgets.js | 4 +++ ui (gen4)/lib/keyboard.js | 10 ++++-- ui (gen4)/package.json | 4 +-- 7 files changed, 77 insertions(+), 4 deletions(-) create mode 100755 ui (gen4)/features/alias.js diff --git a/ui (gen4)/features/alias.js b/ui (gen4)/features/alias.js new file mode 100755 index 00000000..a00dd3c3 --- /dev/null +++ b/ui (gen4)/features/alias.js @@ -0,0 +1,57 @@ +/********************************************************************** +* +* +* +**********************************************************************/ +((typeof define)[0]=='u'?function(f){module.exports=f(require)}:define) +(function(require){ var module={} // make module AMD/node compatible... +/*********************************************************************/ + +var actions = require('lib/actions') +var features = require('lib/features') + +var core = require('features/core') + + + +/*********************************************************************/ + +var Alias = +module.Alias = core.ImageGridFeatures.Feature({ + title: '', + doc: '', + + tag: 'alias', + + config: { + //aliases: { + //}, + }, + + handlers: [ + ['alias', + function(_, alias, target){ + console.log(alias, target) + // remove alias... + if(target === null || target === false){ + var aliases = this.config.aliases || {} + + delete aliases[alias] + + if(Object.keys(alias).length == 0){ + delete this.config.aliases + } + + // save alias... + } else { + var aliases = this.config.aliases = this.config.aliases || {} + + aliases[alias] = target + } + }]], +}) + + + +/********************************************************************** +* vim:set ts=4 sw=4 : */ return module }) diff --git a/ui (gen4)/features/all.js b/ui (gen4)/features/all.js index f9bb5f4d..02b7ae29 100755 --- a/ui (gen4)/features/all.js +++ b/ui (gen4)/features/all.js @@ -19,6 +19,7 @@ require('features/recover') require('features/history') require('features/app') require('features/peer') +require('features/alias') require('features/ui') // XXX require('features/ui-blank-render') diff --git a/ui (gen4)/features/keyboard.js b/ui (gen4)/features/keyboard.js index f0a0c545..7b86822c 100755 --- a/ui (gen4)/features/keyboard.js +++ b/ui (gen4)/features/keyboard.js @@ -802,6 +802,9 @@ module.Keyboard = core.ImageGridFeatures.Feature({ var that = this this.__keyboard_config = this.keybindings || GLOBAL_KEYBOARD + // string action call parser... + this.parseStringHandler = this.parseStringAction + this.toggleKeyboardHandling('on') }], diff --git a/ui (gen4)/features/meta.js b/ui (gen4)/features/meta.js index 732df6f3..8e925d88 100755 --- a/ui (gen4)/features/meta.js +++ b/ui (gen4)/features/meta.js @@ -50,6 +50,8 @@ core.ImageGridFeatures.Feature('viewer-testing', [ 'viewer-commandline', 'viewer-minimal', + 'alias', + // read-only mode... // XXX at this point this needs some more tuneup, the following // features are completely disabled when 'edit' is not present diff --git a/ui (gen4)/features/ui-widgets.js b/ui (gen4)/features/ui-widgets.js index e5359e90..440fc2c6 100755 --- a/ui (gen4)/features/ui-widgets.js +++ b/ui (gen4)/features/ui-widgets.js @@ -2295,6 +2295,10 @@ var WidgetTestActions = actions.Actions({ .attr(attrs)) }], + // XXX does not work -- see actions.Actions(..) for details... + testAlias: ['Test/Action alias', + 'focusImage: "prev"'], + // action constructor for testing... makeAction: ['- Test/', function(name){ diff --git a/ui (gen4)/lib/keyboard.js b/ui (gen4)/lib/keyboard.js index 49a02d3f..c015fb6f 100755 --- a/ui (gen4)/lib/keyboard.js +++ b/ui (gen4)/lib/keyboard.js @@ -159,6 +159,7 @@ function doc(text, func){ // XXX add support for suffix to return false / stop_propagation... // XXX should this handle calls??? // i.e. have .call(..) / .apply(..) methods??? +// XXX this is the same as actions.parseStringAction(..), reuse in a logical manner... var parseActionCall = module.parseActionCall = function parseActionCall(txt){ @@ -503,6 +504,8 @@ var KeyboardPrototype = { // stop_propagation: , // } // + // XXX should this be a Keyboard thing or a context thing??? + // XXX revise name... parseStringHandler: parseActionCall, @@ -1097,8 +1100,11 @@ function makeKeyboardHandler(keyboard, unhandled, actions){ res = handler.call(actions) // action call syntax... - } else if(kb.parseStringHandler){ - var h = kb.parseStringHandler(handler) + // XXX should this be a Keyboard thing or a context thing??? + } else if(actions.parseStringHandler || kb.parseStringHandler){ + //} else if(kb.parseStringHandler){ + var h = (actions.parseStringHandler || kb.parseStringHandler)(handler) + //var h = kb.parseStringHandler(handler) if(h && h.action in actions){ did_handling = true diff --git a/ui (gen4)/package.json b/ui (gen4)/package.json index 11030046..1f7b17a6 100755 --- a/ui (gen4)/package.json +++ b/ui (gen4)/package.json @@ -18,11 +18,11 @@ "app-module-path": "^1.0.6", "commander": "^2.11.0", "exiftool": "^0.0.3", - "fs-extra": "^4.0.0", + "fs-extra": "^4.0.1", "fs-walk": "^0.0.1", "glob": "^4.0.6", "guarantee-events": "^1.0.0", - "ig-actions": "^3.2.5", + "ig-actions": "^3.5.1", "ig-features": "^3.2.6", "ig-object": "^1.0.1", "openseadragon": "^2.3.0",