Mercurial > MadButterfly
annotate inkscape/firefox/content/inkscape.js @ 364:a373b4743e63
Add file dialog to add a new scene file into the project.
author | wycc |
---|---|
date | Sat, 14 Mar 2009 15:35:51 +0800 |
parents | 83cae12cf428 |
children | 6adb28388132 |
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'); |
361
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
73 editor.innerHTML = "<embed src="+file+" width=700 height=700 />"; |
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'); | |
352 | 84 ink.innerHTML = "<embed src="+file+" width=700 height=700 />"; |
288 | 85 this.isInProgress = 0; |
86 | |
87 setTimeout("inkscape.fetchDocument()",4000); | |
88 } | |
89 | |
90 Inkscape.prototype.gotoScene = function (n) | |
91 { | |
92 nextScene = n; | |
93 var soapBody = new SOAPObject("START"); | |
94 var sr = new SOAPRequest("START", soapBody); | |
95 SOAPClient.Proxy = "http://localhost:19192/"; | |
96 SOAPClient.SendRequest(sr, function (resp,arg) {arg.gotoScene1(resp);},this); | |
97 this.isInProgress++; | |
98 } | |
99 Inkscape.prototype.gotoScene1 = function (resp,n) | |
100 { | |
101 var soapBody = new SOAPObject("SCENE"); | |
102 var v1 = new SOAPObject("v1"); | |
103 v1.val(nextScene); | |
104 soapBody.appendChild(v1); | |
105 var sr = new SOAPRequest("SCENE", soapBody); | |
106 SOAPClient.Proxy = "http://localhost:19192/"; | |
107 SOAPClient.SendRequest(sr, function (resp,arg) {arg.gotoScene2(resp);},this); | |
108 } | |
109 Inkscape.prototype.gotoScene2 = function (resp) | |
110 { | |
111 var soapBody = new SOAPObject("PUBLISH"); | |
112 var sr = new SOAPRequest("PUBLISH", soapBody); | |
113 SOAPClient.Proxy = "http://localhost:19192/"; | |
114 SOAPClient.SendRequest(sr, function (resp,arg) {arg.gotoScene3(resp);},this); | |
115 } | |
116 | |
117 Inkscape.prototype.gotoScene3 = function (resp) | |
118 { | |
119 this.isInProgress--; | |
120 } | |
121 Inkscape.prototype.publishDocument= function(resp) | |
122 { | |
123 mbsvg = new MBSVGString(resp.Body[0].GETDOCResponse[0].Result[0].Text); | |
124 mbsvg.renderUI(); | |
125 | |
126 var soapBody = new SOAPObject("PUBLISH"); | |
127 var sr = new SOAPRequest("PUBLISH", soapBody); | |
128 SOAPClient.Proxy = "http://localhost:19192/"; | |
129 SOAPClient.SendRequest(sr, function(resp,arg) {arg.operationDone(resp);},this); | |
130 } | |
131 | |
132 Inkscape.prototype.refreshDocument = function(resp) | |
133 { | |
134 var soapBody = new SOAPObject("GETDOC"); | |
135 var sr = new SOAPRequest("GETDOC", soapBody); | |
136 SOAPClient.Proxy = "http://localhost:19192/"; | |
137 SOAPClient.SendRequest(sr, function(resp,arg) { arg.publishDocument(resp);},this); | |
138 } | |
139 | |
140 Inkscape.prototype.operationDone = function (res) | |
141 { | |
142 this.isInProgress--; | |
143 } | |
144 Inkscape.prototype.insertKey= function(n) | |
145 { | |
146 nextScene = n; | |
147 var soapBody = new SOAPObject("START"); | |
148 var sr = new SOAPRequest("START", soapBody); | |
149 SOAPClient.Proxy = "http://localhost:19192/"; | |
150 SOAPClient.SendRequest(sr, function (resp,arg) {arg.insertKey1(resp);},this); | |
151 this.isInProgress++; | |
152 } | |
153 Inkscape.prototype.insertKey1 = function(resp) | |
154 { | |
155 var soapBody = new SOAPObject("INSERTKEY"); | |
156 var v1 = new SOAPObject("v1"); | |
157 v1.attr('type','string'); | |
158 v1.val(currentLayer); | |
159 soapBody.appendChild(v1); | |
160 var v2 = new SOAPObject("v2"); | |
161 v2.val(nextScene); | |
162 soapBody.appendChild(v2); | |
163 var sr = new SOAPRequest("INSERTKEY", soapBody); | |
164 SOAPClient.Proxy = "http://localhost:19192/"; | |
165 SOAPClient.SendRequest(sr, function (resp,arg) {arg.refreshDocument(resp);},this); | |
166 } | |
167 | |
168 Inkscape.prototype.extendScene=function() | |
169 { | |
170 var soapBody = new SOAPObject("START"); | |
171 var sr = new SOAPRequest("START", soapBody); | |
172 SOAPClient.Proxy = "http://localhost:19192/"; | |
173 SOAPClient.SendRequest(sr, function (resp,arg) {arg.extendScene1(resp);},this); | |
174 this.isInProgress++; | |
175 } | |
176 | |
177 | |
178 Inkscape.prototype.extendScene1 = function(resp) | |
179 { | |
180 var soapBody = new SOAPObject("EXTENDSCENE"); | |
181 var v1 = new SOAPObject("v1"); | |
182 v1.attr('type','string'); | |
183 v1.val(currentLayer); | |
184 soapBody.appendChild(v1); | |
185 var v2 = new SOAPObject("v2"); | |
186 v2.val(currentScene); | |
187 soapBody.appendChild(v2); | |
188 var sr = new SOAPRequest("EXTENDSCENE", soapBody); | |
189 SOAPClient.Proxy = "http://localhost:19192/"; | |
190 SOAPClient.SendRequest(sr, function (resp,arg) {arg.refreshDocument(resp);},this); | |
191 } | |
192 | |
193 | |
194 Inkscape.prototype.deleteScene=function() | |
195 { | |
196 var soapBody = new SOAPObject("START"); | |
197 var sr = new SOAPRequest("START", soapBody); | |
198 SOAPClient.Proxy = "http://localhost:19192/"; | |
199 SOAPClient.SendRequest(sr, function (resp,arg) {arg.deleteScene1(resp);},this); | |
200 this.isInProgress++; | |
201 } | |
202 | |
203 Inkscape.prototype.deleteScene1=function(resp) | |
204 { | |
205 var soapBody = new SOAPObject("DELETESCENE"); | |
206 var v1 = new SOAPObject("v1"); | |
207 v1.attr('type','string'); | |
208 v1.val(currentLayer); | |
209 soapBody.appendChild(v1); | |
210 var v2 = new SOAPObject("v2"); | |
211 v2.val(currentScene); | |
212 soapBody.appendChild(v2); | |
213 var sr = new SOAPRequest("EXTENDSCENE", soapBody); | |
214 SOAPClient.Proxy = "http://localhost:19192/"; | |
215 SOAPClient.SendRequest(sr, function (resp,arg) {arg.refreshDocument(resp);},this); | |
216 } | |
217 | |
218 Inkscape.prototype.fetchDocument = function() | |
219 { | |
220 var soapBody = new SOAPObject("START"); | |
221 var sr = new SOAPRequest("START", soapBody); | |
222 SOAPClient.Proxy = "http://localhost:19192/"; | |
223 SOAPClient.SendRequest(sr,function(resp,arg) {arg.refreshDocument(resp);},this); | |
224 this.isInProgress++; | |
225 } | |
226 | |
227 | |
228 | |
229 function MBSVG(file) | |
230 { | |
231 var xmlDoc=document.implementation.createDocument("http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd","",null); | |
232 xmlDoc.async=false; | |
233 xmlDoc.load(file); | |
234 MBSVG_loadFromDoc(this,xmlDoc); | |
235 | |
236 } | |
237 function MBSVGString(xml) | |
238 { | |
239 var xmlParser = new DOMParser(); | |
240 var xmlDoc = xmlParser.parseFromString( xml, 'text/xml'); | |
241 MBSVG_loadFromDoc(this,xmlDoc); | |
242 } | |
243 | |
244 | |
245 | |
246 function MBSVG_loadFromDoc(self,xmlDoc) | |
247 { | |
248 var scenesNode = xmlDoc.getElementsByTagNameNS("http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd","scene"); | |
249 if (scenesNode == null) { | |
250 alert('This is not a valid scene file'); | |
251 } | |
252 var len = scenesNode.length; | |
253 var i,j; | |
254 var max = 0; | |
255 var scenes = new Array(); | |
256 | |
257 // Get the length of scenes | |
258 for(i=0;i<len;i++) { | |
259 var s = scenesNode[i]; | |
260 var start = s.getAttribute("start"); | |
261 var end = s.getAttribute("end"); | |
262 var ref = s.getAttribute("ref"); | |
263 var ss = new Object(); | |
264 | |
265 if (end == null) end = start | |
266 if (max <end) max = end; | |
267 ss.node = s; | |
268 ss.start = start; | |
269 ss.end = end; | |
270 ss.ref = ref; | |
271 ss.layer = null; | |
272 scenes.push(ss); | |
273 } | |
274 if (max < 20) max = 20; | |
275 // Collect all layers | |
276 var nodes = xmlDoc.getElementsByTagNameNS("http://www.w3.org/2000/svg","svg")[0].childNodes; | |
277 var layers = new Array(); | |
278 len = nodes.length; | |
279 for(i=0;i<len;i++) { | |
280 if (nodes[i].localName == 'g') { | |
281 var subnodes = nodes[i].childNodes; | |
282 for(j=0;j<subnodes.length;j++) { | |
283 if (subnodes[j].localName == 'g') { | |
284 for(var k=0;k<scenes.length;k++) { | |
285 if (scenes[k].ref == subnodes[j].getAttribute('id')) { | |
286 scenes[k].layer = nodes[i].getAttribute('id'); | |
287 break; | |
288 } | |
289 } | |
290 } | |
291 } | |
292 layers.push(nodes[i]); | |
293 } | |
294 } | |
295 self.layers = layers; | |
296 self.scenes = scenes; | |
297 self.maxframe = max; | |
298 } | |
299 | |
300 MBSVGString.prototype=MBSVG.prototype; | |
301 MBSVG.prototype.renderUI=function() | |
302 { | |
303 var layers = this.layers; | |
304 var scenes = this.scenes; | |
305 var max = this.maxframe; | |
306 var cmd = "<table border=1>\n"; | |
307 cmd = cmd + "<tr><td></td>"; | |
308 for(var j=1;j<=max;j++) | |
309 cmd = cmd + "<td>"+j+"</td>"; | |
310 | |
311 for(var i=layers.length-1;i>=0;i--) { | |
312 var l = layers[i]; | |
313 var id = l.getAttribute('id'); | |
314 var label = l.getAttribute('inkscape:label'); | |
315 cmd = cmd + "<tr><td>"+label+"</td>"; | |
316 for(j=0;j<max;j++) { | |
317 var empty = 1; | |
318 var n = j +1; | |
319 var id_str = id+"#"+n | |
320 for(var k=0;k<scenes.length;k++) { | |
321 if (id != scenes[k].layer) continue; | |
322 if (n == scenes[k].start) { | |
323 cmd = cmd + "<td><img class='normal' src=start.png id='"+id_str+"' onClick='selectCell(this)' /></td>"; | |
324 empty = 0; | |
325 break; | |
326 } else if ((n>scenes[k].start)&&(n <= scenes[k].end)) { | |
327 cmd = cmd + "<td><img class='normal' src=fill.png id='"+id_str+"' onClick='selectCell(this)' /></td>"; | |
328 empty = 0; | |
329 break; | |
330 } | |
331 } | |
332 if (empty) { | |
333 cmd = cmd + "<td><img class='normal' src=empty.png id='"+id_str+"'onClick='selectCell(this)' /></td>"; | |
334 } | |
335 | |
336 } | |
337 cmd = cmd + "</tr>\n"; | |
338 } | |
339 cmd = cmd + "</table>\n"; | |
340 var frame = document.getElementById('frame'); | |
341 frame.innerHTML=cmd; | |
342 } | |
343 | |
344 | |
345 | |
346 /** | |
347 * UI for madbuilder.html to build the scene editor | |
348 */ | |
349 | |
350 function selectCell(obj) | |
351 { | |
352 var id = obj.getAttribute('id'); | |
353 var layer,n; | |
354 var f = id.split('#'); | |
355 layer=f[0]; | |
356 n = f[1]; | |
357 var img = obj.getAttribute('src'); | |
358 var f = img.split('-'); | |
359 | |
360 if (f[0] == 'active') | |
361 return; | |
362 else { | |
363 obj.setAttribute('src', 'active-'+img); | |
364 } | |
365 | |
366 if (last_select != null) { | |
367 f = last_select.getAttribute('src').split('-'); | |
368 last_select.setAttribute('src', f[1]); | |
369 } | |
370 last_select = obj; | |
371 currentScene = n; | |
372 currentLayer = layer; | |
373 } | |
374 | |
375 | |
376 function onButtonClick(obj) | |
377 { | |
378 if (inkscape.isInProgress != 0) return; | |
379 var id = obj.getAttribute('id'); | |
380 if (id == 'Jump') { | |
381 if (currentScene != 0) | |
382 inkscape.gotoScene(currentScene); | |
383 } else if (id == 'InsertKey') { | |
384 inkscape.insertKey(currentScene); | |
385 } else if (id == 'ExtendScene') { | |
386 inkscape.extendScene(currentScene); | |
387 } else if (id == 'DeleteScene') { | |
388 inkscape.deleteScene(currentScene); | |
389 } else { | |
390 alert(id+' has not been implemented yet'); | |
391 } | |
392 } | |
393 | |
394 function gotoScene_cb(resObj) | |
395 { | |
396 | |
397 } | |
398 var nextScene; | |
399 var currentScene = 0; | |
400 var currentLayer = ''; | |
401 | |
357 | 402 |
403 function dump(n) | |
404 { | |
405 cmd = ""; | |
406 for(k in n) { | |
407 cmd = cmd + k+"="+n[k]+"\n"; | |
408 } | |
409 alert(cmd); | |
410 } | |
288 | 411 |
412 | |
358 | 413 |
357 | 414 |
415 | |
416 | |
358 | 417 function loadInkscapeFile() |
357 | 418 { |
419 ele = $('#mbsvg'); | |
420 file = ele.attr('value'); | |
421 inkscape = new Inkscape("file://"+file); | |
422 | |
352 | 423 file1_animation = [ |
424 { | |
425 attributes: {id:"an1-1"}, | |
426 data: "animation1" | |
427 }, | |
428 { | |
429 attributes: {id:"an1-2"}, | |
430 data: "animation2" | |
431 } | |
432 ]; | |
433 file1 = { | |
434 attributes:{id:"file1"}, | |
435 data: "scene1.mbsvg", | |
436 children: file1_animation | |
437 }; | |
438 file2 = { | |
439 attributes:{id:"file2"}, | |
440 data: "scene2.mbsvg", | |
441 }; | |
442 file3 = { | |
443 attributes:{id:"file3"}, | |
444 data: "scene3.mbsvg", | |
445 }; | |
446 | |
447 scenes = [ file1,file2,file3]; | |
448 src1 = {attributes:{id:"src1"},data:"src1.c"}; | |
449 src2 = {attributes:{id:"src1"},data:"src2.c"}; | |
450 src3 = {attributes:{id:"src1"},data:"src3.c"}; | |
451 | |
452 sources = [src1,src2,src3]; | |
453 | |
358 | 454 } |
455 | |
456 | |
362 | 457 function project_showFile(node) |
458 { | |
459 var file = node.textContent; | |
460 if (endsWith(file,"mbsvg")) { | |
461 project_loadScene(node); | |
462 } else { | |
463 project_loadEditor(node); | |
464 } | |
465 | |
466 } | |
359 | 467 function project_loadScene(node) |
468 { | |
469 var file = node.textContent; | |
470 inkscape = new Inkscape("file://"+file); | |
361
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
471 } |
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
472 |
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
473 |
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
474 function project_loadEditor(node) |
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
475 { |
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
476 var file = node.textContent; |
362 | 477 editor = new TextEditor("file://"+file); |
359 | 478 } |
479 | |
358 | 480 function project_parse(xml) |
481 { | |
482 | |
483 var xmlParser = new DOMParser(); | |
484 var xmlDoc = xmlParser.parseFromString( xml, 'text/xml'); | |
485 var scenesNode = xmlDoc.getElementsByTagName("scene"); | |
486 if (scenesNode == null) { | |
487 alert('This is not a valid scene file'); | |
488 } | |
489 var len = scenesNode.length; | |
490 var i,j; | |
491 var max = 0; | |
492 var scenes = new Array(); | |
493 | |
494 // Get the length of scenes | |
495 for(i=0;i<len;i++) { | |
496 var n = scenesNode[i]; | |
497 var s = new Object(); | |
498 s.attributes = new Object(); | |
499 s.attributes.id = "scene"+i; | |
500 s.state = "open"; | |
501 s.data = n.getAttribute("src"); | |
502 scenes.push(s); | |
503 } | |
504 | |
505 var nodes = xmlDoc.getElementsByTagName("source"); | |
506 var len = nodes.length; | |
507 var i,j; | |
508 var max = 0; | |
509 var sources = []; | |
510 | |
511 // Get the length of scenes | |
512 for(i=0;i<len;i++) { | |
513 var n = nodes[i]; | |
514 var s = new Object(); | |
515 s.attributes = new Object(); | |
516 s.attributes.id = "sources"+i; | |
517 s.state = "open"; | |
518 s.data = n.getAttribute("src"); | |
519 sources.push(s); | |
520 } | |
521 | |
522 var tree = $.tree_create(); | |
523 tree.init($("#filelist"), { | |
524 data: { | |
525 type: "json", | |
526 json : [ | |
527 { | |
528 attributes: {id: "prj"}, | |
529 state: "open", | |
530 data: "Project", | |
531 children: [ | |
532 { attributes:{id:"scenes"}, data:"scene", children: scenes}, | |
533 { attributes:{id:"sources"},data:"sources",children: sources} | |
534 ] | |
535 } | |
536 ], | |
537 }, | |
359 | 538 callback : { |
362 | 539 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 | 540 }, |
358 | 541 ui : { |
357 | 542 context : [ |
543 { | |
544 id: "Open", | |
545 label: "Open", | |
546 icon: "open.png", | |
364
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
547 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
|
548 action: function(NODE,TREE_OBJ) { onTree_openFile(NODE,TREE_OBJ);} |
357 | 549 }, |
550 { | |
551 id: "New", | |
552 label: "New", | |
553 icon: "create.png", | |
554 visible: function(NODE,TREE_OBJ) { if(NODE.length != 1) return false; return NODE[0].id == "prj";}, | |
555 action: function(NODE,TREE_OBJ) { alert("open is not support yet");} | |
556 }, | |
557 { | |
558 id: "Rename", | |
559 label: "Rename", | |
560 icon: "rename.png", | |
561 visible: function(NODE,TREE_OBJ) { if(NODE.length != 1) return false; return NODE[0].id == "prj";}, | |
562 action: function(NODE,TREE_OBJ) { alert("open is not support yet");} | |
358 | 563 } |
357 | 564 ] |
358 | 565 } |
566 | |
567 }); | |
568 } | |
357 | 569 |
364
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
570 function fileDialog_cb() |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
571 { |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
572 var file = $('#filedialogsrc').attr('value'); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
573 filedialog.dialog('close'); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
574 filedialog_cb(file,filedialog_arg); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
575 } |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
576 |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
577 function openFileDialog(callback,arg) |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
578 { |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
579 filedialog_cb = callback; |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
580 filedialog_arg = arg; |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
581 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
|
582 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
|
583 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
|
584 filedialog.show(); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
585 filedialog.dialog('open'); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
586 } |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
587 |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
588 |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
589 function project_addScene(file,treeobj) |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
590 { |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
591 if (file == '') { |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
592 return; |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
593 } |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
594 treeobj.create(false,treeobj.selected,file); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
595 } |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
596 |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
597 function onTree_addSceneFile(node,treeobj) |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
598 { |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
599 //treeobj.create(false,treeobj.selected,"xxx",null,"newscene"); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
600 openFileDialog(project_addScene,treeobj); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
601 } |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
602 |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
603 |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
604 function onTree_openFile(node,treeobj) |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
605 { |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
606 if (node[0].id == "scenes") { |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
607 onTree_addSceneFile(node,treeobj); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
608 } else if (node[0].id == "sources") { |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
609 onTree_addSourceFile(node,treeobj); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
610 } |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
611 } |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
612 |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
613 |
358 | 614 function system_read(fname) { |
615 try { | |
616 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); | |
617 } catch (e) { | |
618 alert("Permission to read file was denied."); | |
619 } | |
620 var file = Components.classes["@mozilla.org/file/local;1"] | |
621 .createInstance(Components.interfaces.nsILocalFile); | |
622 try { | |
623 file.initWithPath( fname ); | |
624 if ( file.exists() == false ) { | |
625 alert("File does not exist"); | |
626 } | |
627 var is = Components.classes["@mozilla.org/network/file-input-stream;1"] | |
628 .createInstance( Components.interfaces.nsIFileInputStream ); | |
629 is.init( file,0x01, 00004, null); | |
630 var sis = Components.classes["@mozilla.org/scriptableinputstream;1"] | |
631 .createInstance( Components.interfaces.nsIScriptableInputStream ); | |
632 sis.init( is ); | |
633 var output = sis.read( sis.available() ); | |
634 sis.close(); | |
635 } catch(e) { | |
636 alert(fname+" does not exist"); | |
637 } | |
638 return output; | |
357 | 639 } |
358 | 640 |
641 function project_loadFile() | |
642 { | |
643 prjname = $('#mbsvg').attr('value'); | |
644 var prj = system_read(prjname); | |
645 project_parse(prj); | |
364
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
646 filedialog.dialog('close'); |
358 | 647 } |
648 | |
649 var last_select = null; | |
650 | |
364
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
651 $('#filedialog').dialog({ width:500}); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
652 jQuery(document).ready(function() { |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
653 filedialog = jQuery('#filedialog'); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
654 filedialog.dialog({width:500, |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
655 modal: true, |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
656 autopen:false, |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
657 title:'Please select a file'}); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
658 filedialog.show(); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
659 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
|
660 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
|
661 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
|
662 filedialog.dialog("open"); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
663 }); |
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 |