From 5e7fafd9c51139b111c630b95b6c511dc367459f Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Thu, 8 Aug 2013 23:38:33 +0400 Subject: [PATCH] more tweaking of the crop api in connection with saving and loading data... Signed-off-by: Alex A. Naanou --- ui/data.js | 23 +++++++++++++++-------- ui/files.js | 5 ++++- ui/localstorage.js | 6 +++++- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/ui/data.js b/ui/data.js index 59167ea1..e7cc4cad 100755 --- a/ui/data.js +++ b/ui/data.js @@ -1157,7 +1157,7 @@ function getPrevLocation(){ /******************************************************* Crop Data ***/ function isViewCropped(){ - return !(CROP_STACK.length == 0) + return CROP_STACK.length != 0 } @@ -1170,10 +1170,9 @@ function getAllData(){ } -// XXX make keep_ribbons option work... +// NOTE: this will not update .current state... +// XXX should this set the .current to anything but null or the first elem??? function makeCroppedData(gids, keep_ribbons){ - var cur = DATA.current - var old_data = DATA var res = { varsion: '2.0', current: null, @@ -1196,20 +1195,21 @@ function makeCroppedData(gids, keep_ribbons){ }) } - cur = getGIDBefore(cur, 0) - cur = cur == null ? gids[0] : cur - res.current = cur - return res } function cropDataTo(gids, keep_ribbons){ var prev_state = DATA + var cur = DATA.current CROP_STACK.push(prev_state) DATA = makeCroppedData(gids, keep_ribbons) + cur = getGIDBefore(cur) + cur = cur == null ? gids[0] : cur + DATA.current = cur + reloadViewer() updateImages() @@ -1242,10 +1242,17 @@ function uncropData(){ function showAllData(){ var prev_state = DATA + var cur = DATA.current DATA = getAllData() CROP_STACK = [] + // XXX do we need to check if this exists??? + // ...in theory, as long as there are no global destructive + // operations, no. + // keep the current position... + DATA.current = cur + reloadViewer() updateImages() diff --git a/ui/files.js b/ui/files.js index 2131e078..6525d5ab 100755 --- a/ui/files.js +++ b/ui/files.js @@ -438,7 +438,10 @@ function saveFileState(name, no_normalize_path){ } } - dumpJSON(name + '-data.json', getAllData()) + var data = getAllData() + data.current = DATA.current + + dumpJSON(name + '-data.json', data) // XXX do we need to do this??? saveFileMarks(name) diff --git a/ui/localstorage.js b/ui/localstorage.js index c05dcdc5..ce3174a7 100755 --- a/ui/localstorage.js +++ b/ui/localstorage.js @@ -48,7 +48,11 @@ function loadLocalStorageData(attr){ } function saveLocalStorageData(attr){ attr = attr == null ? DATA_ATTR : attr - localStorage[attr] = JSON.stringify(getAllData()) + + var data = getAllData() + data.current = DATA.current + + localStorage[attr] = JSON.stringify(data) saveLocalStorageBaseURL(attr) }