From 729bc48212d7244539c99ca206be673eed011115 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Mon, 6 Feb 2012 16:07:46 -0800 Subject: integrated save for the document tabs, detect codemirror history to show document dirty indicator. Signed-off-by: Ananya Sen --- js/data/menu-data.js | 6 ++++-- js/io/document/document-controller.js | 19 +++++++++++++------ js/io/document/text-document.js | 1 + js/stage/stage-view.reel/stage-view.js | 29 +++++++++++++++++++---------- js/stage/stage.reel/stage.js | 15 +++++++++++++++ 5 files changed, 52 insertions(+), 18 deletions(-) diff --git a/js/data/menu-data.js b/js/data/menu-data.js index bafc30da..07337fa0 100755 --- a/js/data/menu-data.js +++ b/js/data/menu-data.js @@ -37,7 +37,8 @@ exports.MenuData = Montage.create( Montage, { { "displayText" : "Save", "hasSubMenu" : false, - "enabled": true + "enabled": true, + "action": "executeSave" }, { "displayText" : "Save As", @@ -48,7 +49,8 @@ exports.MenuData = Montage.create( Montage, { { "displayText" : "Save All", "hasSubMenu" : false, - "enabled": true + "enabled": true, + "action": "executeSaveAll" }, { "displayText" : "", diff --git a/js/io/document/document-controller.js b/js/io/document/document-controller.js index 51575a24..1a5d6058 100755 --- a/js/io/document/document-controller.js +++ b/js/io/document/document-controller.js @@ -72,6 +72,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, this.eventManager.addEventListener("appLoaded", this, false); this.eventManager.addEventListener("executeFileOpen", this, false); this.eventManager.addEventListener("executeNewFile", this, false); + this.eventManager.addEventListener("executeSave", this, false); } }, @@ -87,8 +88,6 @@ var DocumentController = exports.DocumentController = Montage.create(Component, pickerSettings.callback = this.openFileWithURI; pickerSettings.callbackScope = this; this.application.ninja.filePickerController.showFilePicker(pickerSettings); - - //this.openDocument({"type": "js", "source": this.tmpSourceForTesting}); } }, @@ -101,6 +100,12 @@ var DocumentController = exports.DocumentController = Montage.create(Component, } }, + handleExecuteSave: { + value: function(event) { + this.activeDocument.save(); + } + }, + createNewFile:{ value:function(newFileObj){ //console.log(newFileObj);//contains the template uri and the new file uri @@ -240,7 +245,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, //if file dirty then save if(this.activeDocument.dirtyFlag === true){ - this.activeDocument.save(true); + this.activeDocument.save(true /*remove the codemirror div after saving*/); this.activeDocument.dirtyFlag=false; } @@ -382,12 +387,13 @@ var DocumentController = exports.DocumentController = Montage.create(Component, _hideCurrentDocument: { value: function() { if(this.activeDocument) { - this.activeDocument.container.style["display"] = "none"; - if(this.activeDocument.currentView === "design" || this.activeDocument.currentView === "design"){ + if(this.activeDocument.currentView === "design"){ + this.application.ninja.stage.saveStageScroll(); this.activeDocument.container.parentNode.style["display"] = "none"; this.application.ninja.stage.hideCanvas(true); this.application.ninja.stage.stageView.hideRulers(); } + this.activeDocument.container.style["display"] = "none"; } } }, @@ -396,8 +402,9 @@ var DocumentController = exports.DocumentController = Montage.create(Component, value: function() { if(this.activeDocument) { this.activeDocument.container.style["display"] = "block"; - if(this.activeDocument.currentView === "design" || this.activeDocument.currentView === "design"){ + if(this.activeDocument.currentView === "design"){ this.activeDocument.container.parentNode.style["display"] = "block"; + this.application.ninja.stage.applySavedScroll(); this.application.ninja.stage.hideCanvas(false); this.application.ninja.stage.stageView.showRulers(); } diff --git a/js/io/document/text-document.js b/js/io/document/text-document.js index 683c513c..7db8e91a 100755 --- a/js/io/document/text-document.js +++ b/js/io/document/text-document.js @@ -100,6 +100,7 @@ var TextDocument = exports.TextDocument = Montage.create(baseDocumentModule.Base var codemirrorDiv = this.textArea.parentNode.querySelector(".CodeMirror"); if(!!codemirrorDiv){codemirrorDiv.parentNode.removeChild(codemirrorDiv);} } + //console.log("$$$saved : "+this.uri+" : "+this.textArea.value); //persist to filesystem } } diff --git a/js/stage/stage-view.reel/stage-view.js b/js/stage/stage-view.reel/stage-view.js index 6f20b87b..f8817b13 100755 --- a/js/stage/stage-view.reel/stage-view.js +++ b/js/stage/stage-view.reel/stage-view.js @@ -76,10 +76,7 @@ exports.StageView = Montage.create(Component, { // Temporary function to create a Codemirror text view createTextView: { value: function(doc) { - //save current document - if(this.application.ninja.documentController.activeDocument.currentView === "code"){ - this.application.ninja.documentController.activeDocument.save(true); - } + this.application.ninja.documentController.activeDocument.save(true /*remove the codemirror div after saving*/); this.application.ninja.documentController._hideCurrentDocument(); this.hideOtherDocuments(doc.uuid); var type; @@ -100,7 +97,14 @@ exports.StageView = Montage.create(Component, { doc.editor = CodeMirror.fromTextArea(doc.textArea, { lineNumbers: true, mode: type, - onChange: function(){doc.dirtyFlag=true;}, + onChange: function(){ + var historySize = doc.editor.historySize(); + if((historySize.undo===0 && historySize.redo===0) || (historySize.undo>0)){ + doc.dirtyFlag=true; + }else if(historySize.undo===0 && historySize.redo>0){ + doc.dirtyFlag=false; + } + }, onCursorActivity: function() { //documentController._codeEditor.editor.setLineClass(documentController._codeEditor.hline, null); //documentController._codeEditor.hline = documentController._codeEditor.editor.setLineClass(documentController._codeEditor.editor.getCursor().line, "activeline"); @@ -118,13 +122,16 @@ exports.StageView = Montage.create(Component, { switchDocument:{ value: function(doc){ + this.application.ninja.documentController.activeDocument.save(true /*remove the codemirror div after saving*/); - //if dirty SAVE codemirror into textarea - if(this.application.ninja.documentController.activeDocument.currentView === "code"){ - this.application.ninja.documentController.activeDocument.save(true); + this.application.ninja.documentController._hideCurrentDocument(); + + + if(this.application.ninja.documentController.activeDocument.currentView === "design"){ + console.log("scrollLeft: "+ this.application.ninja.stage._iframeContainer.scrollLeft); + console.log("scrollTop: "+ this.application.ninja.stage._iframeContainer.scrollTop); } - this.application.ninja.documentController._hideCurrentDocument(); this.application.ninja.documentController.activeDocument = doc; @@ -148,7 +155,7 @@ exports.StageView = Montage.create(Component, { doc.editor = CodeMirror.fromTextArea(doc.textArea, { lineNumbers: true, mode: type, - onChange: function(){doc.dirtyFlag=true;}, + onChange: function(){doc.dirtyFlag=true;console.log("undo stack:",doc.editor.historySize());}, onCursorActivity: function() { //documentController._codeEditor.editor.setLineClass(documentController._codeEditor.hline, null); //documentController._codeEditor.hline = documentController._codeEditor.editor.setLineClass(documentController._codeEditor.editor.getCursor().line, "activeline"); @@ -160,6 +167,8 @@ exports.StageView = Montage.create(Component, { if(this.application.ninja.documentController.activeDocument.documentType === "htm" || this.application.ninja.documentController.activeDocument.documentType === "html") { this.application.ninja.stage._scrollFlag = true; // TODO HACK to prevent type error on Hide/Show Iframe + + // TODO dispatch event here // appDelegateModule.MyAppDelegate.onSetActiveDocument(); } diff --git a/js/stage/stage.reel/stage.js b/js/stage/stage.reel/stage.js index 9e2df5a2..4364b45d 100755 --- a/js/stage/stage.reel/stage.js +++ b/js/stage/stage.reel/stage.js @@ -876,5 +876,20 @@ exports.Stage = Montage.create(Component, { this.stageDeps.snapManager.updateWorkingPlaneFromView(); } + }, + + saveStageScroll:{ + value: function(){ + this.savedLeftScroll = this._iframeContainer.scrollLeft; + this.savedTopScroll = this._iframeContainer.scrollTop; + } + }, + applySavedScroll:{ + value: function(){ + this._iframeContainer.scrollLeft = this.savedLeftScroll; + this._scrollLeft = this.savedLeftScroll; + this._iframeContainer.scrollTop = this.savedTopScroll; + this._scrollTop = this.savedTopScroll; + } } }); \ No newline at end of file -- cgit v1.2.3