367
|
1 function Wizard()
|
|
2 {
|
|
3 this.dialog = $('#wizard');
|
|
4 this.dialog.dialog({width:600,autoOpen:false});
|
|
5 this.step2 = $('#wizard_step2');
|
|
6 this.step2.dialog({width:600,autoOpen:false});
|
|
7 this.step3 = $('#wizard_step3');
|
|
8 this.step3.dialog({width:600,autoOpen:false});
|
|
9 }
|
|
10
|
|
11
|
|
12 Wizard.prototype.execute=function(cb)
|
|
13 {
|
|
14 this.dialog.dialog('open');
|
|
15 }
|
|
16
|
|
17 aaa=1
|
|
18 // In the first step, users will select the project type.
|
|
19 Wizard.prototype.step1_cb=function(type)
|
|
20 {
|
|
21 this.type = type;
|
|
22 var obj = $('#wizardname');
|
|
23 this.name = obj.attr('value');
|
|
24 this.step2.dialog('open');
|
|
25 this.dialog.dialog('close');
|
|
26 this.step3.dialog('close');
|
|
27 }
|
|
28
|
|
29 // In the step 2, get the output path
|
|
30 Wizard.prototype.step2_cb=function()
|
|
31 {
|
|
32 this.dir = $('#wizardpath').attr('value');
|
|
33 this.step2.dialog('close');
|
|
34 this.step3.dialog('open');
|
|
35 }
|
|
36
|
|
37 // In the step 3, generate files
|
|
38 Wizard.prototype.step3_cb=function()
|
|
39 {
|
|
40 this.generate_source('main.c','main.c');
|
|
41 this.generate_source('app.h',this.name+'.h');
|
|
42 this.generate_source('app.c',this.name+'.c');
|
|
43 this.generate_source('app.prj',this.name+'.prj');
|
|
44 this.generate_source('Makefile','Makefile');
|
|
45 this.done_cb();
|
|
46 }
|
|
47
|
|
48 Wizard.prototype.done_cb=function()
|
|
49 {
|
|
50 this.step3.dialog('close');
|
|
51 this.cb(this.dir+this.name+'.prj');
|
|
52 }
|
|
53
|
|
54
|
|
55 Wizard.prototype.generate_source=function (tmpl,fname)
|
|
56 {
|
|
57 var file = system_open_write(this.dir+'/'+fname);
|
|
58 var template = system_open_read('wizard/'+this.type+'/'+tmpl);
|
|
59 if (template == null) {
|
|
60 alert('Can not find template file '+tmpl);
|
|
61 return;
|
|
62 }
|
|
63 if (file == null) {
|
|
64 alert('Can not create '+fname);
|
|
65 return;
|
|
66 }
|
|
67 var data = template.read(template.available());
|
|
68 // FIXME: replace name here
|
|
69 file.write(data.data.length);
|
|
70 file.close();
|
|
71 template.close();
|
|
72 }
|
|
73
|