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 {
|
371
|
32 this.dir = $('#outputpath').attr('value');
|
367
|
33 this.step2.dialog('close');
|
|
34 this.step3.dialog('open');
|
371
|
35 system_mkdir(this.dir);
|
367
|
36 this.generate_source('main.c','main.c');
|
371
|
37 this.step3.append('main.c<br>');
|
|
38 this.generate_source('list.mbsvg','list.mbsvg');
|
|
39 this.step3.append('list.mbsvg<br>');
|
367
|
40 this.generate_source('app.h',this.name+'.h');
|
371
|
41 this.step3.append(this.name+'.h<br>');
|
367
|
42 this.generate_source('app.c',this.name+'.c');
|
371
|
43 this.step3.append(this.name+'.c<br>');
|
367
|
44 this.generate_source('app.prj',this.name+'.prj');
|
371
|
45 this.step3.append('app.prj<br>');
|
367
|
46 this.generate_source('Makefile','Makefile');
|
371
|
47 this.step3.append('Makefile<br>');
|
367
|
48 this.done_cb();
|
|
49 }
|
|
50
|
|
51 Wizard.prototype.done_cb=function()
|
|
52 {
|
|
53 this.step3.dialog('close');
|
371
|
54 this.cb(this.dir+'/'+this.name+'.prj');
|
367
|
55 }
|
|
56
|
|
57
|
|
58 Wizard.prototype.generate_source=function (tmpl,fname)
|
|
59 {
|
|
60 var file = system_open_write(this.dir+'/'+fname);
|
371
|
61 var template = system_open_read('/usr/local/share/mb/template/'+this.type+'/'+tmpl);
|
367
|
62 if (template == null) {
|
|
63 return;
|
|
64 }
|
|
65 if (file == null) {
|
|
66 return;
|
|
67 }
|
|
68 var data = template.read(template.available());
|
371
|
69 var regex = /\%n/gi;
|
367
|
70 // FIXME: replace name here
|
371
|
71 data=data.replace(regex,this.name);
|
|
72 file.write(data,data.length);
|
367
|
73 file.close();
|
|
74 template.close();
|
|
75 }
|
|
76
|