diff options
Diffstat (limited to 'js/stage')
-rwxr-xr-x | js/stage/stage-view.reel/stage-view.js | 83 | ||||
-rwxr-xr-x | js/stage/stage.reel/stage.js | 33 |
2 files changed, 62 insertions, 54 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 |
diff --git a/js/stage/stage.reel/stage.js b/js/stage/stage.reel/stage.js index 4364b45d..8c0f0fa0 100755 --- a/js/stage/stage.reel/stage.js +++ b/js/stage/stage.reel/stage.js | |||
@@ -116,9 +116,6 @@ exports.Stage = Montage.create(Component, { | |||
116 | _userContentLeft: { value: 0 }, | 116 | _userContentLeft: { value: 0 }, |
117 | _userContentTop: { value: 0 }, | 117 | _userContentTop: { value: 0 }, |
118 | _userContentBorder: { value: 0 }, | 118 | _userContentBorder: { value: 0 }, |
119 | savedLeftScroll: { value: null }, | ||
120 | savedTopScroll: { value: null }, | ||
121 | |||
122 | 119 | ||
123 | documentRoot: { | 120 | documentRoot: { |
124 | get: function () { return this._documentRoot; }, | 121 | get: function () { return this._documentRoot; }, |
@@ -247,6 +244,8 @@ exports.Stage = Montage.create(Component, { | |||
247 | 244 | ||
248 | this._scrollLeft = this._iframeContainer.scrollLeft; | 245 | this._scrollLeft = this._iframeContainer.scrollLeft; |
249 | this._scrollTop = this._iframeContainer.scrollTop; | 246 | this._scrollTop = this._iframeContainer.scrollTop; |
247 | this.application.ninja.currentDocument.savedLeftScroll = this._iframeContainer.scrollLeft; | ||
248 | this.application.ninja.currentDocument.savedTopScroll = this._iframeContainer.scrollTop; | ||
250 | 249 | ||
251 | this.userContentBorder = parseInt(this._documentRoot.elementModel.controller.getProperty(this._documentRoot, "border")); | 250 | this.userContentBorder = parseInt(this._documentRoot.elementModel.controller.getProperty(this._documentRoot, "border")); |
252 | 251 | ||
@@ -878,18 +877,18 @@ exports.Stage = Montage.create(Component, { | |||
878 | } | 877 | } |
879 | }, | 878 | }, |
880 | 879 | ||
881 | saveStageScroll:{ | 880 | saveScroll:{ |
882 | value: function(){ | 881 | value: function(){ |
883 | this.savedLeftScroll = this._iframeContainer.scrollLeft; | 882 | this.application.ninja.documentController.activeDocument.savedLeftScroll = this._iframeContainer.scrollLeft; |
884 | this.savedTopScroll = this._iframeContainer.scrollTop; | 883 | this.application.ninja.documentController.activeDocument.savedTopScroll = this._iframeContainer.scrollTop; |
885 | } | 884 | } |
886 | }, | 885 | }, |
887 | applySavedScroll:{ | 886 | restoreScroll:{ |
888 | value: function(){ | 887 | value: function(){ |
889 | this._iframeContainer.scrollLeft = this.savedLeftScroll; | 888 | this._iframeContainer.scrollLeft = this.application.ninja.documentController.activeDocument.savedLeftScroll; |
890 | this._scrollLeft = this.savedLeftScroll; | 889 | this._scrollLeft = this.application.ninja.documentController.activeDocument.savedLeftScroll; |
891 | this._iframeContainer.scrollTop = this.savedTopScroll; | 890 | this._iframeContainer.scrollTop = this.application.ninja.documentController.activeDocument.savedTopScroll; |
892 | this._scrollTop = this.savedTopScroll; | 891 | this._scrollTop = this.application.ninja.documentController.activeDocument.savedTopScroll; |
893 | } | 892 | } |
894 | } | 893 | } |
895 | }); \ No newline at end of file | 894 | }); \ No newline at end of file |