diff options
Diffstat (limited to 'js/mediators/element-mediator.js')
-rwxr-xr-x | js/mediators/element-mediator.js | 261 |
1 files changed, 85 insertions, 176 deletions
diff --git a/js/mediators/element-mediator.js b/js/mediators/element-mediator.js index 09f2aeed..919aaec1 100755 --- a/js/mediators/element-mediator.js +++ b/js/mediators/element-mediator.js | |||
@@ -28,16 +28,15 @@ exports.ElementMediator = Montage.create(Component, { | |||
28 | value: function(elements, rules, notify) { | 28 | value: function(elements, rules, notify) { |
29 | if(Array.isArray(elements)) { | 29 | if(Array.isArray(elements)) { |
30 | elements.forEach(function(element) { | 30 | elements.forEach(function(element) { |
31 | element = element; | ||
32 | ElementController.addElement(element, rules); | 31 | ElementController.addElement(element, rules); |
32 | if(element.elementModel && element.elementModel.props3D) { | ||
33 | element.elementModel.props3D.init(element, false); | ||
34 | } | ||
33 | }); | 35 | }); |
34 | } else { | 36 | } else { |
35 | ElementController.addElement(elements, rules); | 37 | ElementController.addElement(elements, rules); |
36 | 38 | if(elements.elementModel && elements.elementModel.props3D) { | |
37 | // TODO - Check with webgl branch - Props seem to be already there. | 39 | elements.elementModel.props3D.init(elements, false); |
38 | var prop3d = this.get3DProperties(elements); | ||
39 | if(prop3d) { | ||
40 | elements.elementModel.controller["set3DProperties"](elements, [prop3d], 0, true); | ||
41 | } | 40 | } |
42 | } | 41 | } |
43 | 42 | ||
@@ -84,6 +83,23 @@ exports.ElementMediator = Montage.create(Component, { | |||
84 | } | 83 | } |
85 | }, | 84 | }, |
86 | 85 | ||
86 | replaceElement: { | ||
87 | value: function(newChild, oldChild, notify) { | ||
88 | |||
89 | this.application.ninja.currentDocument.documentRoot.replaceChild(newChild, oldChild); | ||
90 | |||
91 | var undoLabel = "replace element"; | ||
92 | |||
93 | document.application.undoManager.add(undoLabel, this.replaceElement, this, oldChild, newChild); | ||
94 | |||
95 | this.application.ninja.documentController.activeDocument.needsSave = true; | ||
96 | |||
97 | if(notify || notify === undefined) { | ||
98 | NJevent("elementReplaced", {type : "replaceElement", data: {"newChild": newChild, "oldChild": oldChild}}); | ||
99 | } | ||
100 | } | ||
101 | }, | ||
102 | |||
87 | getProperty: { | 103 | getProperty: { |
88 | value: function(el, prop, valueMutator) { | 104 | value: function(el, prop, valueMutator) { |
89 | if(!el.elementModel) { | 105 | if(!el.elementModel) { |
@@ -122,70 +138,25 @@ exports.ElementMediator = Montage.create(Component, { | |||
122 | }, | 138 | }, |
123 | 139 | ||
124 | /** | 140 | /** |
125 | Set a property change command for an element or array of elements | 141 | Set a property change command for an element or array of elements |
126 | @param els: Array of elements. Can contain 1 or more elements | 142 | @param element: Element |
127 | @param p: Property to set | 143 | @param attribute: Attribute to set |
128 | @param value: Value to be set. This is an array of values corresponding to the array of elements | 144 | @param value: Value to be set. |
129 | @param eventType: Change/Changing. Will be passed to the dispatched event | 145 | @param currentValue: current value |
130 | @param source: String for the source object making the call | 146 | @param source: String for the source object making the call |
131 | @param currentValue *OPTIONAL*: current value array. If not found the current value is calculated | 147 | */ |
132 | @param stageRedraw: *OPTIONAL*: True. If set to false the stage will not redraw the selection/outline | ||
133 | */ | ||
134 | setAttribute: { | 148 | setAttribute: { |
135 | value: function(el, att, value, eventType, source, currentValue) { | 149 | value: function(element, attribute, value, currentValue, source) { |
136 | 150 | element.elementModel.controller["setAttribute"](element, attribute, value); | |
137 | if(eventType === "Changing") { | ||
138 | this._setAttribute(el, att, value, eventType, source); | ||
139 | } else { | ||
140 | // Calculate currentValue if not found for each element | ||
141 | if(currentValue === null) { | ||
142 | currentValue = el.getAttribute(att); | ||
143 | } | ||
144 | |||
145 | var command = Montage.create(Command, { | ||
146 | _el: { value: el }, | ||
147 | _att: { value: att }, | ||
148 | _value: { value: value }, | ||
149 | _previous: { value: currentValue }, | ||
150 | _eventType: { value: eventType}, | ||
151 | _source: { value: "undo-redo"}, | ||
152 | description: { value: "Set Attribute"}, | ||
153 | receiver: { value: this}, | ||
154 | 151 | ||
155 | execute: { | 152 | // Add to the undo |
156 | value: function(senderObject) { | 153 | var undoLabel = "Attribute change"; |
157 | if(senderObject) this._source = senderObject; | 154 | document.application.undoManager.add(undoLabel, this.setAttribute, this, element, attribute, currentValue, value, source); |
158 | this.receiver._setAttribute(this._el, this._att, this._value, this._eventType, this._source); | ||
159 | this._source = "undo-redo"; | ||
160 | return ""; | ||
161 | } | ||
162 | }, | ||
163 | |||
164 | unexecute: { | ||
165 | value: function() { | ||
166 | this.receiver._setAttribute(this._el, this._att, this._previous, this._eventType, this._source); | ||
167 | return ""; | ||
168 | } | ||
169 | } | ||
170 | }); | ||
171 | |||
172 | NJevent("sendToUndo", command); | ||
173 | command.execute(source); | ||
174 | } | ||
175 | |||
176 | } | ||
177 | }, | ||
178 | |||
179 | _setAttribute: { | ||
180 | value: function(el, att, value, eventType, source) { | ||
181 | el.elementModel.controller["setAttribute"](el, att, value); | ||
182 | 155 | ||
183 | NJevent("attribute" + eventType, {type : "setAttribute", source: source, data: {"els": el, "prop": att, "value": value}, redraw: null}); | 156 | NJevent("attributeChange"); |
184 | } | 157 | } |
185 | }, | 158 | }, |
186 | 159 | ||
187 | |||
188 | |||
189 | /** | 160 | /** |
190 | Set a property change command for an element or array of elements | 161 | Set a property change command for an element or array of elements |
191 | @param els: Array of elements. Can contain 1 or more elements | 162 | @param els: Array of elements. Can contain 1 or more elements |
@@ -197,7 +168,7 @@ exports.ElementMediator = Montage.create(Component, { | |||
197 | @param stageRedraw: *OPTIONAL*: True. If set to false the stage will not redraw the selection/outline | 168 | @param stageRedraw: *OPTIONAL*: True. If set to false the stage will not redraw the selection/outline |
198 | */ | 169 | */ |
199 | setProperty: { | 170 | setProperty: { |
200 | value: function(els, p, value, eventType, source, currentValue, stageRedraw) { | 171 | value: function(els, p, value, eventType, source, currentValue) { |
201 | if(eventType === "Changing") { | 172 | if(eventType === "Changing") { |
202 | this._setProperty(els, p, value, eventType, source); | 173 | this._setProperty(els, p, value, eventType, source); |
203 | } else { | 174 | } else { |
@@ -248,7 +219,7 @@ exports.ElementMediator = Montage.create(Component, { | |||
248 | var el; | 219 | var el; |
249 | 220 | ||
250 | for(var i=0, item; item = els[i]; i++) { | 221 | for(var i=0, item; item = els[i]; i++) { |
251 | item.elementModel.controller["setProperty"](item, p, value[i]); | 222 | item.elementModel.controller["setProperty"](item, p, value[i], eventType, source); |
252 | } | 223 | } |
253 | 224 | ||
254 | NJevent("element" + eventType, {type : "setProperty", source: source, data: {"els": els, "prop": p, "value": value}, redraw: null}); | 225 | NJevent("element" + eventType, {type : "setProperty", source: source, data: {"els": els, "prop": p, "value": value}, redraw: null}); |
@@ -256,130 +227,68 @@ exports.ElementMediator = Montage.create(Component, { | |||
256 | }, | 227 | }, |
257 | 228 | ||
258 | /** | 229 | /** |
259 | Set a property change command for an element or array of elements | 230 | Sets a property object for an element or array of elements. The same properties object gets applied to all the elements |
260 | @param els: Array of elements. Can contain 1 or more elements | 231 | @param elements: Array of elements objects: element, properties and previousProperties |
261 | @param props: Property/ies object containing both the value and property | ||
262 | @param eventType: Change/Changing. Will be passed to the dispatched event | 232 | @param eventType: Change/Changing. Will be passed to the dispatched event |
263 | @param source: String for the source object making the call | 233 | @param source: String for the source object making the call |
264 | @param currentProps *OPTIONAL*: current properties objects array. If not found it will be calculated | ||
265 | @param stageRedraw: *OPTIONAL*: True. If set to false the stage will not redraw the selection/outline | ||
266 | */ | 234 | */ |
267 | setProperties: { | 235 | setProperties: { |
268 | value: function(els, props, eventType, source, currentProps, stageRedraw) { | 236 | value: function(elements, eventType, source) { |
269 | if(eventType === "Changing") { | 237 | |
270 | this._setProperties(els, props, eventType, source); | 238 | elements.forEach(function(elementObject) { |
271 | } else { | 239 | elementObject.element.elementModel.controller["setProperties"](elementObject.element, elementObject.properties); |
272 | var command = Montage.create(Command, { | 240 | }); |
273 | _els: { value: els }, | 241 | |
274 | _props: { value: props }, | 242 | if(eventType !== "Changing") { |
275 | _previous: { value: currentProps }, | 243 | var undoLabel = "Properties change"; |
276 | _eventType: { value: eventType}, | 244 | elements.forEach(function(elementObject) { |
277 | _source: { value: "undo-redo"}, | 245 | var swap = elementObject.properties; |
278 | description: { value: "Set Properties"}, | 246 | elementObject.properties = elementObject.previousProperties; |
279 | receiver: { value: this}, | 247 | elementObject.previousProperties = swap; |
280 | |||
281 | execute: { | ||
282 | value: function(senderObject) { | ||
283 | if(senderObject) this._source = senderObject; | ||
284 | this.receiver._setProperties(this._els, this._props, this._eventType, this._source); | ||
285 | this._source = "undo-redo"; | ||
286 | return ""; | ||
287 | } | ||
288 | }, | ||
289 | |||
290 | unexecute: { | ||
291 | value: function() { | ||
292 | this.receiver._setProperties(this._els, this._previous, this._eventType, this._source); | ||
293 | return ""; | ||
294 | } | ||
295 | } | ||
296 | }); | 248 | }); |
297 | 249 | document.application.undoManager.add(undoLabel, this.setProperties, this, elements, eventType, source); | |
298 | NJevent("sendToUndo", command); | ||
299 | command.execute(source); | ||
300 | } | 250 | } |
301 | } | ||
302 | }, | ||
303 | |||
304 | _setProperties: { | ||
305 | value: function(els, props, eventType, source) { | ||
306 | var propsArray; | ||