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