comparison inkscape/firefox/content/inkscape.js @ 358:50d33c3987ba

Add loader for project file.
author wycc
date Wed, 11 Mar 2009 07:52:30 +0800
parents 6fd8da22a5ef
children b4bd4819091c
comparison
equal deleted inserted replaced
357:6fd8da22a5ef 358:50d33c3987ba
391 } 391 }
392 alert(cmd); 392 alert(cmd);
393 } 393 }
394 394
395 395
396 function openFile() 396
397 { 397
398 alert('bug'); 398
399 $.modal('<div>My data</div>'); 399
400 alert('done'); 400 function loadInkscapeFile()
401 }
402
403
404 var last_select = null;
405
406 $('#inkscape').html('Please select the project file<br>');
407 $('#inkscape').append('<input type=file value="Select the project file" id="mbsvg" accept="image/png">');
408 $('#inkscape').append('<input type=button value="Load" onclick="loadFile()">');
409
410
411 function loadFile()
412 { 401 {
413 ele = $('#mbsvg'); 402 ele = $('#mbsvg');
414 file = ele.attr('value'); 403 file = ele.attr('value');
415 inkscape = new Inkscape("file://"+file); 404 inkscape = new Inkscape("file://"+file);
416 405
417 var tree = $.tree_create();
418 file1_animation = [ 406 file1_animation = [
419 { 407 {
420 attributes: {id:"an1-1"}, 408 attributes: {id:"an1-1"},
421 data: "animation1" 409 data: "animation1"
422 }, 410 },
444 src2 = {attributes:{id:"src1"},data:"src2.c"}; 432 src2 = {attributes:{id:"src1"},data:"src2.c"};
445 src3 = {attributes:{id:"src1"},data:"src3.c"}; 433 src3 = {attributes:{id:"src1"},data:"src3.c"};
446 434
447 sources = [src1,src2,src3]; 435 sources = [src1,src2,src3];
448 436
449 tree.init($("#filelist"), { 437 }
450 data: { 438
451 type: "json", 439
452 json : { 440 function project_parse(xml)
453 attributes: {id: "prj"}, state: "open", data: "Project", 441 {
454 children: [ 442
455 { attributes:{id:"scenes"}, data:"scene", children: scenes}, 443 var xmlParser = new DOMParser();
456 { attributes:{id:"sources"},data:"sources",children: sources} 444 var xmlDoc = xmlParser.parseFromString( xml, 'text/xml');
457 ] 445 var scenesNode = xmlDoc.getElementsByTagName("scene");
458 } 446 if (scenesNode == null) {
459 }, 447 alert('This is not a valid scene file');
460 ui : { 448 }
449 var len = scenesNode.length;
450 var i,j;
451 var max = 0;
452 var scenes = new Array();
453
454 // Get the length of scenes
455 for(i=0;i<len;i++) {
456 var n = scenesNode[i];
457 var s = new Object();
458 s.attributes = new Object();
459 s.attributes.id = "scene"+i;
460 s.state = "open";
461 s.data = n.getAttribute("src");
462 scenes.push(s);
463 }
464
465 var nodes = xmlDoc.getElementsByTagName("source");
466 var len = nodes.length;
467 var i,j;
468 var max = 0;
469 var sources = [];
470
471 // Get the length of scenes
472 for(i=0;i<len;i++) {
473 var n = nodes[i];
474 var s = new Object();
475 s.attributes = new Object();
476 s.attributes.id = "sources"+i;
477 s.state = "open";
478 s.data = n.getAttribute("src");
479 sources.push(s);
480 }
481
482 var tree = $.tree_create();
483 tree.init($("#filelist"), {
484 data: {
485 type: "json",
486 json : [
487 {
488 attributes: {id: "prj"},
489 state: "open",
490 data: "Project",
491 children: [
492 { attributes:{id:"scenes"}, data:"scene", children: scenes},
493 { attributes:{id:"sources"},data:"sources",children: sources}
494 ]
495 }
496 ],
497 },
498 ui : {
461 context : [ 499 context : [
462 { 500 {
463 id: "Open", 501 id: "Open",
464 label: "Open", 502 label: "Open",
465 icon: "open.png", 503 icon: "open.png",
477 id: "Rename", 515 id: "Rename",
478 label: "Rename", 516 label: "Rename",
479 icon: "rename.png", 517 icon: "rename.png",
480 visible: function(NODE,TREE_OBJ) { if(NODE.length != 1) return false; return NODE[0].id == "prj";}, 518 visible: function(NODE,TREE_OBJ) { if(NODE.length != 1) return false; return NODE[0].id == "prj";},
481 action: function(NODE,TREE_OBJ) { alert("open is not support yet");} 519 action: function(NODE,TREE_OBJ) { alert("open is not support yet");}
482 }, 520 }
483 ] 521 ]
484 }, 522 }
485 523
486 }); 524 });
487 } 525 }
526
527 function system_read(fname) {
528 try {
529 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
530 } catch (e) {
531 alert("Permission to read file was denied.");
532 }
533 var file = Components.classes["@mozilla.org/file/local;1"]
534 .createInstance(Components.interfaces.nsILocalFile);
535 try {
536 file.initWithPath( fname );
537 if ( file.exists() == false ) {
538 alert("File does not exist");
539 }
540 var is = Components.classes["@mozilla.org/network/file-input-stream;1"]
541 .createInstance( Components.interfaces.nsIFileInputStream );
542 is.init( file,0x01, 00004, null);
543 var sis = Components.classes["@mozilla.org/scriptableinputstream;1"]
544 .createInstance( Components.interfaces.nsIScriptableInputStream );
545 sis.init( is );
546 var output = sis.read( sis.available() );
547 sis.close();
548 } catch(e) {
549 alert(fname+" does not exist");
550 }
551 return output;
552 }
553
554 function project_loadFile()
555 {
556 prjname = $('#mbsvg').attr('value');
557 var prj = system_read(prjname);
558 project_parse(prj);
559 }
560
561 var last_select = null;
562
563 $('#inkscape').html('Please select the project file<br>');
564 $('#inkscape').append('<input type=file value="Select the project file" id="mbsvg" accept="image/png">');
565 $('#inkscape').append('<input type=button value="Load" onclick="project_loadFile()">');