From 48d4dd0f0570f4ac3556f228846ed0fd98a674e5 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Mon, 9 Apr 2012 16:47:56 -0700 Subject: setProperties to the montage undo/redo Signed-off-by: Valerio Virgillito --- js/mediators/element-mediator.js | 62 ++++++++++------------------------------ 1 file changed, 15 insertions(+), 47 deletions(-) (limited to 'js/mediators/element-mediator.js') 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, { }, /** - Set a property change command for an element or array of elements + Sets a property object for an element or array of elements. The same properties object gets applied to all the elements @param els: Array of elements. Can contain 1 or more elements - @param props: Property/ies object containing both the value and property + @param properties: Properties object containing both the value and property + @param currentProperties: current properties object for undo/redo. Must be an valid object or null @param eventType: Change/Changing. Will be passed to the dispatched event @param source: String for the source object making the call - @param currentProps *OPTIONAL*: current properties objects array. If not found it will be calculated - @param stageRedraw: *OPTIONAL*: True. If set to false the stage will not redraw the selection/outline */ setProperties: { - value: function(els, props, eventType, source, currentProps, stageRedraw) { - if(eventType === "Changing") { - this._setProperties(els, props, eventType, source); - } else { - var command = Montage.create(Command, { - _els: { value: els }, - _props: { value: props }, - _previous: { value: currentProps }, - _eventType: { value: eventType}, - _source: { value: "undo-redo"}, - description: { value: "Set Properties"}, - receiver: { value: this}, - - execute: { - value: function(senderObject) { - if(senderObject) this._source = senderObject; - this.receiver._setProperties(this._els, this._props, this._eventType, this._source); - this._source = "undo-redo"; - return ""; - } - }, - - unexecute: { - value: function() { - this.receiver._setProperties(this._els, this._previous, this._eventType, this._source); - return ""; - } - } - }); - - NJevent("sendToUndo", command); - command.execute(source); - } - } - }, - - _setProperties: { - value: function(els, props, eventType, source) { - var propsArray; - - for(var i=0, item; item = els[i]; i++) { - item.elementModel.controller["setProperties"](item, props, i); + value: function(elements, properties, currentProperties, eventType, source) { + // Assume elements is an array of elements always + elements.forEach(function(element) { + element.elementModel.controller["setProperties"](element, properties); + }); + + // Add to undo only when a change is requested + if(eventType !== "Changing") { + var undoLabel = "Properties change"; + document.application.undoManager.add(undoLabel, this.setProperties, this, elements, currentProperties, properties, eventType, source); } - NJevent("element" + eventType, {type : "setProperties", source: source, data: {"els": els, "prop": props, "value": props}, redraw: null}); + // Dispatch the element change/changing event. + NJevent("element" + eventType, {type : "setProperties", source: source, data: {"els": elements, "prop": properties, "value": properties}, redraw: null}); } }, -- cgit v1.2.3 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 From f91e64235eb03c889ff4f5577c3e3480cd0d787f Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Fri, 13 Apr 2012 00:30:19 -0700 Subject: removing _undo array and _targets array and use object instead of matching arrays to set properties Signed-off-by: Valerio Virgillito --- js/mediators/element-mediator.js | 94 ++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 61 deletions(-) (limited to 'js/mediators/element-mediator.js') diff --git a/js/mediators/element-mediator.js b/js/mediators/element-mediator.js index 6ab33eff..a5f72462 100755 --- a/js/mediators/element-mediator.js +++ b/js/mediators/element-mediator.js @@ -234,8 +234,25 @@ exports.ElementMediator = Montage.create(Component, { @param eventType: Change/Changing. Will be passed to the dispatched event @param source: String for the source object making the call */ + /*value: function(elements, properties, currentProperties, eventType, source) {*/ setProperties: { - value: function(elements, properties, currentProperties, eventType, source) { + value: function(elements, eventType, source) { + + elements.forEach(function(elementObject) { + elementObject.element.elementModel.controller["setProperties"](elementObject.element, elementObject.properties); + }); + + if(eventType !== "Changing") { + var undoLabel = "Properties change"; + elements.forEach(function(elementObject) { + var swap = elementObject.properties; + elementObject.properties = elementObject.previousProperties; + elementObject.previousProperties = swap; + }); + document.application.undoManager.add(undoLabel, this.setProperties, this, elements, eventType, source); + } + + /* // Assume elements is an array of elements always elements.forEach(function(element) { element.elementModel.controller["setProperties"](element, properties); @@ -246,79 +263,34 @@ exports.ElementMediator = Montage.create(Component, { var undoLabel = "Properties change"; document.application.undoManager.add(undoLabel, this.setProperties, this, elements, currentProperties, properties, eventType, source); } + */ + // Map the elements for the event data + var els = elements.map(function(element) { + return element.element; + }); // Dispatch the element change/changing event. - NJevent("element" + eventType, {type : "setProperties", source: source, data: {"els": elements, "prop": properties, "value": properties}, redraw: null}); + NJevent("element" + eventType, {type : "setProperties", source: source, data: {"els": els, "prop": elements[0].properties, "value": elements}, 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 - @param props: Property/ies object containing both the value and property - @param eventType: Change/Changing. Will be passed to the dispatched event - @param source: String for the source object making the call - @param currentProps *OPTIONAL*: current properties objects array. If not found it will be calculated - @param stageRedraw: *OPTIONAL*: True. If set to false the stage will not redraw the selection/outline - */ set3DProperties: { - value: function(els, props, eventType, source, currentProps, stageRedraw) { - if(eventType === "Changing") { - this._set3DProperties(els, props, eventType, source); - } else { - // Calculate currentProps if not found for each element - if(!currentProps) { - var that = this; - currentProps = els.map(function(item) { - return that.get3DProperties(item); - }); - } - - var command = Montage.create(Command, { - _els: { value: els }, - _props: { value: props }, - _previous: { value: currentProps }, - _eventType: { value: eventType}, - _source: { value: "undo-redo"}, - description: { value: "Set 3D Properties"}, - receiver: { value: this}, - - execute: { - value: function(senderObject) { - if(senderObject) this._source = senderObject; - this.receiver._set3DProperties(this._els, this._props, this._eventType, this._source); - this._source = "undo-redo"; - return ""; - } - }, - - unexecute: { - value: function() { - this.receiver._set3DProperties(this._els, this._previous, this._eventType, this._source); - return ""; - } - } - }); - - NJevent("sendToUndo", command); - command.execute(source); - } - } - }, - - _set3DProperties: { - value: function(els, props, eventType, source) { + value: function(elements, eventType, source) { var update3DModel = false; if(eventType === "Change") { update3DModel = true; } - for(var i=0, item; item = els[i]; i++) { - item.elementModel.controller["set3DProperties"](item, props, i, update3DModel); + for(var i=0, item; item = elements[i]; i++) { + item.element.elementModel.controller["set3DProperties"](item.element, item.properties, update3DModel); } - NJevent("element" + eventType, {type : "set3DProperties", source: source, data: {"els": els, "prop": "matrix", "value": props}, redraw: null}); + var els = elements.map(function(element) { + return element.element; + }); + + NJevent("element" + eventType, {type : "set3DProperties", source: source, data: {"els": els, "prop": "matrix", "value": elements}, redraw: null}); } }, @@ -529,7 +501,7 @@ exports.ElementMediator = Montage.create(Component, { setMatrix: { value: function(el, mat, isChanging, source) { var dist = el.elementModel.controller["getPerspectiveDist"](el); - el.elementModel.controller["set3DProperties"](el, [{mat:mat, dist:dist}], 0, !isChanging); + el.elementModel.controller["set3DProperties"](el, {mat:mat, dist:dist}, !isChanging); if(isChanging) { NJevent("elementChanging", {type : "setMatrix", source: source, data: {"els": [el], "prop": "matrix", "value": mat}, redraw: null}); -- cgit v1.2.3 From 26dbf63bdc26850d6bbd9eaa44aae002f19f3bfa Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Fri, 13 Apr 2012 01:10:49 -0700 Subject: Cleanup Signed-off-by: Valerio Virgillito --- js/mediators/element-mediator.js | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) (limited to 'js/mediators/element-mediator.js') diff --git a/js/mediators/element-mediator.js b/js/mediators/element-mediator.js index a5f72462..fb3f2f27 100755 --- a/js/mediators/element-mediator.js +++ b/js/mediators/element-mediator.js @@ -168,7 +168,7 @@ exports.ElementMediator = Montage.create(Component, { @param stageRedraw: *OPTIONAL*: True. If set to false the stage will not redraw the selection/outline */ setProperty: { - value: function(els, p, value, eventType, source, currentValue, stageRedraw) { + value: function(els, p, value, eventType, source, currentValue) { if(eventType === "Changing") { this._setProperty(els, p, value, eventType, source); } else { @@ -228,13 +228,10 @@ exports.ElementMediator = Montage.create(Component, { /** Sets a property object for an element or array of elements. The same properties object gets applied to all the elements - @param els: Array of elements. Can contain 1 or more elements - @param properties: Properties object containing both the value and property - @param currentProperties: current properties object for undo/redo. Must be an valid object or null + @param elements: Array of elements objects: element, properties and previousProperties @param eventType: Change/Changing. Will be passed to the dispatched event @param source: String for the source object making the call */ - /*value: function(elements, properties, currentProperties, eventType, source) {*/ setProperties: { value: function(elements, eventType, source) { @@ -252,19 +249,8 @@ exports.ElementMediator = Montage.create(Component, { document.application.undoManager.add(undoLabel, this.setProperties, this, elements, eventType, source); } - /* - // Assume elements is an array of elements always - elements.forEach(function(element) { - element.elementModel.controller["setProperties"](element, properties); - }); - - // Add to undo only when a change is requested - if(eventType !== "Changing") { - var undoLabel = "Properties change"; - document.application.undoManager.add(undoLabel, this.setProperties, this, elements, currentProperties, properties, eventType, source); - } - */ // Map the elements for the event data + // TODO: Clean this up var els = elements.map(function(element) { return element.element; }); @@ -317,7 +303,7 @@ exports.ElementMediator = Montage.create(Component, { @param stageRedraw: *OPTIONAL*: True. If set to false the stage will not redraw the selection/outline */ setColor: { - value: function(els, value, isFill, eventType, source, currentValue, stageRedraw) { + value: function(els, value, isFill, eventType, source, currentValue) { if(eventType === "Changing") { this._setColor(els, value, isFill, eventType, source); @@ -394,7 +380,7 @@ exports.ElementMediator = Montage.create(Component, { @param stageRedraw: *OPTIONAL*: True. If set to false the stage will not redraw the selection/outline */ setStroke: { - value: function(els, value, eventType, source, currentValue, stageRedraw) { + value: function(els, value, eventType, source, currentValue) { if(eventType === "Changing") { this._setStroke(els, value, isFill, eventType, source); -- cgit v1.2.3 From e8b4eebc94db3d2dbddb3e493025c426eaeb63e4 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Fri, 13 Apr 2012 14:22:53 -0700 Subject: collapsing the history panel by default and commenting out the undo for the 3d properties Signed-off-by: Valerio Virgillito --- js/mediators/element-mediator.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'js/mediators/element-mediator.js') diff --git a/js/mediators/element-mediator.js b/js/mediators/element-mediator.js index fb3f2f27..919aaec1 100755 --- a/js/mediators/element-mediator.js +++ b/js/mediators/element-mediator.js @@ -272,6 +272,18 @@ exports.ElementMediator = Montage.create(Component, { item.element.elementModel.controller["set3DProperties"](item.element, item.properties, update3DModel); } + /* + if(eventType === "Change") { + var undoLabel = "3D Properties change"; + elements.forEach(function(elementObject) { + var swap = elementObject.properties; + elementObject.properties = elementObject.previousProperties; + elementObject.previousProperties = swap; + }); + document.application.undoManager.add(undoLabel, this.set3DProperties, this, elements, eventType, source); + } + */ + var els = elements.map(function(element) { return element.element; }); -- cgit v1.2.3