diff options
author | hwc487 | 2012-04-19 13:01:43 -0700 |
---|---|---|
committer | hwc487 | 2012-04-19 13:01:43 -0700 |
commit | e6a20fe64574763483dc602bd759278ccf5e5e68 (patch) | |
tree | 69defe7200206f0257fe90697136fadef59d521e /js/mediators | |
parent | ae7eb87564632ce7c676bd728b8ff2710ff0bb83 (diff) | |
parent | 9284c19f076dec3b47ece7dc7bcd22d74e4246c3 (diff) | |
download | ninja-e6a20fe64574763483dc602bd759278ccf5e5e68.tar.gz |
Merge branch 'master' of github.com:Motorola-Mobility/ninja-internal into Textures
Conflicts:
js/lib/drawing/world.js
js/lib/geom/geom-obj.js
js/lib/rdge/materials/cloud-material.js
js/lib/rdge/materials/deform-material.js
js/lib/rdge/materials/flat-material.js
js/lib/rdge/materials/material.js
js/lib/rdge/materials/pulse-material.js
js/lib/rdge/materials/relief-tunnel-material.js
js/lib/rdge/materials/square-tunnel-material.js
js/lib/rdge/materials/star-material.js
js/lib/rdge/materials/taper-material.js
js/lib/rdge/materials/tunnel-material.js
js/lib/rdge/materials/twist-material.js
js/lib/rdge/materials/twist-vert-material.js
js/lib/rdge/materials/uber-material.js
js/lib/rdge/materials/water-material.js
js/lib/rdge/materials/z-invert-material.js
Diffstat (limited to 'js/mediators')
-rwxr-xr-x | js/mediators/drag-drop-mediator.js | 12 | ||||
-rwxr-xr-x | js/mediators/element-mediator.js | 439 | ||||
-rw-r--r-- | js/mediators/io-mediator.js | 1096 | ||||
-rwxr-xr-x | js/mediators/keyboard-mediator.js | 55 | ||||
-rwxr-xr-x | js/mediators/mouse-mediator.js | 4 |
5 files changed, 709 insertions, 897 deletions
diff --git a/js/mediators/drag-drop-mediator.js b/js/mediators/drag-drop-mediator.js index 8663b06e..eedab8fc 100755 --- a/js/mediators/drag-drop-mediator.js +++ b/js/mediators/drag-drop-mediator.js | |||
@@ -111,6 +111,7 @@ exports.DragDropMediator = Montage.create(Component, { | |||
111 | fileName = tempName; | 111 | fileName = tempName; |
112 | } | 112 | } |
113 | if (save && save.success && save.status === 201) { | 113 | if (save && save.success && save.status === 201) { |
114 | var self = this; | ||
114 | // | 115 | // |
115 | if (e.currentTarget.fileType.indexOf('svg') !== -1) { | 116 | if (e.currentTarget.fileType.indexOf('svg') !== -1) { |
116 | element = NJUtils.makeNJElement('embed', 'SVG', 'block');//TODO: Verify this is proper | 117 | element = NJUtils.makeNJElement('embed', 'SVG', 'block');//TODO: Verify this is proper |
@@ -121,19 +122,18 @@ exports.DragDropMediator = Montage.create(Component, { | |||
121 | element.src = url+'/'+fileName; | 122 | element.src = url+'/'+fileName; |
122 | } | 123 | } |
123 | //TODO: Remove temp fix for elements to redraw on drop | 124 | //TODO: Remove temp fix for elements to redraw on drop |
125 | |||
124 | element.onload = function () { | 126 | element.onload = function () { |
125 | NJevent("elementAdding", {el: element, data: rules}); | 127 | self.application.ninja.elementMediator.addElements(element, rules); |
126 | } | 128 | }; |
127 | // | 129 | // |
128 | rules = { | 130 | rules = { |
129 | 'position': 'absolute', | 131 | 'position': 'absolute', |
130 | 'top' : (parseInt(e.currentTarget.filePosition.y) - parseInt(this.application.ninja.stage.userContentTop)) + 'px', | 132 | 'top' : (parseInt(e.currentTarget.filePosition.y) - parseInt(this.application.ninja.stage.userContentTop)) + 'px', |
131 | 'left' : (parseInt(e.currentTarget.filePosition.x) - parseInt(this.application.ninja.stage.userContentLeft)) + 'px', | 133 | 'left' : (parseInt(e.currentTarget.filePosition.x) - parseInt(this.application.ninja.stage.userContentLeft)) + 'px' |
132 | '-webkit-transform-style' : 'preserve-3d', | ||
133 | '-webkit-transform' : 'perspective(1400) matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' | ||
134 | }; | 134 | }; |
135 | // | 135 | // |
136 | NJevent("elementAdding", {el: element, data: rules}); | 136 | self.application.ninja.elementMediator.addElements(element, rules); |
137 | } else { | 137 | } else { |
138 | //TODO: HANDLE ERROR ON SAVING FILE TO BE ADDED AS ELEMENT | 138 | //TODO: HANDLE ERROR ON SAVING FILE TO BE ADDED AS ELEMENT |
139 | } | 139 | } |
diff --git a/js/mediators/element-mediator.js b/js/mediators/element-mediator.js index d62fa1f8..919aaec1 100755 --- a/js/mediators/element-mediator.js +++ b/js/mediators/element-mediator.js | |||
@@ -5,146 +5,97 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
5 | </copyright> */ | 5 | </copyright> */ |
6 | 6 | ||
7 | var Montage = require("montage/core/core").Montage, | 7 | var Montage = require("montage/core/core").Montage, |
8 | NJComponent = require("js/lib/nj-base").NJComponent; | 8 | Component = require("montage/ui/component").Component; |
9 | 9 | ||
10 | var ElementController = require("js/controllers/elements/element-controller").ElementController, | 10 | var ElementController = require("js/controllers/elements/element-controller").ElementController, |
11 | Command = require("js/controllers/undo-controller").Command, | 11 | Command = require("js/controllers/undo-controller").Command, |
12 | GroupCommand = require("js/controllers/undo-controller").GroupCommand, | ||
13 | NJUtils = require("js/lib/NJUtils").NJUtils; | 12 | NJUtils = require("js/lib/NJUtils").NJUtils; |
14 | 13 | ||
15 | exports.ElementMediator = Montage.create(NJComponent, { | 14 | exports.ElementMediator = Montage.create(Component, { |
16 | 15 | ||
17 | deleteDelegate: { | ||
18 | value: null | ||
19 | }, | ||
20 | 16 | ||
21 | deserializedFromTemplate: { | 17 | addDelegate: { |
22 | value: function () { | 18 | enumerable: false, |
23 | this.eventManager.addEventListener("elementAdding", this, false); | 19 | value: null |
24 | this.eventManager.addEventListener("deleting", this, false); | ||
25 | } | ||
26 | }, | 20 | }, |
27 | 21 | ||
28 | // TODO use the specific controller to be able to subclass the functionality | 22 | deleteDelegate: { |
29 | handleElementAdding: { | 23 | enumerable: false, |
30 | value: function(event) { | 24 | value: null |
31 | this.addElement(event.detail.el, event.detail.data); | ||
32 | } | ||
33 | }, | 25 | }, |
34 | 26 | ||
35 | handleDeleting: { | 27 | addElements: { |
36 | value: function(event) { | 28 | value: function(elements, rules, notify) { |
37 | if(this.deleteDelegate && (typeof this.deleteDelegate.handleDelete === 'function')) { | 29 | if(Array.isArray(elements)) { |
38 | this.deleteDelegate.handleDelete(); | 30 | elements.forEach(function(element) { |
39 | } else { | 31 | ElementController.addElement(element, rules); |
40 | // Add the Undo/Redo | 32 | if(element.elementModel && element.elementModel.props3D) { |
41 | var els = [], | 33 | element.elementModel.props3D.init(element, false); |
42 | len = this.application.ninja.selectedElements.length; | ||
43 | |||
44 | if(len) { | ||
45 | for(var i = 0; i<len; i++) { | ||
46 | els.push(this.application.ninja.selectedElements[i]); | ||
47 | } | ||
48 | |||
49 | for(i=0; i<len; i++) { | ||
50 | this._removeElement(els[i]._element); | ||
51 | } | 34 | } |
52 | 35 | }); | |
53 | NJevent( "deleteSelection", els ); | 36 | } else { |
37 | ElementController.addElement(elements, rules); | ||
38 | if(elements.elementModel && elements.elementModel.props3D) { | ||
39 | elements.elementModel.props3D.init(elements, false); | ||
54 | } | 40 | } |
55 | } | 41 | } |
56 | } | ||
57 | }, | ||
58 | |||
59 | addElement: { | ||
60 | value: function(el, rules, noEvent) { | ||
61 | var command = Montage.create(Command, { | ||
62 | _el: { value: el }, | ||
63 | _rules: { value: rules }, | ||
64 | _noEvent: { value: noEvent }, | ||
65 | 42 | ||
66 | description: { value: "Adding Element"}, | 43 | if(this.addDelegate && typeof (this.addDelegate['onAddElements']) === "function") { |
44 | this.addDelegate['onAddElements'].call(this.addDelegate, elements); | ||
45 | } | ||
67 | 46 | ||
68 | receiver: { value: this}, | 47 | var undoLabel = "add element"; |
69 | 48 | ||
70 | execute: { | 49 | document.application.undoManager.add(undoLabel, this.removeElements, this, elements, notify); |
71 | value: function() { | ||
72 | this.receiver._addElement(this._el, this._rules, this._noEvent); | ||
73 | return this._el; | ||
74 | } | ||
75 | }, | ||
76 | 50 | ||
77 | unexecute: { | 51 | this.application.ninja.documentController.activeDocument.needsSave = true; |
78 | value: function() { | ||
79 | this.receiver._removeElement(this._el, this._rules, this._noEvent); | ||
80 | return this._el; | ||
81 | } | ||
82 | } | ||
83 | }); | ||
84 | |||
85 | NJevent("sendToUndo", command); | ||
86 | command.execute(); | ||
87 | } | ||
88 | }, | ||
89 | 52 | ||
90 | _addElement: { | 53 | if(notify || notify === undefined) { |
91 | value: function(el, rules, noEvent) { | 54 | NJevent("elementAdded", elements); |
92 | ElementController.addElement(el, rules); | ||
93 | var p3d = this.get3DProperties(el); | ||
94 | if(p3d) { | ||
95 | el.elementModel.controller["set3DProperties"](el, [p3d], 0, true); | ||
96 | } | ||
97 | if(!noEvent) { | ||
98 | this.application.ninja.documentController.activeDocument.needsSave = true; | ||
99 | NJevent("elementAdded", el); | ||
100 | } | 55 | } |
101 | } | 56 | } |
102 | }, | 57 | }, |
103 | 58 | ||
104 | deleteElements: { | 59 | removeElements: { |
105 | value: function(items) { | 60 | value: function(elements, notify /* Used for the add undo */) { |
106 | // Add the Undo/Redo | ||
107 | var len, el; | ||
108 | 61 | ||
109 | len = items.length; | 62 | if(this.deleteDelegate && (typeof this.deleteDelegate.handleDelete === 'function')) { |
63 | return this.deleteDelegate.handleDelete(); | ||
64 | // this.handleDelete.call(deleteDelegate); | ||
65 | } | ||
110 | 66 | ||
111 | if(len) { | 67 | if(Array.isArray(elements)) { |
68 | elements = Array.prototype.slice.call(elements, 0); | ||
69 | elements.forEach(function(element) { | ||
70 | ElementController.removeElement(element); | ||
71 | }); | ||
72 | } else { | ||
73 | ElementController.removeElement(elements); | ||
74 | } | ||
112 | 75 | ||
113 | for(var i = len - 1; i >= 0; i--) { | 76 | var undoLabel = "add element"; |
114 | el = items[i]._element || items[i]; | ||
115 | this._removeElement(el); | ||
116 | } | ||
117 | 77 | ||
118 | NJevent( "deleteSelection", items ); | 78 | document.application.undoManager.add(undoLabel, this.addElements, this, elements, null, notify); |
119 | } |