From db0fa4e454b76d8a2bd6ba47c6f10166761179e7 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Wed, 4 Apr 2012 14:06:38 -0700 Subject: Adding replaceElement routine and event so Timeline can avoid removing and adding layers and PI and SelectionController can avoid deselecting and reselecting the element. Signed-off-by: Nivesh Rajbhandari --- js/controllers/elements/shapes-controller.js | 8 ++----- js/controllers/selection-controller.js | 7 +++++++ js/helper-classes/3D/draw-utils.js | 31 +++++++++++++++++++++++++++- js/helper-classes/3D/snap-manager.js | 9 ++++++-- js/mediators/element-mediator.js | 17 +++++++++++++++ 5 files changed, 63 insertions(+), 9 deletions(-) diff --git a/js/controllers/elements/shapes-controller.js b/js/controllers/elements/shapes-controller.js index c9164e3e..e792c646 100755 --- a/js/controllers/elements/shapes-controller.js +++ b/js/controllers/elements/shapes-controller.js @@ -73,12 +73,8 @@ exports.ShapesController = Montage.create(CanvasController, { canvas.width = el.width; canvas.height = el.height; canvas.elementModel = el.elementModel; - this.application.ninja.currentDocument.documentRoot.replaceChild(canvas, el); - NJevent("elementsRemoved", el); - el = canvas; - this.toggleWebGlMode(el, value); - el.elementModel.shapeModel.GLWorld.render(); - this.application.ninja.selectionController.selectElement(el); + this.toggleWebGlMode(canvas, value); + this.application.ninja.elementMediator.replaceElement(canvas, el); return; case "strokeMaterial": var sm = Object.create(MaterialsModel.getMaterial(value)); diff --git a/js/controllers/selection-controller.js b/js/controllers/selection-controller.js index dbb3f30d..5665b09c 100755 --- a/js/controllers/selection-controller.js +++ b/js/controllers/selection-controller.js @@ -45,6 +45,7 @@ exports.SelectionController = Montage.create(Component, { this.eventManager.addEventListener("openDocument", this, false); this.eventManager.addEventListener("elementAdded", this, false); this.eventManager.addEventListener("elementsRemoved", this, false); + this.eventManager.addEventListener("elementReplaced", this, false); this.eventManager.addEventListener("selectAll", this, false); this.eventManager.addEventListener("switchDocument", this, false); this.eventManager.addEventListener("closeDocument", this, false); @@ -103,6 +104,12 @@ exports.SelectionController = Montage.create(Component, { } }, + handleElementReplaced: { + value: function(event) { + this.application.ninja.selectedElements[this.application.ninja.selectedElements.indexOf(event.detail.data.oldChild)] = event.detail.data.newChild; + } + }, + handleSelectAll: { value: function(event) { var selected = [], childNodes = []; diff --git a/js/helper-classes/3D/draw-utils.js b/js/helper-classes/3D/draw-utils.js index c7c1c08d..a5428ea3 100755 --- a/js/helper-classes/3D/draw-utils.js +++ b/js/helper-classes/3D/draw-utils.js @@ -112,6 +112,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { this.eventManager.addEventListener("elementsRemoved", this, false); this.eventManager.addEventListener("elementChange", this, false); this.eventManager.addEventListener("closeDocument", this, false); + this.eventManager.addEventListener("elementReplaced", this, false); } }, @@ -170,13 +171,41 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { this.removeElement(element); }, this); } else { - this.removeElement(elements._element || elements); + this.removeElement(elements); } this.drawWorkingPlane(); } }, + handleElementReplaced: { + value: function(event) { + var oldElement = event.detail.data.oldChild; + var newElement = event.detail.data.newChild; + + // check if we already know about this object + var n = this._eltArray.length, + plane; + for (var i=0; i