From 1daf146c849a0a8dbd2b61b14218c9a39bdee3a7 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Fri, 3 Feb 2012 17:22:48 -0800 Subject: added editor tab save while switching code view tabs, integrated new file dialog with io mediator to open the new file in a new tab Signed-off-by: Ananya Sen --- js/io/document/base-document.js | 7 +++++- js/io/document/document-controller.js | 41 ++++++++++++++++++++++++++++++----- js/io/document/html-document.js | 28 ++++++++++++++++++++++++ js/io/document/text-document.js | 16 ++++++++++++++ 4 files changed, 86 insertions(+), 6 deletions(-) (limited to 'js/io/document') diff --git a/js/io/document/base-document.js b/js/io/document/base-document.js index d3601de5..ecc92447 100755 --- a/js/io/document/base-document.js +++ b/js/io/document/base-document.js @@ -87,7 +87,12 @@ var BaseDocument = exports.BaseDocument = Montage.create(Montage, { value: function() { // Have the XHR here? } - } + }, + save:{ + value:function(){ + //base function - to be overridden + } + } }); \ No newline at end of file diff --git a/js/io/document/document-controller.js b/js/io/document/document-controller.js index 7cc0eeeb..b900dee4 100755 --- a/js/io/document/document-controller.js +++ b/js/io/document/document-controller.js @@ -103,7 +103,32 @@ var DocumentController = exports.DocumentController = Montage.create(Component, createNewFile:{ value:function(newFileObj){ - //console.log(newFileObj); + //console.log(newFileObj);//contains the template uri and the new file uri + if(!newFileObj) return; + this.application.ninja.ioMediator.fileNew(newFileObj.newFilePath, newFileObj.fileTemplateUri, this.openNewFile, this); + + if((newFileObj.fileExtension !== ".html") && (newFileObj.fileExtension !== ".htm")){//open code view + + }else{ + //open design view + } + } + }, + + /** + * Public method + * doc contains: + * type : file type, like js, css, etc + * name : file name + * source : file content + * uri : file uri + */ + openNewFile:{ + value:function(doc){ + if(!doc){ + doc = {"type": "js", "name": "filename", "source": "test file content", "uri": "/fs/fsd/"} ; + } + this.openDocument(doc); } }, @@ -160,7 +185,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, newDoc.initialize(doc, docUuid, textArea, textArea.parentNode); // Tmp this will be filled with the real content - newDoc.textArea.innerHTML = doc.source; //this.tmpSourceForTesting; + newDoc.textArea.value = doc.source; //this.tmpSourceForTesting; this.textDocumentOpened(newDoc); @@ -175,7 +200,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, textDocumentOpened: { value: function(doc) { - this.activeDocument = doc; + this.application.ninja.stage.stageView.createTextView(doc); @@ -377,7 +402,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component, value: function() { if(this.activeDocument) { this.activeDocument.container.style["display"] = "none"; - //if(this.activeDocument.documentType === "htm" || this.activeDocument.documentType === "html") this.application.ninja.stage.toggleCanvas(); + if(this.activeDocument.currentView === "design" || this.activeDocument.currentView === "design"){ + this.activeDocument.container.parentNode.style["display"] = "none"; + this.application.ninja.stage.hideCanvas(true); + } } } }, @@ -386,7 +414,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component, value: function() { if(this.activeDocument) { this.activeDocument.container.style["display"] = "block"; - //if(this.activeDocument.documentType === "htm" || this.activeDocument.documentType === "html") this.application.ninja.stage.toggleCanvas(); + if(this.activeDocument.currentView === "design" || this.activeDocument.currentView === "design"){ + this.activeDocument.container.parentNode.style["display"] = "block"; + this.application.ninja.stage.hideCanvas(false); + } } } }, diff --git a/js/io/document/html-document.js b/js/io/document/html-document.js index fc7dd05b..24d4e7e4 100755 --- a/js/io/document/html-document.js +++ b/js/io/document/html-document.js @@ -43,9 +43,16 @@ var HTMLDocument = exports.HTMLDocument = Montage.create(baseDocumentModule.Base } }, + // PUBLIC MEMBERS cssLoadInterval: { value: null, enumerable: false }, + codeViewDocument:{ + writable: true, + enumerable: true, + value:null + }, + /* * PUBLIC API */ @@ -432,5 +439,26 @@ var HTMLDocument = exports.HTMLDocument = Montage.create(baseDocumentModule.Base */ } } + }, + + /** + * public method + * parameter: + * removeCodeMirrorDivFlag - for code view, tell to remove the codemirror div after saving + */ + save:{ + value:function(removeCodeMirrorDivFlag){ + if(this.currentView === "design"){ + //generate html and save + }else if((this.currentView === "code") && (this.codeViewDocument !== null)){ + if(removeCodeMirrorDivFlag === true){ + this.codeViewDocument.save(true); + }else{ + this.codeViewDocument.save(); + } + //persist to filesystem + } + + } } }); \ No newline at end of file diff --git a/js/io/document/text-document.js b/js/io/document/text-document.js index 156aaacb..a768779f 100755 --- a/js/io/document/text-document.js +++ b/js/io/document/text-document.js @@ -85,6 +85,22 @@ var TextDocument = exports.TextDocument = Montage.create(baseDocumentModule.Base xhr.send(''); } + }, + + /** + * public method + * parameter: + * removeCodeMirrorDivFlag - for code view, tell to remove the codemirror div after saving + */ + save:{ + value:function(removeCodeMirrorDivFlag){ + this.editor.save(); + if(removeCodeMirrorDivFlag === true){ + var codemirrorDiv = this.textArea.parentNode.querySelector(".CodeMirror"); + if(!!codemirrorDiv){codemirrorDiv.parentNode.removeChild(codemirrorDiv);} + } + //persist to filesystem + } } }); \ No newline at end of file -- cgit v1.2.3