aboutsummaryrefslogtreecommitdiff
path: root/js/controllers
diff options
context:
space:
mode:
authorValerio Virgillito2012-02-16 11:22:32 -0800
committerValerio Virgillito2012-02-16 11:22:32 -0800
commit71619045b692015b0889a4f5c381c1dee9c056cd (patch)
tree9b844d18df96c028360404f718fadfdd7c681aad /js/controllers
parent9aed3035ed7b0807ec198327ddd8305596331491 (diff)
parent729e32ee70b0dd30a3b498ed7d1636b1b5b56a43 (diff)
downloadninja-71619045b692015b0889a4f5c381c1dee9c056cd.tar.gz
Merge pull request #45 from joseeight/FileIO
File IO
Diffstat (limited to 'js/controllers')
-rwxr-xr-xjs/controllers/document-controller.js71
1 files changed, 36 insertions, 35 deletions
diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js
index 84b994ce..b1a22c1b 100755
--- a/js/controllers/document-controller.js
+++ b/js/controllers/document-controller.js
@@ -9,8 +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/io/document/html-document").HTMLDocument, 12 HTMLDocument = require("js/document/html-document").HTMLDocument,
13 TextDocument = require("js/io/document/text-document").TextDocument, 13 TextDocument = require("js/document/text-document").TextDocument,
14 DocumentController; 14 DocumentController;
15//////////////////////////////////////////////////////////////////////// 15////////////////////////////////////////////////////////////////////////
16// 16//
@@ -28,29 +28,23 @@ DocumentController = exports.DocumentController = Montage.create(Component, {
28 _iframeHolder: { value: null, enumerable: false }, 28 _iframeHolder: { value: null, enumerable: false },
29 _textHolder: { value: null, enumerable: false }, 29 _textHolder: { value: null, enumerable: false },
30 _codeMirrorCounter: {value: 1, enumerable: false}, 30 _codeMirrorCounter: {value: 1, enumerable: false},
31 31
32 tmpSourceForTesting: {
33 value: "function CodeMirror(place, givenOptions) {" +
34 "// Determine effective options based on given values and defaults." +
35 "var options = {}, defaults = CodeMirror.defaults; }"
36 },
37
38 activeDocument: { 32 activeDocument: {
39 get: function() { 33 get: function() {
40 return this._activeDocument; 34 return this._activeDocument;
41 }, 35 },
42 set: function(doc) { 36 set: function(doc) {
43 if(this._activeDocument) this._activeDocument.isActive = false; 37 if(!!this._activeDocument) this._activeDocument.isActive = false;
44
45 if(this._documents.indexOf(doc) === -1) this._documents.push(doc);
46 38
47 this._activeDocument = doc; 39 this._activeDocument = doc;
48 this._activeDocument.isActive = true; 40 if(!!this._activeDocument){
49 41
50 if(!!this._activeDocument.editor){ 42 if(this._documents.indexOf(doc) === -1) this._documents.push(doc);
51 this._activeDocument.editor.focus(); 43 this._activeDocument.isActive = true;
44 if(!!this._activeDocument.editor){
45 this._activeDocument.editor.focus();
46 }
52 } 47 }
53
54 } 48 }
55 }, 49 },
56 50
@@ -62,21 +56,12 @@ DocumentController = exports.DocumentController = Montage.create(Component, {
62 this.eventManager.addEventListener("executeSave", this, false); 56 this.eventManager.addEventListener("executeSave", this, false);
63 57
64 this.eventManager.addEventListener("recordStyleChanged", this, false); 58 this.eventManager.addEventListener("recordStyleChanged", this, false);
65
66 // Temporary testing opening a new file after Ninja has loaded
67 this.eventManager.addEventListener("executeNewProject", this, false);
68 } 59 }
69 }, 60 },
70 61
71 handleAppLoaded: { 62 handleAppLoaded: {
72 value: function() { 63 value: function() {
73 //this.openDocument({"type": "html"}); 64 //
74 }
75 },
76
77 handleExecuteNewProject: {
78 value: function() {
79 this.openDocument({"type": "html"});
80 } 65 }
81 }, 66 },
82 67
@@ -104,16 +89,26 @@ DocumentController = exports.DocumentController = Montage.create(Component, {
104 handleExecuteSave: { 89 handleExecuteSave: {
105 value: function(event) { 90 value: function(event) {
106 //Text and HTML document classes should return the same save object for fileSave 91 //Text and HTML document classes should return the same save object for fileSave
107 this.application.ninja.ioMediator.fileSave(this.activeDocument.save(), this.clearDocumentDirtyFlag.bind(this)); 92 this.application.ninja.ioMediator.fileSave(this.activeDocument.save(), this.fileSaveResult.bind(this));
108 } 93 }
109 }, 94 },
110 95 ////////////////////////////////////////////////////////////////////
96 //
97 fileSaveResult: {
98 value: function (result) {
99 if(result.status === 204){
100 this.clearDocumentDirtyFlag();
101 }
102 }
103 },
104 ////////////////////////////////////////////////////////////////////
105
106
111 clearDocumentDirtyFlag:{ 107 clearDocumentDirtyFlag:{
112 value: function(){ 108 value: function(){
113 this.activeDocument.dirtyFlag = false; 109 this.activeDocument.dirtyFlag = false;
114 } 110 }
115 }, 111 },
116 ////////////////////////////////////////////////////////////////////
117 112
118 113
119 createNewFile:{ 114 createNewFile:{
@@ -189,7 +184,7 @@ DocumentController = exports.DocumentController = Montage.create(Component, {
189 switch (doc.extension) { 184 switch (doc.extension) {
190 case 'html': case 'html': 185 case 'html': case 'html':
191 //Open in designer view 186 //Open in designer view
192 Montage.create(HTMLDocument).initialize(doc, Uuid.generate(), this._createIframeElement(), this._onOpenDocument); 187 Montage.create(HTMLDocument).initialize(doc, Uuid.generate(), this._createIframeElement(), this._onOpenDocument.bind(this));
193 break; 188 break;
194 default: 189 default:
195 //Open in code view 190 //Open in code view
@@ -255,7 +250,6 @@ DocumentController = exports.DocumentController = Montage.create(Component, {
255 } 250 }
256 251
257 var doc = this._findDocumentByUUID(id); 252 var doc = this._findDocumentByUUID(id);
258 this._removeDocumentView(doc.container);
259 253
260 var closeDocumentIndex = this._findIndexByUUID(id); 254 var closeDocumentIndex = this._findIndexByUUID(id);
261 this._documents.splice(this._findIndexByUUID(id), 1); 255 this._documents.splice(this._findIndexByUUID(id), 1);
@@ -268,8 +262,11 @@ DocumentController = exports.DocumentController = Montage.create(Component, {
268 nextDocumentIndex = closeDocumentIndex - 1; 262 nextDocumentIndex = closeDocumentIndex - 1;
269 } 263 }
270 this.application.ninja.stage.stageView.switchDocument(this._documents[nextDocumentIndex]); 264 this.application.ninja.stage.stageView.switchDocument(this._documents[nextDocumentIndex]);
265 this._removeDocumentView(doc.container);
271 }else if(this._documents.length === 0){ 266 }else if(this._documents.length === 0){
272 //if there are no documents to switch to then just show the iframeContainer 267 this.activeDocument = null;
268 this._removeDocumentView(doc.container);
269 this.application.ninja.stage.stageView.hideRulers();
273 document.getElementById("iframeContainer").style.display="block"; 270 document.getElementById("iframeContainer").style.display="block";
274 } 271 }
275 } 272 }
@@ -280,11 +277,15 @@ DocumentController = exports.DocumentController = Montage.create(Component, {
280 _onOpenDocument: { 277 _onOpenDocument: {
281 value: function(doc){ 278 value: function(doc){
282 //var data = DocumentManager.activeDocument; 279 //var data = DocumentManager.activeDocument;
283 //DocumentManager._hideCurrentDocument();
284 280
285 //stageManagerModule.stageManager.toggleCanvas(); 281 this._hideCurrentDocument();
282 this.application.ninja.stage.stageView.hideOtherDocuments(doc.uuid);
283
284 this.application.ninja.stage.hideCanvas(false);
285
286 this.activeDocument = doc;
286 287
287 DocumentController.activeDocument = doc; 288 this._showCurrentDocument();
288 289
289 NJevent("onOpenDocument", doc); 290 NJevent("onOpenDocument", doc);
290// appDelegateModule.MyAppDelegate.onSetActiveDocument(); 291// appDelegateModule.MyAppDelegate.onSetActiveDocument();