diff options
author | Jose Antonio Marquez Russo | 2012-02-08 15:45:21 -0800 |
---|---|---|
committer | Jose Antonio Marquez Russo | 2012-02-08 15:45:21 -0800 |
commit | fb4fdc82afe9ef62402fa3f2ccb5c291f703c7a8 (patch) | |
tree | 92a796e34530d1a724ddb24ef22e59ffef13c12a /js/stage/stage-view.reel | |
parent | 5a69d5be181ea98fa842977885ebd8c861dda6ca (diff) | |
parent | ab6f2f7ada39a9b27408575af9a565daf0a9d291 (diff) | |
download | ninja-fb4fdc82afe9ef62402fa3f2ccb5c291f703c7a8.tar.gz |
Merge pull request #3 from ananyasen/FileIO
Setting up io-mediator to add new functionality.
Diffstat (limited to 'js/stage/stage-view.reel')
-rwxr-xr-x | js/stage/stage-view.reel/stage-view.js | 83 |
1 files changed, 46 insertions, 37 deletions
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, { | |||
76 | // Temporary function to create a Codemirror text view | 76 | // Temporary function to create a Codemirror text view |
77 | createTextView: { | 77 | createTextView: { |
78 | value: function(doc) { | 78 | value: function(doc) { |
79 | this.application.ninja.documentController.activeDocument.save(true /*remove the codemirror div after saving*/); | ||
80 | this.application.ninja.documentController._hideCurrentDocument(); | 79 | this.application.ninja.documentController._hideCurrentDocument(); |
81 | this.hideOtherDocuments(doc.uuid); | 80 | this.hideOtherDocuments(doc.uuid); |
82 | var type; | 81 | var type; |
@@ -93,13 +92,12 @@ exports.StageView = Montage.create(Component, { | |||
93 | document.getElementById("codeMirror_"+doc.uuid).style.display="block"; | 92 | document.getElementById("codeMirror_"+doc.uuid).style.display="block"; |
94 | 93 | ||
95 | var documentController = this.application.ninja.documentController; | 94 | var documentController = this.application.ninja.documentController; |
96 | |||
97 | doc.editor = CodeMirror.fromTextArea(doc.textArea, { | 95 | doc.editor = CodeMirror.fromTextArea(doc.textArea, { |
98 | lineNumbers: true, | 96 | lineNumbers: true, |
99 | mode: type, | 97 | mode: type, |
100 | onChange: function(){ | 98 | onChange: function(){ |
101 | var historySize = doc.editor.historySize(); | 99 | var historySize = doc.editor.historySize(); |
102 | if((historySize.undo===0 && historySize.redo===0) || (historySize.undo>0)){ | 100 | if(historySize.undo>0){ |
103 | doc.dirtyFlag=true; | 101 | doc.dirtyFlag=true; |
104 | }else if(historySize.undo===0 && historySize.redo>0){ | 102 | }else if(historySize.undo===0 && historySize.redo>0){ |
105 | doc.dirtyFlag=false; | 103 | doc.dirtyFlag=false; |
@@ -122,16 +120,11 @@ exports.StageView = Montage.create(Component, { | |||
122 | 120 | ||
123 | switchDocument:{ | 121 | switchDocument:{ |
124 | value: function(doc){ | 122 | value: function(doc){ |
125 | this.application.ninja.documentController.activeDocument.save(true /*remove the codemirror div after saving*/); | 123 | //save editor cursor position |
126 | 124 | if(!!this.application.ninja.documentController.activeDocument.editor){ | |
127 | this.application.ninja.documentController._hideCurrentDocument(); | 125 | this.application.ninja.documentController.activeDocument.hline = this.application.ninja.documentController.activeDocument.editor.getCursor(true); |
128 | |||
129 | |||
130 | if(this.application.ninja.documentController.activeDocument.currentView === "design"){ | ||
131 | console.log("scrollLeft: "+ this.application.ninja.stage._iframeContainer.scrollLeft); | ||
132 | console.log("scrollTop: "+ this.application.ninja.stage._iframeContainer.scrollTop); | ||
133 | } | 126 | } |
134 | 127 | this.application.ninja.documentController._hideCurrentDocument(); | |
135 | 128 | ||
136 | this.application.ninja.documentController.activeDocument = doc; | 129 | this.application.ninja.documentController.activeDocument = doc; |
137 | 130 | ||
@@ -140,34 +133,15 @@ exports.StageView = Montage.create(Component, { | |||
140 | 133 | ||
141 | var documentController = this.application.ninja.documentController; | 134 | var documentController = this.application.ninja.documentController; |
142 | 135 | ||
143 | if(this.application.ninja.documentController.activeDocument.currentView === "code"){ | 136 | //restore editor cursor position |
144 | var type; | 137 | if(!!this.application.ninja.documentController.activeDocument.editor){ |
145 | switch(doc.documentType) { | 138 | this.application.ninja.documentController.activeDocument.editor.setCursor(this.application.ninja.documentController.activeDocument.hline); |
146 | case "css" : | 139 | document.getElementById("codeMirror_"+this.application.ninja.documentController.activeDocument.uuid).getElementsByClassName("CodeMirror")[0].focus(); |
147 | type = "css"; | ||
148 | break; | ||
149 | case "js" : | ||
150 | type = "javascript"; | ||
151 | break; | ||
152 | } | ||
153 | |||
154 | //add the codemirror div again for editting | ||
155 | doc.editor = CodeMirror.fromTextArea(doc.textArea, { | ||
156 | lineNumbers: true, | ||
157 | mode: type, | ||
158 | onChange: function(){doc.dirtyFlag=true;console.log("undo stack:",doc.editor.historySize());}, | ||
159 | onCursorActivity: function() { | ||
160 | //documentController._codeEditor.editor.setLineClass(documentController._codeEditor.hline, null); | ||
161 | //documentController._codeEditor.hline = documentController._codeEditor.editor.setLineClass(documentController._codeEditor.editor.getCursor().line, "activeline"); | ||
162 | } | ||
163 | }); | ||
164 | |||
165 | //this.application.ninja.documentController._codeEditor.hline = this.application.ninja.documentController._codeEditor.editor.setLineClass(0, "activeline"); | ||
166 | } | 140 | } |
167 | 141 | ||
168 | if(this.application.ninja.documentController.activeDocument.documentType === "htm" || this.application.ninja.documentController.activeDocument.documentType === "html") { | 142 | if(this.application.ninja.documentController.activeDocument.currentView === "design") { |
169 | this.application.ninja.stage._scrollFlag = true; // TODO HACK to prevent type error on Hide/Show Iframe | 143 | this.application.ninja.stage._scrollFlag = true; // TODO HACK to prevent type error on Hide/Show Iframe |
170 | 144 | this.application.ninja.currentDocument = this.application.ninja.documentController.activeDocument; | |
171 | 145 | ||
172 | // TODO dispatch event here | 146 | // TODO dispatch event here |
173 | // appDelegateModule.MyAppDelegate.onSetActiveDocument(); | 147 | // appDelegateModule.MyAppDelegate.onSetActiveDocument(); |
@@ -232,5 +206,40 @@ exports.StageView = Montage.create(Component, { | |||
232 | this.application.ninja.rulerTop.style.display = "none"; | 206 | this.application.ninja.rulerTop.style.display = "none"; |
233 | this.application.ninja.rulerLeft.style.display = "none"; | 207 | this.application.ninja.rulerLeft.style.display = "none"; |
234 | } | 208 | } |
209 | }, | ||
210 | |||
211 | switchViews: { | ||
212 | value: function() { | ||
213 | |||
214 | //save file if dirty | ||
215 | |||
216 | this.application.ninja.stage.saveStageScroll(); | ||
217 | this.application.ninja.documentController._hideCurrentDocument(); | ||
218 | |||
219 | if(this.application.ninja.documentController.activeDocument.currentView === "design") { | ||
220 | this.application.ninja.documentController._textHolder.style.display = "none"; | ||
221 | this.application.ninja.documentController.activeDocument.container.style["display"] = "block"; | ||
222 | this.application.ninja.stage._scrollFlag = true; | ||
223 | //this._showCurrentDocument(); | ||
224 | this.application.ninja.stage.applySavedScroll(); | ||
225 | |||
226 | } else { | ||
227 | this.application.ninja.stage._scrollFlag = false; // TODO HACK to prevent type error on Hide/Show Iframe | ||
228 | |||
229 | var codeview = this.application.ninja.documentController.activeDocument.container; | ||
230 | //this._textHolder.style.display = "block"; | ||
231 | //codeview.firstChild.innerHTML = this.activeDocument.iframe.contentWindow.document.body.parentNode.innerHTML; | ||
232 | |||
233 | // this._codeEditor.editor = CodeMirror.fromTextArea(codeview.firstChild, { | ||
234 | // lineNumbers: true, | ||
235 | // mode: "htmlmixed", | ||
236 | // onCursorActivity: function() { | ||
237 | // DocumentController._codeEditor.editor.setLineClass(DocumentController._codeEditor.hline, null); | ||
238 | // DocumentController._codeEditor.hline = DocumentController._codeEditor.editor.setLineClass(DocumentController._codeEditor.editor.getCursor().line, "activeline"); | ||
239 | // } | ||
240 | // }); | ||
241 | // this._codeEditor.hline = DocumentController._codeEditor.editor.setLineClass(0, "activeline"); | ||
242 | } | ||
243 | } | ||
235 | } | 244 | } |
236 | }); \ No newline at end of file | 245 | }); \ No newline at end of file |