aboutsummaryrefslogtreecommitdiff
path: root/js/controllers
diff options
context:
space:
mode:
authorArmen Kesablyan2012-05-23 14:34:58 -0700
committerArmen Kesablyan2012-05-23 14:34:58 -0700
commitc21db7f1e4a0582777bdb5366df5d023a915b779 (patch)
treec4d29cb4686101d4a480ae836d20187879cf5400 /js/controllers
parent3ed95247e9ea4b0a7833401ed6809647b7c4acbf (diff)
parent1a7e347810401e6262d9d7bad1c3583e6773993b (diff)
downloadninja-c21db7f1e4a0582777bdb5366df5d023a915b779.tar.gz
Merge branch 'refs/heads/dom-architecture' into binding
Conflicts: js/data/panels-data.js Signed-off-by: Armen Kesablyan <armen@motorola.com>
Diffstat (limited to 'js/controllers')
-rw-r--r--js/controllers/code-editor-controller.js40
-rwxr-xr-xjs/controllers/document-controller.js247
-rwxr-xr-xjs/controllers/elements/body-controller.js2
-rwxr-xr-xjs/controllers/selection-controller.js4
-rwxr-xr-xjs/controllers/styles-controller.js149
5 files changed, 268 insertions, 174 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..3e15511d 100755
--- a/js/controllers/document-controller.js
+++ b/js/controllers/document-controller.js
@@ -9,11 +9,8 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
9var Montage = require("montage/core/core").Montage, 9var Montage = require("montage/core/core").Montage,
10 Component = require("montage/ui/component").Component, 10 Component = require("montage/ui/component").Component,
11 Uuid = require("montage/core/uuid").Uuid, 11 Uuid = require("montage/core/uuid").Uuid,
12 HTMLDocument = require("js/document/html-document").HTMLDocument, 12 HTMLDocument = require("js/document/document-html").HtmlDocument,
13 TextDocument = require("js/document/text-document").TextDocument; 13 TextDocument = require("js/document/document-text").TextDocument;
14
15 // New Document Objects
16var Document = require("js/document/document-html").HtmlDocument;
17//////////////////////////////////////////////////////////////////////// 14////////////////////////////////////////////////////////////////////////
18// 15//
19var DocumentController = exports.DocumentController = Montage.create(Component, { 16var DocumentController = exports.DocumentController = Montage.create(Component, {
@@ -51,10 +48,6 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
51 if(!!this._activeDocument){ 48 if(!!this._activeDocument){
52 if(this._documents.indexOf(doc) === -1) this._documents.push(doc); 49 if(this._documents.indexOf(doc) === -1) this._documents.push(doc);
53 this._activeDocument.isActive = true; 50 this._activeDocument.isActive = true;
54
55 if(!!this._activeDocument.editor){
56 this._activeDocument.editor.focus();
57 }
58 } 51 }
59 } 52 }
60 }, 53 },
@@ -145,18 +138,19 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
145 value: function(event) { 138 value: function(event) {
146 // 139 //
147 if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ 140 if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){
148 // 141 //Currently we don't need a callback handler
149 this.activeDocument.model.save(this.testCallback.bind(this)); //this.fileSaveResult.bind(this) 142 //this.activeDocument.model.save(this.saveExecuted.bind(this));
143 this.activeDocument.model.save();
150 } else { 144 } else {
151 //Error: 145 //Error: cloud not available and/or no active document
152 } 146 }
153 } 147 }
154 }, 148 },
155 testCallback: { 149 ////////////////////////////////////////////////////////////////////
150 //
151 saveExecuted: {
156 value: function (value) { 152 value: function (value) {
157 console.log(value); 153 //File saved, any callbacks or events should go here
158 //TODO: Move this to the model.save()
159 this.activeDocument.model.needsSave = false;
160 } 154 }
161 }, 155 },
162 //////////////////////////////////////////////////////////////////// 156 ////////////////////////////////////////////////////////////////////
@@ -177,8 +171,8 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
177 value: function(event) { 171 value: function(event) {
178 var saveAsSettings = event._event.settings || {}; 172 var saveAsSettings = event._event.settings || {};
179 if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ 173 if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){
180 saveAsSettings.fileName = this.activeDocument.name; 174 saveAsSettings.fileName = this.activeDocument.model.file.name;
181 saveAsSettings.folderUri = this.activeDocument.uri.substring(0, this.activeDocument.uri.lastIndexOf("/")); 175 saveAsSettings.folderUri = this.activeDocument.model.file.uri.substring(0, this.activeDocument.model.file.uri.lastIndexOf("/"));
182 saveAsSettings.callback = this.saveAsCallback.bind(this); 176 saveAsSettings.callback = this.saveAsCallback.bind(this);
183 this.application.ninja.newFileController.showSaveAsDialog(saveAsSettings); 177 this.application.ninja.newFileController.showSaveAsDialog(saveAsSettings);
184 } 178 }
@@ -310,42 +304,38 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
310 this.activeDocument.uri = fileUri; 304 this.activeDocument.uri = fileUri;
311 //save a new file 305 //save a new file
312 //use the ioMediator.fileSaveAll when implemented 306 //use the ioMediator.fileSaveAll when implemented
313 this.activeDocument._userDocument.name=filename; 307 this.activeDocument.model.file.name = filename;