diff options
author | Nivesh Rajbhandari | 2012-04-04 14:06:38 -0700 |
---|---|---|
committer | Nivesh Rajbhandari | 2012-04-04 14:06:38 -0700 |
commit | db0fa4e454b76d8a2bd6ba47c6f10166761179e7 (patch) | |
tree | ad28f7324d2d08163247e9be8f0982d6739e5eaf | |
parent | 8482e23cd9b8c4700b5130f2588e5eb24d376536 (diff) | |
download | ninja-db0fa4e454b76d8a2bd6ba47c6f10166761179e7.tar.gz |
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 <mqg734@motorola.com>
-rwxr-xr-x | js/controllers/elements/shapes-controller.js | 8 | ||||
-rwxr-xr-x | js/controllers/selection-controller.js | 7 | ||||
-rwxr-xr-x | js/helper-classes/3D/draw-utils.js | 31 | ||||
-rwxr-xr-x | js/helper-classes/3D/snap-manager.js | 9 | ||||
-rwxr-xr-x | 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, { | |||
73 | canvas.width = el.width; | 73 | canvas.width = el.width; |
74 | canvas.height = el.height; | 74 | canvas.height = el.height; |
75 | canvas.elementModel = el.elementModel; | 75 | canvas.elementModel = el.elementModel; |
76 | this.application.ninja.currentDocument.documentRoot.replaceChild(canvas, el); | 76 | this.toggleWebGlMode(canvas, value); |
77 | NJevent("elementsRemoved", el); | 77 | this.application.ninja.elementMediator.replaceElement(canvas, el); |
78 | el = canvas; | ||
79 | this.toggleWebGlMode(el, value); | ||
80 | el.elementModel.shapeModel.GLWorld.render(); | ||
81 | this.application.ninja.selectionController.selectElement(el); | ||
82 | return; | 78 | return; |
83 | case "strokeMaterial": | 79 | case "strokeMaterial": |
84 | var sm = Object.create(MaterialsModel.getMaterial(value)); | 80 | 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, { | |||
45 | this.eventManager.addEventListener("openDocument", this, false); | 45 | this.eventManager.addEventListener("openDocument", this, false); |
46 | this.eventManager.addEventListener("elementAdded", this, false); | 46 | this.eventManager.addEventListener("elementAdded", this, false); |
47 | this.eventManager.addEventListener("elementsRemoved", this, false); | 47 | this.eventManager.addEventListener("elementsRemoved", this, false); |
48 | this.eventManager.addEventListener("elementReplaced", this, false); | ||
48 | this.eventManager.addEventListener("selectAll", this, false); | 49 | this.eventManager.addEventListener("selectAll", this, false); |
49 | this.eventManager.addEventListener("switchDocument", this, false); | 50 | this.eventManager.addEventListener("switchDocument", this, false); |
50 | this.eventManager.addEventListener("closeDocument", this, false); | 51 | this.eventManager.addEventListener("closeDocument", this, false); |
@@ -103,6 +104,12 @@ exports.SelectionController = Montage.create(Component, { | |||
103 | } | 104 | } |
104 | }, | 105 | }, |
105 | 106 | ||
107 | handleElementReplaced: { | ||
108 | value: function(event) { | ||
109 | this.application.ninja.selectedElements[this.application.ninja.selectedElements.indexOf(event.detail.data.oldChild)] = event.detail.data.newChild; | ||
110 | } | ||
111 | }, | ||
112 | |||
106 | handleSelectAll: { | 113 | handleSelectAll: { |
107 | value: function(event) { | 114 | value: function(event) { |
108 | var selected = [], childNodes = []; | 115 | 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, { | |||
112 | this.eventManager.addEventListener("elementsRemoved", this, false); | 112 | this.eventManager.addEventListener("elementsRemoved", this, false); |
113 | this.eventManager.addEventListener("elementChange", this, false); | 113 | this.eventManager.addEventListener("elementChange", this, false); |
114 | this.eventManager.addEventListener("closeDocument", this, false); | 114 | this.eventManager.addEventListener("closeDocument", this, false); |
115 | this.eventManager.addEventListener("elementReplaced", this, false); | ||
115 | } | 116 | } |
116 | }, | 117 | }, |
117 | 118 | ||
@@ -170,13 +171,41 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { | |||
170 | this.removeElement(element); | 171 | this.removeElement(element); |
171 | }, this); | 172 | }, this); |
172 | } else { | 173 | } else { |
173 | this.removeElement(elements._element || elements); | 174 | this.removeElement(elements); |
174 | } | 175 | } |
175 | 176 | ||
176 | this.drawWorkingPlane(); | 177 | this.drawWorkingPlane(); |
177 | } | 178 | } |
178 | }, | 179 | }, |
179 | 180 | ||
181 | handleElementReplaced: { | ||
182 | value: function(event) { | ||
183 | var oldElement = event.detail.data.oldChild; | ||
184 | var newElement = event.detail.data.newChild; | ||
185 | |||
186 | // check if we already know about this object | ||
187 | var n = this._eltArray.length, | ||
188 | plane; | ||
189 | for (var i=0; i<n; i++) { | ||
190 | if (oldElement === this._eltArray[i]) { | ||
191 | this._eltArray[i] = newElement; | ||
192 | plane = this._planesArray[i]; | ||
193 | break; | ||
194 | } | ||
195 | } | ||
196 | |||
197 | if(!plane) { | ||
198 | this._eltArray.push( newElement ); | ||
199 | plane = Object.create(this.ElementPlanes, {}); | ||
200 | this._planesArray.push( plane ); | ||
201 | } | ||
202 | |||
203 | plane.setElement( newElement ); | ||
204 | plane.init(); | ||
205 | newElement.elementModel.props3D.elementPlane = plane; | ||
206 | } | ||
207 | }, | ||
208 | |||
180 | _shouldUpdatePlanes: { | 209 | _shouldUpdatePlanes: { |
181 | value: function(props) { | 210 | value: function(props) { |
182 | if(!props) { | 211 | if(!props) { |
diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js index 9f6b9ed1..a401c363 100755 --- a/js/helper-classes/3D/snap-manager.js +++ b/js/helper-classes/3D/snap-manager.js | |||
@@ -124,6 +124,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { | |||
124 | initialize: { | 124 | initialize: { |
125 | value: function() { | 125 | value: function() { |
126 | this.eventManager.addEventListener("elementsRemoved", this, false); | 126 | this.eventManager.addEventListener("elementsRemoved", this, false); |
127 | this.eventManager.addEventListener("elementReplaced", this, false); | ||
127 | } | 128 | } |
128 | }, | 129 | }, |
129 | 130 | ||
@@ -170,15 +171,19 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { | |||
170 | if(Array.isArray(elements)) { | 171 | if(Array.isArray(elements)) { |
171 | elements = Array.prototype.slice.call(elements, 0); | 172 | elements = Array.prototype.slice.call(elements, 0); |
172 | elements.forEach(function(element) { | 173 | elements.forEach(function(element) { |
173 | element = element._element || element; | ||
174 | self.removeElementFrom2DCache(element); | 174 | self.removeElementFrom2DCache(element); |
175 | }); | 175 | }); |
176 | } else { | 176 | } else { |
177 | this.removeElementFrom2DCache(elements._element || elements); | 177 | this.removeElementFrom2DCache(elements); |
178 | } | 178 | } |
179 | } | 179 | } |
180 | }, | 180 | }, |
181 | 181 | ||
182 | handleElementReplaced: { | ||
183 | value: function(event) { | ||
184 | this._isCacheInvalid = true; | ||
185 | } | ||
186 | }, | ||
182 | 187 | ||
183 | setCurrentStage: { | 188 | setCurrentStage: { |
184 | value: function(stage) { | 189 | value: function(stage) { |
diff --git a/js/mediators/element-mediator.js b/js/mediators/element-mediator.js index 09f2aeed..b0efc02b 100755 --- a/js/mediators/element-mediator.js +++ b/js/mediators/element-mediator.js | |||
@@ -84,6 +84,23 @@ exports.ElementMediator = Montage.create(Component, { | |||
84 | } | 84 | } |
85 | }, | 85 | }, |
86 | 86 | ||
87 | replaceElement: { | ||
88 | value: function(newChild, oldChild, notify) { | ||
89 | |||
90 | this.application.ninja.currentDocument.documentRoot.replaceChild(newChild, oldChild); | ||
91 | |||
92 | var undoLabel = "replace element"; | ||
93 | |||
94 | document.application.undoManager.add(undoLabel, this.replaceElement, this, oldChild, newChild); | ||
95 | |||
96 | this.application.ninja.documentController.activeDocument.needsSave = true; | ||
97 | |||
98 | if(notify || notify === undefined) { | ||
99 | NJevent("elementReplaced", {type : "replaceElement", data: {"newChild": newChild, "oldChild": oldChild}}); | ||
100 | } | ||
101 | } | ||
102 | }, | ||
103 | |||
87 | getProperty: { | 104 | getProperty: { |
88 | value: function(el, prop, valueMutator) { | 105 | value: function(el, prop, valueMutator) { |
89 | if(!el.elementModel) { | 106 | if(!el.elementModel) { |