diff options
Diffstat (limited to 'js/panels/Materials/materials-library-panel.reel/materials-library-panel.js')
-rwxr-xr-x | js/panels/Materials/materials-library-panel.reel/materials-library-panel.js | 111 |
1 files changed, 101 insertions, 10 deletions
diff --git a/js/panels/Materials/materials-library-panel.reel/materials-library-panel.js b/js/panels/Materials/materials-library-panel.reel/materials-library-panel.js index cf0d4e93..8c1aa1dc 100755 --- a/js/panels/Materials/materials-library-panel.reel/materials-library-panel.js +++ b/js/panels/Materials/materials-library-panel.reel/materials-library-panel.js | |||
@@ -7,14 +7,36 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
7 | var Montage = require("montage/core/core").Montage, | 7 | var Montage = require("montage/core/core").Montage, |
8 | Component = require("montage/ui/component").Component, | 8 | Component = require("montage/ui/component").Component, |
9 | MaterialsData = require("js/panels/Materials/materials-data.json"), | 9 | MaterialsData = require("js/panels/Materials/materials-data.json"), |
10 | Popup = require("montage/ui/popup/popup.reel").Popup; | 10 | Popup = require("montage/ui/popup/popup.reel").Popup, |
11 | MaterialsModel = require("js/models/materials-model").MaterialsModel, | ||
12 | LeafNode = require("js/components/treeview/ninja-leaf.reel").Leaf; | ||
11 | 13 | ||
12 | exports.MaterialsLibraryPanel = Montage.create(Component, { | 14 | exports.MaterialsLibraryPanel = Montage.create(Component, { |
13 | 15 | ||
16 | deleteButton: { | ||
17 | value: null | ||
18 | }, | ||
19 | |||
14 | materialsData: { | 20 | materialsData: { |
15 | value: null | 21 | value: null |
16 | }, | 22 | }, |
17 | 23 | ||
24 | materialId: { | ||
25 | value: null | ||
26 | }, | ||
27 | |||
28 | selectedMaterialNode: { | ||
29 | value: null | ||
30 | }, | ||
31 | |||
32 | customMaterialsBranch: { | ||
33 | value: null | ||
34 | }, | ||
35 | |||
36 | customMaterialsCounter: { | ||
37 | value: 2 | ||
38 | }, | ||
39 | |||
18 | _hasFocus: { | 40 | _hasFocus: { |
19 | enumerable: false, | 41 | enumerable: false, |
20 | value: false | 42 | value: false |
@@ -36,21 +58,32 @@ exports.MaterialsLibraryPanel = Montage.create(Component, { | |||
36 | value:function(event) { | 58 | value:function(event) { |
37 | switch(event._currentTarget.label) | 59 | switch(event._currentTarget.label) |
38 | { | 60 | { |
39 | case "Add": | 61 | case "Duplicate": |
40 | console.log("Add new material"); | 62 | this.duplicateMaterial(); |
41 | break; | 63 | break; |
42 | case "Copy": | 64 | case "Edit": |
43 | console.log("Copy selected material"); | 65 | // console.log("Edit selected material"); |
66 | this._showMaterialPopup({ materialId: this.materialId }); | ||
44 | break; | 67 | break; |
45 | case "Delete": | 68 | case "Delete": |
46 | console.log("Delete selected material"); | 69 | this.deleteMaterial(); |
47 | break; | 70 | break; |
48 | } | 71 | } |
49 | } | 72 | } |
50 | }, | 73 | }, |
51 | 74 | ||
52 | handleNodeActivation: { | 75 | handleNodeActivation: { |
53 | value:function(obj) { | 76 | value: function(obj, event) { |
77 | this.selectedMaterialNode = event.currentTarget; | ||
78 | this.materialId = obj.id; | ||
79 | this.deleteButton.enabled = !!obj.canDelete; | ||
80 | } | ||
81 | }, | ||
82 | |||
83 | handleDblclick: { | ||
84 | value:function(obj, event) { | ||
85 | this.selectedMaterialNode = event.currentTarget; | ||
86 | this.materialId = obj.id; | ||
54 | this._showMaterialPopup({ materialId: obj.id }); | 87 | this._showMaterialPopup({ materialId: obj.id }); |
55 | } | 88 | } |
56 | }, | 89 | }, |
@@ -58,7 +91,6 @@ exports.MaterialsLibraryPanel = Montage.create(Component, { | |||
58 | handleShowMaterialPopup: { | 91 | handleShowMaterialPopup: { |
59 | enumerable: false, | 92 | enumerable: false, |
60 | value: function (event) { | 93 | value: function (event) { |
61 | //this._showMaterialPopup(event.detail.materialId); | ||
62 | this._showMaterialPopup(event.detail); | 94 | this._showMaterialPopup(event.detail); |
63 | } | 95 | } |
64 | }, | 96 | }, |
@@ -80,15 +112,16 @@ exports.MaterialsLibraryPanel = Montage.create(Component, { | |||
80 | if(!this._materialPopup) | 112 | if(!this._materialPopup) |
81 | { | 113 | { |
82 | this._materialPopup = Popup.create(); | 114 | this._materialPopup = Popup.create(); |
115 | this._materialInfo.materialsLibraryRef = this; | ||
83 | this._materialPopup.content = this._materialInfo; | 116 | this._materialPopup.content = this._materialInfo; |
117 | this._materialPopup.delegate = this; | ||
84 | this._materialPopup.modal = false; | 118 | this._materialPopup.modal = false; |
85 | this.eventManager.addEventListener("hideMaterialPopup", this, false); | 119 | this.eventManager.addEventListener("hideMaterialPopup", this, false); |
86 | this._materialPopup.addEventListener("show", this, false); | 120 | this._materialPopup.addEventListener("show", this, false); |
87 | } | 121 | } |
88 | this._materialPopup.show(); | 122 | this._materialPopup.show(); |
89 | 123 | ||
90 | materialID = materialObj.materialId; | 124 | this._materialInfo.loadMaterials(materialObj.materialId, materialObj.useSelection, materialObj.whichMaterial); |
91 | this._materialInfo.loadMaterials(materialID, materialObj.useSelection, materialObj.whichMaterial); | ||
92 | } | 125 | } |
93 | }, | 126 | }, |
94 | 127 | ||
@@ -96,8 +129,66 @@ exports.MaterialsLibraryPanel = Montage.create(Component, { | |||
96 | enumerable: false, | 129 | enumerable: false, |
97 | value: function (event) { | 130 | value: function (event) { |
98 | if(this._materialPopup){ | 131 | if(this._materialPopup){ |
132 | // console.log("hiding material popup"); | ||
133 | this._materialInfo.destroy(); | ||
99 | this._materialPopup.hide(); | 134 | this._materialPopup.hide(); |
100 | } | 135 | } |
101 | } | 136 | } |
137 | }, | ||
138 | |||
139 | duplicateMaterial: { | ||
140 | enumerable: false, | ||
141 | value: function (matCopyName) { | ||
142 | // console.log("Duplicate selected material"); | ||
143 | var mat = MaterialsModel.getMaterial(this.materialId); | ||
144 | if(mat) { | ||
145 | var matCopy = mat.dup(); | ||
146 | if(!matCopyName) { | ||
147 | matCopyName = this.materialId + "_" + this.customMaterialsCounter++; | ||
148 | } | ||
149 | matCopy.setName(matCopyName); | ||
150 | MaterialsModel.addMaterial(matCopy); | ||
151 | |||
152 | var leaf = LeafNode.create(); | ||
153 | leaf.id = matCopyName; | ||
154 | leaf.label = matCopyName; | ||
155 | leaf.treeNodeType = "leaf"; | ||
156 | leaf.canDelete = true; | ||
157 | if(!this.customMaterialsBranch) { | ||
158 | this.customMaterialsBranch = this.materialsController.branchControllers[2]; | ||
159 | } | ||
160 | this.customMaterialsBranch.content.push(leaf); | ||
161 | } | ||
162 | } | ||
163 | }, | ||
164 | |||
165 | deleteMaterial: { | ||
166 | enumerable: false, | ||
167 | value: function () { | ||
168 | // console.log("Delete selected material"); | ||
169 | if(!this.customMaterialsBranch) { | ||
170 | this.customMaterialsBranch = this.materialsController.branchControllers[2]; | ||
171 | } | ||
172 | |||
173 | var mat = MaterialsModel.getMaterial(this.materialId); | ||
174 | if(mat) { | ||
175 | MaterialsModel.removeMaterial(this.materialId); | ||
176 | |||
177 | var index = this.customMaterialsBranch.selectedIndexes[0]; | ||
178 | this.customMaterialsBranch.content.splice(index, 1); | ||
179 | } | ||
180 | |||
181 | this.deleteButton.enabled = false; | ||
182 | } | ||
183 | }, | ||
184 | |||
185 | willPositionPopup: { | ||
186 | value: function(popup, defaultPosition) { | ||
187 | var content = popup.content.element, | ||
188 | contentHt = parseFloat(content.style.height) || content.offsetHeight || 0, | ||
189 | contentWd = parseFloat(content.style.width) || content.offsetWidth || 0, | ||
190 | pt = webkitConvertPointFromNodeToPage(this.selectedMaterialNode, new WebKitPoint(0, 0)); | ||
191 | return {top: pt.y - contentHt + 10, left: pt.x - contentWd + 10}; | ||
192 | } | ||
102 | } | 193 | } |
103 | }); \ No newline at end of file |