diff options
Diffstat (limited to 'js/controllers/document-controller.js')
-rwxr-xr-x | js/controllers/document-controller.js | 264 |
1 files changed, 46 insertions, 218 deletions
diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 2c34eedf..4f122b3b 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js | |||
@@ -8,37 +8,47 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
8 | // | 8 | // |
9 | var Montage = require("montage/core/core").Montage, | 9 | var 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, | ||
12 | HTMLDocument = require("js/document/document-html").HtmlDocument, | 11 | HTMLDocument = require("js/document/document-html").HtmlDocument, |
13 | TextDocument = require("js/document/document-text").TextDocument; | 12 | TextDocument = require("js/document/document-text").TextDocument; |
14 | //////////////////////////////////////////////////////////////////////// | 13 | //////////////////////////////////////////////////////////////////////// |
15 | // | 14 | // |
16 | exports.DocumentController = Montage.create(Component, { | 15 | exports.DocumentController = Montage.create(Component, { |
17 | // | 16 | // |
18 | hasTemplate: {value: false}, | 17 | hasTemplate: { |
19 | _documents: {value: []}, | 18 | value: false |
20 | //TODO: what is this?!?! | 19 | }, |
21 | _hackInitialStyles: {value: true}, | 20 | |
22 | _activeDocument: { value: null }, | 21 | documents: { |
23 | //TODO: Are any of these needed? | 22 | value: [] |
24 | _iframeCounter: { value: 1, enumerable: false }, | 23 | }, |
25 | _iframeHolder: { value: null, enumerable: false }, | 24 | |
26 | _textHolder: { value: null, enumerable: false }, | 25 | _currentDocument: { |
27 | _codeMirrorCounter: {value: 1, enumerable: false}, | 26 | value : null |
28 | 27 | }, | |
29 | activeDocument: { | 28 | |
30 | get: function() { | 29 | currentDocument : { |
31 | return this._activeDocument; | 30 | get : function() { |
31 | return this._currentDocument; | ||
32 | }, | 32 | }, |
33 | set: function(doc) { | 33 | set : function(value) { |
34 | //if(!!this._activeDocument){ this._activeDocument.isActive = false;} | 34 | if (value === this._currentDocument) { |
35 | return; | ||
36 | } | ||
37 | |||
38 | if(this._currentDocument) { | ||
39 | this._currentDocument.model.currentView.hide(); | ||
40 | } | ||
41 | |||
42 | this._currentDocument = value; | ||
35 | 43 | ||
36 | this._activeDocument = doc; | 44 | if(!value) { |
37 | 45 | ||
38 | if(!!this._activeDocument){ | 46 | } else { |
39 | if(this._documents.indexOf(doc) === -1) this._documents.push(doc); | 47 | this._currentDocument.model.currentView.show(); |
40 | this._activeDocument.isActive = true; | ||
41 | } | 48 | } |
49 | |||
50 | |||
51 | |||
42 | } | 52 | } |
43 | }, | 53 | }, |
44 | 54 | ||
@@ -52,8 +62,6 @@ exports.DocumentController = Montage.create(Component, { | |||
52 | this.eventManager.addEventListener("executeSaveAll", this, false); | 62 | this.eventManager.addEventListener("executeSaveAll", this, false); |
53 | this.eventManager.addEventListener("executeFileClose", this, false); | 63 | this.eventManager.addEventListener("executeFileClose", this, false); |
54 | this.eventManager.addEventListener("executeFileCloseAll", this, false); | 64 | this.eventManager.addEventListener("executeFileCloseAll", this, false); |
55 | |||
56 | this.eventManager.addEventListener("styleSheetDirty", this, false); | ||
57 | } | 65 | } |
58 | }, | 66 | }, |
59 | 67 | ||
@@ -70,11 +78,11 @@ exports.DocumentController = Montage.create(Component, { | |||
70 | if (this.redirectRequests && request.parentFrameId !== -1) { | 78 | if (this.redirectRequests && request.parentFrameId !== -1) { |
71 | //Checking for proper URL redirect (from different directories) | 79 | //Checking for proper URL redirect (from different directories) |
72 | if (request.url.indexOf('js/document/templates/banner') !== -1) { | 80 | if (request.url.indexOf('js/document/templates/banner') !== -1) { |
73 | return {redirectUrl: this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+request.url.split(chrome.extension.getURL('js/document/templates/banner/'))[1]}; | 81 | return {redirectUrl: this.application.ninja.coreIoApi.rootUrl+this.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+request.url.split(chrome.extension.getURL('js/document/templates/banner/'))[1]}; |
74 | } else if (request.url.indexOf('js/document/templates/html') !== -1) { | 82 | } else if (request.url.indexOf('js/document/templates/html') !== -1) { |
75 | return {redirectUrl: this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+request.url.split(chrome.extension.getURL('js/document/templates/html/'))[1]}; | 83 | return {redirectUrl: this.application.ninja.coreIoApi.rootUrl+this.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+request.url.split(chrome.extension.getURL('js/document/templates/html/'))[1]}; |
76 | } else if (request.url.indexOf('js/document/templates/app') !== -1) { | 84 | } else if (request.url.indexOf('js/document/templates/app') !== -1) { |
77 | return {redirectUrl: this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+request.url.split(chrome.extension.getURL('js/document/templates/app/'))[1]}; | 85 | return {redirectUrl: this.application.ninja.coreIoApi.rootUrl+this.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+request.url.split(chrome.extension.getURL('js/document/templates/app/'))[1]}; |
78 | } else { | 86 | } else { |
79 | //Error, not a valid folder | 87 | //Error, not a valid folder |
80 | } | 88 | } |
@@ -98,13 +106,7 @@ exports.DocumentController = Montage.create(Component, { | |||
98 | }, | 106 | }, |
99 | //////////////////////////////////////////////////////////////////// | 107 | //////////////////////////////////////////////////////////////////// |
100 | 108 | ||
101 | 109 | ||
102 | |||
103 | |||
104 | |||
105 | |||
106 | |||
107 | |||
108 | handleExecuteFileOpen: { | 110 | handleExecuteFileOpen: { |
109 | value: function(event) { | 111 | value: function(event) { |
110 | var pickerSettings = event._event.settings || {}; | 112 | var pickerSettings = event._event.settings || {}; |
@@ -308,11 +310,11 @@ exports.DocumentController = Montage.create(Component, { | |||
308 | 310 | ||
309 | //Open in designer view | 311 | //Open in designer view |
310 | this.redirectRequests = false; | 312 | this.redirectRequests = false; |
311 | Montage.create(HTMLDocument).init(file, this, this._onOpenDocument, 'design', template); | 313 | Montage.create(HTMLDocument).init(file, this.application.ninja, this.application.ninja.openDocument, 'design', template); |
312 | break; | 314 | break; |
313 | default: | 315 | default: |
314 | //Open in code view | 316 | //Open in code view |
315 | Montage.create(TextDocument).init(file, this, this._onOpenTextDocument, 'code'); | 317 | Montage.create(TextDocument).init(file, this.application.ninja, this.application.ninja.openDocument, 'code'); |
316 | break; | 318 | break; |
317 | } | 319 | } |
318 | } | 320 | } |
@@ -325,47 +327,9 @@ exports.DocumentController = Montage.create(Component, { | |||
325 | } | 327 | } |
326 | }, | 328 | }, |
327 | 329 | ||
328 | //todo: remove this funciton as it is not used | ||
329 | textDocumentOpened: { | ||
330 | value: function(doc) { | ||
331 | |||
332 | |||
333 | |||
334 | this.application.ninja.stage.stageView.createTextView(doc); | ||
335 | |||
336 | /* | ||
337 | DocumentManager._hideCurrentDocument(); | ||
338 | stageManagerModule.stageManager._scrollFlag = false; // TODO HACK to prevent type error on Hide/Show Iframe | ||
339 | DocumentManager.activeDocument = doc; | ||
340 | |||
341 | var type; | ||
342 | |||
343 | switch(doc.documentType) { | ||
344 | case "css" : | ||
345 | type = "css"; | ||
346 | break; | ||
347 | case "js" : | ||
348 | type = "javascript"; | ||
349 | break; | ||
350 | } | ||
351 | |||
352 | DocumentManager._codeEditor.editor = CodeMirror.fromTextArea(doc.textArea, { | ||
353 | lineNumbers: true, | ||
354 | mode: type, | ||
355 | onCursorActivity: function() { | ||
356 | DocumentManager._codeEditor.editor.setLineClass(DocumentManager._codeEditor.hline, null); | ||
357 | DocumentManager._codeEditor.hline = DocumentManager._codeEditor.editor.setLineClass(DocumentManager._codeEditor.editor.getCursor().line, "activeline"); | ||
358 | } | ||
359 | }); | ||
360 | DocumentManager._codeEditor.hline = DocumentManager._codeEditor.editor.setLineClass(0, "activeline"); | ||
361 | */ | ||
362 | |||
363 | } | ||
364 | }, | ||
365 | |||
366 | closeFile: { | 330 | closeFile: { |
367 | value: function(document) { | 331 | value: function(document) { |
368 | document.closeDocument(this, this.onCloseFile); | 332 | document.closeDocument(this.application.ninja, this.application.ninja.closeFile); |
369 | } | 333 | } |
370 | }, | 334 | }, |
371 | 335 | ||
@@ -373,7 +337,8 @@ exports.DocumentController = Montage.create(Component, { | |||
373 | value: function(doc) { | 337 | value: function(doc) { |
374 | var previousFocusedDocument; | 338 | var previousFocusedDocument; |
375 | 339 | ||
376 | this._documents.splice(this._documents.indexOf(doc), 1); | 340 | // this._documents.splice(this._documents.indexOf(doc), 1); |
341 | this.application.ninja.docController.removeObjects(this._documents.indexOf(doc)); | ||
377 | 342 | ||
378 | if(this._documents.length > 0) { | 343 | if(this._documents.length > 0) { |
379 | previousFocusedDocument = this._documents[this._documents.length - 1]; | 344 | previousFocusedDocument = this._documents[this._documents.length - 1]; |
@@ -398,83 +363,14 @@ exports.DocumentController = Montage.create(Component, { | |||
398 | } | 363 | } |
399 | }, | 364 | }, |
400 | 365 | ||
401 | closeDocument: { | ||
402 | value: function(id) { | ||
403 | var doc = this._findDocumentByUUID(id); | ||
404 | |||
405 | var closeDocumentIndex = this._findIndexByUUID(id); | ||
406 | this._documents.splice(this._findIndexByUUID(id), 1); | ||
407 | |||
408 | if(this.activeDocument.uuid === id && this._documents.length > 0) {//closing the active document tab | ||
409 | var nextDocumentIndex = -1 ; | ||
410 | if((this._documents.length > 0) && (closeDocumentIndex === 0)){ | ||
411 | nextDocumentIndex = 0; | ||
412 | }else if((this._documents.length > 0) && (closeDocumentIndex > 0)){ | ||
413 | nextDocumentIndex = closeDocumentIndex - 1; | ||
414 | } | ||
415 | this.application.ninja.stage.stageView.switchDocument(this._documents[nextDocumentIndex]); | ||
416 | if(typeof doc.stopVideos !== "undefined"){doc.stopVideos();} | ||