aboutsummaryrefslogtreecommitdiff
path: root/js/controllers/document-controller.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/controllers/document-controller.js')
-rwxr-xr-xjs/controllers/document-controller.js175
1 files changed, 90 insertions, 85 deletions
diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js
index f6b850b2..7758f346 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 },
@@ -311,42 +304,38 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
311 this.activeDocument.uri = fileUri; 304 this.activeDocument.uri = fileUri;
312 //save a new file 305 //save a new file
313 //use the ioMediator.fileSaveAll when implemented 306 //use the ioMediator.fileSaveAll when implemented
314 this.activeDocument._userDocument.name=filename; 307 this.activeDocument.model.file.name = filename;
315 this.activeDocument._userDocument.root=destination; 308 this.activeDocument.model.file.uri = fileUri;
316 this.activeDocument._userDocument.uri=fileUri; 309 this.activeDocument.model.save();
317 this.application.ninja.ioMediator.fileSave(this.activeDocument.save(), this.fileSaveResult.bind(this));
318 //
319 } 310 }
320 }, 311 },
321 312
322 //////////////////////////////////////////////////////////////////// 313 ////////////////////////////////////////////////////////////////////
323 openDocument: { 314 openDocument: {
324 value: function(doc) { 315 value: function(file) {
325 var template, dimensions; 316 var template, dimensions;
326 if (doc.content.body.indexOf('Ninja-Banner Dimensions@@@') !== -1) { 317
327 dimensions = (doc.content.body.split('Ninja-Banner Dimensions@@@'))[1].split('-->')[0].split('x');
328 dimensions = {width: parseInt(dimensions[0]), height: parseInt(dimensions[1])};
329 template = {type: 'banner', size: dimensions};
330 }
331 // TODO: HACKS to remove 318 // TODO: HACKS to remove
332 this.documentHackReference = doc; 319 this.documentHackReference = file;
333 document.getElementById("iframeContainer").style.overflow = "hidden"; 320 document.getElementById("iframeContainer").style.overflow = "hidden";
334 // 321 //
335 switch (doc.extension) { 322 switch (file.extension) {
336 case 'html': 323 case 'html':
324
325 if (file.content.body.indexOf('Ninja-Banner Dimensions@@@') !== -1) {
326 dimensions = (file.content.body.split('Ninja-Banner Dimensions@@@'))[1].split('-->')[0].split('x');
327 dimensions = {width: parseInt(dimensions[0]), height: parseInt(dimensions[1])};
328 template = {type: 'banner', size: dimensions};
329 }
330
337 //Open in designer view 331 //Open in designer view
338 this._hackRootFlag = false; 332 this._hackRootFlag = false;
339 Montage.create(Document).init(doc, this, this._onOpenDocument, 'design', template); 333 Montage.create(HTMLDocument).init(file, this, this._onOpenDocument, 'design', template);
340 break; 334 break;
341 default: 335 default:
342 //Open in code view 336 //Open in code view
343 var code = Montage.create(TextDocument, {"source": {value: doc.content}}), docuuid = Uuid.generate(), textArea; 337 Montage.create(TextDocument).init(file, this, this._onOpenTextDocument, 'code');
344 textArea = this.application.ninja.stage.stageView.createTextAreaElement(docuuid); 338 break;
345 code.initialize(doc, docuuid, textArea, textArea.parentNode);
346 //code.init(doc.name, doc.uri, doc.extension, null, docuuid);
347 code.textArea.value = doc.content;
348 this.application.ninja.stage.stageView.createTextView(code);
349 break;
350 } 339 }
351 } 340 }
352 }, 341 },
@@ -357,7 +346,8 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
357 console.log("URI is: ", uri); 346 console.log("URI is: ", uri);
358 } 347 }
359 }, 348 },
360 349
350 //todo: remove this funciton as it is not used
361 textDocumentOpened: { 351 textDocumentOpened: {
362 value: function(doc) { 352 value: function(doc) {
363 353
@@ -408,14 +398,18 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
408 398
409 this._activeDocument = null; 399 this._activeDocument = null;
410 400
411 this.application.ninja.stage.stageView.hideRulers(); 401 this.application.ninja.stage.hideRulers();
412
413// document.getElementById("iframeContainer").style.display="block";
414 402
415 this.application.ninja.stage.hideCanvas(true); 403 this.application.ninja.stage.hideCanvas(true);
416 404
405 //TODO: Use references for those instead of calling getElementById
406 if(this._documents.length === 0){
407 document.getElementById("iframeContainer").style.display="block";
408 document.getElementById("codeViewContainer").style.display="block";
409 }
417 410
418 NJevent("closeDocument", doc.model.file.uri); 411 NJevent("closeDocument", doc.model.file.uri);
412
419 //TODO: Delete object here 413 //TODO: Delete object here
420 } 414 }
421 }, 415 },
@@ -459,14 +453,12 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
459 if(this.activeDocument) { 453 if(this.activeDocument) {
460 // There is a document currently opened 454 // There is a document currently opened
461 currentDocument = this.activeDocument; 455 currentDocument = this.activeDocument;
462
463 //this.application.ninja.stage.stageView.restoreAllPanels();
464 } else { 456 } else {
465 // There is no document opened 457 // There is no document opened
466 458
467 // Show the rulers 459 // Show the rulers
468 // TODO: Move this indo design view 460 // TODO: Move this indo design view
469 this.application.ninja.stage.stageView.showRulers(); 461 this.application.ninja.stage.showRulers();
470 462
471 // Show the canvas 463 // Show the canvas
472 this.application.ninja.stage.hideCanvas(false); 464 this.application.ninja.stage.hideCanvas(false);
@@ -484,69 +476,82 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
484 } 476 }
485 }, 477 },
486 478
487 switchDocuments: {
488 value: function(currentDocument, newDocument, didCreate) {
489
490 if(currentDocument) {
491 currentDocument.serializeDocument();
492 479
493 this.application.ninja.selectionController._selectionContainer = null; 480 _onOpenTextDocument: {
494 currentDocument.model.views.design.propertiesPanel.clear(); 481 value: function(doc) {
495 currentDocument.model.views.design.hide(); 482 var currentDocument = null;
483 if(this.activeDocument) {
484 // There is a document currently opened
485 currentDocument = this.activeDocument;
496 } 486 }
497 487
498 this.application.ninja.stage.clearAllCanvas(); 488 this.application.ninja.currentDocument = this.activeDocument = doc;
499 489
500 if(didCreate) { 490 document.getElementById("iframeContainer").style.display = "none";
501 newDocument.model.views.design.iframe.style.opacity = 1; 491 this.application.ninja.codeEditorController.applySettings();
502 NJevent("onOpenDocument", newDocument); 492
503 } else { 493 this.switchDocuments(currentDocument, doc, true);
504 this.activeDocument = newDocument;
505 newDocument.model.views.design.show();
506 newDocument.deserializeDocument();
507 NJevent("onSwitchDocument");
508 }
509 } 494 }
510 }, 495 },
511 496
497 switchDocuments: {
498 value: function(currentDocument, newDocument, didCreate) {
512 499
513 _onOpenTextDocument: { 500 if(currentDocument) {
514 value: function(doc) { 501 if(currentDocument.currentView === "design") {
515 if(this.activeDocument) { 502 currentDocument.serializeDocument();
516 if(this.activeDocument.currentView === "design"){ 503 this.application.ninja._currentSelectedContainer = this.application.ninja.selectionController._selectionContainer = null;
517 this.activeDocument.saveAppState(); 504 currentDocument.model.views.design.propertiesPanel.clear();
518 this.activeDocument.container.parentNode.style["display"] = "none";
519 this.application.ninja.stage.hideCanvas(true);
520 this.application.ninja.stage.stageView.hideRulers();
521 } 505 }
522 506
523 this.activeDocument.container.style["display"] = "none"; 507 currentDocument.model.isActive = false;
524 }