changeset 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 912d05129b4f
files inkscape/firefox/content/inkscape.js inkscape/firefox/content/madbuilder.html
diffstat 2 files changed, 61 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/inkscape/firefox/content/inkscape.js	Sat Mar 14 15:35:51 2009 +0800
+++ b/inkscape/firefox/content/inkscape.js	Sat Mar 14 16:42:37 2009 +0800
@@ -375,17 +375,22 @@
 
 function onButtonClick(obj)
 {
-	if (inkscape.isInProgress != 0) return;
 	var id = obj.getAttribute('id');
 	if (id == 'Jump') {
+		if (inkscape.isInProgress != 0) return;
 		if (currentScene != 0)
 			inkscape.gotoScene(currentScene);
 	} else if (id == 'InsertKey') {
+		if (inkscape.isInProgress != 0) return;
 		inkscape.insertKey(currentScene);
 	} else if (id == 'ExtendScene') {
+		if (inkscape.isInProgress != 0) return;
 		inkscape.extendScene(currentScene);
 	} else if (id == 'DeleteScene') {
+		if (inkscape.isInProgress != 0) return;
 		inkscape.deleteScene(currentScene);
+	} else if (id == 'Save') {
+		project_save();
 	} else {
 		alert(id+' has not been implemented yet');
 	}
@@ -520,6 +525,7 @@
 	}
 
   	var tree = $.tree_create();
+	project_tree = tree;
   	tree.init($("#filelist"), {
 	    data: {
   		type: "json",
@@ -596,10 +602,18 @@
 
 function onTree_addSceneFile(node,treeobj)
 {
-	//treeobj.create(false,treeobj.selected,"xxx",null,"newscene");
 	openFileDialog(project_addScene,treeobj);
 }
 
+function project_addSource(file,treeobj)
+{
+	treeobj.create(false,treeobj.selected,file);
+}
+
+function onTree_addSourceFile(node,treeobj)
+{
+	openFileDialog(project_addSource,treeobj);
+}
 
 function onTree_openFile(node,treeobj)
 {
@@ -637,15 +651,59 @@
 	}
 	return output;
 }
+function system_write(fname,xml) {
+	try {
+		netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+	} catch (e) {
+		alert("Permission to read file was denied.");
+	}
+	var file = Components.classes["@mozilla.org/file/local;1"]
+					.createInstance(Components.interfaces.nsILocalFile);
+	try {
+		file.initWithPath( fname );
+		var fostream = Components.classes["@mozilla.org/network/file-output-stream;1"]
+						.createInstance( Components.interfaces.nsIFileOutputStream );
+		fostream.init( file,0x02|0x8|0x20, 0666,0);
+		fostream.write( xml,xml.length );
+		fostream.close();
+	} catch(e) {
+		alert(fname+" does not exist");
+	}
+}
 
 function project_loadFile()
 {
 	prjname = $('#mbsvg').attr('value');
+	project_name = prjname;
 	var prj = system_read(prjname);
 	project_parse(prj);
 	filedialog.dialog('close');
 }
 
+
+function project_save()
+{
+	var i;
+	
+	var xml = "<project>\n";
+	var scenes = $('#scenes');
+	var sources = $('#sources');
+	var list = project_tree.getJSON(scenes);
+	var len = list.children.length;
+
+	for(i=0;i<len;i++) {
+		xml = xml + "\t<scene src='"+list.children[i].data+"' />\n";
+	}
+	list = project_tree.getJSON(sources);
+	len = list.children.length;
+	for(i=0;i<len;i++) {
+		xml = xml + "\t<source src='"+list.children[i].data+"' />\n";
+	}
+	xml = xml + "</project>\n";
+	system_write(project_name,xml);
+
+}
+
 var last_select = null;
 
 $('#filedialog').dialog({ width:500});
--- a/inkscape/firefox/content/madbuilder.html	Sat Mar 14 15:35:51 2009 +0800
+++ b/inkscape/firefox/content/madbuilder.html	Sat Mar 14 16:42:37 2009 +0800
@@ -62,6 +62,7 @@
 	<a class='button' href='#'> <span id='MakeButton' onClick='onButtonClick(this)'>make Button</span></a>
 	<a class='button' href='#'> <span id='EditAnimation' onClick='onButtonClick(this)'>Edit Animation</span></a>
 	<a class='button' href='#'> <span id='Test' onClick='onButtonClick(this)'>Test</span></a>
+	<a class='button' href='#'> <span id='Save' onClick='onButtonClick(this)'>Save</span></a>
 	<br/>
 	<br/>
 </div>