From 4c3aac5eabd93052b1554a03d78235215bb49db4 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Tue, 29 May 2012 00:34:40 -0700 Subject: document bindings phase 1 - using array controller to bind the current document to all ninja components - removed open document event - removed references to the document controller Signed-off-by: Valerio Virgillito --- js/mediators/element-mediator.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'js/mediators/element-mediator.js') diff --git a/js/mediators/element-mediator.js b/js/mediators/element-mediator.js index f71a6f4d..1d5e9ade 100755 --- a/js/mediators/element-mediator.js +++ b/js/mediators/element-mediator.js @@ -48,7 +48,7 @@ exports.ElementMediator = Montage.create(Component, { document.application.undoManager.add(undoLabel, this.removeElements, this, elements, notify); - this.application.ninja.documentController.activeDocument.model.needsSave = true; + this.application.ninja.currentDocument.model.needsSave = true; if(notify || notify === undefined) { NJevent("elementAdded", elements); @@ -77,7 +77,7 @@ exports.ElementMediator = Montage.create(Component, { document.application.undoManager.add(undoLabel, this.addElements, this, elements, null, notify); - this.application.ninja.documentController.activeDocument.model.needsSave = true; + this.application.ninja.currentDocument.model.needsSave = true; NJevent("elementsRemoved", elements); } @@ -92,7 +92,7 @@ exports.ElementMediator = Montage.create(Component, { document.application.undoManager.add(undoLabel, this.replaceElement, this, oldChild, newChild); - this.application.ninja.documentController.activeDocument.model.needsSave = true; + this.application.ninja.currentDocument.model.needsSave = true; if(notify || notify === undefined) { NJevent("elementReplaced", {type : "replaceElement", data: {"newChild": newChild, "oldChild": oldChild}}); -- cgit v1.2.3 From d44f3196c925332dcaf45f7cf8c64e22a1994bb9 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Mon, 4 Jun 2012 17:11:06 -0700 Subject: Fill and Ink-Bottle fixes. Signed-off-by: Nivesh Rajbhandari --- js/mediators/element-mediator.js | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'js/mediators/element-mediator.js') diff --git a/js/mediators/element-mediator.js b/js/mediators/element-mediator.js index 1d5e9ade..7244b58e 100755 --- a/js/mediators/element-mediator.js +++ b/js/mediators/element-mediator.js @@ -389,7 +389,6 @@ 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 @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 */ setStroke: { value: function(els, value, eventType, source, currentValue) { @@ -448,6 +447,44 @@ exports.ElementMediator = Montage.create(Component, { } }, + getFill: { + value: function(el, fillProperties) { + return el.elementModel.controller["getFill"](el, fillProperties); + } + }, + + + /** + Set a property change command for an element or array of elements + @param els: Array of elements. Can contain 1 or more elements + @param value: Value to be set. This is the fill info + @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 + */ + setFill: { + value: function(els, value, eventType, source, currentValue) { + + if(eventType !== "Changing") { + // Calculate currentValue if not found for each element + if(!currentValue) { + var that = this, + val = value; + currentValue = els.map(function(item) { + return that.getFill(item, val); + }); + } + document.application.undoManager.add("Set fill", this.setFill, this, els, currentValue, eventType, source, value); + } + + for(var i=0, item; item = els[i]; i++) { + item.elementModel.controller["setFill"](item, (value[i] || value), eventType, source); + } + + NJevent("element" + eventType, {type : "setFill", source: source, data: {"els": els, "prop": "fill", "value": value}, redraw: null}); + } + }, + //-------------------------------------------------------------------------------------------------------- // Routines to get/set 3D properties get3DProperty: { -- cgit v1.2.3 From 945fac7b1593260757b6f2864810ca9916d7d698 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Tue, 5 Jun 2012 11:36:03 -0700 Subject: Updated ink bottle tool to support color-chip's checkbox and undo/redo for strokes/borders. Signed-off-by: Nivesh Rajbhandari --- js/mediators/element-mediator.js | 61 ++++++++-------------------------------- 1 file changed, 11 insertions(+), 50 deletions(-) (limited to 'js/mediators/element-mediator.js') diff --git a/js/mediators/element-mediator.js b/js/mediators/element-mediator.js index 7244b58e..da8cbb76 100755 --- a/js/mediators/element-mediator.js +++ b/js/mediators/element-mediator.js @@ -373,17 +373,13 @@ exports.ElementMediator = Montage.create(Component, { }, getStroke: { - value: function(el) { - if(!el.elementModel) { - NJUtils.makeElementModel(el, "Div", "block"); - } - return el.elementModel.controller["getStroke"](el); + value: function(el, strokeProperties) { + return el.elementModel.controller["getStroke"](el, strokeProperties); } }, - /** - Set a property change command for an element or array of elements + Set stroke/border properties on an element or array of elements @param els: Array of elements. Can contain 1 or more elements @param value: Value to be set. This is the stroke info @param eventType: Change/Changing. Will be passed to the dispatched event @@ -393,54 +389,20 @@ exports.ElementMediator = Montage.create(Component, { setStroke: { value: function(els, value, eventType, source, currentValue) { - if(eventType === "Changing") { - this._setStroke(els, value, isFill, eventType, source); - } else { + if(eventType !== "Changing") { // Calculate currentValue if not found for each element if(!currentValue) { - var that = this; + var that = this, + val = value; currentValue = els.map(function(item) { - return that.getStroke(item); + return that.getStroke(item, val); }); } - - var command = Montage.create(Command, { - _els: { value: els }, - _value: { value: value }, - _previous: { value: currentValue }, - _eventType: { value: eventType}, - _source: { value: "undo-redo"}, - description: { value: "Set Color"}, - receiver: { value: this}, - - execute: { - value: function(senderObject) { - if(senderObject) this._source = senderObject; - this.receiver._setStroke(this._els, this._value, this._eventType, this._source); - this._source = "undo-redo"; - return ""; - } - }, - - unexecute: { - value: function() { - this.receiver._setStroke(this._els, this._previous, this._eventType, this._source); - return ""; - } - } - }); - - NJevent("sendToUndo", command); - command.execute(source); + document.application.undoManager.add("Set stroke", this.setStroke, this, els, currentValue, eventType, source, value); } - } - }, - - _setStroke: { - value: function(els, value, eventType, source) { for(var i=0, item; item = els[i]; i++) { - item.elementModel.controller["setStroke"](item, value); + item.elementModel.controller["setStroke"](item, (value[i] || value), eventType, source); } NJevent("element" + eventType, {type : "setStroke", source: source, data: {"els": els, "prop": "stroke", "value": value}, redraw: null}); @@ -453,9 +415,8 @@ exports.ElementMediator = Montage.create(Component, { } }, - /** - Set a property change command for an element or array of elements + Set fill/background properties for an element or array of elements @param els: Array of elements. Can contain 1 or more elements @param value: Value to be set. This is the fill info @param eventType: Change/Changing. Will be passed to the dispatched event @@ -478,7 +439,7 @@ exports.ElementMediator = Montage.create(Component, { } for(var i=0, item; item = els[i]; i++) { - item.elementModel.controller["setFill"](item, (value[i] || value), eventType, source); + item.elementModel.controller["setFill"](item, (value[i] || value)); } NJevent("element" + eventType, {type : "setFill", source: source, data: {"els": els, "prop": "fill", "value": value}, redraw: null}); -- cgit v1.2.3 From e28eb9158a50d7e6d97dbc68066e591ac600c241 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Tue, 5 Jun 2012 21:40:44 -0700 Subject: removing all model creators. The elementModel is now a getter that will create a new model when needed. Signed-off-by: Valerio Virgillito --- js/mediators/element-mediator.js | 42 +++------------------------------------- 1 file changed, 3 insertions(+), 39 deletions(-) (limited to 'js/mediators/element-mediator.js') diff --git a/js/mediators/element-mediator.js b/js/mediators/element-mediator.js index 1d5e9ade..cecb4392 100755 --- a/js/mediators/element-mediator.js +++ b/js/mediators/element-mediator.js @@ -29,15 +29,12 @@ exports.ElementMediator = Montage.create(Component, { if(Array.isArray(elements)) { elements.forEach(function(element) { ElementController.addElement(element, rules); - if(element.elementModel && element.elementModel.props3D) { - element.elementModel.props3D.init(element, false); - } + element.elementModel.props3D.init(element, false); }); } else { ElementController.addElement(elements, rules); - if(elements.elementModel && elements.elementModel.props3D) { - elements.elementModel.props3D.init(elements, false); - } + elements.elementModel.props3D.init(elements, false); + } if(this.addDelegate && typeof (this.addDelegate['onAddElements']) === "function") { @@ -102,11 +99,6 @@ exports.ElementMediator = Montage.create(Component, { getProperty: { value: function(el, prop, valueMutator) { - if(!el.elementModel) { - console.log("Element has no Model -> One should have been created"); - NJUtils.makeElementModel(el, "Div", "block"); - } - if(valueMutator && typeof valueMutator === "function") { return valueMutator(el.elementModel.controller["getProperty"](el, prop)); } else { @@ -117,22 +109,12 @@ exports.ElementMediator = Montage.create(Component, { getShapeProperty: { value: function(el, prop) { - if(!el.elementModel) { - console.log("Element has no Model -> One should have been created"); - NJUtils.makeElementModel(el, "Canvas", "block", true); - } - return el.elementModel.controller["getShapeProperty"](el, prop); } }, setShapeProperty: { value: function(el, prop, value) { - if(!el.elementModel) { - console.log("Element has no Model -> One should have been created"); - NJUtils.makeElementModel(el, "Canvas", "block", true); - } - return el.elementModel.controller["setShapeProperty"](el, prop, value); } }, @@ -297,9 +279,6 @@ exports.ElementMediator = Montage.create(Component, { // Routines to get/set color getColor: { value: function(el, isFill, borderSide) { - if(!el.elementModel) { - NJUtils.makeModelFromElement(el); - } return el.elementModel.controller["getColor"](el, isFill, borderSide); } }, @@ -374,9 +353,6 @@ exports.ElementMediator = Montage.create(Component, { getStroke: { value: function(el) { - if(!el.elementModel) { - NJUtils.makeElementModel(el, "Div", "block"); - } return el.elementModel.controller["getStroke"](el); } }, @@ -452,18 +428,12 @@ exports.ElementMediator = Montage.create(Component, { // Routines to get/set 3D properties get3DProperty: { value: function(el, prop) { - if(!el.elementModel) { - NJUtils.makeModelFromElement(el); - } return el.elementModel.controller["get3DProperty"](el, prop); } }, get3DProperties: { value: function(el) { - if(!el.elementModel) { - NJUtils.makeModelFromElement(el); - } // var mat = this.getMatrix(el); // var dist = this.getPerspectiveDist(el); var mat = el.elementModel.controller["getMatrix"](el); @@ -474,18 +444,12 @@ exports.ElementMediator = Montage.create(Component, { getMatrix: { value: function(el) { - if(!el.elementModel) { - NJUtils.makeModelFromElement(el); - } return el.elementModel.controller["getMatrix"](el); } }, getPerspectiveDist: { value: function(el) { - if(!el.elementModel) { - NJUtils.makeModelFromElement(el); - } return el.elementModel.controller["getPerspectiveDist"](el); } }, -- cgit v1.2.3