aboutsummaryrefslogtreecommitdiff
path: root/js/controllers/document-controller.js
diff options
context:
space:
mode:
authorAnanya Sen2012-05-21 16:42:26 -0700
committerAnanya Sen2012-05-21 16:42:26 -0700
commit2cc8e58f6bb9f64a7473e62aecd013fa55167231 (patch)
tree4969012e500a27c72cf59c0a631990c6b9a1c333 /js/controllers/document-controller.js
parentc3c2ffc8d057660b7c42b45442885cd0d2d598bc (diff)
downloadninja-2cc8e58f6bb9f64a7473e62aecd013fa55167231.tar.gz
- added opening multiple code and design view documents
- switching between multiple code and design view documents - Note: closing of documents, when multiple documents are open, is not yet implemented Signed-off-by: Ananya Sen <Ananya.Sen@motorola.com>
Diffstat (limited to 'js/controllers/document-controller.js')
-rwxr-xr-xjs/controllers/document-controller.js105
1 files changed, 64 insertions, 41 deletions
diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js
index 814a30e1..26c3ebaa 100755
--- a/js/controllers/document-controller.js
+++ b/js/controllers/document-controller.js
@@ -52,10 +52,6 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
52 if(!!this._activeDocument){ 52 if(!!this._activeDocument){
53 if(this._documents.indexOf(doc) === -1) this._documents.push(doc); 53 if(this._documents.indexOf(doc) === -1) this._documents.push(doc);
54 this._activeDocument.isActive = true; 54 this._activeDocument.isActive = true;
55
56 if(!!this._activeDocument.editor){
57 this._activeDocument.editor.focus();
58 }
59 } 55 }
60 } 56 }
61 }, 57 },
@@ -312,10 +308,9 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
312 this.activeDocument.uri = fileUri; 308 this.activeDocument.uri = fileUri;
313 //save a new file 309 //save a new file
314 //use the ioMediator.fileSaveAll when implemented 310 //use the ioMediator.fileSaveAll when implemented
315 this.activeDocument._userDocument.name=filename; 311 this.activeDocument.model.file.name=filename;
316 this.activeDocument._userDocument.root=destination; 312 this.activeDocument.model.file.uri=fileUri;
317 this.activeDocument._userDocument.uri=fileUri; 313 this.activeDocument.model.save();
318 this.application.ninja.ioMediator.fileSave(this.activeDocument.save(), this.fileSaveResult.bind(this));
319 // 314 //
320 } 315 }
321 }, 316 },
@@ -408,7 +403,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
408 403
409 this._activeDocument = null; 404 this._activeDocument = null;
410 405
411 this.application.ninja.stage.stageView.hideRulers(); 406 this.application.ninja.stage.hideRulers();
412 407
413// document.getElementById("iframeContainer").style.display="block"; 408// document.getElementById("iframeContainer").style.display="block";
414 409
@@ -471,7 +466,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
471 466
472 // Show the rulers 467 // Show the rulers
473 // TODO: Move this indo design view 468 // TODO: Move this indo design view
474 this.application.ninja.stage.stageView.showRulers(); 469 this.application.ninja.stage.showRulers();
475 470
476 // Show the canvas 471 // Show the canvas
477 this.application.ninja.stage.hideCanvas(false); 472 this.application.ninja.stage.hideCanvas(false);
@@ -489,53 +484,81 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
489 } 484 }
490 }, 485 },
491 486
487
488 _onOpenTextDocument: {
489 value: function(doc) {
490 var currentDocument=null;
491 if(this.activeDocument) {
492 // There is a document currently opened
493 currentDocument = this.activeDocument;
494 }
495
496 this.application.ninja.stage._scrollFlag = false; // TODO HACK to prevent type error on Hide/Show Iframe
497 this.activeDocument = doc;
498 document.getElementById("iframeContainer").style.display = "none";
499 this.application.ninja.codeEditorController.applySettings();
500 this.switchDocuments(currentDocument, doc, true);
501 }
502 },
503
492 switchDocuments: { 504 switchDocuments: {
493 value: function(currentDocument, newDocument, didCreate) { 505 value: function(currentDocument, newDocument, didCreate) {
494 506
495 if(currentDocument) { 507 if(currentDocument && currentDocument.currentView === "design") {
496 currentDocument.serializeDocument(); 508 currentDocument.serializeDocument();
497
498 this.application.ninja.selectionController._selectionContainer = null; 509 this.application.ninja.selectionController._selectionContainer = null;
499 currentDocument.model.views.design.propertiesPanel.clear(); 510 currentDocument.model.views.design.propertiesPanel.clear();
500 currentDocument.model.views.design.hide();
501 } 511 }
502 512
503 this.application.ninja.stage.clearAllCanvas(); 513 if(currentDocument) {
514 currentDocument.model.currentView.hide();
515 currentDocument.model.isActive = false;
516 }
517 if(currentDocument && newDocument && (currentDocument.model.parentContainer !== newDocument.model.parentContainer)){
518 currentDocument.model.parentContainer.style["display"] = "none";
519 }
504 520
505 if(didCreate) { 521 if(newDocument && newDocument.currentView === "code"){
506 newDocument.model.views.design.iframe.style.opacity = 1; 522 this.application.ninja.stage.showCodeViewBar(true);
507 NJevent("onOpenDocument", newDocument); 523 this.application.ninja.stage.collapseAllPanels();
508 } else { 524 this.application.ninja.stage.hideCanvas(true);
509 this.activeDocument = newDocument; 525 this.application.ninja.stage.hideRulers();
510 newDocument.model.views.design.show(); 526
511 newDocument.deserializeDocument(); 527 newDocument.model.views.code.editor.focus();
512 NJevent("onSwitchDocument"); 528
529 }else if(currentDocument && newDocument && newDocument.currentView === "design"){
530 this.application.ninja.stage.showCodeViewBar(false);
531 this.application.ninja.stage.restoreAllPanels();
532 this.application.ninja.stage.hideCanvas(false);
533 this.application.ninja.stage.showRulers();
513 } 534 }
514 }
515 },
516 535
536 this.application.ninja.stage.clearAllCanvas();
517 537
518 _onOpenTextDocument: { 538 if(didCreate) {
519 value: function(doc) { 539 newDocument.model.currentView.show();
520 if(this.activeDocument) { 540 newDocument.model.parentContainer.style["display"] = "block";
541 if(newDocument.currentView === "design") {
542 newDocument.model.views.design.iframe.style.opacity = 1;
543 NJevent("onOpenDocument", newDocument);
544 }
545 }
546 else {
547 this.activeDocument = newDocument;
521 548
522 if(this.activeDocument.currentView === "design"){ 549 newDocument.model.currentView.show();
523 this.activeDocument.saveAppState(); 550 if(currentDocument && newDocument && (currentDocument.model.parentContainer !== newDocument.model.parentContainer)){
524 this.activeDocument.parentContainer.style["display"] = "none"; 551 newDocument.model.parentContainer.style["display"] = "block";
525 this.application.ninja.stage.hideCanvas(true);
526 this.application.ninja.stage.stageView.hideRulers();
527 } 552 }
528 553
529 this.activeDocument.container.style["display"] = "none"; 554 if(newDocument.currentView === "design") {
555 newDocument.deserializeDocument();
556 NJevent("onSwitchDocument");
557 }else{
558 newDocument.model.isActive = true;
559 this.application.ninja.codeEditorController.applySettings();//should be called after activeDocument is updated
560 }
530 } 561 }
531
532 this.application.ninja.stage._scrollFlag = false; // TODO HACK to prevent type error on Hide/Show Iframe
533 this.activeDocument = doc;
534 //hide the iframe when switching to code view
535 document.getElementById("iframeContainer").style.display = "none";
536 doc.model.views.code.showCodeViewBar(true);
537 this.application.ninja.codeEditorController.applySettings();
538 doc.model.views.code.collapseAllPanels();
539 } 562 }
540 }, 563 },
541 564