From 36b2e540f06cef3887e7d0fea60527fee51e2a40 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Wed, 8 Feb 2012 15:36:53 -0800 Subject: fixed undo/redo for each code view document, changed new file integration with io mediator Signed-off-by: Ananya Sen --- js/stage/stage-view.reel/stage-view.js | 83 +++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 37 deletions(-) (limited to 'js/stage/stage-view.reel') diff --git a/js/stage/stage-view.reel/stage-view.js b/js/stage/stage-view.reel/stage-view.js index f8817b13..1e85b4fd 100755 --- a/js/stage/stage-view.reel/stage-view.js +++ b/js/stage/stage-view.reel/stage-view.js @@ -76,7 +76,6 @@ exports.StageView = Montage.create(Component, { // Temporary function to create a Codemirror text view createTextView: { value: function(doc) { - this.application.ninja.documentController.activeDocument.save(true /*remove the codemirror div after saving*/); this.application.ninja.documentController._hideCurrentDocument(); this.hideOtherDocuments(doc.uuid); var type; @@ -93,13 +92,12 @@ exports.StageView = Montage.create(Component, { document.getElementById("codeMirror_"+doc.uuid).style.display="block"; var documentController = this.application.ninja.documentController; - doc.editor = CodeMirror.fromTextArea(doc.textArea, { lineNumbers: true, mode: type, onChange: function(){ var historySize = doc.editor.historySize(); - if((historySize.undo===0 && historySize.redo===0) || (historySize.undo>0)){ + if(historySize.undo>0){ doc.dirtyFlag=true; }else if(historySize.undo===0 && historySize.redo>0){ doc.dirtyFlag=false; @@ -122,16 +120,11 @@ exports.StageView = Montage.create(Component, { switchDocument:{ value: function(doc){ - this.application.ninja.documentController.activeDocument.save(true /*remove the codemirror div after saving*/); - - 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); + //save editor cursor position + if(!!this.application.ninja.documentController.activeDocument.editor){ + this.application.ninja.documentController.activeDocument.hline = this.application.ninja.documentController.activeDocument.editor.getCursor(true); } - + this.application.ninja.documentController._hideCurrentDocument(); this.application.ninja.documentController.activeDocument = doc; @@ -140,34 +133,15 @@ exports.StageView = Montage.create(Component, { var documentController = this.application.ninja.documentController; - if(this.application.ninja.documentController.activeDocument.currentView === "code"){ - var type; - switch(doc.documentType) { - case "css" : - type = "css"; - break; - case "js" : - type = "javascript"; - break; - } - - //add the codemirror div again for editting - doc.editor = CodeMirror.fromTextArea(doc.textArea, { - lineNumbers: true, - mode: type, - 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"); - } - }); - - //this.application.ninja.documentController._codeEditor.hline = this.application.ninja.documentController._codeEditor.editor.setLineClass(0, "activeline"); + //restore editor cursor position + if(!!this.application.ninja.documentController.activeDocument.editor){ + this.application.ninja.documentController.activeDocument.editor.setCursor(this.application.ninja.documentController.activeDocument.hline); + document.getElementById("codeMirror_"+this.application.ninja.documentController.activeDocument.uuid).getElementsByClassName("CodeMirror")[0].focus(); } - if(this.application.ninja.documentController.activeDocument.documentType === "htm" || this.application.ninja.documentController.activeDocument.documentType === "html") { + if(this.application.ninja.documentController.activeDocument.currentView === "design") { this.application.ninja.stage._scrollFlag = true; // TODO HACK to prevent type error on Hide/Show Iframe - + this.application.ninja.currentDocument = this.application.ninja.documentController.activeDocument; // TODO dispatch event here // appDelegateModule.MyAppDelegate.onSetActiveDocument(); @@ -232,5 +206,40 @@ exports.StageView = Montage.create(Component, { this.application.ninja.rulerTop.style.display = "none"; this.application.ninja.rulerLeft.style.display = "none"; } + }, + + switchViews: { + value: function() { + + //save file if dirty + + this.application.ninja.stage.saveStageScroll(); + this.application.ninja.documentController._hideCurrentDocument(); + + if(this.application.ninja.documentController.activeDocument.currentView === "design") { + this.application.ninja.documentController._textHolder.style.display = "none"; + this.application.ninja.documentController.activeDocument.container.style["display"] = "block"; + this.application.ninja.stage._scrollFlag = true; + //this._showCurrentDocument(); + this.application.ninja.stage.applySavedScroll(); + + } else { + this.application.ninja.stage._scrollFlag = false; // TODO HACK to prevent type error on Hide/Show Iframe + + var codeview = this.application.ninja.documentController.activeDocument.container; + //this._textHolder.style.display = "block"; + //codeview.firstChild.innerHTML = this.activeDocument.iframe.contentWindow.document.body.parentNode.innerHTML; + +// this._codeEditor.editor = CodeMirror.fromTextArea(codeview.firstChild, { +// lineNumbers: true, +// mode: "htmlmixed", +// onCursorActivity: function() { +// DocumentController._codeEditor.editor.setLineClass(DocumentController._codeEditor.hline, null); +// DocumentController._codeEditor.hline = DocumentController._codeEditor.editor.setLineClass(DocumentController._codeEditor.editor.getCursor().line, "activeline"); +// } +// }); +// this._codeEditor.hline = DocumentController._codeEditor.editor.setLineClass(0, "activeline"); + } + } } }); \ No newline at end of file -- cgit v1.2.3