aboutsummaryrefslogtreecommitdiff
path: root/js/stage/stage-view.reel/stage-view.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/stage/stage-view.reel/stage-view.js')
-rwxr-xr-xjs/stage/stage-view.reel/stage-view.js227
1 files changed, 227 insertions, 0 deletions
diff --git a/js/stage/stage-view.reel/stage-view.js b/js/stage/stage-view.reel/stage-view.js
new file mode 100755
index 00000000..6f20b87b
--- /dev/null
+++ b/js/stage/stage-view.reel/stage-view.js
@@ -0,0 +1,227 @@
1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */
6
7/**
8@requires montage/core/core
9@requires montage/ui/component
10*/
11var Montage = require("montage/core/core").Montage,
12 Component = require("montage/ui/component").Component;
13
14exports.StageView = Montage.create(Component, {
15 _documents: {
16 value : []
17 },
18
19 docs: {
20 get: function() {
21 return this._documents;
22 },
23 set: function(value) {
24 //console.log(value);
25 }
26 },
27
28 templateDidLoad: {
29 value: function() {
30 this.eventManager.addEventListener("appLoaded", this, false);
31 }
32 },
33
34 didDraw:{
35 value: function() {
36 if(!this.application.ninja.documentController._textHolder) this.application.ninja.documentController._textHolder = this.element;
37 }
38 },
39
40 handleAppLoaded: {
41 value: function() {
42
43 // Don't bind for now
44 /*
45 Object.defineBinding(this, "docs", {
46 boundObject: this.application.ninja.documentController,
47 boundObjectPropertyPath: "_documents"
48 });
49 */
50
51 }
52 },
53
54 /**
55 * Creates a text area which will contain the content of the opened text document.
56 */
57 createTextAreaElement: {
58 value: function(uuid) {
59
60
61 var codeMirrorDiv = document.createElement("div");
62 codeMirrorDiv.id = "codeMirror_" + uuid;
63 codeMirrorDiv.style.display = "block";
64 this.element.appendChild(codeMirrorDiv);
65
66 var textArea = document.createElement("textarea");
67 textArea.id = "code";
68 textArea.name = "code";
69
70 codeMirrorDiv.appendChild(textArea);
71
72 return textArea;
73 }
74 },
75
76 // Temporary function to create a Codemirror text view
77 createTextView: {
78 value: function(doc) {
79 //save current document
80 if(this.application.ninja.documentController.activeDocument.currentView === "code"){
81 this.application.ninja.documentController.activeDocument.save(true);
82 }
83 this.application.ninja.documentController._hideCurrentDocument();
84 this.hideOtherDocuments(doc.uuid);
85 var type;
86 switch(doc.documentType) {
87 case "css" :
88 type = "css";
89 break;
90 case "js" :
91 type = "javascript";
92 break;
93 }
94
95 //fix hack
96 document.getElementById("codeMirror_"+doc.uuid).style.display="block";
97
98 var documentController = this.application.ninja.documentController;
99
100 doc.editor = CodeMirror.fromTextArea(doc.textArea, {
101 lineNumbers: true,
102 mode: type,
103 onChange: function(){doc.dirtyFlag=true;},
104 onCursorActivity: function() {
105 //documentController._codeEditor.editor.setLineClass(documentController._codeEditor.hline, null);
106 //documentController._codeEditor.hline = documentController._codeEditor.editor.setLineClass(documentController._codeEditor.editor.getCursor().line, "activeline");
107 }
108 });
109
110 //this.application.ninja.documentController._codeEditor.hline = this.application.ninja.documentController._codeEditor.editor.setLineClass(0, "activeline");
111 this.application.ninja.stage._scrollFlag = false; // TODO HACK to prevent type error on Hide/Show Iframe
112 this.application.ninja.documentController.activeDocument = doc;
113 this.application.ninja.stage.hideCanvas(true);
114 }
115 },
116
117
118
119 switchDocument:{
120 value: function(doc){
121
122 //if dirty SAVE codemirror into textarea
123 if(this.application.ninja.documentController.activeDocument.currentView === "code"){
124 this.application.ninja.documentController.activeDocument.save(true);
125 }
126
127 this.application.ninja.documentController._hideCurrentDocument();
128
129 this.application.ninja.documentController.activeDocument = doc;
130
131 this.application.ninja.stage._scrollFlag = false; // TODO HACK to prevent type error on Hide/Show Iframe
132 this.application.ninja.documentController._showCurrentDocument();
133
134 var documentController = this.application.ninja.documentController;
135
136 if(this.application.ninja.documentController.activeDocument.currentView === "code"){
137 var type;
138 switch(doc.documentType) {
139 case "css" :
140 type = "css";
141 break;
142 case "js" :
143 type = "javascript";
144 break;
145 }
146
147 //add the codemirror div again for editting
148 doc.editor = CodeMirror.fromTextArea(doc.textArea, {
149 lineNumbers: true,
150 mode: type,
151 onChange: function(){doc.dirtyFlag=true;},
152 onCursorActivity: function() {
153 //documentController._codeEditor.editor.setLineClass(documentController._codeEditor.hline, null);
154 //documentController._codeEditor.hline = documentController._codeEditor.editor.setLineClass(documentController._codeEditor.editor.getCursor().line, "activeline");
155 }
156 });
157
158 //this.application.ninja.documentController._codeEditor.hline = this.application.ninja.documentController._codeEditor.editor.setLineClass(0, "activeline");
159 }
160
161 if(this.application.ninja.documentController.activeDocument.documentType === "htm" || this.application.ninja.documentController.activeDocument.documentType === "html") {
162 this.application.ninja.stage._scrollFlag = true; // TODO HACK to prevent type error on Hide/Show Iframe
163 // TODO dispatch event here
164 // appDelegateModule.MyAppDelegate.onSetActiveDocument();
165 }
166
167 }
168 },
169
170 refreshCodeDocument:{
171 value:function(doc){
172
173 }
174 },
175 addCodeDocument:{
176 value:function(doc){
177 var type;
178 switch(doc.documentType) {
179 case "css" :
180 type = "css";
181 break;
182 case "js" :
183 type = "javascript";
184 break;
185 }
186
187 var codeM = CodeMirror.fromTextArea(doc.textArea, {
188 lineNumbers: true,
189 mode: type,
190 onCursorActivity: function() {
191 //documentController._codeEditor.editor.setLineClass(documentController._codeEditor.hline, null);
192 //documentController._codeEditor.hline = documentController._codeEditor.editor.setLineClass(documentController._codeEditor.editor.getCursor().line, "activeline");
193 }
194 });
195 }
196 },
197 hideCodeDocument:{
198 value:function(docUuid){
199 //hide the previous Codemirror div
200
201 }
202 },
203 hideOtherDocuments:{
204 value:function(docUuid){
205 //use CodeMirror toTextArea() to remove editor and save content into textarea
206 this.application.ninja.documentController._documents.forEach(function(aDoc){
207 if(aDoc.currentView === "design"){
208 aDoc.container.parentNode.style["display"] = "none";
209 }else if((aDoc.currentView === "code") && (aDoc.uuid !== docUuid)){
210 aDoc.container.style["display"] = "none";
211 }
212 }, this);
213 }
214 },
215 showRulers:{
216 value:function(){
217 this.application.ninja.rulerTop.style.display = "block";
218 this.application.ninja.rulerLeft.style.display = "block";
219 }
220 },
221 hideRulers:{
222 value:function(){
223 this.application.ninja.rulerTop.style.display = "none";
224 this.application.ninja.rulerLeft.style.display = "none";
225 }
226 }
227}); \ No newline at end of file