src/Main.vala
[app.Builder.js] / src / Main.vala
1 /**
2  * Test the writer code...
3
4
5 */
6  
7 int main (string[] args) {
8         
9         
10         
11         
12         new JsRender.Lang_Class();
13
14         var app =  BuilderApplication.singleton(  args);
15         
16         if (BuilderApplication.opt_debug  || BuilderApplication.opt_compile_project == null) {
17                 GLib.Log.set_handler(null, 
18                         GLib.LogLevelFlags.LEVEL_DEBUG | GLib.LogLevelFlags.LEVEL_WARNING, 
19                         (dom, lvl, msg) => {
20                         print("%s: %s\n", dom, msg);
21                 });
22         }
23         
24      
25         if (BuilderApplication.opt_list_projects) {
26                  
27                 //BuilderApplication.compileBjs();
28         Project.Project.loadAll();
29                 print("Projects\n %s\n", Project.Project.listAllToString());
30                 GLib.Process.exit(Posix.EXIT_SUCCESS);
31         }
32     Project.Project.loadAll();
33     
34     if (BuilderApplication.opt_list_projects) {
35                  
36                 //BuilderApplication.compileBjs();
37
38                 print("Projects\n %s\n", Project.Project.listAllToString());
39                 GLib.Process.exit(Posix.EXIT_SUCCESS);
40         }
41         Project.Project cur_project = null;
42     if (BuilderApplication.opt_compile_project != null) {
43                  
44                  
45                 cur_project = Project.Project.getProjectByHash( BuilderApplication.opt_compile_project);
46                 
47                 if (cur_project == null) {
48                         GLib.error("invalid project %s, use --list-projects to show project ids",BuilderApplication.opt_compile_project);
49                 }
50                 cur_project.scanDirs();
51                 
52                 
53         }
54         
55         if (BuilderApplication.opt_list_files) {
56                 if (cur_project == null) {
57                         GLib.error("missing project, use --project to select which project");
58                 }
59                 print("Files for %s\n %s\n", cur_project.name, cur_project.listAllFilesToString());
60                 GLib.Process.exit(Posix.EXIT_SUCCESS);
61         }
62     
63     if (BuilderApplication.opt_bjs_compile != null) {
64                 if (cur_project == null) {
65                         GLib.error("missing project, use --project to select which project");
66                 }       
67                 var file = cur_project.getByName(BuilderApplication.opt_bjs_compile);
68                 if (file == null) {
69                         GLib.error("missing file %s in project %s", BuilderApplication.opt_bjs_compile, cur_project.name);
70                 }
71                 //BuilderApplication.compileBjs();
72                 file.loadItems();
73         var str = file.toSourceCode();
74           
75           
76         if (!BuilderApplication.opt_debug) {
77                 print("%s", str);
78                 GLib.Process.exit(Posix.EXIT_SUCCESS);
79                 }
80                 
81                 
82         var str_ar = str.split("\n");
83         for(var i =0;i<str_ar.length;i++) {
84                 var node = file.tree.lineToNode(i+1);
85                 var prop = node == null ? null : node.lineToProp(i+1);
86                 print("%d: %s   :  %s\n", 
87                         i+1, 
88                         node == null ? "......"  : (prop == null ? "????????" : prop),
89                         str_ar[i]
90                         );
91         }
92                 
93                 GLib.Process.exit(Posix.EXIT_SUCCESS);
94         }
95         
96     
97         if (BuilderApplication.opt_compile_target != null) {
98                  
99                 Palete.ValaSourceCompiler.buildApplication();
100                 
101                 GLib.Process.exit(Posix.EXIT_SUCCESS);
102         }
103         
104          
105         
106         GLib.debug("project = %s\n", BuilderApplication.opt_compile_project);
107         
108         Gtk.init (ref args);
109          
110         GtkClutter.init (ref args);
111
112         GLib.Log.set_always_fatal(LogLevelFlags.LEVEL_ERROR | LogLevelFlags.LEVEL_CRITICAL); 
113         
114     
115     
116     // respond to other arguments
117     
118         /*var proj = Project.Project.getProject("Pman.Core");
119         if (proj == null) {
120                 print("could not load test project Pman.Core");
121                 return 0;
122         }
123         proj.scanDirs();
124         */
125
126         var w = Xcls_MainWindow.singleton();
127         //w.ref();
128         //w.project = proj;
129         
130         w.el.show_all();
131         // it looks like showall after children causes segfault on ubuntu 14.4
132         w.initChildren();
133         w.windowstate.switchState(WindowState.State.FILES);
134         
135         Gtk.main();
136     app = null;
137         
138         return 0;
139 }