diff --git a/ui (gen4)/lib/widget/browse-walk.js b/ui (gen4)/lib/widget/browse-walk.js index 90f8ee77..0527748d 100755 --- a/ui (gen4)/lib/widget/browse-walk.js +++ b/ui (gen4)/lib/widget/browse-walk.js @@ -6,7 +6,8 @@ var fs = require('fs') var path = require('path') -var walk = require('glob') +var promise = require('promise') +var glob = require('glob') var guaranteeEvents = require('guarantee-events') define(function(require){ var module = {} @@ -64,24 +65,40 @@ function(path, make){ path = /^[a-zA-Z]:$/.test(path.trim()) ? path+'/' : path var fullpath = false + var stat = promise.denodeify(fs.stat) - fs.readdir(path, function(err, files){ - // XXX - if(err){ - return - } + return new promise(function(resolve, reject){ + fs.readdir(path, function(err, files){ + // XXX + if(err){ + reject(err) + return + } + var res = [] - files.forEach(function(file){ - fs.stat(path +'/'+ file, function(err, stat){ - if(err){ - make(fullpath - ? path +'/'+ file - : file, null, true) - } else { - make(fullpath - ? path +'/'+ file - : file + (stat.isDirectory() ? '/' : '')) - } + files.map(function(file){ + return stat(path +'/'+ file) + .catch(function(err){ + make(fullpath + ? path +'/'+ file + : file, null, true) + }) + .then(function(res){ + if(!res){ + return + } + make(fullpath + ? path +'/'+ file + : file + (res.isDirectory() ? '/' : '')) + }) + // NOTE: we are not using promise.all(..) here because it + // triggers BEFORE the first make(..) is called... + .then(function(){ + res.push(file) + if(res.length == files.length){ + resolve() + } + }) }) }) }) diff --git a/ui (gen4)/lib/widget/browse.js b/ui (gen4)/lib/widget/browse.js index 2a8b9731..70a64b5c 100755 --- a/ui (gen4)/lib/widget/browse.js +++ b/ui (gen4)/lib/widget/browse.js @@ -19,6 +19,8 @@ define(function(require){ var module = {} console.log('>>> browse') +//var promise = require('promise') + var keyboard = require('../keyboard') var object = require('../../object') var widget = require('./widget') @@ -374,7 +376,7 @@ var BrowserPrototype = { .toArray() }, set path(value){ - return this.update(value) + this.update(value) }, // String path... @@ -462,6 +464,7 @@ var BrowserPrototype = { // - build the path // - build the element list // - bind to control events + // - return a deferred // // This will trigger the 'update' event. // @@ -500,6 +503,8 @@ var BrowserPrototype = { var focus = browser.find(':focus').length > 0 list = list || this.list + var deferred = $.Deferred() + // string path and terminated with '/' -- no selection... if(typeof(path) == typeof('str') && !/[\\\/]/.test(path.trim().slice(-1))){ path = this.path2list(path) @@ -522,10 +527,13 @@ var BrowserPrototype = { p.append($('