Store user selected filePath on the Piskel instance stored in pskl.app.piskelController. Getter and Setter in PublicPiskelController for filePath.

This commit is contained in:
Lee Grey
2015-03-16 23:13:36 +13:00
parent fa6f2e5db6
commit b168e8ca76
3 changed files with 27 additions and 9 deletions

View File

@@ -136,6 +136,14 @@
return this.piskelController.piskel;
};
ns.PublicPiskelController.prototype.setSavePath = function (savePath) {
this.piskelController.piskel.savePath = savePath;
}
ns.PublicPiskelController.prototype.getSavePath = function () {
return this.piskelController.piskel.savePath;
}
ns.PublicPiskelController.prototype.raiseSaveStateEvent_ = function (fn, args) {
$.publish(Events.PISKEL_SAVE_STATE, {
type : pskl.service.HistoryService.REPLAY_NO_SNAPSHOT,

View File

@@ -165,15 +165,21 @@
ns.SaveController.prototype.saveFileDesktop_ = function () {
this.beforeSaving_();
var serialized = pskl.app.piskelController.serialize();
// TODO: hold on to the full path to the file:
var fullSavePath = null;
// TODO: if we already have a filename (and we are sure this is the same document!!!)
// then save over the old file without opening a save dialog (using nodejs 'fs' api)
pskl.utils.FileUtils.desktopSaveAs(serialized, null, function (filename) {
this.onSaveSuccess_();
this.afterSaving_();
fullSavePath = filename;
}.bind(this));
var savePath = pskl.app.piskelController.getSavePath();
// if we already have a filename, just save the file (using nodejs 'fs' api)
if (savePath !== null) {
pskl.utils.FileUtils.desktopSaveToFile(serialized, savePath, function () {
this.onSaveSuccess_();
this.afterSaving_();
}.bind(this));
} else {
// "save as" = open a save dialog, and store the returned save path
pskl.utils.FileUtils.desktopSaveAs(serialized, null, function (selectedSavePath) {
this.onSaveSuccess_();
this.afterSaving_();
pskl.app.piskelController.setSavePath(selectedSavePath);
}.bind(this));
}
}
ns.SaveController.prototype.getName = function () {

View File

@@ -20,6 +20,10 @@
this.height = height;
this.descriptor = descriptor;
/** @type {String} */
this.savePath = null;
} else {
throw 'Missing arguments in Piskel constructor : ' + Array.prototype.join.call(arguments, ",");
}