From 45ae62302b175774c1e1af82ff144ecb2fe770d7 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Mon, 9 Apr 2012 22:58:10 -0700 Subject: setAttribute added to the undo/redo Signed-off-by: Valerio Virgillito --- js/mediators/element-mediator.js | 71 ++++++++-------------------------------- 1 file changed, 13 insertions(+), 58 deletions(-) (limited to 'js/mediators/element-mediator.js') diff --git a/js/mediators/element-mediator.js b/js/mediators/element-mediator.js index 738e65fc..6ab33eff 100755 --- a/js/mediators/element-mediator.js +++ b/js/mediators/element-mediator.js @@ -138,70 +138,25 @@ exports.ElementMediator = Montage.create(Component, { }, /** - Set a property change command for an element or array of elements - @param els: Array of elements. Can contain 1 or more elements - @param p: Property to set - @param value: Value to be set. This is an array of values corresponding to the array of elements - @param eventType: Change/Changing. Will be passed to the dispatched event - @param source: String for the source object making the call - @param currentValue *OPTIONAL*: current value array. If not found the current value is calculated - @param stageRedraw: *OPTIONAL*: True. If set to false the stage will not redraw the selection/outline - */ + Set a property change command for an element or array of elements + @param element: Element + @param attribute: Attribute to set + @param value: Value to be set. + @param currentValue: current value + @param source: String for the source object making the call + */ setAttribute: { - value: function(el, att, value, eventType, source, currentValue) { + value: function(element, attribute, value, currentValue, source) { + element.elementModel.controller["setAttribute"](element, attribute, value); - if(eventType === "Changing") { - this._setAttribute(el, att, value, eventType, source); - } else { - // Calculate currentValue if not found for each element - if(currentValue === null) { - currentValue = el.getAttribute(att); - } - - var command = Montage.create(Command, { - _el: { value: el }, - _att: { value: att }, - _value: { value: value }, - _previous: { value: currentValue }, - _eventType: { value: eventType}, - _source: { value: "undo-redo"}, - description: { value: "Set Attribute"}, - receiver: { value: this}, - - execute: { - value: function(senderObject) { - if(senderObject) this._source = senderObject; - this.receiver._setAttribute(this._el, this._att, this._value, this._eventType, this._source); - this._source = "undo-redo"; - return ""; - } - }, - - unexecute: { - value: function() { - this.receiver._setAttribute(this._el, this._att, this._previous, this._eventType, this._source); - return ""; - } - } - }); - - NJevent("sendToUndo", command); - command.execute(source); - } + // Add to the undo + var undoLabel = "Attribute change"; + document.application.undoManager.add(undoLabel, this.setAttribute, this, element, attribute, currentValue, value, source); + NJevent("attributeChange"); } }, - _setAttribute: { - value: function(el, att, value, eventType, source) { - el.elementModel.controller["setAttribute"](el, att, value); - - NJevent("attribute" + eventType, {type : "setAttribute", source: source, data: {"els": el, "prop": att, "value": value}, redraw: null}); - } - }, - - - /** Set a property change command for an element or array of elements @param els: Array of elements. Can contain 1 or more elements -- cgit v1.2.3