diff options
Diffstat (limited to 'js/controllers/document-controller.js')
-rwxr-xr-x | js/controllers/document-controller.js | 182 |
1 files changed, 36 insertions, 146 deletions
diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 2c34eedf..948e4550 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js | |||
@@ -8,38 +8,18 @@ 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 }, | ||
25 | _iframeHolder: { value: null, enumerable: false }, | ||
26 | _textHolder: { value: null, enumerable: false }, | ||
27 | _codeMirrorCounter: {value: 1, enumerable: false}, | ||
28 | |||
29 | activeDocument: { | ||
30 | get: function() { | ||
31 | return this._activeDocument; | ||
32 | }, | ||
33 | set: function(doc) { | ||
34 | //if(!!this._activeDocument){ this._activeDocument.isActive = false;} | ||
35 | |||
36 | this._activeDocument = doc; | ||
37 | |||
38 | if(!!this._activeDocument){ | ||
39 | if(this._documents.indexOf(doc) === -1) this._documents.push(doc); | ||
40 | this._activeDocument.isActive = true; | ||
41 | } | ||
42 | } | ||
43 | }, | 23 | }, |
44 | 24 | ||
45 | deserializedFromTemplate: { | 25 | deserializedFromTemplate: { |
@@ -52,8 +32,6 @@ exports.DocumentController = Montage.create(Component, { | |||
52 | this.eventManager.addEventListener("executeSaveAll", this, false); | 32 | this.eventManager.addEventListener("executeSaveAll", this, false); |
53 | this.eventManager.addEventListener("executeFileClose", this, false); | 33 | this.eventManager.addEventListener("executeFileClose", this, false); |
54 | this.eventManager.addEventListener("executeFileCloseAll", this, false); | 34 | this.eventManager.addEventListener("executeFileCloseAll", this, false); |
55 | |||
56 | this.eventManager.addEventListener("styleSheetDirty", this, false); | ||
57 | } | 35 | } |
58 | }, | 36 | }, |
59 | 37 | ||
@@ -70,11 +48,11 @@ exports.DocumentController = Montage.create(Component, { | |||
70 | if (this.redirectRequests && request.parentFrameId !== -1) { | 48 | if (this.redirectRequests && request.parentFrameId !== -1) { |
71 | //Checking for proper URL redirect (from different directories) | 49 | //Checking for proper URL redirect (from different directories) |
72 | if (request.url.indexOf('js/document/templates/banner') !== -1) { | 50 | 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]}; | 51 | 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) { | 52 | } 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]}; | 53 | 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) { | 54 | } 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]}; | 55 | 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 { | 56 | } else { |
79 | //Error, not a valid folder | 57 | //Error, not a valid folder |
80 | } | 58 | } |
@@ -98,13 +76,7 @@ exports.DocumentController = Montage.create(Component, { | |||
98 | }, | 76 | }, |
99 | //////////////////////////////////////////////////////////////////// | 77 | //////////////////////////////////////////////////////////////////// |
100 | 78 | ||
101 | 79 | ||
102 | |||
103 | |||
104 | |||
105 | |||
106 | |||
107 | |||
108 | handleExecuteFileOpen: { | 80 | handleExecuteFileOpen: { |
109 | value: function(event) { | 81 | value: function(event) { |
110 | var pickerSettings = event._event.settings || {}; | 82 | var pickerSettings = event._event.settings || {}; |
@@ -325,44 +297,6 @@ exports.DocumentController = Montage.create(Component, { | |||
325 | } | 297 | } |
326 | }, | 298 | }, |
327 | 299 | ||
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: { | 300 | closeFile: { |
367 | value: function(document) { | 301 | value: function(document) { |
368 | document.closeDocument(this, this.onCloseFile); | 302 | document.closeDocument(this, this.onCloseFile); |
@@ -373,7 +307,8 @@ exports.DocumentController = Montage.create(Component, { | |||
373 | value: function(doc) { | 307 | value: function(doc) { |
374 | var previousFocusedDocument; | 308 | var previousFocusedDocument; |
375 | 309 | ||
376 | this._documents.splice(this._documents.indexOf(doc), 1); | 310 | // this._documents.splice(this._documents.indexOf(doc), 1); |
311 | this.application.ninja.docController.removeObjects(this._documents.indexOf(doc)); | ||
377 | 312 | ||
378 | if(this._documents.length > 0) { | 313 | if(this._documents.length > 0) { |
379 | previousFocusedDocument = this._documents[this._documents.length - 1]; | 314 | previousFocusedDocument = this._documents[this._documents.length - 1]; |
@@ -433,48 +368,44 @@ exports.DocumentController = Montage.create(Component, { | |||
433 | // Open document callback | 368 | // Open document callback |
434 | _onOpenDocument: { | 369 | _onOpenDocument: { |
435 | value: function(doc){ | 370 | value: function(doc){ |
436 | var currentDocument; | 371 | |
437 | if(this.activeDocument) { | 372 | |
373 | // Bypass all and call main. | ||
374 | // TODO: Call ninja directly once this is all cleaned up. | ||
375 | |||
376 | this.application.ninja.handleOnOpenDocument(doc); | ||
377 | |||
378 | |||
379 | // var currentDocument; | ||
380 | // if(this.activeDocument) { | ||
438 | // There is a document currently opened | 381 | // There is a document currently opened |
439 | currentDocument = this.activeDocument; | 382 | // currentDocument = this.activeDocument; |
440 | } else { | 383 | // } else { |
441 | // There is no document opened | 384 | // There is no document opened |
442 | 385 | ||
443 | // Show the rulers | 386 | // } |
444 | // TODO: Move this indo design view | ||
445 | this.application.ninja.stage.showRulers(); | ||
446 | |||
447 | // Show the canvas | ||
448 | this.application.ninja.stage.hideCanvas(false); | ||
449 | } | ||
450 | 387 | ||
451 | // Set the active document | 388 | // Set the active document |
452 | this.activeDocument = doc; | 389 | // this.activeDocument = doc; |
390 | |||
391 | |||
392 | // this.switchDocuments(currentDocument, doc, true); | ||
453 | 393 | ||
454 | // Initialize the documentRoot styles | ||
455 | this.initializeRootStyles(doc.model.documentRoot); | ||
456 | // Flag to stop stylesheet dirty event | ||
457 | this._hackInitialStyles = false; | ||
458 | 394 | ||
459 | this.switchDocuments(currentDocument, doc, true); | ||
460 | } | 395 | } |
461 | }, | 396 | }, |
462 | 397 | ||
463 | 398 | ||
464 | _onOpenTextDocument: { | 399 | _onOpenTextDocument: { |
465 | value: function(doc) { | 400 | value: function(doc) { |
466 | var currentDocument = null; | ||
467 | if(this.activeDocument) { | ||
468 | // There is a document currently opened | ||
469 | currentDocument = this.activeDocument; | ||
470 | } | ||
471 | 401 | ||
472 | this.application.ninja.currentDocument = this.activeDocument = doc; | 402 | this.application.ninja.handleOnOpenDocument(doc); |
473 |