From 4c3aac5eabd93052b1554a03d78235215bb49db4 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Tue, 29 May 2012 00:34:40 -0700 Subject: document bindings phase 1 - using array controller to bind the current document to all ninja components - removed open document event - removed references to the document controller Signed-off-by: Valerio Virgillito --- js/stage/layout.js | 37 +++++++++++++++++++++++++------------ js/stage/stage-deps.js | 40 ++++++++++++++++++++++++++++------------ js/stage/stage.reel/stage.html | 18 +++++++++--------- js/stage/stage.reel/stage.js | 37 +++++++++++++++++++++++++------------ 4 files changed, 87 insertions(+), 45 deletions(-) (limited to 'js/stage') diff --git a/js/stage/layout.js b/js/stage/layout.js index 460c8b4a..8b66150d 100755 --- a/js/stage/layout.js +++ b/js/stage/layout.js @@ -23,6 +23,28 @@ exports.Layout = Montage.create(Component, { drawFillColor: { value: 'rgba(255,255,255,1)' }, ctxLineWidth: { value: 0.2 }, + _currentDocument: { + value : null, + enumerable : false + }, + + currentDocument : { + get : function() { + return this._currentDocument; + }, + set : function(value) { + if (value === this._currentDocument || value.getProperty("currentView") !== "design") { + return; + } + + this._currentDocument = value; + + if(this._currentDocument) { + this.elementsToDraw = this._currentDocument.model.documentRoot.childNodes; + } + } + }, + _layoutView: { value: "layoutAll" }, @@ -58,15 +80,6 @@ exports.Layout = Montage.create(Component, { } }, - handleOpenDocument: { - value: function() { - // Initial elements to draw are the childrens of the root element - if(this.application.ninja.documentController.activeDocument.currentView === "design") { - this.elementsToDraw = this.application.ninja.documentController.activeDocument.model.documentRoot.childNodes; - } - } - }, - // Redraw stage only once after all deletion is completed handleElementsRemoved: { value: function(event) { @@ -79,11 +92,11 @@ exports.Layout = Montage.create(Component, { value: function(event) { var containerIndex; - if(this.application.ninja.documentController.activeDocument === null){ + if(this.currentDocument === null){ return; } - if(this.application.ninja.documentController.activeDocument.currentView === "design"){ + if(this.currentDocument.currentView === "design"){ // Make an array copy of the line node list which is not an array like object this.domTree = this.application.ninja.currentDocument.model.views.design.getLiveNodeList(true); // Index of the current container @@ -219,7 +232,7 @@ exports.Layout = Montage.create(Component, { if(this.layoutView === "layoutAll") { this.ctx.strokeStyle = 'rgba(0,0,0,1)'; // Black Stroke this.ctx.strokeRect(bounds3D[0][0]+5.5, bounds3D[0][1]-15.5, 70, 11); - this.ctx.fillStyle = 'rgba(255,255,255,1)' // White Fill + this.ctx.fillStyle = 'rgba(255,255,255,1)'; // White Fill this.ctx.fillRect(bounds3D[0][0]+6, bounds3D[0][1]-15, 69, 10); this.ctx.fillStyle = 'rgba(0,0,0,1)'; diff --git a/js/stage/stage-deps.js b/js/stage/stage-deps.js index 896d4a5b..756844fd 100755 --- a/js/stage/stage-deps.js +++ b/js/stage/stage-deps.js @@ -14,6 +14,34 @@ var Montage = require("montage/core/core").Montage, VecUtils = require("js/helper-classes/3D/vec-utils").VecUtils; exports.StageDeps = Montage.create(Component, { + + _currentDocument: { + value : null, + enumerable : false + }, + + currentDocument : { + get : function() { + return this._currentDocument; + }, + set : function(value) { + if (value === this._currentDocument || value.getProperty("currentView") !== "design") { + return; + } + + this._currentDocument = value; + + if(this._currentDocument) { + workingPlane = [0,0,1,0]; + + snapManager._isCacheInvalid = true; + snapManager.setupDragPlaneFromPlane (workingPlane); + + drawUtils.initializeFromDocument(); + } + } + }, + viewUtils: { value: viewUtils }, @@ -59,18 +87,6 @@ exports.StageDeps = Montage.create(Component, { } }, - handleOpenDocument: { - value: function() { - - workingPlane = [0,0,1,0]; - - snapManager._isCacheInvalid = true; - snapManager.setupDragPlaneFromPlane (workingPlane); - - drawUtils.initializeFromDocument(); - } - }, - handleSwitchDocument: { value: function(){ workingPlane = [0,0,1,0]; diff --git a/js/stage/stage.reel/stage.html b/js/stage/stage.reel/stage.html index 30c3d231..89b674ab 100755 --- a/js/stage/stage.reel/stage.html +++ b/js/stage/stage.reel/stage.html @@ -18,25 +18,25 @@ } }, - "StageDeps1": { + "stageDeps": { "prototype": "js/stage/stage-deps", "properties": { "stage": {"@": "owner"} + }, + "bindings": { + "currentDocument": {"<-": "@owner.currentDocument"} } }, - "layout1": { + "layout": { "prototype": "js/stage/layout", "properties": { "canvas": {"#": "layoutCanvas"}, "stage": {"@": "owner"} }, "bindings": { - "layoutView": { - "boundObject": {"@": "owner" }, - "boundObjectPropertyPath": "appModel.layoutView", - "oneway": true - } + "layoutView": {"<-": "@owner.appModel.layoutView"}, + "currentDocument": {"<-": "@owner.currentDocument"} } }, @@ -59,8 +59,8 @@ "_layoutCanvas": {"#": "layoutCanvas"}, "_canvas": {"#": "stageCanvas"}, "_drawingCanvas": {"#": "drawingCanvas"}, - "stageDeps": {"@": "StageDeps1"}, - "layout": {"@": "layout1"}, + "stageDeps": {"@": "stageDeps"}, + "layout": {"@": "layout"}, "stageView": {"@": "stageView"}, "textTool": {"@": "textTool"}, "focusManager": {"@": "focusManager"} diff --git a/js/stage/stage.reel/stage.js b/js/stage/stage.reel/stage.js index c7afb95c..e00d2b54 100755 --- a/js/stage/stage.reel/stage.js +++ b/js/stage/stage.reel/stage.js @@ -155,25 +155,41 @@ exports.Stage = Montage.create(Component, { set: function(value) { this._userContentBorder = value; } }, - _activeDocument : { + _currentDocument: { value : null, enumerable : false }, - activeDocument : { + currentDocument : { get : function() { - return this._activeDocument; + return this._currentDocument; }, - set : function(document) { - ///// If the document is null set default stylesheets to null + set : function(value) { + // TODO: WRONG! Fails when going from design to code view + if (value === this._currentDocument || value.getProperty("currentView") !== "design") { + console.log("Stage - current document not set since the same value of " + this._currentDocument + " and value " + value); + return; + } - if(!document) { - return false; + if(!value) { + // Show the rulers + this.showRulers(); + // Show the canvas + this.hideCanvas(false); } - ///// setting document via binding - this._activeDocument = document; + //console.log("Stage - set current document with value of " + value); + this._currentDocument = value; + + if(this._currentDocument.currentView === "design") { + this.clearAllCanvas(); + this.initWithDocument(false); + } + if(!this._currentDocument) { + this.hideRulers(); + this.hideCanvas(true); + } }, enumerable : false }, @@ -295,9 +311,6 @@ exports.Stage = Montage.create(Component, { this._scrollLeft = 0; this._scrollTop = 0; - this.stageDeps.handleOpenDocument(); - this.layout.handleOpenDocument(); - if(designView._template) { var initialLeft = parseInt((this.canvas.width - designView._template.size.width)/2); var initialTop = parseInt((this.canvas.height - designView._template.size.height)/2); -- cgit v1.2.3