Mercurial > MadButterfly
annotate inkscape/firefox/content/inkscape.js @ 377:06b40e01cac4
merge
author | wycc |
---|---|
date | Sat, 04 Apr 2009 06:12:42 +0800 |
parents | 7d244a85dd68 |
children | 29145d2affdb |
rev | line source |
---|---|
288 | 1 var isInProgress=0; |
2 | |
3 var MAX_DUMP_DEPTH = 10; | |
4 var inkscape; | |
5 | |
362 | 6 |
7 function endsWith(str, s){ | |
8 var reg = new RegExp (s + "$"); | |
9 return reg.test(str); | |
10 } | |
288 | 11 |
12 function dumpObj(obj, name, indent, depth) { | |
13 if (depth > MAX_DUMP_DEPTH) { | |
14 return indent + name + ": <Maximum Depth Reached>\n"; | |
15 } | |
16 if (typeof obj == "object") { | |
17 var child = null; | |
18 var output = indent + name + "\n"; | |
19 indent += "\t"; | |
20 for (var item in obj) | |
21 { | |
22 try { | |
23 child = obj[item]; | |
24 } catch (e) { | |
25 child = "<Unable to Evaluate>"; | |
26 } | |
27 if (typeof child == "object") { | |
28 output += dumpObj(child, item, indent, depth + 1); | |
29 } else { | |
30 output += indent + item + ": " + child + "\n"; | |
31 } | |
32 } | |
33 return output; | |
34 } else { | |
35 return obj; | |
36 } | |
37 } | |
38 function dumpObjItem(obj, name, indent, depth) { | |
39 if (depth > MAX_DUMP_DEPTH) { | |
40 return indent + name + ": <Maximum Depth Reached>\n"; | |
41 } | |
42 if (typeof obj == "object") { | |
43 var child = null; | |
44 var output = indent + name + "\n"; | |
45 indent += "\t"; | |
46 for (var item in obj) | |
47 { | |
48 try { | |
49 child = obj[item]; | |
50 } catch (e) { | |
51 child = "<Unable to Evaluate>"; | |
52 } | |
53 if (typeof child == "object") { | |
54 output += dumpObjItem(child, item, indent, depth + 1); | |
55 } else { | |
56 output += indent + item + ":\n"; | |
57 } | |
58 } | |
59 return output; | |
60 } else { | |
61 return obj; | |
62 } | |
63 } | |
361
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
64 |
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
65 /** |
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
66 * TextEditor class |
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
67 * |
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
68 */ |
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
69 |
362 | 70 function TextEditor(file) |
361
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
71 { |
362 | 72 var editor = document.getElementById('inkscape'); |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
73 editor.innerHTML = "<embed src="+file+" width=900 height=700 />"; |
361
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
74 this.isInProgress = 0; |
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
75 } |
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
76 |
288 | 77 /** |
78 * Inkscape class | |
79 * | |
80 */ | |
81 function Inkscape(file) | |
82 { | |
83 var ink = document.getElementById('inkscape'); | |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
84 ink.innerHTML = "<embed src="+file+" width=900 height=700 />"; |
288 | 85 this.isInProgress = 0; |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
86 this.callback = null; |
288 | 87 |
88 setTimeout("inkscape.fetchDocument()",4000); | |
89 } | |
90 | |
91 Inkscape.prototype.gotoScene = function (n) | |
92 { | |
93 nextScene = n; | |
94 var soapBody = new SOAPObject("START"); | |
95 var sr = new SOAPRequest("START", soapBody); | |
96 SOAPClient.Proxy = "http://localhost:19192/"; | |
97 SOAPClient.SendRequest(sr, function (resp,arg) {arg.gotoScene1(resp);},this); | |
98 this.isInProgress++; | |
99 } | |
100 Inkscape.prototype.gotoScene1 = function (resp,n) | |
101 { | |
102 var soapBody = new SOAPObject("SCENE"); | |
103 var v1 = new SOAPObject("v1"); | |
104 v1.val(nextScene); | |
105 soapBody.appendChild(v1); | |
106 var sr = new SOAPRequest("SCENE", soapBody); | |
107 SOAPClient.Proxy = "http://localhost:19192/"; | |
108 SOAPClient.SendRequest(sr, function (resp,arg) {arg.gotoScene2(resp);},this); | |
109 } | |
110 Inkscape.prototype.gotoScene2 = function (resp) | |
111 { | |
112 var soapBody = new SOAPObject("PUBLISH"); | |
113 var sr = new SOAPRequest("PUBLISH", soapBody); | |
114 SOAPClient.Proxy = "http://localhost:19192/"; | |
115 SOAPClient.SendRequest(sr, function (resp,arg) {arg.gotoScene3(resp);},this); | |
116 } | |
117 | |
118 Inkscape.prototype.gotoScene3 = function (resp) | |
119 { | |
120 this.isInProgress--; | |
121 } | |
122 Inkscape.prototype.publishDocument= function(resp) | |
123 { | |
124 mbsvg = new MBSVGString(resp.Body[0].GETDOCResponse[0].Result[0].Text); | |
125 mbsvg.renderUI(); | |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
126 if (this.callback) |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
127 this.callback(mbsvg); |
288 | 128 |
129 var soapBody = new SOAPObject("PUBLISH"); | |
130 var sr = new SOAPRequest("PUBLISH", soapBody); | |
131 SOAPClient.Proxy = "http://localhost:19192/"; | |
132 SOAPClient.SendRequest(sr, function(resp,arg) {arg.operationDone(resp);},this); | |
133 } | |
134 | |
135 Inkscape.prototype.refreshDocument = function(resp) | |
136 { | |
137 var soapBody = new SOAPObject("GETDOC"); | |
138 var sr = new SOAPRequest("GETDOC", soapBody); | |
139 SOAPClient.Proxy = "http://localhost:19192/"; | |
140 SOAPClient.SendRequest(sr, function(resp,arg) { arg.publishDocument(resp);},this); | |
141 } | |
142 | |
143 Inkscape.prototype.operationDone = function (res) | |
144 { | |
145 this.isInProgress--; | |
146 } | |
147 Inkscape.prototype.insertKey= function(n) | |
148 { | |
149 nextScene = n; | |
150 var soapBody = new SOAPObject("START"); | |
151 var sr = new SOAPRequest("START", soapBody); | |
152 SOAPClient.Proxy = "http://localhost:19192/"; | |
153 SOAPClient.SendRequest(sr, function (resp,arg) {arg.insertKey1(resp);},this); | |
154 this.isInProgress++; | |
155 } | |
156 Inkscape.prototype.insertKey1 = function(resp) | |
157 { | |
158 var soapBody = new SOAPObject("INSERTKEY"); | |
159 var v1 = new SOAPObject("v1"); | |
160 v1.attr('type','string'); | |
161 v1.val(currentLayer); | |
162 soapBody.appendChild(v1); | |
163 var v2 = new SOAPObject("v2"); | |
164 v2.val(nextScene); | |
165 soapBody.appendChild(v2); | |
166 var sr = new SOAPRequest("INSERTKEY", soapBody); | |
167 SOAPClient.Proxy = "http://localhost:19192/"; | |
168 SOAPClient.SendRequest(sr, function (resp,arg) {arg.refreshDocument(resp);},this); | |
169 } | |
170 | |
171 Inkscape.prototype.extendScene=function() | |
172 { | |
173 var soapBody = new SOAPObject("START"); | |
174 var sr = new SOAPRequest("START", soapBody); | |
175 SOAPClient.Proxy = "http://localhost:19192/"; | |
176 SOAPClient.SendRequest(sr, function (resp,arg) {arg.extendScene1(resp);},this); | |
177 this.isInProgress++; | |
178 } | |
179 | |
180 | |
181 Inkscape.prototype.extendScene1 = function(resp) | |
182 { | |
183 var soapBody = new SOAPObject("EXTENDSCENE"); | |
184 var v1 = new SOAPObject("v1"); | |
185 v1.attr('type','string'); | |
186 v1.val(currentLayer); | |
187 soapBody.appendChild(v1); | |
188 var v2 = new SOAPObject("v2"); | |
189 v2.val(currentScene); | |
190 soapBody.appendChild(v2); | |
191 var sr = new SOAPRequest("EXTENDSCENE", soapBody); | |
192 SOAPClient.Proxy = "http://localhost:19192/"; | |
193 SOAPClient.SendRequest(sr, function (resp,arg) {arg.refreshDocument(resp);},this); | |
194 } | |
195 | |
196 | |
197 Inkscape.prototype.deleteScene=function() | |
198 { | |
199 var soapBody = new SOAPObject("START"); | |
200 var sr = new SOAPRequest("START", soapBody); | |
201 SOAPClient.Proxy = "http://localhost:19192/"; | |
202 SOAPClient.SendRequest(sr, function (resp,arg) {arg.deleteScene1(resp);},this); | |
203 this.isInProgress++; | |
204 } | |
205 | |
206 Inkscape.prototype.deleteScene1=function(resp) | |
207 { | |
208 var soapBody = new SOAPObject("DELETESCENE"); | |
209 var v1 = new SOAPObject("v1"); | |
210 v1.attr('type','string'); | |
211 v1.val(currentLayer); | |
212 soapBody.appendChild(v1); | |
213 var v2 = new SOAPObject("v2"); | |
214 v2.val(currentScene); | |
215 soapBody.appendChild(v2); | |
216 var sr = new SOAPRequest("EXTENDSCENE", soapBody); | |
217 SOAPClient.Proxy = "http://localhost:19192/"; | |
218 SOAPClient.SendRequest(sr, function (resp,arg) {arg.refreshDocument(resp);},this); | |
219 } | |
220 | |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
221 Inkscape.prototype.fetchDocument = function(callback) |
288 | 222 { |
223 var soapBody = new SOAPObject("START"); | |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
224 this.callback = callback |
288 | 225 var sr = new SOAPRequest("START", soapBody); |
226 SOAPClient.Proxy = "http://localhost:19192/"; | |
227 SOAPClient.SendRequest(sr,function(resp,arg) {arg.refreshDocument(resp);},this); | |
228 this.isInProgress++; | |
229 } | |
230 | |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
231 /* |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
232 * This module is used to define a symbol for the MadButterfly. This function will search for symbol which is defined in the current select object. We will list all SVG elements |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
233 * in the left side, multiple variables can be defined at one time. When any element is selected, the defined symbol will be listed in the right side. |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
234 * |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
235 */ |
288 | 236 |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
237 Inkscape.prototype.MakeSymbol=function() |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
238 { |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
239 function callback(mbsvg) { |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
240 this.loadSymbolScreen(mbsvg); |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
241 } |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
242 inkscape.fetchDocument(callback); |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
243 } |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
244 |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
245 Inkscape.prototype.loadSymbolScreen=function (mbsvg) { |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
246 // Swap the left side to be the SVG element tree. |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
247 var i,l; |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
248 |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
249 symboldialog.dialog('open'); |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
250 l = mbsvg.selected_objects.length; |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
251 var jsonobj = [] |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
252 for(i=0;i<l;i++) { |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
253 // Add symbol into the tree |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
254 var obj = { attributes: {id: 'sym'+i}, data : mbsvg.selected_objects[i]}; |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
255 jsonobj.push(obj); |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
256 } |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
257 this.symboltree = $.tree_create(); |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
258 this.symboltree.init($("#symbollist"), { |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
259 data: { |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
260 type: "json", |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
261 json : jsonobj |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
262 }, |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
263 callback : { |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
264 ondblclk : function(NODE,TREE_OBJ) { this.refreshSymbolPanel(TREE_OBJ); TREE_OBJ.toggle_branch.call(TREE_OBJ, NODE); TREE_OBJ.select_branch.call(TREE_OBJ, NODE);} |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
265 } |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
266 |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
267 }); |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
268 // Swap the right side to be the symbol editor screen. |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
269 symboldialog.show(); |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
270 } |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
271 |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
272 jQuery(document).ready(function() { |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
273 symboldialog = jQuery('#symboldialog'); |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
274 symboldialog.dialog({width:500, |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
275 modal: true, |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
276 autoOpen:false, |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
277 title:'Please select a file'}); |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
278 symboldialog.hide(); |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
279 symboldialog.append("<div id='symbollist'>"); |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
280 symboldialog.append("<div id='symbol'>"); |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
281 }); |
288 | 282 |
283 function MBSVG(file) | |
284 { | |
285 var xmlDoc=document.implementation.createDocument("http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd","",null); | |
286 xmlDoc.async=false; | |
287 xmlDoc.load(file); | |
288 MBSVG_loadFromDoc(this,xmlDoc); | |
289 | |
290 } | |
291 function MBSVGString(xml) | |
292 { | |
293 var xmlParser = new DOMParser(); | |
294 var xmlDoc = xmlParser.parseFromString( xml, 'text/xml'); | |
295 MBSVG_loadFromDoc(this,xmlDoc); | |
296 } | |
297 | |
298 | |
299 | |
300 function MBSVG_loadFromDoc(self,xmlDoc) | |
301 { | |
302 var scenesNode = xmlDoc.getElementsByTagNameNS("http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd","scene"); | |
303 if (scenesNode == null) { | |
304 alert('This is not a valid scene file'); | |
305 } | |
306 var len = scenesNode.length; | |
307 var i,j; | |
308 var max = 0; | |
309 var scenes = new Array(); | |
310 | |
311 // Get the length of scenes | |
312 for(i=0;i<len;i++) { | |
313 var s = scenesNode[i]; | |
314 var start = s.getAttribute("start"); | |
315 var end = s.getAttribute("end"); | |
316 var ref = s.getAttribute("ref"); | |
317 var ss = new Object(); | |
318 | |
319 if (end == null) end = start | |
320 if (max <end) max = end; | |
321 ss.node = s; | |
322 ss.start = start; | |
323 ss.end = end; | |
324 ss.ref = ref; | |
325 ss.layer = null; | |
326 scenes.push(ss); | |
327 } | |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
328 if (max < 20) max = 30; |
288 | 329 // Collect all layers |
330 var nodes = xmlDoc.getElementsByTagNameNS("http://www.w3.org/2000/svg","svg")[0].childNodes; | |
331 var layers = new Array(); | |
332 len = nodes.length; | |
333 for(i=0;i<len;i++) { | |
334 if (nodes[i].localName == 'g') { | |
335 var subnodes = nodes[i].childNodes; | |
336 for(j=0;j<subnodes.length;j++) { | |
337 if (subnodes[j].localName == 'g') { | |
338 for(var k=0;k<scenes.length;k++) { | |
339 if (scenes[k].ref == subnodes[j].getAttribute('id')) { | |
340 scenes[k].layer = nodes[i].getAttribute('id'); | |
341 break; | |
342 } | |
343 } | |
344 } | |
345 } | |
346 layers.push(nodes[i]); | |
347 } | |
348 } | |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
349 var select = xmlDoc.getElementsByTagNameNS("http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd","select"); |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
350 len = select.length; |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
351 selectobjs = []; |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
352 for(i=0;i<len;i++) { |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
353 selectobjs.push(select[i].getAttribute('ref')); |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
354 } |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
355 self.selected_objects = selectobjs; |
288 | 356 self.layers = layers; |
357 self.scenes = scenes; | |
358 self.maxframe = max; | |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
359 self.doc = xmlDoc; |
288 | 360 } |
361 | |
362 MBSVGString.prototype=MBSVG.prototype; | |
363 MBSVG.prototype.renderUI=function() | |
364 { | |
365 var layers = this.layers; | |
366 var scenes = this.scenes; | |
367 var max = this.maxframe; | |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
368 var cmd = "<table border=0>\n"; |
288 | 369 cmd = cmd + "<tr><td></td>"; |
370 for(var j=1;j<=max;j++) | |
371 cmd = cmd + "<td>"+j+"</td>"; | |
372 | |
373 for(var i=layers.length-1;i>=0;i--) { | |
374 var l = layers[i]; | |
375 var id = l.getAttribute('id'); | |
376 var label = l.getAttribute('inkscape:label'); | |
377 cmd = cmd + "<tr><td>"+label+"</td>"; | |
378 for(j=0;j<max;j++) { | |
379 var empty = 1; | |
380 var n = j +1; | |
381 var id_str = id+"#"+n | |
382 for(var k=0;k<scenes.length;k++) { | |
383 if (id != scenes[k].layer) continue; | |
384 if (n == scenes[k].start) { | |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
385 cmd = cmd + "<td><img class='normal' width='16' src=start.png id='"+id_str+"' onClick='selectCell(this)' /></td>"; |
288 | 386 empty = 0; |
387 break; | |
388 } else if ((n>scenes[k].start)&&(n <= scenes[k].end)) { | |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
389 cmd = cmd + "<td><img class='normal' width='16' src=fill.png id='"+id_str+"' onClick='selectCell(this)' /></td>"; |
288 | 390 empty = 0; |
391 break; | |
392 } | |
393 } | |
394 if (empty) { | |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
395 cmd = cmd + "<td><img class='normal' width='16' src=empty.png id='"+id_str+"'onClick='selectCell(this)' /></td>"; |
288 | 396 } |
397 | |
398 } | |
399 cmd = cmd + "</tr>\n"; | |
400 } | |
401 cmd = cmd + "</table>\n"; | |
402 var frame = document.getElementById('frame'); | |
403 frame.innerHTML=cmd; | |
404 } | |
405 | |
406 | |
407 | |
408 /** | |
409 * UI for madbuilder.html to build the scene editor | |
410 */ | |
411 | |
412 function selectCell(obj) | |
413 { | |
414 var id = obj.getAttribute('id'); | |
415 var layer,n; | |
416 var f = id.split('#'); | |
417 layer=f[0]; | |
418 n = f[1]; | |
419 var img = obj.getAttribute('src'); | |
420 var f = img.split('-'); | |
421 | |
422 if (f[0] == 'active') | |
423 return; | |
424 else { | |
425 obj.setAttribute('src', 'active-'+img); | |
426 } | |
427 | |
428 if (last_select != null) { | |
429 f = last_select.getAttribute('src').split('-'); | |
430 last_select.setAttribute('src', f[1]); | |
431 } | |
432 last_select = obj; | |
433 currentScene = n; | |
434 currentLayer = layer; | |
435 } | |
436 | |
437 | |
438 function onButtonClick(obj) | |
439 { | |
440 var id = obj.getAttribute('id'); | |
441 if (id == 'Jump') { | |
365
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
442 if (inkscape.isInProgress != 0) return; |
288 | 443 if (currentScene != 0) |
444 inkscape.gotoScene(currentScene); | |
445 } else if (id == 'InsertKey') { | |
365
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
446 if (inkscape.isInProgress != 0) return; |
288 | 447 inkscape.insertKey(currentScene); |
448 } else if (id == 'ExtendScene') { | |
365
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
449 if (inkscape.isInProgress != 0) return; |
288 | 450 inkscape.extendScene(currentScene); |
451 } else if (id == 'DeleteScene') { | |
365
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
452 if (inkscape.isInProgress != 0) return; |
288 | 453 inkscape.deleteScene(currentScene); |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
454 } else if (id == 'MakeSymbol') { |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
455 if (inkscape.isInProgress != 0) return; |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
456 inkscape.MakeSymbol(); |
365
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
457 } else if (id == 'Save') { |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
458 project_save(); |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
459 } else if (id == 'Test') { |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
460 if (project_compile()) { |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
461 project_run(); |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
462 } else { |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
463 } |
288 | 464 } else { |
465 alert(id+' has not been implemented yet'); | |
466 } | |
467 } | |
468 | |
469 function gotoScene_cb(resObj) | |
470 { | |
471 | |
472 } | |
473 var nextScene; | |
474 var currentScene = 0; | |
475 var currentLayer = ''; | |
476 | |
357 | 477 |
478 function dump(n) | |
479 { | |
480 cmd = ""; | |
481 for(k in n) { | |
482 cmd = cmd + k+"="+n[k]+"\n"; | |
483 } | |
484 alert(cmd); | |
485 } | |
288 | 486 |
487 | |
358 | 488 |
357 | 489 |
490 | |
491 | |
358 | 492 function loadInkscapeFile() |
357 | 493 { |
494 ele = $('#mbsvg'); | |
495 file = ele.attr('value'); | |
496 inkscape = new Inkscape("file://"+file); | |
497 | |
352 | 498 file1_animation = [ |
499 { | |
500 attributes: {id:"an1-1"}, | |
501 data: "animation1" | |
502 }, | |
503 { | |
504 attributes: {id:"an1-2"}, | |
505 data: "animation2" | |
506 } | |
507 ]; | |
508 file1 = { | |
509 attributes:{id:"file1"}, | |
510 data: "scene1.mbsvg", | |
511 children: file1_animation | |
512 }; | |
513 file2 = { | |
514 attributes:{id:"file2"}, | |
515 data: "scene2.mbsvg", | |
516 }; | |
517 file3 = { | |
518 attributes:{id:"file3"}, | |
519 data: "scene3.mbsvg", | |
520 }; | |
521 | |
522 scenes = [ file1,file2,file3]; | |
523 src1 = {attributes:{id:"src1"},data:"src1.c"}; | |
524 src2 = {attributes:{id:"src1"},data:"src2.c"}; | |
525 src3 = {attributes:{id:"src1"},data:"src3.c"}; | |
526 | |
527 sources = [src1,src2,src3]; | |
528 | |
358 | 529 } |
530 | |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
531 function project_compile() |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
532 { |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
533 } |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
534 |
358 | 535 |
362 | 536 function project_showFile(node) |
537 { | |
538 var file = node.textContent; | |
539 if (endsWith(file,"mbsvg")) { | |
540 project_loadScene(node); | |
541 } else { | |
542 project_loadEditor(node); | |
543 } | |
544 | |
545 } | |
359 | 546 function project_loadScene(node) |
547 { | |
548 var file = node.textContent; | |
371 | 549 if (file.substr(0,1) == '/') |
550 inkscape = new Inkscape("file://"+file); | |
551 else | |
552 inkscape = new Inkscape("file://"+project_dir+'/'+file); | |
361
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
553 } |
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
554 |
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
555 |
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
556 function project_loadEditor(node) |
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
557 { |
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
558 var file = node.textContent; |
371 | 559 if (file.substr(0,1) == '/') |
560 editor = new TextEditor("file://"+file); | |
561 else | |
562 editor = new TextEditor("file://"+project_dir+'/'+file); | |
359 | 563 } |
564 | |
358 | 565 function project_parse(xml) |
566 { | |
567 | |
568 var xmlParser = new DOMParser(); | |
569 var xmlDoc = xmlParser.parseFromString( xml, 'text/xml'); | |
570 var scenesNode = xmlDoc.getElementsByTagName("scene"); | |
571 if (scenesNode == null) { | |
572 alert('This is not a valid scene file'); | |
573 } | |
574 var len = scenesNode.length; | |
575 var i,j; | |
576 var max = 0; | |
577 var scenes = new Array(); | |
578 | |
579 // Get the length of scenes | |
580 for(i=0;i<len;i++) { | |
581 var n = scenesNode[i]; | |
582 var s = new Object(); | |
583 s.attributes = new Object(); | |
584 s.attributes.id = "scene"+i; | |
585 s.state = "open"; | |
586 s.data = n.getAttribute("src"); | |
587 scenes.push(s); | |
588 } | |
589 | |
590 var nodes = xmlDoc.getElementsByTagName("source"); | |
591 var len = nodes.length; | |
592 var i,j; | |
593 var max = 0; | |
594 var sources = []; | |
595 | |
596 // Get the length of scenes | |
597 for(i=0;i<len;i++) { | |
598 var n = nodes[i]; | |
599 var s = new Object(); | |
600 s.attributes = new Object(); | |
601 s.attributes.id = "sources"+i; | |
602 s.state = "open"; | |
603 s.data = n.getAttribute("src"); | |
604 sources.push(s); | |
605 } | |
606 | |
607 var tree = $.tree_create(); | |
365
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
608 project_tree = tree; |
358 | 609 tree.init($("#filelist"), { |
610 data: { | |
611 type: "json", | |
612 json : [ | |
613 { | |
614 attributes: {id: "prj"}, | |
615 state: "open", | |
616 data: "Project", | |
617 children: [ | |
618 { attributes:{id:"scenes"}, data:"scene", children: scenes}, | |
619 { attributes:{id:"sources"},data:"sources",children: sources} | |
620 ] | |
621 } | |
622 ], | |
623 }, | |
359 | 624 callback : { |
362 | 625 ondblclk : function(NODE,TREE_OBJ) { project_showFile(NODE); TREE_OBJ.toggle_branch.call(TREE_OBJ, NODE); TREE_OBJ.select_branch.call(TREE_OBJ, NODE);} |
359 | 626 }, |
358 | 627 ui : { |
357 | 628 context : [ |
629 { | |
630 id: "Open", | |
631 label: "Open", | |
632 icon: "open.png", | |
364
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
633 visible: function(NODE,TREE_OBJ) { if(NODE.length != 1) return false; return true;}, |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
634 action: function(NODE,TREE_OBJ) { onTree_openFile(NODE,TREE_OBJ);} |
357 | 635 }, |
636 { | |
637 id: "New", | |
638 label: "New", | |
639 icon: "create.png", | |
640 visible: function(NODE,TREE_OBJ) { if(NODE.length != 1) return false; return NODE[0].id == "prj";}, | |
641 action: function(NODE,TREE_OBJ) { alert("open is not support yet");} | |
642 }, | |
643 { | |
644 id: "Rename", | |
645 label: "Rename", | |
646 icon: "rename.png", | |
647 visible: function(NODE,TREE_OBJ) { if(NODE.length != 1) return false; return NODE[0].id == "prj";}, | |
648 action: function(NODE,TREE_OBJ) { alert("open is not support yet");} | |
358 | 649 } |
357 | 650 ] |
358 | 651 } |
652 | |
653 }); | |
654 } | |
357 | 655 |
364
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
656 function fileDialog_cb() |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
657 { |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
658 var file = $('#filedialogsrc').attr('value'); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
659 filedialog.dialog('close'); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
660 filedialog_cb(file,filedialog_arg); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
661 } |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
662 |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
663 function openFileDialog(callback,arg) |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
664 { |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
665 filedialog_cb = callback; |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
666 filedialog_arg = arg; |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
667 filedialog.html('Please select the scene file<br>'); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
668 filedialog.append('<input type=file value="Select the scene file" id="filedialogsrc">'); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
669 filedialog.append('<input type=button value="Load" onclick="fileDialog_cb()">'); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
670 filedialog.show(); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
671 filedialog.dialog('open'); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
672 } |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
673 |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
674 |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
675 function project_addScene(file,treeobj) |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
676 { |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
677 if (file == '') { |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
678 return; |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
679 } |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
680 treeobj.create(false,treeobj.selected,file); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
681 } |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
682 |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
683 function onTree_addSceneFile(node,treeobj) |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
684 { |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
685 openFileDialog(project_addScene,treeobj); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
686 } |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
687 |
365
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
688 function project_addSource(file,treeobj) |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
689 { |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
690 treeobj.create(false,treeobj.selected,file); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
691 } |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
692 |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
693 function onTree_addSourceFile(node,treeobj) |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
694 { |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
695 openFileDialog(project_addSource,treeobj); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
696 } |
364
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
697 |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
698 function onTree_openFile(node,treeobj) |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
699 { |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
700 if (node[0].id == "scenes") { |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
701 onTree_addSceneFile(node,treeobj); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
702 } else if (node[0].id == "sources") { |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
703 onTree_addSourceFile(node,treeobj); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
704 } |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
705 } |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
706 |
367 | 707 function system_open_read(fname) { |
708 try { | |
709 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); | |
710 } catch (e) { | |
711 alert("Permission to read file was denied."); | |
712 } | |
713 var file = Components.classes["@mozilla.org/file/local;1"] | |
714 .createInstance(Components.interfaces.nsILocalFile); | |
715 try { | |
716 file.initWithPath( fname ); | |
717 if ( file.exists() == false ) { | |
718 alert("File does not exist"); | |
719 } | |
720 var is = Components.classes["@mozilla.org/network/file-input-stream;1"] | |
721 .createInstance( Components.interfaces.nsIFileInputStream ); | |
722 is.init( file,0x01, 00004, null); | |
723 var sis = Components.classes["@mozilla.org/scriptableinputstream;1"] | |
724 .createInstance( Components.interfaces.nsIScriptableInputStream ); | |
725 sis.init( is ); | |
726 } catch(e) { | |
727 alert(fname+" does not exist"); | |
728 } | |
729 return sis; | |
730 } | |
364
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
731 |
358 | 732 function system_read(fname) { |
733 try { | |
734 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); | |
735 } catch (e) { | |
736 alert("Permission to read file was denied."); | |
737 } | |
738 var file = Components.classes["@mozilla.org/file/local;1"] | |
739 .createInstance(Components.interfaces.nsILocalFile); | |
740 try { | |
741 file.initWithPath( fname ); | |
742 if ( file.exists() == false ) { | |
743 alert("File does not exist"); | |
744 } | |
745 var is = Components.classes["@mozilla.org/network/file-input-stream;1"] | |
746 .createInstance( Components.interfaces.nsIFileInputStream ); | |
747 is.init( file,0x01, 00004, null); | |
748 var sis = Components.classes["@mozilla.org/scriptableinputstream;1"] | |
749 .createInstance( Components.interfaces.nsIScriptableInputStream ); | |
750 sis.init( is ); | |
751 var output = sis.read( sis.available() ); | |
752 sis.close(); | |
753 } catch(e) { | |
754 alert(fname+" does not exist"); | |
755 } | |
756 return output; | |
357 | 757 } |
367 | 758 function system_open_write(fname) { |
759 try { | |
760 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); | |
761 } catch (e) { | |
762 alert("Permission to read file was denied."); | |
763 } | |
764 var file = Components.classes["@mozilla.org/file/local;1"] | |
765 .createInstance(Components.interfaces.nsILocalFile); | |
766 try { | |
767 file.initWithPath( fname ); | |
768 var fostream = Components.classes["@mozilla.org/network/file-output-stream;1"] | |
769 .createInstance( Components.interfaces.nsIFileOutputStream ); | |
770 fostream.init( file,0x02|0x8|0x20, 0666,0); | |
771 } catch(e) { | |
371 | 772 alert('can not create '+fname); |
367 | 773 } |
774 return fostream; | |
775 } | |
365
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
776 function system_write(fname,xml) { |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
777 try { |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
778 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
779 } catch (e) { |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
780 alert("Permission to read file was denied."); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
781 } |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
782 var file = Components.classes["@mozilla.org/file/local;1"] |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
783 .createInstance(Components.interfaces.nsILocalFile); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
784 try { |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
785 file.initWithPath( fname ); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
786 var fostream = Components.classes["@mozilla.org/network/file-output-stream;1"] |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
787 .createInstance( Components.interfaces.nsIFileOutputStream ); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
788 fostream.init( file,0x02|0x8|0x20, 0666,0); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
789 fostream.write( xml,xml.length ); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
790 fostream.close(); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
791 } catch(e) { |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
792 alert(fname+" does not exist"); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
793 } |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
794 } |
358 | 795 |
371 | 796 function system_mkdir(path) |
797 { | |
798 try { | |
799 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); | |
800 } catch (e) { | |
801 alert("Permission to read file was denied."); | |
802 } | |
803 var file = Components.classes["@mozilla.org/file/local;1"] | |
804 .createInstance(Components.interfaces.nsILocalFile); | |
805 try { | |
806 file.initWithPath(path); | |
807 if( !file.exists() || !file.isDirectory() ) { // if it doesn't exist, create | |
808 file.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0777); | |
809 } | |
810 } catch(e) { | |
811 alert('Failed to create directopry '+path+e); | |
812 } | |
813 } | |
814 | |
815 function getPathDirectory(path) | |
816 { | |
817 var s = path.lastIndexOf('/'); | |
818 if (s == -1) | |
819 return ''; | |
820 else | |
821 return path.substr(0,s); | |
822 } | |
823 | |
358 | 824 function project_loadFile() |
825 { | |
826 prjname = $('#mbsvg').attr('value'); | |
365
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
827 project_name = prjname; |
371 | 828 project_dir = getPathDirectory(prjname); |
358 | 829 var prj = system_read(prjname); |
830 project_parse(prj); | |
364
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
831 filedialog.dialog('close'); |
358 | 832 } |
833 | |
365
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
834 |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
835 function project_save() |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
836 { |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
837 var i; |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
838 |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
839 var xml = "<project>\n"; |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
840 var scenes = $('#scenes'); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
841 var sources = $('#sources'); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
842 var list = project_tree.getJSON(scenes); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
843 var len = list.children.length; |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
844 |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
845 for(i=0;i<len;i++) { |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
846 xml = xml + "\t<scene src='"+list.children[i].data+"' />\n"; |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
847 } |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
848 list = project_tree.getJSON(sources); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
849 len = list.children.length; |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
850 for(i=0;i<len;i++) { |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
851 xml = xml + "\t<source src='"+list.children[i].data+"' />\n"; |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
852 } |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
853 xml = xml + "</project>\n"; |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
854 system_write(project_name,xml); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
855 |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
856 } |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
857 |
367 | 858 |
859 function onLoadProject(path) | |
860 { | |
861 project_name = path; | |
371 | 862 project_dir = getPathDirectory(project_name); |
367 | 863 var prj = system_read(project_name); |
864 project_parse(prj); | |
865 } | |
866 | |
358 | 867 var last_select = null; |
367 | 868 var wizard = new Wizard(); |
869 wizard.cb = onLoadProject; | |
364
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
870 $('#filedialog').dialog({ width:500}); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
871 jQuery(document).ready(function() { |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
872 filedialog = jQuery('#filedialog'); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
873 filedialog.dialog({width:500, |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
874 modal: true, |
367 | 875 autoOpen:false, |
364
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
876 title:'Please select a file'}); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
877 filedialog.show(); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
878 filedialog.html('Please select the project file<br>'); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
879 filedialog.append('<input type=file value="Select the project file" id="mbsvg" accept="image/png">'); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
880 filedialog.append('<input type=button value="Load" onclick="project_loadFile()">'); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
881 filedialog.dialog("open"); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
882 }); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
883 |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
884 $('#frame').draggable(); |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
885 $('#btns').draggable({cursor:'crosshair'}); |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
886 $('#list').tabs(); |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
887 $('#display').tabs(); |