From c9b581f6dbc920636256fe69b7dff0975c43979b Mon Sep 17 00:00:00 2001 From: Lee Grey Date: Sun, 22 Mar 2015 00:39:23 +1300 Subject: [PATCH] When running in Node-Webkit, hold onto the full savePath when opening.piskel files via the gui or drag and drop. --- src/js/service/DesktopStorageService.js | 6 +++--- src/js/service/HistoryService.js | 1 - src/js/utils/PiskelFileUtils.js | 13 ++++++++++++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/js/service/DesktopStorageService.js b/src/js/service/DesktopStorageService.js index c26a1e70..940b7bcd 100644 --- a/src/js/service/DesktopStorageService.js +++ b/src/js/service/DesktopStorageService.js @@ -34,12 +34,12 @@ ns.DesktopStorageService.prototype.openPiskel = function () { pskl.utils.FileUtilsDesktop.chooseFileDialog(function(filename){ - var chosenFilename = filename; - pskl.utils.FileUtilsDesktop.readFile(chosenFilename, function(content){ + var savePath = filename; + pskl.utils.FileUtilsDesktop.readFile(savePath, function(content){ pskl.utils.PiskelFileUtils.decodePiskelFile(content, function (piskel, descriptor, fps) { piskel.setDescriptor(descriptor); // store save path so we can re-save without opening the save dialog - piskel.savePath = chosenFilename; + piskel.savePath = savePath; pskl.app.piskelController.setPiskel(piskel); pskl.app.animationController.setFPS(fps); }); diff --git a/src/js/service/HistoryService.js b/src/js/service/HistoryService.js index 75281953..94d11bd9 100644 --- a/src/js/service/HistoryService.js +++ b/src/js/service/HistoryService.js @@ -8,7 +8,6 @@ this.stateQueue = []; this.currentIndex = -1; - this.lastLoadState = -1; this.saveNextAsSnapshot = false; diff --git a/src/js/utils/PiskelFileUtils.js b/src/js/utils/PiskelFileUtils.js index c236583c..009f1355 100644 --- a/src/js/utils/PiskelFileUtils.js +++ b/src/js/utils/PiskelFileUtils.js @@ -13,7 +13,18 @@ loadFromFile : function (file, onSuccess, onError) { pskl.utils.FileUtils.readFile(file, function (content) { var rawPiskel = pskl.utils.Base64.toText(content); - ns.PiskelFileUtils.decodePiskelFile(rawPiskel, onSuccess, onError); + ns.PiskelFileUtils.decodePiskelFile( + rawPiskel, + function (piskel, descriptor, fps) { + // if using Node-Webkit, store the savePath on load + // Note: the 'path' property is unique to Node-Webkit, and holds the full path + if (pskl.utils.Environment.detectNodeWebkit()) { + piskel.savePath = file.path; + } + onSuccess(piskel, descriptor, fps); + }, + onError + ); }); },