aboutsummaryrefslogtreecommitdiff
path: root/js/io/document
diff options
context:
space:
mode:
Diffstat (limited to 'js/io/document')
-rwxr-xr-x[-rw-r--r--]js/io/document/base-document.js5
-rwxr-xr-x[-rw-r--r--]js/io/document/document-controller.js243
-rwxr-xr-x[-rw-r--r--]js/io/document/html-document.js12
-rwxr-xr-x[-rw-r--r--]js/io/document/text-document.js21
4 files changed, 195 insertions, 86 deletions
diff --git a/js/io/document/base-document.js b/js/io/document/base-document.js
index 44f54f78..d3601de5 100644..100755
--- a/js/io/document/base-document.js
+++ b/js/io/document/base-document.js
@@ -31,6 +31,11 @@ var BaseDocument = exports.BaseDocument = Montage.create(Montage, {
31 set: function(value) { this._uri = value; } 31 set: function(value) { this._uri = value; }
32 }, 32 },
33 33
34 externalUri: {
35 get: function() { return this._externalUri; },
36 set: function(value) { this._externalUri = value; }
37 },
38
34 documentType: { 39 documentType: {
35 get: function() { return this._documentType; }, 40 get: function() { return this._documentType; },
36 set: function(value) { this._documentType = value; } 41 set: function(value) { this._documentType = value; }
diff --git a/js/io/document/document-controller.js b/js/io/document/document-controller.js
index 99177de0..d7a19e35 100644..100755
--- a/js/io/document/document-controller.js
+++ b/js/io/document/document-controller.js
@@ -12,26 +12,34 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
12@requires js/document/text-document 12@requires js/document/text-document
13*/ 13*/
14 14
15// TODO : Fix deps from Montage V4 Archi
16
17var Montage = require("montage/core/core").Montage, 15var Montage = require("montage/core/core").Montage,
18 Component = require("montage/ui/component").Component, 16 Component = require("montage/ui/component").Component,
19 Uuid = require("montage/core/uuid").Uuid; 17 Uuid = require("montage/core/uuid").Uuid,
20 18 //nj= ("js/lib/NJUtils.js").NJUtils,
21var HTMLDocument = require("js/io/document/html-document").HTMLDocument; 19 HTMLDocument = require("js/io/document/html-document").HTMLDocument,
22var TextDocument = require("js/io/document/text-document").TextDocument; 20 TextDocument = require("js/io/document/text-document").TextDocument;
23 21
24var DocumentController = exports.DocumentController = Montage.create(Component, { 22var DocumentController = exports.DocumentController = Montage.create(Component, {
25 hasTemplate: { value: false }, 23 hasTemplate: {
24 value: false
25 },
26
27 _documents: {
28 value: []
29 },
26 30
27 _documents: { value: [] },
28 _documentsHash: { value: {} },
29 _activeDocument: { value: null }, 31 _activeDocument: { value: null },
30 _iframeCounter: { value: 1, enumerable: false }, 32 _iframeCounter: { value: 1, enumerable: false },
31 _iframeHolder: { value: null, enumerable: false }, 33 _iframeHolder: { value: null, enumerable: false },
32 _textHolder: { value: null, enumerable: false }, 34 _textHolder: { value: null, enumerable: false },
33 _codeMirrorCounter: {value: 1, enumerable: false}, 35 _codeMirrorCounter: {value: 1, enumerable: false},
34 36
37 tmpSourceForTesting: {
38 value: "function CodeMirror(place, givenOptions) {" +
39 "// Determine effective options based on given values and defaults." +
40 "var options = {}, defaults = CodeMirror.defaults; }"
41 },
42
35 _codeEditor: { 43 _codeEditor: {
36 value: { 44 value: {
37 "editor": { 45 "editor": {
@@ -50,33 +58,21 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
50 return this._activeDocument; 58 return this._activeDocument;
51 }, 59 },
52 set: function(doc) { 60 set: function(doc) {
53 if(this._activeDocument) { 61 if(this._activeDocument) this._activeDocument.isActive = false;
54 if(this.activeDocument.documentType === "htm" || this.activeDocument.documentType === "html") {
55 // TODO selection should use the document own selectionModel
56 //this._activeDocument.selectionModel = selectionManagerModule.selectionManager._selectedItems;
57 }
58
59 this._activeDocument.isActive = false;
60 }
61 62
62 if(this._documents.indexOf(doc) === -1) { 63 if(this._documents.indexOf(doc) === -1) this._documents.push(doc);
63 //this._documentsHash[doc.uuid] = this._documents.push(doc) - 1;
64 this._documents.push(doc);
65 }
66 64
67 this._activeDocument = doc; 65 this._activeDocument = doc;
68 this._activeDocument.isActive = true; 66 this._activeDocument.isActive = true;
69 67
70 if(this.activeDocument.documentType === "htm" || this.activeDocument.documentType === "html") {
71 // TODO selection should use the document own selectionModel
72 //selectionManagerModule.selectionManager._selectedItems = this._activeDocument.selectionModel;
73 }
74 } 68 }
75 }, 69 },
76 70
77 deserializedFromTemplate: { 71 deserializedFromTemplate: {
78 value: function() { 72 value: function() {
79 this.eventManager.addEventListener("appLoaded", this, false); 73 this.eventManager.addEventListener("appLoaded", this, false);
74
75 this.eventManager.addEventListener("executeFileOpen", this, false);
80 } 76 }
81 }, 77 },
82 78
@@ -86,37 +82,146 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
86 } 82 }
87 }, 83 },
88 84
85 handleExecuteFileOpen: {
86 value: function(event) {
87 var pickerSettings = event._event.settings || {};
88 pickerSettings.callback = this.openFileWithURI;
89 pickerSettings.callbackScope = this;
90 this.application.ninja.filePickerController.showFilePicker(pickerSettings);
91
92 //this.openDocument({"type": "js", "source": this.tmpSourceForTesting});
93 }
94 },
95
96 openFileWithURI: {
97 value: function(uriArrayObj) {
98 var uri = "", fileContent = "", response=null, filename="", fileType="js";
99 if(!!uriArrayObj && !!uriArrayObj.uri && (uriArrayObj.uri.length > 0)){
100 uri = uriArrayObj.uri[0];
101 }
102 //console.log("URI is: ", uri);
103
104 if(!!uri){
105 response = this.application.ninja.coreIoApi.openFile({"uri":uri});
106 if((response.success === true) && ((response.status === 200) || (response.status === 304))){
107 fileContent = response.content;
108 }
109
110 //console.log("$$$ "+uri+"\n content = \n\n\n"+ fileContent+"\n\n\n");
111 filename = nj.getFileNameFromPath(uri);
112 if(uri.indexOf('.') != -1){
113 fileType = uri.substr(uri.lastIndexOf('.') + 1);
114 }
115 this.openDocument({"type": ""+fileType, "name": ""+filename, "source": fileContent, "uri": uri});
116 }
117
118 }
119 },
120
121
122 openProjectWithURI: {
123 value: function(uri) {
124 console.log("URI is: ", uri);
125
126 }
127 },
128
89 /** Open a Document **/ 129 /** Open a Document **/
90 openDocument: { 130 openDocument: {
91 value: function(doc) { 131 value: function(doc) {
92 var d; 132 var newDoc;
93 133
94 if(!doc) return false; 134 if(!doc) return false;
95 135
96 try { 136 // try {
97 if (doc.type === 'html' || doc.type === 'htm') { 137 if (doc.type === 'html' || doc.type === 'htm') {
98 d = Montage.create(HTMLDocument); 138 newDoc = Montage.create(HTMLDocument);
99 d.initialize(doc, Uuid.generate(), this._createIframeElement(), this._onOpenDocument); 139 newDoc.initialize(doc, Uuid.generate(), this._createIframeElement(), this._onOpenDocument);
100 } else { 140 } else {
101 d = Montage.create(TextDocument); 141 newDoc = Montage.create(TextDocument, {
102 d.initialize(doc, Uuid.generate(), this._createTextAreaElement(), this._onOpenTextDocument); 142 "source": { value: doc.source }
143 });
144 var docUuid = Uuid.generate();
145 var textArea = this.application.ninja.stage.stageView.createTextAreaElement(docUuid);
146 newDoc.initialize(doc, docUuid, textArea, textArea.parentNode);
147
148 // Tmp this will be filled with the real content
149 newDoc.textArea.innerHTML = doc.source; //this.tmpSourceForTesting;
150
151 this.textDocumentOpened(newDoc);
152
103 } 153 }
104 154
105 } catch (err) { 155 // } catch (err) {
106 console.log("Could not open Document ", err); 156 // console.log("Could not open Document ", err);
107 } 157 // }
108 } 158 }
109 }, 159 },
110 160
161 textDocumentOpened: {
162 value: function(doc) {
163
164 this.activeDocument = doc;
165
166 this.application.ninja.stage.stageView.createTextView(doc);
167
168 /*
169 DocumentManager._hideCurrentDocument();
170 stageManagerModule.stageManager._scrollFlag = false; // TODO HACK to prevent type error on Hide/Show Iframe
171 DocumentManager.activeDocument = doc;
172
173 var type;
174
175 switch(doc.documentType) {
176 case "css" :