comparison inkscape/firefox/content/inkscape.js @ 371:3d21115297ba

Add textmenu template
author wycc
date Tue, 17 Mar 2009 08:31:04 +0800
parents e21e9447f545
children 7d244a85dd68
comparison
equal deleted inserted replaced
370:fce37d9c296f 371:3d21115297ba
470 470
471 } 471 }
472 function project_loadScene(node) 472 function project_loadScene(node)
473 { 473 {
474 var file = node.textContent; 474 var file = node.textContent;
475 inkscape = new Inkscape("file://"+file); 475 if (file.substr(0,1) == '/')
476 inkscape = new Inkscape("file://"+file);
477 else
478 inkscape = new Inkscape("file://"+project_dir+'/'+file);
476 } 479 }
477 480
478 481
479 function project_loadEditor(node) 482 function project_loadEditor(node)
480 { 483 {
481 var file = node.textContent; 484 var file = node.textContent;
482 editor = new TextEditor("file://"+file); 485 if (file.substr(0,1) == '/')
486 editor = new TextEditor("file://"+file);
487 else
488 editor = new TextEditor("file://"+project_dir+'/'+file);
483 } 489 }
484 490
485 function project_parse(xml) 491 function project_parse(xml)
486 { 492 {
487 493
687 file.initWithPath( fname ); 693 file.initWithPath( fname );
688 var fostream = Components.classes["@mozilla.org/network/file-output-stream;1"] 694 var fostream = Components.classes["@mozilla.org/network/file-output-stream;1"]
689 .createInstance( Components.interfaces.nsIFileOutputStream ); 695 .createInstance( Components.interfaces.nsIFileOutputStream );
690 fostream.init( file,0x02|0x8|0x20, 0666,0); 696 fostream.init( file,0x02|0x8|0x20, 0666,0);
691 } catch(e) { 697 } catch(e) {
692 alert(fname+" does not exist"); 698 alert('can not create '+fname);
693 } 699 }
694 return fostream; 700 return fostream;
695 } 701 }
696 function system_write(fname,xml) { 702 function system_write(fname,xml) {
697 try { 703 try {
711 } catch(e) { 717 } catch(e) {
712 alert(fname+" does not exist"); 718 alert(fname+" does not exist");
713 } 719 }
714 } 720 }
715 721
722 function system_mkdir(path)
723 {
724 try {
725 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
726 } catch (e) {
727 alert("Permission to read file was denied.");
728 }
729 var file = Components.classes["@mozilla.org/file/local;1"]
730 .createInstance(Components.interfaces.nsILocalFile);
731 try {
732 file.initWithPath(path);
733 if( !file.exists() || !file.isDirectory() ) { // if it doesn't exist, create
734 file.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0777);
735 }
736 } catch(e) {
737 alert('Failed to create directopry '+path+e);
738 }
739 }
740
741 function getPathDirectory(path)
742 {
743 var s = path.lastIndexOf('/');
744 if (s == -1)
745 return '';
746 else
747 return path.substr(0,s);
748 }
749
716 function project_loadFile() 750 function project_loadFile()
717 { 751 {
718 prjname = $('#mbsvg').attr('value'); 752 prjname = $('#mbsvg').attr('value');
719 project_name = prjname; 753 project_name = prjname;
754 project_dir = getPathDirectory(prjname);
720 var prj = system_read(prjname); 755 var prj = system_read(prjname);
721 project_parse(prj); 756 project_parse(prj);
722 filedialog.dialog('close'); 757 filedialog.dialog('close');
723 } 758 }
724 759
748 783
749 784
750 function onLoadProject(path) 785 function onLoadProject(path)
751 { 786 {
752 project_name = path; 787 project_name = path;
788 project_dir = getPathDirectory(project_name);
753 var prj = system_read(project_name); 789 var prj = system_read(project_name);
754 project_parse(prj); 790 project_parse(prj);
755 } 791 }
756 792
757 var last_select = null; 793 var last_select = null;