aboutsummaryrefslogtreecommitdiff
path: root/js/controllers/selection-controller.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/controllers/selection-controller.js')
-rwxr-xr-xjs/controllers/selection-controller.js154
1 files changed, 43 insertions, 111 deletions
diff --git a/js/controllers/selection-controller.js b/js/controllers/selection-controller.js
index 53cca029..5665b09c 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,11 @@ 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);
48 this.eventManager.addEventListener("elementReplaced", this, false);
49 this.eventManager.addEventListener("selectAll", this, false); 49 this.eventManager.addEventListener("selectAll", this, false);
50 this.eventManager.addEventListener("deleteSelection", this, false);
51 this.eventManager.addEventListener("switchDocument", this, false); 50 this.eventManager.addEventListener("switchDocument", this, false);
52 this.eventManager.addEventListener("closeDocument", this, false); 51 this.eventManager.addEventListener("closeDocument", this, false);
53// defaultEventManager.addEventListener( "undo", this, false);
54// defaultEventManager.addEventListener( "redo", this, false);
55 } 52 }
56 }, 53 },
57 54
@@ -67,35 +64,25 @@ exports.SelectionController = Montage.create(Component, {
67 64
68 initWithDocument: { 65 initWithDocument: {
69 value: function(currentSelectionArray) { 66 value: function(currentSelectionArray) {
70 this._selectedItems = [];
71 this._isDocument = true; 67 this._isDocument = true;
72 68
73 if(currentSelectionArray) { 69 if(currentSelectionArray) {
74 if(currentSelectionArray.length >= 1) { 70 if(currentSelectionArray.length >= 1) {
75 this._selectedItems = currentSelectionArray;
76 this._isDocument = false; 71 this._isDocument = false;
77 72
78
79
80 this.application.ninja.selectedElements = currentSelectionArray; 73 this.application.ninja.selectedElements = currentSelectionArray;
81 NJevent("selectionChange", {"elements": this.application.ninja.selectedElements, "isDocument": this._isDocument}); 74 NJevent("selectionChange", {"elements": this.application.ninja.selectedElements, "isDocument": this._isDocument});
82
83
84
85 } 75 }
86 } 76 }
87 77
88 //
89 this._selectionContainer = this.application.ninja.currentSelectedContainer; 78 this._selectionContainer = this.application.ninja.currentSelectedContainer;
90
91 } 79 }
92 }, 80 },
93 81
94 handleSwitchDocument: { 82 handleSwitchDocument: {
95 value: function() { 83 value: function() {
96 if(this.application.ninja.documentController.activeDocument.currentView === "design"){ 84 if(this.application.ninja.documentController.activeDocument.currentView === "design"){
97 this._selectedItems = this.application.ninja.selectedElements.slice(0); 85 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} ); 86 NJevent("selectionChange", {"elements": this.application.ninja.selectedElements, "isDocument": this._isDocument} );
100 } 87 }
101 } 88 }
@@ -107,25 +94,22 @@ exports.SelectionController = Montage.create(Component, {
107 } 94 }
108 }, 95 },
109 96
110 handleElementDeleted: { 97 handleElementsRemoved: {
111 value: function(event) { 98 value: function(event) {
112 if(!this._isDocument) { 99 if(!this._isDocument) {
113 if(this.findSelectedElement(event.detail) !== -1) { 100 this.application.ninja.selectedElements = [];
114 this.executeSelectElement(); 101 this._isDocument = true;
115 var element = event.detail; 102 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 } 103 }
126 } 104 }
127 }, 105 },
128 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
129 handleSelectAll: { 113 handleSelectAll: {
130 value: function(event) { 114 value: function(event) {
131 var selected = [], childNodes = []; 115 var selected = [], childNodes = [];
@@ -142,23 +126,19 @@ exports.SelectionController = Montage.create(Component, {
142 } 126 }
143 }, 127 },
144 128
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 /** 129 /**
154 * 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.
155 */ 131 */
156 executeSelectElement: { 132 executeSelectElement: {
157 value: function(item) { 133 value: function(element) {
158 this.application.ninja.selectedElements = []; 134 this.application.ninja.selectedElements = [];
159 135
160 if(item) { 136 if(element) {
161 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 }
162 this._isDocument = false; 142 this._isDocument = false;
163 } else { 143 } else {
164 this._isDocument = true; 144 this._isDocument = true;
@@ -171,23 +151,20 @@ exports.SelectionController = Montage.create(Component, {
171 }, 151 },
172 152
173 selectElement: { 153 selectElement: {
174 value: function(item) { 154 value: function(element) {
175 155
176 if(this.findSelectedElement(item) === -1) { 156 if(this.findSelectedElement(element) === -1) {
177 157
178 if(this.application.ninja.currentDocument.inExclusion(item) !== -1){ 158 if(this.application.ninja.currentDocument.inExclusion(element) !== -1){
179 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.
180 this.executeSelectElement(); // Else execute selection with no item 160 this.executeSelectElement(); // Else execute selection with no element
181 } else { 161 } else {
182 162 if(element.parentNode.uuid === this.selectionContainer.uuid) {
183// if(item.parentNode.id === "UserContent") { 163 this.executeSelectElement(element);
184 if(item.parentNode.uuid === this.selectionContainer.uuid) {
185 this.executeSelectElement(item);
186 } else { 164 } else {
187 var outerElement = item.parentNode; 165 var outerElement = element.parentNode;
188 166
189 while(outerElement.parentNode && outerElement.parentNode.uuid !== this.selectionContainer.uuid) { 167 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 168 // If element is higher up than current container then return
192 if(outerElement.id === "UserContent") return; 169 if(outerElement.id === "UserContent") return;
193 // else keep going up the chain 170 // else keep going up the chain
@@ -202,13 +179,13 @@ exports.SelectionController = Montage.create(Component, {
202 }, 179 },
203 180
204 selectElements: { 181 selectElements: {
205 value: function(items) { 182 value: function(elements) {
206 if(items && items.length > 0) { 183 if(elements && elements.length > 0) {
207 var that = this; 184 var that = this;
208 this.application.ninja.selectedElements = []; 185 this.application.ninja.selectedElements = [];
209 186
210 items.forEach(function(item) { 187 elements.forEach(function(element) {
211 that.application.ninja.selectedElements.push({_element: item, uuid: item.uuid}); 188 that.application.ninja.selectedElements.push(element);
212 that._isDocument = false; 189 that._isDocument = false;
213 }); 190 });
214 191
@@ -218,22 +195,22 @@ exports.SelectionController = Montage.create(Component, {
218 }, 195 },
219 196
220 shiftSelectElement: { 197 shiftSelectElement: {
221 value: function(item) { 198 value: function(element) {
222 if(this.application.ninja.currentDocument.inExclusion(item) !== -1) return;