From e065244ac75d1d0f25fd5c75cb58e714a13fe16b Mon Sep 17 00:00:00 2001 From: Jonathan Duran Date: Wed, 14 Mar 2012 08:59:17 -0700 Subject: Squashed commit of the following: merge master into timeline Signed-off-by: Jonathan Duran --- js/controllers/document-controller.js | 50 ++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 4 deletions(-) (limited to 'js/controllers/document-controller.js') diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index a8056519..87e93465 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -60,8 +60,9 @@ var DocumentController = exports.DocumentController = Montage.create(Component, this.eventManager.addEventListener("executeSave", this, false); this.eventManager.addEventListener("executeSaveAs", this, false); this.eventManager.addEventListener("executeSaveAll", this, false); + this.eventManager.addEventListener("executeFileClose", this, false); - this.eventManager.addEventListener("recordStyleChanged", this, false); + this.eventManager.addEventListener("styleSheetDirty", this, false); } }, @@ -157,17 +158,29 @@ var DocumentController = exports.DocumentController = Montage.create(Component, if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ saveAsSettings.fileName = this.activeDocument.name; saveAsSettings.folderUri = this.activeDocument.uri.substring(0, this.activeDocument.uri.lastIndexOf("/")); - //add callback + saveAsSettings.callback = this.saveAsCallback.bind(this); this.application.ninja.newFileController.showSaveAsDialog(saveAsSettings); } } }, - + //////////////////////////////////////////////////////////////////// + handleExecuteFileClose:{ + value: function(event) { + if(this.activeDocument && this.application.ninja.coreIoApi.cloudAvailable()){ + this.closeDocument(this.activeDocument.uuid); + } + } + }, + //////////////////////////////////////////////////////////////////// // fileSaveResult: { value: function (result) { - if(result.status === 204){ + if((result.status === 204) || (result.status === 404)){//204=>existing file || 404=>new file... saved this.activeDocument.needsSave = false; + if(this.application.ninja.currentDocument !== null){ + //clear Dirty StyleSheets for the saved document + this.application.ninja.stylesController.clearDirtyStyleSheets(this.application.ninja.currentDocument); + } } } }, @@ -249,6 +262,29 @@ var DocumentController = exports.DocumentController = Montage.create(Component, }, //////////////////////////////////////////////////////////////////// // + saveAsCallback:{ + value:function(saveAsDetails){ + var fileUri = null, filename = saveAsDetails.filename, destination = saveAsDetails.destination; + //update document metadata + this.activeDocument.name = ""+filename; + //prepare new file uri + if(destination && (destination.charAt(destination.length -1) !== "/")){ + destination = destination + "/"; + } + fileUri = destination+filename; + + this.activeDocument.uri = fileUri; + //save a new file + //use the ioMediator.fileSaveAll when implemented + this.activeDocument._userDocument.name=filename; + this.activeDocument._userDocument.root=destination; + this.activeDocument._userDocument.uri=fileUri; + this.application.ninja.ioMediator.fileSave(this.activeDocument.save(), this.fileSaveResult.bind(this)); + // + } + }, + + //////////////////////////////////////////////////////////////////// openDocument: { value: function(doc) { @@ -515,5 +551,11 @@ var DocumentController = exports.DocumentController = Montage.create(Component, value: function() { return "userDocument_" + (this._iframeCounter++); } + }, + + handleStyleSheetDirty:{ + value:function(){ + this.activeDocument.needsSave = true; } + } }); -- cgit v1.2.3