changeset 367:e21e9447f545

Add wizard. We still need to add the template files.
author wycc
date Sun, 15 Mar 2009 17:17:06 +0800
parents 912d05129b4f
children 080aca2b7c47
files inkscape/firefox/content/inkscape.js inkscape/firefox/content/madbuilder.html inkscape/firefox/content/wizard.js
diffstat 3 files changed, 150 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/inkscape/firefox/content/inkscape.js	Sat Mar 14 18:36:57 2009 +0800
+++ b/inkscape/firefox/content/inkscape.js	Sun Mar 15 17:17:06 2009 +0800
@@ -624,6 +624,30 @@
 	}
 }
 
+function system_open_read(fname) {
+	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 );
+		if ( file.exists() == false ) {
+			alert("File does not exist");
+		}
+		var is = Components.classes["@mozilla.org/network/file-input-stream;1"]
+						.createInstance( Components.interfaces.nsIFileInputStream );
+		is.init( file,0x01, 00004, null);
+		var sis = Components.classes["@mozilla.org/scriptableinputstream;1"]
+						.createInstance( Components.interfaces.nsIScriptableInputStream );
+		sis.init( is );
+	} catch(e) {
+		alert(fname+" does not exist");
+	}
+	return sis;
+}
 
 function system_read(fname) {
 	try {
@@ -651,6 +675,24 @@
 	}
 	return output;
 }
+function system_open_write(fname) {
+	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);
+	} catch(e) {
+		alert(fname+" does not exist");
+	}
+	return fostream;
+}
 function system_write(fname,xml) {
 	try {
 		netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
@@ -704,14 +746,23 @@
 
 }
 
+
+function onLoadProject(path)
+{
+	project_name = path;
+	var prj = system_read(project_name);
+	project_parse(prj);
+}
+
 var last_select = null;
-
+var wizard = new Wizard();
+wizard.cb = onLoadProject;
 $('#filedialog').dialog({ width:500});
 jQuery(document).ready(function() {
 		filedialog = jQuery('#filedialog');
 		filedialog.dialog({width:500,
 				   modal: true,
-			           autopen:false,
+			           autoOpen:false,
 				   title:'Please select a file'});
 		filedialog.show();
 		filedialog.html('Please select the project file<br>');
--- a/inkscape/firefox/content/madbuilder.html	Sat Mar 14 18:36:57 2009 +0800
+++ b/inkscape/firefox/content/madbuilder.html	Sun Mar 15 17:17:06 2009 +0800
@@ -9,7 +9,7 @@
 	<script language="javascript" src="tree_component.js"></script>
 	<script type="text/javascript" src="jquery-ui-1.7.custom.min.js"></script>
 	<script type="text/javascript" src="jquery.simplemodal-1.2.3.pack.js"></script>
-
+	<script type="text/javascript" src="wizard.js"></script>
 
 	<style type="text/css"> 
 		.normal {
@@ -63,6 +63,7 @@
 	<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>
+	<a class='button' href='#'> <span id='Wizard' onClick='wizard.execute()'>Wizard</span></a>
 	<br/>
 	<br/>
 </div>
@@ -70,6 +71,28 @@
 	<tr><td width=200 height=700 valign=top><div id='filelist' valign=top></div></td><td width=700 height=700 valign=top> <div id='inkscape'></div><div id='editor'></div></td></tr>
 </table>		
 <div id='filedialog'></div>
+
+<div id='wizard'>
+	The name of the project<br>
+	<input type=text id='wizardname' value='default'/><br>
+	Please select the type of applications.<br>
+	<ul>
+		<a href='#' onClick="wizard.step1_cb('text')"><li> Text only menu </li></a>
+		<a href='#' onClick="wizard.step1_cb('preview')"><li> Text with preview menu </li></a>
+	</ul>
+
+</div>
+
+<div id='wizard_step2'>
+	Please select the output path<br>
+	<input id='outputpath' type=file value='/tmp' /><br>
+	<a class 'buttopn' href='#'><span onClick='wizard.step1_cb()'>Prev</span></a>
+	<a class 'buttopn' href='#'><span onClick='wizard.step3_cb()'>Next</span></a>
+</div>
+<div id='wizard_step3'>
+	The step 3 is not implemented yet
+</div>
+
 <script type="text/javascript" src="inkscape.js" >
 </script>
 </body>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inkscape/firefox/content/wizard.js	Sun Mar 15 17:17:06 2009 +0800
@@ -0,0 +1,73 @@
+function Wizard()
+{
+	this.dialog = $('#wizard');
+	this.dialog.dialog({width:600,autoOpen:false});
+	this.step2 = $('#wizard_step2');
+	this.step2.dialog({width:600,autoOpen:false});
+	this.step3 = $('#wizard_step3');
+	this.step3.dialog({width:600,autoOpen:false});
+}
+
+
+Wizard.prototype.execute=function(cb)
+{
+	this.dialog.dialog('open');
+}
+
+aaa=1
+// In the first step, users will select the project type.
+Wizard.prototype.step1_cb=function(type)
+{
+	this.type = type;
+	var obj = $('#wizardname');
+	this.name = obj.attr('value');
+	this.step2.dialog('open');
+	this.dialog.dialog('close');
+	this.step3.dialog('close');
+}
+
+// In the step 2, get the output path
+Wizard.prototype.step2_cb=function()
+{
+	this.dir = $('#wizardpath').attr('value');
+	this.step2.dialog('close');
+	this.step3.dialog('open');
+}
+
+// In the step 3, generate files
+Wizard.prototype.step3_cb=function()
+{
+	this.generate_source('main.c','main.c');
+	this.generate_source('app.h',this.name+'.h');
+	this.generate_source('app.c',this.name+'.c');
+	this.generate_source('app.prj',this.name+'.prj');
+	this.generate_source('Makefile','Makefile');
+	this.done_cb();
+}
+
+Wizard.prototype.done_cb=function()
+{
+	this.step3.dialog('close');
+	this.cb(this.dir+this.name+'.prj');
+}
+
+
+Wizard.prototype.generate_source=function (tmpl,fname)
+{
+	var file = system_open_write(this.dir+'/'+fname);
+	var template = system_open_read('wizard/'+this.type+'/'+tmpl);
+	if (template == null) {
+		alert('Can not find template file '+tmpl);
+		return;
+	}
+	if (file == null) {
+		alert('Can not create '+fname);
+		return;
+	}
+	var data = template.read(template.available());
+	// FIXME: replace name here
+	file.write(data.data.length);
+	file.close();
+	template.close();
+}
+