aboutsummaryrefslogtreecommitdiff
path: root/js/mediators/element-mediator.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/mediators/element-mediator.js')
-rwxr-xr-xjs/mediators/element-mediator.js133
1 files changed, 28 insertions, 105 deletions
diff --git a/js/mediators/element-mediator.js b/js/mediators/element-mediator.js
index a05ca631..6ab33eff 100755
--- a/js/mediators/element-mediator.js
+++ b/js/mediators/element-mediator.js
@@ -138,70 +138,25 @@ exports.ElementMediator = Montage.create(Component, {
138 }, 138 },
139 139
140 /** 140 /**
141 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
142 @param els: Array of elements. Can contain 1 or more elements 142 @param element: Element
143 @param p: Property to set 143 @param attribute: Attribute to set
144 @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.
145 @param eventType: Change/Changing. Will be passed to the dispatched event 145 @param currentValue: current value
146 @param source: String for the source object making the call 146 @param source: String for the source object making the call
147 @param currentValue *OPTIONAL*: current value array. If not found the current value is calculated 147 */
148 @param stageRedraw: *OPTIONAL*: True. If set to false the stage will not redraw the selection/outline
149 */
150 setAttribute: { 148 setAttribute: {
151 value: function(el, att, value, eventType, source, currentValue) { 149 value: function(element, attribute, value, currentValue, source) {
152 150 element.elementModel.controller["setAttribute"](element, attribute, value);
153 if(eventType === "Changing") {
154 this._setAttribute(el, att, value, eventType, source);
155 } else {
156 // Calculate currentValue if not found for each element
157 if(currentValue === null) {
158 currentValue = el.getAttribute(att);
159 }
160
161 var command = Montage.create(Command, {
162 _el: { value: el },
163 _att: { value: att },
164 _value: { value: value },
165 _previous: { value: currentValue },
166 _eventType: { value: eventType},
167 _source: { value: "undo-redo"},
168 description: { value: "Set Attribute"},
169 receiver: { value: this},
170
171 execute: {
172 value: function(senderObject) {
173 if(senderObject) this._source = senderObject;
174 this.receiver._setAttribute(this._el, this._att, this._value, this._eventType, this._source);
175 this._source = "undo-redo";
176 return "";
177 }
178 },
179
180 unexecute: {
181 value: function() {
182 this.receiver._setAttribute(this._el, this._att, this._previous, this._eventType, this._source);
183 return "";
184 }
185 }
186 });
187
188 NJevent("sendToUndo", command);
189 command.execute(source);
190 }
191
192 }
193 },
194 151
195 _setAttribute: { 152 // Add to the undo
196 value: function(el, att, value, eventType, source) { 153 var undoLabel = "Attribute change";
197 el.elementModel.controller["setAttribute"](el, att, value); 154 document.application.undoManager.add(undoLabel, this.setAttribute, this, element, attribute, currentValue, value, source);
198 155
199 NJevent("attribute" + eventType, {type : "setAttribute", source: source, data: {"els": el, "prop": att, "value": value}, redraw: null}); 156 NJevent("attributeChange");
200 } 157 }
201 }, 158 },
202 159
203
204
205 /** 160 /**
206 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
207 @param els: Array of elements. Can contain 1 or more elements 162 @param els: Array of elements. Can contain 1 or more elements
@@ -272,60 +227,28 @@ exports.ElementMediator = Montage.create(Component, {
272 }, 227 },
273 228
274 /** 229 /**
275 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
276 @param els: Array of elements. Can contain 1 or more elements 231 @param els: Array of elements. Can contain 1 or more elements
277 @param props: Property/ies object containing both the value and property 232 @param properties: Properties object containing both the value and property
233 @param currentProperties: current properties object for undo/redo. Must be an valid object or null
278 @param eventType: Change/Changing. Will be passed to the dispatched event 234 @param eventType: Change/Changing. Will be passed to the dispatched event
279 @param source: String for the source object making the call 235 @param source: String for the source object making the call
280 @param currentProps *OPTIONAL*: current properties objects array. If not found it will be calculated
281 @param stageRedraw: *OPTIONAL*: True. If set to false the stage will not redraw the selection/outline
282 */ 236 */
283 setProperties: { 237 setProperties: {
284 value: function(els, props, eventType, source, currentProps, stageRedraw) { 238 value: function(elements, properties, currentProperties, eventType, source) {
285 if(eventType === "Changing") { 239 // Assume elements is an array of elements always
286 this._setProperties(els, props, eventType, source); 240 elements.forEach(function(element) {
287 } else { 241 element.elementModel.controller["setProperties"](element, properties);
288 var command = Montage.create(Command, { 242 });
289 _els: { value: els }, 243
290 _props: { value: props }, 244 // Add to undo only when a change is requested
291 _previous: { value: currentProps }, 245 if(eventType !== "Changing") {
292 _eventType: { value: eventType}, 246 var undoLabel = "Properties change";
293 _source: { value: "undo-redo"}, 247 document.application.undoManager.add(undoLabel, this.setProperties, this, elements, currentProperties, properties, eventType, source);
294 description: { value: "Set Properties"},
295 receiver: { value: this},
296
297 execute: {
298 value: function(senderObject) {
299 if(senderObject) this._source = senderObject;
300 this.receiver._setProperties(this._els, this._props, this._eventType, this._source);
301 this._source = "undo-redo";
302 return "";
303 }
304 },
305
306 unexecute: {
307 value: function() {
308 this.receiver._setProperties(this._els, this._previous, this._eventType, this._source);
309 return "";
310 }
311 }
312 });
313
314 NJevent("sendToUndo", command);
315 command.execute(source);
316 }
317 }
318 },
319
320 _setProperties: {
321 value: function(els, props, eventType, source) {
322 var propsArray;
323
324 for(var i=0, item; item = els[i]; i++) {
325 item.elementModel.controller["setProperties"](item, props, i);
326 } 248 }
327 249
328 NJevent("element" + eventType, {type : "setProperties", source: source, data: {"els": els, "prop": props, "value": props}, redraw: null}); 250 // Dispatch the element change/changing event.
251 NJevent("element" + eventType, {type : "setProperties", source: source, data: {"els": elements, "prop": properties, "value": properties}, redraw: null});
329 } 252 }
330 }, 253 },
331 254