diff options
author | Valerio Virgillito | 2012-07-18 16:24:45 -0700 |
---|---|---|
committer | Valerio Virgillito | 2012-07-18 16:24:45 -0700 |
commit | f79f7c540d8533eed8fc562b809e15dcfea94438 (patch) | |
tree | 955b0d51fb163fb0a5165a6e16bf503de4cda712 /js/ui/menu/menu-controller.js | |
parent | 71650434d5b78c2b86dc8a689d0c9034d418f38b (diff) | |
parent | 6f2e455a77179f81dfd19037c078c158d3e14ee2 (diff) | |
download | ninja-f79f7c540d8533eed8fc562b809e15dcfea94438.tar.gz |
Merge branch 'menu-fixes' of https://github.com/mencio/ninja
Diffstat (limited to 'js/ui/menu/menu-controller.js')
-rw-r--r-- | js/ui/menu/menu-controller.js | 636 |
1 files changed, 636 insertions, 0 deletions
diff --git a/js/ui/menu/menu-controller.js b/js/ui/menu/menu-controller.js new file mode 100644 index 00000000..c80745f4 --- /dev/null +++ b/js/ui/menu/menu-controller.js | |||
@@ -0,0 +1,636 @@ | |||
1 | /* <copyright> | ||
2 | Copyright (c) 2012, Motorola Mobility LLC. | ||
3 | All Rights Reserved. | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without | ||
6 | modification, are permitted provided that the following conditions are met: | ||
7 | |||
8 | * Redistributions of source code must retain the above copyright notice, | ||
9 | this list of conditions and the following disclaimer. | ||
10 | |||
11 | * Redistributions in binary form must reproduce the above copyright notice, | ||
12 | this list of conditions and the following disclaimer in the documentation | ||
13 | and/or other materials provided with the distribution. | ||
14 | |||
15 | * Neither the name of Motorola Mobility LLC nor the names of its | ||
16 | contributors may be used to endorse or promote products derived from this | ||
17 | software without specific prior written permission. | ||
18 | |||
19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
29 | POSSIBILITY OF SUCH DAMAGE. | ||
30 | </copyright> */ | ||
31 | |||
32 | var Montage = require("montage/core/core").Montage, | ||
33 | Component = require("montage/ui/component").Component; | ||
34 | |||
35 | exports.MenuController = Montage.create(Component, { | ||
36 | |||
37 | _currentDocument: { | ||
38 | value : null | ||
39 | }, | ||
40 | |||
41 | currentDocument : { | ||
42 | get : function() { | ||
43 | return this._currentDocument; | ||
44 | }, | ||
45 | set : function(value) { | ||
46 | if (value === this._currentDocument) { | ||
47 | return; | ||
48 | } | ||
49 | |||
50 | if(this._currentDocument && this._currentDocument.currentView === "design") { | ||
51 | this._currentDocument.model.draw3DGrid = document.application.model.show3dGrid; | ||
52 | } | ||
53 | |||
54 | this._currentDocument = value; | ||
55 | |||
56 | if(this._currentDocument && this._currentDocument.currentView === "design") { | ||
57 | document.application.model.show3dGrid = this._currentDocument.model.draw3DGrid; | ||
58 | this.topLevelMenu[2].entries[5].checked = this._currentDocument.model.draw3DGrid; | ||
59 | } | ||
60 | |||
61 | if(!this._currentDocument) { | ||
62 | // No document - disable all menu items | ||
63 | this.documentEnabledItems.forEach(function(index) { | ||
64 | index.enabled = false; | ||
65 | }); | ||
66 | this.designDocumentEnabledItems.forEach(function(index) { | ||
67 | index.enabled = false; | ||
68 | }); | ||
69 | } else { | ||
70 | this.documentEnabledItems.forEach(function(index) { | ||
71 | index.enabled = true; | ||
72 | }); | ||
73 | |||
74 | if(this.currentDocument.currentView === "design") { | ||
75 | this.designDocumentEnabledItems.forEach(function(index) { | ||
76 | index.enabled = true; | ||
77 | }); | ||
78 | } else { | ||
79 | this.designDocumentEnabledItems.forEach(function(index) { | ||
80 | index.enabled = false; | ||
81 | }); | ||
82 | } | ||
83 | } | ||
84 | |||
85 | } | ||
86 | }, | ||
87 | |||
88 | didCreate: { | ||
89 | value: function() { | ||
90 | var self = this; | ||
91 | |||
92 | this.topLevelMenu.forEach(function(item) { | ||
93 | item.entries.forEach(function(entry) { | ||
94 | if(entry.depend) { | ||
95 | if(entry.depend === "document") { | ||
96 | self.documentEnabledItems.push(entry); | ||
97 | } else if(entry.depend === "designDocument") { | ||
98 | self.designDocumentEnabledItems.push(entry); | ||
99 | } | ||
100 | } | ||
101 | }); | ||
102 | }); | ||
103 | } | ||
104 | }, | ||
105 | |||
106 | documentEnabledItems: { | ||
107 | value: [] | ||
108 | }, | ||
109 | |||
110 | designDocumentEnabledItems: { | ||
111 | value: [] | ||
112 | }, | ||
113 | |||
114 | toggleItem: { | ||
115 | value: function(value) { | ||
116 | this['handle' + value.substr(0, value.indexOf("-"))](value.slice(value.indexOf("-") + 1)); | ||
117 | } | ||
118 | }, | ||
119 | |||
120 | |||
121 | handlelayout: { | ||
122 | value: function(value) { | ||
123 | this.topLevelMenu[2].entries[2].entries.forEach(function(entry) { | ||
124 | if(entry.boundProperty === value && !entry.checked){ | ||
125 | entry.checked = true; | ||
126 | document.application.model.layoutView = value; | ||
127 | } else if(entry.boundProperty !== value && entry.checked) { | ||
128 | entry.checked = false; | ||
129 | } | ||
130 | }); | ||
131 | } | ||
132 | }, | ||
133 | |||
134 | handlesnap: { | ||
135 | value: function(value) { | ||
136 | if(value === "onoff") { | ||
137 | this.topLevelMenu[2].entries[3].checked = !this.topLevelMenu[2].entries[3].checked; | ||
138 | this.topLevelMenu[2].entries[4].enabled = this.topLevelMenu[2].entries[3].checked; | ||
139 | document.application.model.snap = value; | ||
140 | } else { | ||
141 | this.topLevelMenu[2].entries[4].entries.forEach(function(entry) { | ||
142 | if(entry.boundProperty === value) { | ||
143 | entry.checked = !entry.checked; | ||
144 | document.application.model[entry.boundProperty] = entry.checked; | ||
145 | } | ||
146 | }); | ||
147 | } | ||
148 | } | ||
149 | }, | ||
150 | |||
151 | handlegrid: { | ||
152 | value: function(value) { | ||
153 | this.topLevelMenu[2].entries[5].checked = !this.topLevelMenu[2].entries[5].checked; | ||
154 | document.application.model.show3dGrid = this.topLevelMenu[2].entries[5].checked; | ||
155 | } | ||
156 | }, | ||
157 | |||
158 | handleview: { | ||
159 | value: function(value) { | ||
160 | if(this.topLevelMenu[2].entries[7].boundProperty === value) { | ||
161 | if(!this.topLevelMenu[2].entries[7].checked) { | ||
162 | this.topLevelMenu[2].entries[7].checked = true; | ||
163 | this.topLevelMenu[2].entries[8].checked = false; | ||
164 | this.topLevelMenu[2].entries[9].checked = false; | ||
165 | document.application.model.documentStageView = value; | ||
166 | } | ||
167 | } else if(this.topLevelMenu[2].entries[8].boundProperty === value) { | ||
168 | if(!this.topLevelMenu[2].entries[8].checked) { | ||
169 | this.topLevelMenu[2].entries[7].checked = false; | ||
170 | this.topLevelMenu[2].entries[8].checked = true; | ||
171 | this.topLevelMenu[2].entries[9].checked = false; | ||
172 | document.application.model.documentStageView = value; | ||
173 | } | ||
174 | } else { | ||
175 | if(!this.topLevelMenu[2].entries[9].checked) { | ||
176 | this.topLevelMenu[2].entries[7].checked = false; | ||
177 | this.topLevelMenu[2].entries[8].checked = false; | ||
178 | this.topLevelMenu[2].entries[9].checked = true; | ||
179 | document.application.model.documentStageView = value; | ||
180 | } | ||
181 | } | ||
182 | } | ||
183 | }, | ||
184 | |||
185 | topLevelMenu: { | ||
186 | value: [ | ||
187 | { | ||
188 | "label": "File", | ||
189 | "entries": [ | ||
190 | { | ||
191 | "label" : "New Project", | ||
192 | "checked": false, | ||
193 | "submenu" : false, | ||
194 | "entries": [], | ||
195 | "enabled": false, | ||
196 | "action": "executeNewProject" | ||
197 | }, | ||
198 | { | ||
199 | "label" : "New File", | ||
200 | "checked": false, | ||
201 | "submenu" : false, | ||
202 | "entries": [], | ||
203 | "enabled": true, | ||
204 | "action": "executeNewFile" | ||
205 | }, | ||
206 | { | ||
207 | "label" : "Open File", | ||
208 | "checked": false, | ||
209 | "submenu" : false, | ||
210 | "entries": [], | ||
211 | "enabled": true, | ||
212 | "action": "executeFileOpen" | ||
213 | }, | ||
214 | { | ||
215 | "label" : "Close File", | ||
216 | "checked": false, | ||
217 | "submenu" : false, | ||
218 | "entries": [], | ||
219 | "enabled": false, | ||
220 | "depend": "document", | ||
221 | "action": "executeFileClose" | ||
222 | }, | ||
223 | { | ||
224 | "label" : "Close All", | ||
225 | "checked": false, | ||
226 | "submenu" : false, | ||
227 | "entries": [], | ||
228 | "enabled": false, | ||
229 | "depend": "document", | ||