From 3c7e772203dc35f7731ba6d224cf26d2a4135135 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Thu, 5 Dec 2013 04:22:31 +0400 Subject: [PATCH] added history pruning -- removal of non-existant paths, not sure if this strategy is good enough... Signed-off-by: Alex A. Naanou --- ui/compatibility.js | 1 - ui/urlhistory.js | 18 +++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/ui/compatibility.js b/ui/compatibility.js index ee3bce11..7ab0ac31 100755 --- a/ui/compatibility.js +++ b/ui/compatibility.js @@ -58,7 +58,6 @@ if(window.CEF_dumpJSON != null){ // paths to included utils... execPathPush('./vips/bin') - // Things ImageGrid needs... // XXX do we need assync versions?? window.listDir = function(path){ diff --git a/ui/urlhistory.js b/ui/urlhistory.js index d10ba348..a9ae5d22 100755 --- a/ui/urlhistory.js +++ b/ui/urlhistory.js @@ -18,6 +18,18 @@ var BASE_URL_LIMIT = 10 * URL history... */ +// XXX this depends on fs.existsSync(...) +function pruneBaseURLHistory(){ + if(window.fs == null){ + return BASE_URL_HISTORY + } + BASE_URL_HISTORY = BASE_URL_HISTORY.filter(function(e){ + return fs.existsSync(osPath(e)) + }) + return BASE_URL_HISTORY +} + + // Setup history event handlers... // // NOTE: this will save history state to localStorage... @@ -26,6 +38,8 @@ function setupBaseURLHistory(){ .on('baseURLChanged', function(evt, old_url, new_url){ var updated = false + pruneBaseURLHistory() + // store the old and new urls in history unless they already // exist... if(BASE_URL_HISTORY.indexOf(old_url) < 0){ @@ -102,6 +116,7 @@ function getURLHistoryPrev(){ // NOTE: this will not affect history url order... function makeURLHistoryLoader(get, end_msg){ return function(){ + pruneBaseURLHistory() var url = get() if(url != BASE_URL){ statusNotify(loadDir(url)) @@ -118,7 +133,8 @@ var loadURLHistoryPrev = makeURLHistoryLoader(getURLHistoryPrev, 'at first URL') // NOTE: this can accept either path or history index... // NOTE: this will not reload an already loaded url... function loadURLHistoryAt(a){ - a = a < 0 ? BASE_URL_HISTORY + a : a + pruneBaseURLHistory() + a = a < 0 ? BASE_URL_HISTORY.length + a : a var url = typeof(a) == typeof(123) ? Math.min(a < 0 ? 0 : a, BASE_URL_HISTORY.length-1) : a if(url != BASE_URL){ statusNotify(loadDir(url))