From dc07d95cd1b82f8aa73bd022340a42fb29069947 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Mon, 23 May 2016 03:42:53 +0300 Subject: [PATCH] tweaks and fixes... Signed-off-by: Alex A. Naanou --- ui (gen4)/features/cli.js | 65 ++++++++++++++++++++++++- ui (gen4)/features/filesystem.js | 82 +++++++++++++++++--------------- ui (gen4)/features/meta.js | 3 +- ui (gen4)/features/sharp.js | 29 ++++++----- ui (gen4)/features/ui-widgets.js | 3 ++ 5 files changed, 128 insertions(+), 54 deletions(-) diff --git a/ui (gen4)/features/cli.js b/ui (gen4)/features/cli.js index 30558826..0933addb 100755 --- a/ui (gen4)/features/cli.js +++ b/ui (gen4)/features/cli.js @@ -43,17 +43,37 @@ var base = require('features/base') // alone at first and then either create new instances or setup // additional features as needed... + + +var CLIActions = actions.Actions({ + makeIndex: ['- System/', + function(path){ + var that = this + + return this.loadImages(path) + .then(function(){ return that.makePreviews('all') }) + .then(function(){ return that.sortImages() }) + //.then(function(){ return that.readAllMetadata() }) + .then(function(){ return that.saveIndex() }) + }], +}) + + var CLI = module.CLI = core.ImageGridFeatures.Feature({ title: '', doc: '', tag: 'commandline', - depends: ['lifecycle'], + depends: [ + 'lifecycle' + ], isApplicable: function(){ return this.runtime == 'node' || this.runtime == 'nw' }, + actions: CLIActions, + handlers: [ ['start', function(){ @@ -133,6 +153,45 @@ module.CLI = core.ImageGridFeatures.Feature({ .setup(that, ['viewer-minimal']) }) + .option('repl, --repl', 'start an ImageGrin REPL', function(){ + //var repl = require('repl') + + //var ig = core.ImageGridFeatures + + repl.start({ + prompt: 'ig> ', + + input: process.stdin, + output: process.stdout, + + ignoreUndefined: true, + + /* + eval: function(str, context, filename, callback){ + var res + + var lst = str.split(/\s+/) + var cmd = lst.shift() + + // we got an action... + if(cmd == 'var'){ + eval(str, context, filename, callback) + + // action... + } else if(cmd in ig){ + ig[cmd].apply(ig, lst.map(eval)) + + // err + } else { + // XXX + } + + callback(null, res) + }, + */ + }) + }) + // XXX the problem with this is that it still tires // to find and run 'ig-index'... /* @@ -147,7 +206,9 @@ module.CLI = core.ImageGridFeatures.Feature({ .arguments(' [args]') .action(function(action, args){ // XXX - console.log('>>>>', action, args) + //console.log('>>>>', action, args, !!that[action]) + + that[action](args) }) .parse(argv) diff --git a/ui (gen4)/features/filesystem.js b/ui (gen4)/features/filesystem.js index 5cae58d2..aeb6333c 100755 --- a/ui (gen4)/features/filesystem.js +++ b/ui (gen4)/features/filesystem.js @@ -279,50 +279,55 @@ var FileSystemLoaderActions = actions.Actions({ method: 'loadImages', } - glob(path + '/'+ this.config['image-file-pattern'], - {stat: !!this.config['image-file-read-stat']}) - .on('error', function(err){ - console.log('!!!!', err) - }) - /* - .on('match', function(img){ - // XXX stat stuff... - fse.statSync(img) - }) - */ - .on('end', function(lst){ - that.loadURLs(lst, path) - // XXX do we need to normalize paths after we get them from glob?? - //that.loadURLs(lst.map(pathlib.posix.normalize), path) - //that.loadURLs(lst - // .map(function(p){ return util.normalizePath(p) }), path) + return new Promise(function(resolve, reject){ + glob(path + '/'+ that.config['image-file-pattern'], + {stat: !!that.config['image-file-read-stat']}) + .on('error', function(err){ + console.log('!!!!', err) + reject(err) + }) + /* + .on('match', function(img){ + // XXX stat stuff... + fse.statSync(img) + }) + */ + .on('end', function(lst){ + that.loadURLs(lst, path) + // XXX do we need to normalize paths after we get them from glob?? + //that.loadURLs(lst.map(pathlib.posix.normalize), path) + //that.loadURLs(lst + // .map(function(p){ return util.normalizePath(p) }), path) - if(!!that.config['image-file-read-stat']){ - var stats = this.statCache - var p = pathlib.posix + if(!!that.config['image-file-read-stat']){ + var stats = this.statCache + var p = pathlib.posix - that.images.forEach(function(gid, img){ - var stat = stats[p.join(img.base_path, img.path)] + that.images.forEach(function(gid, img){ + var stat = stats[p.join(img.base_path, img.path)] - img.atime = stat.atime - img.mtime = stat.mtime - img.ctime = stat.ctime - img.birthtime = stat.birthtime + img.atime = stat.atime + img.mtime = stat.mtime + img.ctime = stat.ctime + img.birthtime = stat.birthtime - img.size = stat.size + img.size = stat.size - // XXX do we need anything else??? - }) - } + // XXX do we need anything else??? + }) + } - // NOTE: we set it again because .loadURLs() does a clear - // before it starts loading... - // XXX is this a bug??? - that.__location = { - path: path, - method: 'loadImages', - } - }) + // NOTE: we set it again because .loadURLs() does a clear + // before it starts loading... + // XXX is this a bug??? + that.__location = { + path: path, + method: 'loadImages', + } + + resolve(that) + }) + }) }], // XXX auto-detect format or let the user chose... @@ -1087,6 +1092,7 @@ var FileSystemWriterActions = actions.Actions({ // - vertical // - horizontal // - ... + // XXX this repeats sharp.SharpActions.config['preview-sizes'] 'export-preview-sizes': [ '500', '900', diff --git a/ui (gen4)/features/meta.js b/ui (gen4)/features/meta.js index 5787939f..8d143280 100755 --- a/ui (gen4)/features/meta.js +++ b/ui (gen4)/features/meta.js @@ -39,6 +39,7 @@ core.ImageGridFeatures.Feature('viewer-minimal', [ 'image-bookmarks', 'fs', + 'sharp', 'metadata', ]) @@ -52,8 +53,6 @@ core.ImageGridFeatures.Feature('viewer-testing', [ 'ui', 'keyboard', - 'sharp', - 'ui-ribbons-placement', 'ui-fullscreen-controls', diff --git a/ui (gen4)/features/sharp.js b/ui (gen4)/features/sharp.js index 5cfc7fab..9044b857 100755 --- a/ui (gen4)/features/sharp.js +++ b/ui (gen4)/features/sharp.js @@ -45,6 +45,7 @@ var SharpActions = actions.Actions({ 'preview-normalized': true, + // XXX this repeats filesystem.FileSystemWriterActions.config['export-preview-sizes'] 'preview-sizes': [ 1920, 1280, @@ -100,30 +101,32 @@ var SharpActions = actions.Actions({ .sort() .reverse() - sizes = sizes || cfg_sizes - sizes = sizes instanceof Array ? sizes : [sizes] + if(sizes){ + sizes = sizes instanceof Array ? sizes : [sizes] + // normalize to preview size... + sizes = (this.config['preview-normalized'] ? + sizes + .map(function(s){ + return cfg_sizes.filter(function(c){ return c >= s }).pop() || s }) + : sizes) + .unique() - // normalize to preview size... - sizes = (this.config['preview-normalized'] ? - sizes - .map(function(s){ - return cfg_sizes.filter(function(c){ return c >= s }).pop() || s }) - : sizes) - .unique() + } else { + sizes = cfg_sizes + } var that = this return Promise.all(images.map(function(gid){ var data = that.images[gid] - var preview = data.preview = data.preview || {} var path = that.getImagePath(gid) - var img = sharp(path) + var preview = data.preview = data.preview || {} + var img = sharp(path) return img.metadata().then(function(metadata){ var orig_res = Math.max(metadata.width, metadata.height) return Promise.all(sizes.map(function(res){ - // skip if image is smaller than res... if(res >= orig_res){ return @@ -193,6 +196,7 @@ module.Sharp = core.ImageGridFeatures.Feature({ // - if image too large to set the preview to "loading..." // - create previews... // - update image... + /* ['updateImage.pre', function(gid){ var that = this @@ -216,6 +220,7 @@ module.Sharp = core.ImageGridFeatures.Feature({ }) } }] + //*/ ], }) diff --git a/ui (gen4)/features/ui-widgets.js b/ui (gen4)/features/ui-widgets.js index 472afb64..63c12e1e 100755 --- a/ui (gen4)/features/ui-widgets.js +++ b/ui (gen4)/features/ui-widgets.js @@ -1035,11 +1035,14 @@ var WidgetTestActions = actions.Actions({ make('---') + make('close parent') .on('open', function(){ that.parent.close() }) + make('...') + // NOTE: the dialog's .parent is not yet set at this point... // This will finalize the dialog...