diff --git a/ui (gen4)/features/filesystem.js b/ui (gen4)/features/filesystem.js index 4b534dbe..5ce071d9 100755 --- a/ui (gen4)/features/filesystem.js +++ b/ui (gen4)/features/filesystem.js @@ -79,6 +79,17 @@ var FileSystemLoaderActions = actions.Actions({ loaded_paths: null, + // XXX should this be more general??? + reloadState: ['File/Reload viewer state...', + function(){ + if(this.location + && this.location.method + && this.location.path){ + return this[this.location.method](this.location.path) + } + }], + + // XXX is this a hack??? // XXX need a more generic form... checkPath: ['- File/', @@ -161,11 +172,6 @@ var FileSystemLoaderActions = actions.Actions({ for(var i=0; i < paths.length; i++){ var k = paths[i] - // XXX save dates... - // XXX not sure if this is the right way to go.... - res[k].__dates && console.log('DATES:', res[k].__dates) - res[k].__date && console.log('LOADED:', res[k].__date) - // skip empty indexes... // XXX should we rebuild or list here??? if(res[k].data == null || res[k].images == null){ @@ -215,6 +221,7 @@ var FileSystemLoaderActions = actions.Actions({ that.__location = { path: loaded.length == 1 ? loaded[0] : path, method: 'loadIndex', + from: from_date || 'all', } }) }], @@ -538,6 +545,74 @@ var FileSystemLoaderUIActions = actions.Actions({ // XXX should these be dialog objects??? browseIndex: ['File/Load index...', makeBrowseProxy('loadIndex')], browseImages: ['File/Load images...', makeBrowseProxy('loadImages')], + + // XXX add dialog to list sub-indexes... + // XXX + + // NOTE: this will show nothing if .location.method is not loadIndex.. + // + // XXX handle named saves... + // XXX add ability to name a save... + // XXX need to handle saves when loaded a specific history position... + listSaveHistoryDialog: ['File/List save history...', + widgets.makeUIDialog(function(){ + var that = this + + var o = browse.makeLister(null, function(path, make){ + var dialog = this + + // only search for history if we have an index loaded... + if(that.location.method != 'loadIndex'){ + make('No history...', null, true) + return + } + + var from = that.location.from + from = from && Date.fromTimeStamp(from).toShortDate() + + make('Load all') + .on('open', function(){ + that.reloadState() + }) + + make('---') + + that.loadSaveHistoryList() + .catch(function(err){ + // XXX + console.error(err) + }) + .then(function(data){ + var list = [] + + Object.keys(data).forEach(function(path){ + Object.keys(data[path]).forEach(function(d){ + list.push(d) + }) + }) + + list + .sort() + .reverse() + .forEach(function(d){ + var txt = Date.fromTimeStamp(d).toShortDate() + + // XXX get the save name... + make(txt) + .on('open', function(){ + that.loadIndex(that.location.path, d) + }) + // mark the current loaded position... + .addClass(txt == from ? 'highlighted selected' : '') + }) + }) + }) + .on('open', function(){ + o.parent.close() + }) + + return o + })], }) @@ -1442,14 +1517,11 @@ var FileSystemWriterUIActions = actions.Actions({ that.config['export-path'] || that.location.path) dialog.parent.close() }) + .addClass('selected') }) o.dom.addClass('metadata-view tail-action') - setTimeout(function(){ - o.select(-1) - }, 0) - return o })], }) diff --git a/ui (gen4)/features/history.js b/ui (gen4)/features/history.js index 3fd7c18d..a2e05fe4 100755 --- a/ui (gen4)/features/history.js +++ b/ui (gen4)/features/history.js @@ -421,14 +421,21 @@ var URLHistoryUIActions = actions.Actions({ var o = browse.makeLister(null, function(path, make){ - Object.keys(that.url_history) + var l = Object.keys(that.url_history) .reverse() // NOTE: this might get a little slow for // very large sets... - .forEach(function(p){ + .map(function(p){ make(p, {disabled: !that.checkURLFromHistory(p) }) .addClass(p == cur ? 'highlighted selected': '') - }) }, + }) + .length + + if(l == 0){ + make('No history...', null, true) + .find('.button').remove() + } + }, // add item buttons... { itemButtons: [ // move to top... diff --git a/ui (gen4)/features/keyboard.js b/ui (gen4)/features/keyboard.js index 34a781f0..fcda7f2f 100755 --- a/ui (gen4)/features/keyboard.js +++ b/ui (gen4)/features/keyboard.js @@ -140,6 +140,7 @@ module.GLOBAL_KEYBOARD = { H: { default: 'flipHorizontal', ctrl: 'listURLHistory', + 'ctrl+shift': 'listSaveHistoryDialog', alt: 'browseActions: "/History/" -- Open history menu', }, V: 'flipVertical', diff --git a/ui (gen4)/file.js b/ui (gen4)/file.js index 58181825..684eaac9 100755 --- a/ui (gen4)/file.js +++ b/ui (gen4)/file.js @@ -145,6 +145,7 @@ function loadJSON(path){ // ] // } // +// NOTE: this does not use the fs... var groupByDate = module.groupByDate = function(list){ @@ -170,6 +171,7 @@ function(list){ } + // Group file list by keyword... // // this will build a structure in the following format: @@ -192,6 +194,7 @@ function(list){ // the found JSON files. // // NOTE: all files past the first non-diff are skipped. +// NOTE: this does not use the fs... var groupByKeyword = module.groupByKeyword = function(list, from_date, logger){ @@ -205,7 +208,7 @@ function(list, from_date, logger){ .reverse() // skip dates before from_date... // NOTE: from_date is included... - .filter(function(d){ return from_date ? d <= from_date : true }) + .filter(function(d){ return from_date ? d <= from_date || d == 'root' : true }) .forEach(function(d){ dates[d] .sort() @@ -262,10 +265,6 @@ function(list, from_date, logger){ index[k] = index[k].map(function(e){ return e[1] }) } - // XXX revise... - index.__dates = Object.keys(dates) - index.__date = Object.keys(date)[0] - logger && logger.emit('files-queued', queued, index) return index @@ -273,11 +272,19 @@ function(list, from_date, logger){ -// XXX not yet working... +// Load index data listed by timestamp... +// +// NOTE: this returns data similar to groupByDate(..) but will replace +// the 'root' key with a timestamp... +// NOTE: this will include the full history. this is different to what +// groupByKeyword(..) does. +// // XXX handle errors.... var loadSaveHistoryList = module.loadSaveHistoryList = -function(path){ +function(path, index_dir){ + index_dir = index_dir || INDEX_DIR + return new Promise(function(resolve, reject){ // direct index... if(pathlib.basename(path) == index_dir){ @@ -287,9 +294,16 @@ function(path){ logger && logger.emit('error', err) }) .on('end', function(files){ - var res = {} + var data = groupByDate(files) - resolve(Object.keys(groupByDate(files))) + // XXX should we mark the root timestamp in any way??? + if('root' in data && data.root.length > 0){ + // XXX handle stat error... + data[fse.statSync(data.root[0]).birthtime.getTimeStamp()] = data.root + delete data.root + } + + resolve(data) }) // need to locate indexes... @@ -313,7 +327,7 @@ function(path){ // we do not need to include the index // itself in the base path... var p = path.split(index_dir)[0] - res[p] = obj[path] + res[p] = obj })) }) // done... diff --git a/ui (gen4)/lib/widget/browse.js b/ui (gen4)/lib/widget/browse.js index 62120952..0b3a9117 100755 --- a/ui (gen4)/lib/widget/browse.js +++ b/ui (gen4)/lib/widget/browse.js @@ -554,7 +554,15 @@ var BrowserPrototype = { .toArray() }, set path(value){ - this.update(value) + // XXX check if path has changed... + value = this.path2list(value) + var cur = this.path + + // update only if path is different... + value.length == cur.length + && cur + .filter(function(e, i){ return e == value[i] }).length != cur.length + && this.update(value) }, // String path...