comparison inkscape/firefox/content/inkscape.js @ 365:6adb28388132

Add capability to add new scene and source into the project Add Save button to save the project.
author wycc
date Sat, 14 Mar 2009 16:42:37 +0800
parents a373b4743e63
children e21e9447f545
comparison
equal deleted inserted replaced
364:a373b4743e63 365:6adb28388132
373 } 373 }
374 374
375 375
376 function onButtonClick(obj) 376 function onButtonClick(obj)
377 { 377 {
378 if (inkscape.isInProgress != 0) return;
379 var id = obj.getAttribute('id'); 378 var id = obj.getAttribute('id');
380 if (id == 'Jump') { 379 if (id == 'Jump') {
380 if (inkscape.isInProgress != 0) return;
381 if (currentScene != 0) 381 if (currentScene != 0)
382 inkscape.gotoScene(currentScene); 382 inkscape.gotoScene(currentScene);
383 } else if (id == 'InsertKey') { 383 } else if (id == 'InsertKey') {
384 if (inkscape.isInProgress != 0) return;
384 inkscape.insertKey(currentScene); 385 inkscape.insertKey(currentScene);
385 } else if (id == 'ExtendScene') { 386 } else if (id == 'ExtendScene') {
387 if (inkscape.isInProgress != 0) return;
386 inkscape.extendScene(currentScene); 388 inkscape.extendScene(currentScene);
387 } else if (id == 'DeleteScene') { 389 } else if (id == 'DeleteScene') {
390 if (inkscape.isInProgress != 0) return;
388 inkscape.deleteScene(currentScene); 391 inkscape.deleteScene(currentScene);
392 } else if (id == 'Save') {
393 project_save();
389 } else { 394 } else {
390 alert(id+' has not been implemented yet'); 395 alert(id+' has not been implemented yet');
391 } 396 }
392 } 397 }
393 398
518 s.data = n.getAttribute("src"); 523 s.data = n.getAttribute("src");
519 sources.push(s); 524 sources.push(s);
520 } 525 }
521 526
522 var tree = $.tree_create(); 527 var tree = $.tree_create();
528 project_tree = tree;
523 tree.init($("#filelist"), { 529 tree.init($("#filelist"), {
524 data: { 530 data: {
525 type: "json", 531 type: "json",
526 json : [ 532 json : [
527 { 533 {
594 treeobj.create(false,treeobj.selected,file); 600 treeobj.create(false,treeobj.selected,file);
595 } 601 }
596 602
597 function onTree_addSceneFile(node,treeobj) 603 function onTree_addSceneFile(node,treeobj)
598 { 604 {
599 //treeobj.create(false,treeobj.selected,"xxx",null,"newscene");
600 openFileDialog(project_addScene,treeobj); 605 openFileDialog(project_addScene,treeobj);
601 } 606 }
602 607
608 function project_addSource(file,treeobj)
609 {
610 treeobj.create(false,treeobj.selected,file);
611 }
612
613 function onTree_addSourceFile(node,treeobj)
614 {
615 openFileDialog(project_addSource,treeobj);
616 }
603 617
604 function onTree_openFile(node,treeobj) 618 function onTree_openFile(node,treeobj)
605 { 619 {
606 if (node[0].id == "scenes") { 620 if (node[0].id == "scenes") {
607 onTree_addSceneFile(node,treeobj); 621 onTree_addSceneFile(node,treeobj);
635 } catch(e) { 649 } catch(e) {
636 alert(fname+" does not exist"); 650 alert(fname+" does not exist");
637 } 651 }
638 return output; 652 return output;
639 } 653 }
654 function system_write(fname,xml) {
655 try {
656 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
657 } catch (e) {
658 alert("Permission to read file was denied.");
659 }
660 var file = Components.classes["@mozilla.org/file/local;1"]
661 .createInstance(Components.interfaces.nsILocalFile);
662 try {
663 file.initWithPath( fname );
664 var fostream = Components.classes["@mozilla.org/network/file-output-stream;1"]
665 .createInstance( Components.interfaces.nsIFileOutputStream );
666 fostream.init( file,0x02|0x8|0x20, 0666,0);
667 fostream.write( xml,xml.length );
668 fostream.close();
669 } catch(e) {
670 alert(fname+" does not exist");
671 }
672 }
640 673
641 function project_loadFile() 674 function project_loadFile()
642 { 675 {
643 prjname = $('#mbsvg').attr('value'); 676 prjname = $('#mbsvg').attr('value');
677 project_name = prjname;
644 var prj = system_read(prjname); 678 var prj = system_read(prjname);
645 project_parse(prj); 679 project_parse(prj);
646 filedialog.dialog('close'); 680 filedialog.dialog('close');
681 }
682
683
684 function project_save()
685 {
686 var i;
687
688 var xml = "<project>\n";
689 var scenes = $('#scenes');
690 var sources = $('#sources');
691 var list = project_tree.getJSON(scenes);
692 var len = list.children.length;
693
694 for(i=0;i<len;i++) {
695 xml = xml + "\t<scene src='"+list.children[i].data+"' />\n";
696 }
697 list = project_tree.getJSON(sources);
698 len = list.children.length;
699 for(i=0;i<len;i++) {
700 xml = xml + "\t<source src='"+list.children[i].data+"' />\n";
701 }
702 xml = xml + "</project>\n";
703 system_write(project_name,xml);
704
647 } 705 }
648 706
649 var last_select = null; 707 var last_select = null;
650 708
651 $('#filedialog').dialog({ width:500}); 709 $('#filedialog').dialog({ width:500});