aboutsummaryrefslogtreecommitdiff
path: root/js/controllers/selection-controller.js
diff options
context:
space:
mode:
authorNivesh Rajbhandari2012-04-16 16:06:24 -0700
committerNivesh Rajbhandari2012-04-16 16:06:24 -0700
commitc253192a08b499ea7be46fa5438d273e51f7ec5a (patch)
tree18a1f0e3679c0eb993a9dedb537035d3861f49ac /js/controllers/selection-controller.js
parente19376c54eedd1f1c457ba405b2f110be376a559 (diff)
parent4b900ea5cd6bb77eb30cec8c03b9ec9fa662c1e9 (diff)
downloadninja-c253192a08b499ea7be46fa5438d273e51f7ec5a.tar.gz
Merge branch 'refs/heads/ninja-internal' into WebGLFixes
Diffstat (limited to 'js/controllers/selection-controller.js')
-rwxr-xr-xjs/controllers/selection-controller.js148
1 files changed, 43 insertions, 105 deletions
diff --git a/js/controllers/selection-controller.js b/js/controllers/selection-controller.js
index c713b6e5..5665b09c 100755
--- a/js/controllers/selection-controller.js
+++ b/js/controllers/selection-controller.js
@@ -44,13 +44,11 @@ exports.SelectionController = Montage.create(Component, {
44 value: function() { 44 value: function() {
45 this.eventManager.addEventListener("openDocument", this, false); 45 this.eventManager.addEventListener("openDocument", this, false);
46 this.eventManager.addEventListener("elementAdded", this, false); 46 this.eventManager.addEventListener("elementAdded", this, false);
47 this.eventManager.addEventListener("elementDeleted", this, false); 47 this.eventManager.addEventListener("elementsRemoved", this, false);
48 this.eventManager.addEventListener("elementReplaced", this, false);
48 this.eventManager.addEventListener("selectAll", this, false); 49 this.eventManager.addEventListener("selectAll", this, false);
49 this.eventManager.addEventListener("deleteSelection", this, false);
50 this.eventManager.addEventListener("switchDocument", this, false); 50 this.eventManager.addEventListener("switchDocument", this, false);
51 this.eventManager.addEventListener("closeDocument", this, false); 51 this.eventManager.addEventListener("closeDocument", this, false);
52// defaultEventManager.addEventListener( "undo", this, false);
53// defaultEventManager.addEventListener( "redo", this, false);
54 } 52 }
55 }, 53 },
56 54
@@ -66,39 +64,25 @@ exports.SelectionController = Montage.create(Component, {
66 64
67 initWithDocument: { 65 initWithDocument: {
68 value: function(currentSelectionArray) { 66 value: function(currentSelectionArray) {
69 this._selectedItems = [];
70 this._isDocument = true; 67 this._isDocument = true;
71 68
72 if(currentSelectionArray) { 69 if(currentSelectionArray) {
73 if(currentSelectionArray.length >= 1) { 70 if(currentSelectionArray.length >= 1) {
74 this._selectedItems = currentSelectionArray;
75 this._isDocument = false; 71 this._isDocument = false;
76 72
77
78
79 this.application.ninja.selectedElements = currentSelectionArray; 73 this.application.ninja.selectedElements = currentSelectionArray;
80 NJevent("selectionChange", {"elements": this.application.ninja.selectedElements, "isDocument": this._isDocument}); 74 NJevent("selectionChange", {"elements": this.application.ninja.selectedElements, "isDocument": this._isDocument});
81
82
83
84 } 75 }
85 } 76 }
86 77
87 //
88 this._selectionContainer = this.application.ninja.currentSelectedContainer; 78 this._selectionContainer = this.application.ninja.currentSelectedContainer;
89
90 } 79 }
91 }, 80 },
92 81
93 handleSwitchDocument: { 82 handleSwitchDocument: {
94 value: function() { 83 value: function() {
95 if(this.application.ninja.documentController.activeDocument.currentView === "design"){ 84 if(this.application.ninja.documentController.activeDocument.currentView === "design"){
96 this._selectedItems = this.application.ninja.selectedElements.slice(0); 85 this._isDocument = this.application.ninja.selectedElements.length === 0;
97 if(this._selectedItems.length === 0 ){
98 this._isDocument = true;
99 }else{
100 this._isDocument = false;
101 }
102 NJevent("selectionChange", {"elements": this.application.ninja.selectedElements, "isDocument": this._isDocument} ); 86 NJevent("selectionChange", {"elements": this.application.ninja.selectedElements, "isDocument": this._isDocument} );
103 } 87 }
104 } 88 }
@@ -110,16 +94,22 @@ exports.SelectionController = Montage.create(Component, {
110 } 94 }
111 }, 95 },
112 96
113 handleElementDeleted: { 97 handleElementsRemoved: {
114 value: function(event) { 98 value: function(event) {
115 if(!this._isDocument) { 99 if(!this._isDocument) {
116 if(this.findSelectedElement(event.detail) !== -1) { 100 this.application.ninja.selectedElements = [];
117 this.executeSelectElement(); 101 this._isDocument = true;
118 } 102 NJevent("selectionChange", {"elements": this.application.ninja.selectedElements, "isDocument": this._isDocument});
119 } 103 }
120 } 104 }
121 }, 105 },
122 106
107 handleElementReplaced: {
108 value: function(event) {
109 this.application.ninja.selectedElements[this.application.ninja.selectedElements.indexOf(event.detail.data.oldChild)] = event.detail.data.newChild;
110 }
111 },
112
123 handleSelectAll: { 113 handleSelectAll: {
124 value: function(event) { 114 value: function(event) {
125 var selected = [], childNodes = []; 115 var selected = [], childNodes = [];
@@ -136,23 +126,19 @@ exports.SelectionController = Montage.create(Component, {
136 } 126 }
137 }, 127 },
138 128
139 handleDeleteSelection: {
140 value: function(event) {
141 this.application.ninja.selectedElements = [];
142 this._isDocument = true;
143 NJevent("selectionChange", {"elements": this.application.ninja.selectedElements, "isDocument": this._isDocument});
144 }
145 },
146
147 /** 129 /**
148 * Select Element. This function will not check that element, it will simply add it to the selection array. 130 * Select Element. This function will not check that element, it will simply add it to the selection array.
149 */ 131 */
150 executeSelectElement: { 132 executeSelectElement: {
151 value: function(item) { 133 value: function(element) {
152 this.application.ninja.selectedElements = []; 134 this.application.ninja.selectedElements = [];
153 135
154 if(item) { 136 if(element) {
155 this.application.ninja.selectedElements.push({_element: item, uuid: item.uuid}); 137 if(Array.isArray(element)) {
138 this.application.ninja.selectedElements = Array.prototype.slice.call(element, 0);
139 } else {
140 this.application.ninja.selectedElements.push(element);
141 }
156 this._isDocument = false; 142 this._isDocument = false;
157 } else { 143 } else {
158 this._isDocument = true; 144 this._isDocument = true;
@@ -165,23 +151,20 @@ exports.SelectionController = Montage.create(Component, {
165 }, 151 },
166 152
167 selectElement: { 153 selectElement: {
168 value: function(item) { 154 value: function(element) {
169 155
170 if(this.findSelectedElement(item) === -1) { 156 if(this.findSelectedElement(element) === -1) {
171 157
172 if(this.application.ninja.currentDocument.inExclusion(item) !== -1){ 158 if(this.application.ninja.currentDocument.inExclusion(element) !== -1){
173 if(this.isDocument) return; // If the stage is already selected do nothing. 159 if(this.isDocument) return; // If the stage is already selected do nothing.
174 this.executeSelectElement(); // Else execute selection with no item 160 this.executeSelectElement(); // Else execute selection with no element
175 } else { 161 } else {
176 162 if(element.parentNode.uuid === this.selectionContainer.uuid) {
177// if(item.parentNode.id === "UserContent") { 163 this.executeSelectElement(element);
178 if(item.parentNode.uuid === this.selectionContainer.uuid) {
179 this.executeSelectElement(item);
180 } else { 164 } else {
181 var outerElement = item.parentNode; 165 var outerElement = element.parentNode;
182 166
183 while(outerElement.parentNode && outerElement.parentNode.uuid !== this.selectionContainer.uuid) { 167 while(outerElement.parentNode && outerElement.parentNode.uuid !== this.selectionContainer.uuid) {
184 //while(outerElement.parentNode && outerElement.parentNode.id !== "UserContent") {
185 // If element is higher up than current container then return 168 // If element is higher up than current container then return
186 if(outerElement.id === "UserContent") return; 169 if(outerElement.id === "UserContent") return;
187 // else keep going up the chain 170 // else keep going up the chain
@@ -196,13 +179,13 @@ exports.SelectionController = Montage.create(Component, {
196 }, 179 },
197 180
198 selectElements: { 181 selectElements: {
199 value: function(items) { 182 value: function(elements) {
200 if(items && items.length > 0) { 183 if(elements && elements.length > 0) {
201 var that = this; 184 var that = this;
202 this.application.ninja.selectedElements = []; 185 this.application.ninja.selectedElements = [];
203 186
204 items.forEach(function(item) { 187 elements.forEach(function(element) {
205 that.application.ninja.selectedElements.push({_element: item, uuid: item.uuid}); 188 that.application.ninja.selectedElements.push(element);
206 that._isDocument = false; 189 that._isDocument = false;
207 }); 190 });
208 191
@@ -212,22 +195,22 @@ exports.SelectionController = Montage.create(Component, {
212 }, 195 },
213 196
214 shiftSelectElement: { 197 shiftSelectElement: {
215 value: function(item) { 198 value: function(element) {
216 if(this.application.ninja.currentDocument.inExclusion(item) !== -1) return; 199 if(this.application.ninja.currentDocument.inExclusion(element) !== -1) return;
217 200
218 (this.findSelectedElement(item) !== -1 ) ? this.removeElement(item) : this.insertElement(item); 201 (this.findSelectedElement(element) !== -1 ) ? this.removeElement(element) : this.insertElement(element);
219 } 202 }
220 }, 203 },
221