aboutsummaryrefslogtreecommitdiff
path: root/js/mediators
diff options
context:
space:
mode:
authorValerio Virgillito2012-04-09 16:47:56 -0700
committerValerio Virgillito2012-04-09 16:47:56 -0700
commit48d4dd0f0570f4ac3556f228846ed0fd98a674e5 (patch)
tree9fb2e8a02f5d68eb72048c5d11f2f39e77daf9d4 /js/mediators
parent4900f2e6e346df18b1b5a2ac89da5019644ac98a (diff)
downloadninja-48d4dd0f0570f4ac3556f228846ed0fd98a674e5.tar.gz
setProperties to the montage undo/redo
Signed-off-by: Valerio Virgillito <valerio@motorola.com>
Diffstat (limited to 'js/mediators')
-rwxr-xr-xjs/mediators/element-mediator.js62
1 files changed, 15 insertions, 47 deletions
diff --git a/js/mediators/element-mediator.js b/js/mediators/element-mediator.js
index a05ca631..738e65fc 100755
--- a/js/mediators/element-mediator.js
+++ b/js/mediators/element-mediator.js
@@ -272,60 +272,28 @@ exports.ElementMediator = Montage.create(Component, {
272 }, 272 },
273 273
274 /** 274 /**
275 Set a property change command for an element or array of elements 275 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 276 @param els: Array of elements. Can contain 1 or more elements
277 @param props: Property/ies object containing both the value and property 277 @param properties: Properties object containing both the value and property
278 @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 279 @param eventType: Change/Changing. Will be passed to the dispatched event
279 @param source: String for the source object making the call 280 @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 */ 281 */
283 setProperties: { 282 setProperties: {
284 value: function(els, props, eventType, source, currentProps, stageRedraw) { 283 value: function(elements, properties, currentProperties, eventType, source) {
285 if(eventType === "Changing") { 284 // Assume elements is an array of elements always
286 this._setProperties(els, props, eventType, source); 285 elements.forEach(function(element) {
287 } else { 286 element.elementModel.controller["setProperties"](element, properties);
288 var command = Montage.create(Command, { 287 });
289 _els: { value: els }, 288
290 _props: { value: props }, 289 // Add to undo only when a change is requested
291 _previous: { value: currentProps }, 290 if(eventType !== "Changing") {
292 _eventType: { value: eventType}, 291 var undoLabel = "Properties change";
293 _source: { value: "undo-redo"}, 292 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 } 293 }
327 294
328 NJevent("element" + eventType, {type : "setProperties", source: source, data: {"els": els, "prop": props, "value": props}, redraw: null}); 295 // Dispatch the element change/changing event.
296 NJevent("element" + eventType, {type : "setProperties", source: source, data: {"els": elements, "prop": properties, "value": properties}, redraw: null});
329 } 297 }
330 }, 298 },
331 299