aboutsummaryrefslogtreecommitdiff
path: root/js/controllers/selection-controller.js
diff options
context:
space:
mode:
authorJonathan Duran2012-04-04 11:21:46 -0700
committerJonathan Duran2012-04-04 11:21:46 -0700
commit04ca16276e73dbd238b42fd898f8b3cccc730f18 (patch)
tree95aee6605f1018550875812166d292554830d7ca /js/controllers/selection-controller.js
parent61404b1965ffe7011ec86953f853f0954ccc308d (diff)
parenta11ef2eed7049835c8bdfa50a2b893632c46eaa0 (diff)
downloadninja-04ca16276e73dbd238b42fd898f8b3cccc730f18.tar.gz
Merge branch 'refs/heads/NINJAmaster' into TimelineUber
Conflicts: js/panels/Timeline/TimelinePanel.reel/TimelinePanel.js js/tools/SelectionTool.js Signed-off-by: Jonathan Duran <jduran@motorola.com>
Diffstat (limited to 'js/controllers/selection-controller.js')
-rwxr-xr-xjs/controllers/selection-controller.js147
1 files changed, 36 insertions, 111 deletions
diff --git a/js/controllers/selection-controller.js b/js/controllers/selection-controller.js
index 53cca029..dbb3f30d 100755
--- a/js/controllers/selection-controller.js
+++ b/js/controllers/selection-controller.js
@@ -6,8 +6,7 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
6 6
7 7
8var Montage = require("montage/core/core").Montage, 8var Montage = require("montage/core/core").Montage,
9 Component = require("montage/ui/component").Component, 9 Component = require("montage/ui/component").Component;
10 NJUtils = require("js/lib/NJUtils").NJUtils;
11 10
12exports.SelectionController = Montage.create(Component, { 11exports.SelectionController = Montage.create(Component, {
13 12
@@ -45,13 +44,10 @@ exports.SelectionController = Montage.create(Component, {
45 value: function() { 44 value: function() {
46 this.eventManager.addEventListener("openDocument", this, false); 45 this.eventManager.addEventListener("openDocument", this, false);
47 this.eventManager.addEventListener("elementAdded", this, false); 46 this.eventManager.addEventListener("elementAdded", this, false);
48 this.eventManager.addEventListener("elementDeleted", this, false); 47 this.eventManager.addEventListener("elementsRemoved", this, false);
49 this.eventManager.addEventListener("selectAll", this, false); 48 this.eventManager.addEventListener("selectAll", this, false);
50 this.eventManager.addEventListener("deleteSelection", this, false);
51 this.eventManager.addEventListener("switchDocument", this, false); 49 this.eventManager.addEventListener("switchDocument", this, false);
52 this.eventManager.addEventListener("closeDocument", this, false); 50 this.eventManager.addEventListener("closeDocument", this, false);
53// defaultEventManager.addEventListener( "undo", this, false);
54// defaultEventManager.addEventListener( "redo", this, false);
55 } 51 }
56 }, 52 },
57 53
@@ -67,35 +63,25 @@ exports.SelectionController = Montage.create(Component, {
67 63
68 initWithDocument: { 64 initWithDocument: {
69 value: function(currentSelectionArray) { 65 value: function(currentSelectionArray) {
70 this._selectedItems = [];
71 this._isDocument = true; 66 this._isDocument = true;
72 67
73 if(currentSelectionArray) { 68 if(currentSelectionArray) {
74 if(currentSelectionArray.length >= 1) { 69 if(currentSelectionArray.length >= 1) {
75 this._selectedItems = currentSelectionArray;
76 this._isDocument = false; 70 this._isDocument = false;
77 71
78
79
80 this.application.ninja.selectedElements = currentSelectionArray; 72 this.application.ninja.selectedElements = currentSelectionArray;
81 NJevent("selectionChange", {"elements": this.application.ninja.selectedElements, "isDocument": this._isDocument}); 73 NJevent("selectionChange", {"elements": this.application.ninja.selectedElements, "isDocument": this._isDocument});
82
83
84
85 } 74 }
86 } 75 }
87 76
88 //
89 this._selectionContainer = this.application.ninja.currentSelectedContainer; 77 this._selectionContainer = this.application.ninja.currentSelectedContainer;
90
91 } 78 }
92 }, 79 },
93 80
94 handleSwitchDocument: { 81 handleSwitchDocument: {
95 value: function() { 82 value: function() {
96 if(this.application.ninja.documentController.activeDocument.currentView === "design"){ 83 if(this.application.ninja.documentController.activeDocument.currentView === "design"){
97 this._selectedItems = this.application.ninja.selectedElements.slice(0); 84 this._isDocument = this.application.ninja.selectedElements.length === 0;
98 this._isDocument = this._selectedItems.length === 0;
99 NJevent("selectionChange", {"elements": this.application.ninja.selectedElements, "isDocument": this._isDocument} ); 85 NJevent("selectionChange", {"elements": this.application.ninja.selectedElements, "isDocument": this._isDocument} );
100 } 86 }
101 } 87 }
@@ -107,21 +93,12 @@ exports.SelectionController = Montage.create(Component, {
107 } 93 }
108 }, 94 },
109 95
110 handleElementDeleted: { 96 handleElementsRemoved: {
111 value: function(event) { 97 value: function(event) {
112 if(!this._isDocument) { 98 if(!this._isDocument) {
113 if(this.findSelectedElement(event.detail) !== -1) { 99 this.application.ninja.selectedElements = [];
114 this.executeSelectElement(); 100 this._isDocument = true;
115 var element = event.detail; 101 NJevent("selectionChange", {"elements": this.application.ninja.selectedElements, "isDocument": this._isDocument});
116 if (element) {
117 if (element.elementModel) {
118 if (element.elementModel.shapeModel) {
119 if (element.elementModel.shapeModel.GLWorld)
120 element.elementModel.shapeModel.GLWorld.clearTree();
121 }
122 }
123 }
124 }
125 } 102 }
126 } 103 }
127 }, 104 },
@@ -142,23 +119,19 @@ exports.SelectionController = Montage.create(Component, {
142 } 119 }
143 }, 120 },
144 121
145 handleDeleteSelection: {
146 value: function(event) {
147 this.application.ninja.selectedElements = [];
148 this._isDocument = true;
149 NJevent("selectionChange", {"elements": this.application.ninja.selectedElements, "isDocument": this._isDocument});
150 }
151 },
152
153 /** 122 /**
154 * Select Element. This function will not check that element, it will simply add it to the selection array. 123 * Select Element. This function will not check that element, it will simply add it to the selection array.
155 */ 124 */
156 executeSelectElement: { 125 executeSelectElement: {
157 value: function(item) { 126 value: function(element) {
158 this.application.ninja.selectedElements = []; 127 this.application.ninja.selectedElements = [];
159 128
160 if(item) { 129 if(element) {
161 this.application.ninja.selectedElements.push({_element: item, uuid: item.uuid}); 130 if(Array.isArray(element)) {
131 this.application.ninja.selectedElements = Array.prototype.slice.call(element, 0);
132 } else {
133 this.application.ninja.selectedElements.push(element);
134 }
162 this._isDocument = false; 135 this._isDocument = false;
163 } else { 136 } else {
164 this._isDocument = true; 137 this._isDocument = true;
@@ -171,23 +144,20 @@ exports.SelectionController = Montage.create(Component, {
171 }, 144 },
172 145
173 selectElement: { 146 selectElement: {
174 value: function(item) { 147 value: function(element) {
175 148
176 if(this.findSelectedElement(item) === -1) { 149 if(this.findSelectedElement(element) === -1) {
177 150
178 if(this.application.ninja.currentDocument.inExclusion(item) !== -1){ 151 if(this.application.ninja.currentDocument.inExclusion(element) !== -1){
179 if(this.isDocument) return; // If the stage is already selected do nothing. 152 if(this.isDocument) return; // If the stage is already selected do nothing.
180 this.executeSelectElement(); // Else execute selection with no item 153 this.executeSelectElement(); // Else execute selection with no element
181 } else { 154 } else {
182 155 if(element.parentNode.uuid === this.selectionContainer.uuid) {
183// if(item.parentNode.id === "UserContent") { 156 this.executeSelectElement(element);
184 if(item.parentNode.uuid === this.selectionContainer.uuid) {
185 this.executeSelectElement(item);
186 } else { 157 } else {
187 var outerElement = item.parentNode; 158 var outerElement = element.parentNode;
188 159
189 while(outerElement.parentNode && outerElement.parentNode.uuid !== this.selectionContainer.uuid) { 160 while(outerElement.parentNode && outerElement.parentNode.uuid !== this.selectionContainer.uuid) {
190 //while(outerElement.parentNode && outerElement.parentNode.id !== "UserContent") {
191 // If element is higher up than current container then return 161 // If element is higher up than current container then return
192 if(outerElement.id === "UserContent") return; 162 if(outerElement.id === "UserContent") return;
193 // else keep going up the chain 163 // else keep going up the chain
@@ -202,13 +172,13 @@ exports.SelectionController = Montage.create(Component, {
202 }, 172 },
203 173
204 selectElements: { 174 selectElements: {
205 value: function(items) { 175 value: function(elements) {
206 if(items && items.length > 0) { 176 if(elements && elements.length > 0) {
207 var that = this; 177 var that = this;
208 this.application.ninja.selectedElements = []; 178 this.application.ninja.selectedElements = [];
209 179
210 items.forEach(function(item) { 180 elements.forEach(function(element) {
211 that.application.ninja.selectedElements.push({_element: item, uuid: item.uuid}); 181 that.application.ninja.selectedElements.push(element);
212 that._isDocument = false; 182 that._isDocument = false;
213 }); 183 });
214 184
@@ -218,22 +188,22 @@ exports.SelectionController = Montage.create(Component, {
218 }, 188 },
219 189
220 shiftSelectElement: { 190 shiftSelectElement: {
221 value: function(item) { 191 value: function(element) {
222 if(this.application.ninja.currentDocument.inExclusion(item) !== -1) return; 192 if(this.application.ninja.currentDocument.inExclusion(element) !== -1) return;
223 193
224 (this.findSelectedElement(item) !== -1 ) ? this.removeElement(item) : this.insertElement(item); 194 (this.findSelectedElement(element) !== -1 ) ? this.removeElement(element) : this.insertElement(element