aboutsummaryrefslogtreecommitdiff
path: root/js/mediators
diff options
context:
space:
mode:
authorValerio Virgillito2012-04-09 22:58:10 -0700
committerValerio Virgillito2012-04-09 22:58:10 -0700
commit45ae62302b175774c1e1af82ff144ecb2fe770d7 (patch)
tree799c62dbb09a4db51b460a751a88eb359538d0b7 /js/mediators
parent48d4dd0f0570f4ac3556f228846ed0fd98a674e5 (diff)
downloadninja-45ae62302b175774c1e1af82ff144ecb2fe770d7.tar.gz
setAttribute added to the undo/redo
Signed-off-by: Valerio Virgillito <valerio@motorola.com>
Diffstat (limited to 'js/mediators')
-rwxr-xr-xjs/mediators/element-mediator.js71
1 files changed, 13 insertions, 58 deletions
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, {
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) {
150 element.elementModel.controller["setAttribute"](element, attribute, value);
152 151
153 if(eventType === "Changing") { 152 // Add to the undo
154 this._setAttribute(el, att, value, eventType, source); 153 var undoLabel = "Attribute change";
155 } else { 154 document.application.undoManager.add(undoLabel, this.setAttribute, this, element, attribute, currentValue, value, source);
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 155
156 NJevent("attributeChange");
192 } 157 }
193 }, 158 },
194 159
195 _setAttribute: {
196 value: function(el, att, value, eventType, source) {
197 el.elementModel.controller["setAttribute"](el, att, value);
198
199 NJevent("attribute" + eventType, {type : "setAttribute", source: source, data: {"els": el, "prop": att, "value": value}, redraw: null});
200 }
201 },
202
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