aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnanya Sen2012-05-18 16:56:16 -0700
committerAnanya Sen2012-05-18 16:56:16 -0700
commit7a22f7b368ef549a5b30c58a0f3900685b764bdb (patch)
tree44951af31368a5b287057e5cdddf0469cdc30298
parent65cea92d839bcd25ea9094a0798190a4dc4bea35 (diff)
downloadninja-7a22f7b368ef549a5b30c58a0f3900685b764bdb.tar.gz
integrated open code view document in new dom architecture
Signed-off-by: Ananya Sen <Ananya.Sen@motorola.com>
-rw-r--r--js/controllers/code-editor-controller.js40
-rwxr-xr-xjs/controllers/document-controller.js65
-rwxr-xr-xjs/controllers/styles-controller.js2
-rwxr-xr-xjs/document/document-text.js43
-rwxr-xr-xjs/document/models/text.js4
-rwxr-xr-xjs/document/views/code.js193
-rwxr-xr-xjs/stage/stage-view.reel/stage-view.js120
7 files changed, 276 insertions, 191 deletions
diff --git a/js/controllers/code-editor-controller.js b/js/controllers/code-editor-controller.js
index 7913cfc1..e7163bd8 100644
--- a/js/controllers/code-editor-controller.js
+++ b/js/controllers/code-editor-controller.js
@@ -68,7 +68,7 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone
68 * Creates an editor instance 68 * Creates an editor instance
69 */ 69 */
70 createEditor : { 70 createEditor : {
71 value:function(doc, type, documentType){ 71 value:function(codeDocumentView, type, documentType, textDocument){
72 var self = this, editorOptions = null; 72 var self = this, editorOptions = null;
73 73
74 editorOptions = { 74 editorOptions = {
@@ -76,17 +76,17 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone
76 matchBrackets:true, 76 matchBrackets:true,
77 mode: type, 77 mode: type,
78 onChange: function(){ 78 onChange: function(){
79 var historySize = doc.editor.historySize(); 79 var historySize = codeDocumentView.editor.historySize();
80 if(historySize.undo>0){ 80 if(historySize.undo>0){
81 doc.needsSave = true; 81 textDocument.model.needsSave = true;
82 }else if(historySize.undo===0 && historySize.redo>0){ 82 }else if(historySize.undo===0 && historySize.redo>0){
83 doc.needsSave = false; 83 textDocument.model.needsSave = false;
84 } 84 }
85 }, 85 },
86 onCursorActivity: function() { 86 onCursorActivity: function() {
87 doc.editor.matchHighlight("CodeMirror-matchhighlight"); 87 codeDocumentView.editor.matchHighlight("CodeMirror-matchhighlight");
88 doc.editor.setLineClass(doc.editor.hline, null, null); 88 codeDocumentView.editor.setLineClass(codeDocumentView.editor.hline, null, null);
89 doc.editor.hline = doc.editor.setLineClass(doc.editor.getCursor().line, null, "activeline"); 89 codeDocumentView.editor.hline = codeDocumentView.editor.setLineClass(codeDocumentView.editor.getCursor().line, null, "activeline");
90 } 90 }
91 }; 91 };
92 92
@@ -95,9 +95,7 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone
95 editorOptions.onKeyEvent = function(cm, keyEvent){self._codeCompletionKeyEventHandler.call(self, cm, keyEvent, documentType)}; 95 editorOptions.onKeyEvent = function(cm, keyEvent){self._codeCompletionKeyEventHandler.call(self, cm, keyEvent, documentType)};
96 } 96 }
97 97
98 var editor = self.codeEditor.fromTextArea(doc.textArea, editorOptions); 98 var editor = self.codeEditor.fromTextArea(codeDocumentView.textArea, editorOptions);
99
100 //editor.setOption("theme", "night");
101 99
102 return editor; 100 return editor;
103 } 101 }
@@ -215,22 +213,22 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone
215 213
216 autoFormatSelection:{ 214 autoFormatSelection:{
217 value: function(){ 215 value: function(){
218 var range = this.getSelectedRange(this.application.ninja.documentController.activeDocument.editor); 216 var range = this.getSelectedRange(this.application.ninja.documentController.activeDocument.model.views.code.editor);
219 this.application.ninja.documentController.activeDocument.editor.autoFormatRange(range.from, range.to); 217 this.application.ninja.documentController.activeDocument.model.views.code.editor.autoFormatRange(range.from, range.to);
220 } 218 }
221 }, 219 },
222 220
223 commentSelection:{ 221 commentSelection:{
224 value: function(isComment){ 222 value: function(isComment){
225 var range = this.getSelectedRange(this.application.ninja.documentController.activeDocument.editor); 223 var range = this.getSelectedRange(this.application.ninja.documentController.activeDocument.model.views.code.editor);
226 this.application.ninja.documentController.activeDocument.editor.commentRange(isComment, range.from, range.to); 224 this.application.ninja.documentController.activeDocument.model.views.code.editor.commentRange(isComment, range.from, range.to);
227 } 225 }
228 }, 226 },
229 227
230 handleThemeSelection:{ 228 handleThemeSelection:{
231 value: function(){ 229 value: function(){
232 this.application.ninja.documentController.activeDocument.editor.setOption("theme", this.editorTheme); 230 this.application.ninja.documentController.activeDocument.model.views.code.editor.setOption("theme", this.editorTheme);
233 this.application.ninja.stage.stageView.applyTheme("cm-s-"+this.editorTheme); 231 this.application.ninja.documentController.activeDocument.model.views.code.applyTheme("cm-s-"+this.editorTheme);
234 } 232 }
235 }, 233 },
236 234
@@ -238,10 +236,10 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone
238 value:function(value){ 236 value:function(value){
239 var originalFont=13,originalLineHeight=16; 237 var originalFont=13,originalLineHeight=16;
240 this._zoomFactor = value; 238 this._zoomFactor = value;
241 this.application.ninja.documentController.activeDocument.container.style.fontSize = ""+((value/100)*originalFont)+"px"; 239 this.application.ninja.documentController.activeDocument.model.views.code.textViewContainer.style.fontSize = ""+((value/100)*originalFont)+"px";
242 this.application.ninja.documentController.activeDocument.container.style.cursor = "text"; 240 this.application.ninja.documentController.activeDocument.model.views.code.textViewContainer.style.cursor = "text";
243 this.application.ninja.documentController.activeDocument.container.querySelector(".CodeMirror").style.lineHeight = ""+((value/100)*originalLineHeight)+"px"; 241 this.application.ninja.documentController.activeDocument.model.views.code.textViewContainer.querySelector(".CodeMirror").style.lineHeight = ""+((value/100)*originalLineHeight)+"px";
244 this.application.ninja.documentController.activeDocument.editor.refresh();//refresh editor display for xoom 242 this.application.ninja.documentController.activeDocument.model.views.code.editor.refresh();//refresh editor display for xoom
245 } 243 }
246 }, 244 },
247 245
@@ -250,7 +248,7 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone
250 //set theme 248 //set theme
251 this.handleThemeSelection(); 249 this.handleThemeSelection();
252 //check autocomplete support 250 //check autocomplete support
253 this.handleCodeCompletionSupport(this.application.ninja.documentController.activeDocument.documentType); 251 this.handleCodeCompletionSupport(this.application.ninja.documentController.activeDocument.model.file.extension);
254 //set zoom 252 //set zoom
255 this.handleZoom(this._zoomFactor); 253 this.handleZoom(this._zoomFactor);
256 } 254 }
diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js
index cf46e73e..a795d652 100755
--- a/js/controllers/document-controller.js
+++ b/js/controllers/document-controller.js
@@ -13,7 +13,8 @@ var Montage = require("montage/core/core").Montage,
13 TextDocument = require("js/document/text-document").TextDocument; 13 TextDocument = require("js/document/text-document").TextDocument;
14 14
15 // New Document Objects 15 // New Document Objects
16var Document = require("js/document/document-html").HtmlDocument; 16var Document_HTML = require("js/document/document-html").HtmlDocument;
17var Document_Text = require("js/document/document-text").TextDocument;
17//////////////////////////////////////////////////////////////////////// 18////////////////////////////////////////////////////////////////////////
18// 19//
19var DocumentController = exports.DocumentController = Montage.create(Component, { 20var DocumentController = exports.DocumentController = Montage.create(Component, {
@@ -320,32 +321,30 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
320 321
321 //////////////////////////////////////////////////////////////////// 322 ////////////////////////////////////////////////////////////////////
322 openDocument: { 323 openDocument: {
323 value: function(doc) { 324 value: function(file) {
324 var template, dimensions; 325 var template, dimensions;
325 if (doc.content.body.indexOf('Ninja-Banner Dimensions@@@') !== -1) { 326
326 dimensions = (doc.content.body.split('Ninja-Banner Dimensions@@@'))[1].split('-->')[0].split('x');
327 dimensions = {width: parseInt(dimensions[0]), height: parseInt(dimensions[1])};
328 template = {type: 'banner', size: dimensions};
329 }
330 // TODO: HACKS to remove 327 // TODO: HACKS to remove
331 this.documentHackReference = doc; 328 this.documentHackReference = file;
332 document.getElementById("iframeContainer").style.overflow = "hidden"; 329 document.getElementById("iframeContainer").style.overflow = "hidden";
333 // 330 //
334 switch (doc.extension) { 331 switch (file.extension) {
335 case 'html': 332 case 'html':
333
334 if (file.content.body.indexOf('Ninja-Banner Dimensions@@@') !== -1) {
335 dimensions = (file.content.body.split('Ninja-Banner Dimensions@@@'))[1].split('-->')[0].split('x');
336 dimensions = {width: parseInt(dimensions[0]), height: parseInt(dimensions[1])};
337 template = {type: 'banner', size: dimensions};
338 }
339
336 //Open in designer view 340 //Open in designer view
337 this._hackRootFlag = false; 341 this._hackRootFlag = false;
338 Montage.create(Document).init(doc, this, this._onOpenDocument, 'design', template); 342 Montage.create(Document_HTML).init(file, this, this._onOpenDocument, 'design', template);
339 break; 343 break;
340 default: 344 default:
341 //Open in code view 345 //Open in code view
342 var code = Montage.create(TextDocument, {"source": {value: doc.content}}), docuuid = Uuid.generate(), textArea; 346 Montage.create(Document_Text).init(file, this, this._onOpenTextDocument, 'code');
343 textArea = this.application.ninja.stage.stageView.createTextAreaElement(docuuid); 347 break;
344 code.initialize(doc, docuuid, textArea, textArea.parentNode);
345 //code.init(doc.name, doc.uri, doc.extension, null, docuuid);
346 code.textArea.value = doc.content;
347 this.application.ninja.stage.stageView.createTextView(code);
348 break;
349 } 348 }
350 } 349 }
351 }, 350 },
@@ -514,9 +513,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
514 _onOpenTextDocument: { 513 _onOpenTextDocument: {
515 value: function(doc) { 514 value: function(doc) {
516 if(this.activeDocument) { 515 if(this.activeDocument) {
516
517 if(this.activeDocument.currentView === "design"){ 517 if(this.activeDocument.currentView === "design"){
518 this.activeDocument.saveAppState(); 518 this.activeDocument.saveAppState();
519 this.activeDocument.container.parentNode.style["display"] = "none"; 519 this.activeDocument.parentContainer.style["display"] = "none";
520 this.application.ninja.stage.hideCanvas(true); 520 this.application.ninja.stage.hideCanvas(true);
521 this.application.ninja.stage.stageView.hideRulers(); 521 this.application.ninja.stage.stageView.hideRulers();