diff options
-rwxr-xr-x | js/controllers/elements/element-controller.js | 16 | ||||
-rwxr-xr-x | js/mediators/element-mediator.js | 62 | ||||
-rwxr-xr-x | js/tools/SelectionTool.js | 57 |
3 files changed, 42 insertions, 93 deletions
diff --git a/js/controllers/elements/element-controller.js b/js/controllers/elements/element-controller.js index fda3a3c5..adac1420 100755 --- a/js/controllers/elements/element-controller.js +++ b/js/controllers/elements/element-controller.js | |||
@@ -47,9 +47,19 @@ exports.ElementController = Montage.create(Component, { | |||
47 | }, | 47 | }, |
48 | 48 | ||
49 | setProperties: { | 49 | setProperties: { |
50 | value: function(el, props, index) { | 50 | value: function(element, properties) { |
51 | for(var p in props) { | 51 | /* Array of properties is not supported yet |
52 | this.application.ninja.stylesController.setElementStyle(el, p, props[p][index]); | 52 | if(Array.isArray(properties)) { |
53 | |||
54 | elements.forEach(function(property) { | ||
55 | this.application.ninja.stylesController.setElementStyle(element, p, props[p][index]); | ||
56 | }); | ||
57 | } else { | ||
58 | } | ||
59 | */ | ||
60 | |||
61 | for(var property in properties) { | ||
62 | this.application.ninja.stylesController.setElementStyle(element, property, properties[property]); | ||
53 | } | 63 | } |
54 | } | 64 | } |
55 | }, | 65 | }, |
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 | ||
diff --git a/js/tools/SelectionTool.js b/js/tools/SelectionTool.js index 94cc6b83..6dec781b 100755 --- a/js/tools/SelectionTool.js +++ b/js/tools/SelectionTool.js | |||
@@ -372,46 +372,21 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { | |||
372 | } | 372 | } |
373 | } | 373 | } |
374 | } | 374 | } |
375 | if(addToUndoStack) | 375 | |
376 | { | 376 | if(addToUndoStack) { |
377 | if(!this._use3DMode) | 377 | if(!this._use3DMode) { |
378 | { | ||
379 | // if we have a delta, that means the transform handles were used and | 378 | // if we have a delta, that means the transform handles were used and |
380 | // we should update the width and height too. Otherwise, just update left and top. | 379 | // we should update the width and height too. Otherwise, just update left and top. |
381 | if(this._delta) | 380 | if(this._delta) { |
382 | { | 381 | ElementsMediator.setProperties(this.application.ninja.selectedElements, {"left": newLeft, "top": newTop, "width": newWidth, "height": newHeight }, |
383 | ElementsMediator.setProperties(this.application.ninja.selectedElements, | 382 | { "left" : previousLeft, "top" : previousTop, "width": previousWidth, "height": previousHeight}, "Change", "selectionTool"); |
384 | { "left": newLeft, "top": newTop, "width": newWidth, "height": newHeight }, | 383 | } else { |
385 | "Change", | 384 | ElementsMediator.setProperties(this.application.ninja.selectedElements, {"left": newLeft, "top": newTop }, {"left": previousLeft, "top": previousTop}, "Change", "selectionTool"); |
386 | "selectionTool", | ||
387 | { "left" : previousLeft, "top" : previousTop, "width": previousWidth, "height": previousHeight} | ||
388 | ); | ||
389 | } | ||
390 | else | ||
391 | { | ||
392 | ElementsMediator.setProperties(this.application.ninja.selectedElements, | ||
393 | { "left": newLeft, "top": newTop }, | ||
394 | "Change", | ||
395 | "selectionTool", | ||
396 | { "left" : previousLeft, "top" : previousTop } | ||
397 | ); | ||
398 | } | 385 | } |
399 | } | 386 | } else { |
400 | else | ||
401 | { | ||
402 | // TODO - We don't support transform handles in 3d space for now | 387 | // TODO - We don't support transform handles in 3d space for now |
403 | ElementsMediator.setProperties(this.application.ninja.selectedElements, | 388 | ElementsMediator.setProperties(this.application.ninja.selectedElements, {"width": newWidth, "height": newHeight }, {"width": previousWidth, "height": previousHeight}, "Change", "selectionTool"); |
404 | { "width": newWidth, "height": newHeight }, | 389 | ElementsMediator.set3DProperties(this.application.ninja.selectedElements, newStyles, "Change", "translateTool", previousStyles); |
405 | "Change", | ||
406 | "selectionTool", | ||
407 | { "width": previousWidth, "height": previousHeight} | ||
408 | ); | ||
409 | ElementsMediator.set3DProperties(this.application.ninja.selectedElements, | ||
410 | newStyles, | ||
411 | "Change", | ||
412 | "translateTool", | ||
413 | previousStyles | ||
414 | ); | ||
415 | } | 390 | } |
416 | } | 391 | } |
417 | // Save previous value for undo/redo | 392 | // Save previous value for undo/redo |
@@ -471,13 +446,9 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { | |||
471 | } | 446 | } |
472 | } | 447 | } |
473 | 448 | ||
474 | if(newLeft.length) | 449 | if(newLeft.length) { |
475 | { | 450 | ElementsMediator.setProperties(this.application.ninja.selectedElements, {"left": newLeft, "top": newTop }, null, "Changing", "SelectionTool" ); |
476 | ElementsMediator.setProperties(this.application.ninja.selectedElements, | 451 | } else { |
477 | { "left": newLeft, "top": newTop }, "Changing", "SelectionTool" ); | ||
478 | } | ||
479 | else | ||
480 | { | ||
481 | NJevent("elementChanging", {type : "Changing", redraw: false}); | 452 | NJevent("elementChanging", {type : "Changing", redraw: false}); |
482 | } | 453 | } |
483 | } | 454 | } |