change run to use meson/ninja and then exec. - remove libvala code from application...
[roobuilder] / src / JsRender / Gtk.vala
1 /**
2  * 
3  *  this is the code represents a File when using the Gtk view..
4  *   
5  *  It ues NodeToGtk
6  * 
7  * 
8  */
9
10 namespace JsRender {
11
12
13  
14         int gid = 1;
15
16   
17         public  class Gtk : JsRender
18         {
19            
20            
21            public Project.Gtk gproject { 
22                         get {
23                                 return (Project.Gtk) this.project;
24                         }
25                         private set {}
26                 }
27
28             public Gtk(Project.Project project, string path) {
29             
30                 base( project, path);
31                 this.xtype = "Gtk";
32                 this.language = "vala";
33                 
34                 
35                 //this.items = false;
36                 //if (cfg.json) {
37                 //    var jstr =  JSON.parse(cfg.json);
38                 //    this.items = [ jstr ];
39                 //    //console.log(cfg.items.length);
40                 //    delete cfg.json; // not needed!
41                 // }
42                  
43                 
44                 
45                 // super?!?!
46                 this.id = "file-gtk-%d".printf(gid++);
47                 //console.dump(this);
48                 // various loader methods..
49
50                 // Class = list of arguments ... and which property to use as a value.
51            
52
53                 
54                 
55             }
56               
57
58             /*
59             setNSID : function(id)
60             {
61                 
62                 this.items[0]['*class'] = id;
63                 
64                 
65             },
66             getType: function() {
67                 return 'Gtk';
68             },
69             */
70
71                 public   override void   removeFiles() {
72                         var js = GLib.Path.get_dirname(this.path) +"/" +  name + ".js";
73                         if (FileUtils.test(js, FileTest.EXISTS)) {
74                                 GLib.FileUtils.remove(js);
75                         }
76                         var vala = GLib.Path.get_dirname(this.path) +"/" + name + ".vala";
77                         if (FileUtils.test(vala, FileTest.EXISTS)) {
78                                 GLib.FileUtils.remove(vala);
79                         }
80                 }
81             
82                 public   override void  loadItems() throws GLib.Error // : function(cb, sync) == original was async.
83                 {
84                   
85                         print("load Items!\n");
86                         if (this.tree != null) {
87                                 this.loaded = true;
88                         
89                                 return;
90                         }
91                         /*
92                         print("load: %s\n" , this.path);
93                         if (!GLib.FileUtils.test(this.path, GLib.FileTest.EXISTS)) {
94                                 // new file?!?
95                                 this.tree = null;
96                                 this.loaded = true;
97                                 return;
98                         }
99                         */
100
101                         var pa = new Json.Parser();
102                         pa.load_from_file(this.path);
103                         var node = pa.get_root();
104                 
105                         if (node.get_node_type () != Json.NodeType.OBJECT) {
106                                 throw new Error.INVALID_FORMAT ("Unexpected element type %s", node.type_name ());
107                         }
108                         var obj = node.get_object ();
109                 
110                         this.name = obj.get_string_member("name");
111  
112                 
113                         if (obj.has_member("build_module")) { // should check type really..
114                                 this.build_module = obj.get_string_member("build_module");
115                         }
116                         if (obj.has_member("gen_extended")) { // should check type really..
117                                 this.gen_extended = obj.get_boolean_member("gen_extended");
118                         }
119                         
120                          
121                         
122                         // load items[0] ??? into tree...
123                         var bjs_version_str = this.jsonHasOrEmpty(obj, "bjs-version");
124                         bjs_version_str = bjs_version_str == "" ? "1" : bjs_version_str;
125
126                         if (obj.has_member("items") 
127                                 && 
128                                 obj.get_member("items").get_node_type() == Json.NodeType.ARRAY
129                                 &&
130                                 obj.get_array_member("items").get_length() > 0
131                         ) {
132                                 var ar = obj.get_array_member("items");
133                                 var tree_base = ar.get_object_element(0);
134                                 this.tree = new Node();
135                                 this.tree.loadFromJson(tree_base, int.parse(bjs_version_str));
136
137                         }
138                         NodeToVala.mungeFile(this); // force line numbering..
139                         this.loaded = true;
140                 
141                 }
142              
143             
144         
145             public override string toSourcePreview()
146             {
147                         return "";
148                 }
149             public override void setSource(string str) {}
150             
151             int last_source_version = -2;
152             string last_source;
153             public override string toSourceCode() // no seed support currently.
154             {
155                     if (this.version == this.last_source_version) {
156                         return this.last_source;
157                 }
158                     this.last_source =   NodeToVala.mungeFile(this);
159                     this.last_source_version = this.version;
160                     return this.last_source;
161                     
162             }
163             
164             // this is only used by dumping code...
165             public override string toSource() // no seed support currently.
166             {
167                  
168                          return  this.toSourceCode();
169                 
170                 
171             }
172         
173             public override void save() {
174                 this.saveBJS();
175                 // this.saveJS(); - disabled at present.. project settings will probably enable this later..
176         
177                 this.saveVala();
178
179                 this.getLanguageServer().document_save(this);
180                 BuilderApplication.showSpinner("spinner", "document save send");                
181             }
182                 // ignore these calls.
183             public override void saveHTML ( string html ) {}
184                 
185                         
186             /** 
187              *  saveJS
188              * 
189              * save as a javascript file. - not used currently
190              * why is this not save...???
191              * 
192              
193               
194             void saveJS()
195             {
196                  
197                 var fn = GLib.Path.get_dirname(this.path) + "/" + this.name + ".js";
198                 print("WRITE :%s\n " , fn);
199                 this.writeFile(fn, this.toSource());
200                 
201             }
202             */
203             
204             public override string targetName()
205             {
206                 return GLib.Path.get_dirname(this.path) + "/" + this.name + ".vala";
207         }
208             
209             void  saveVala()
210             {
211                         if (this.tree == null) {
212                                 return;
213                         }
214                         var fn = this.targetName();
215                         GLib.debug("WRITE :%s\n " , fn);
216                         try {
217                                 this.writeFile(fn,  NodeToVala.mungeFile(this));
218                 } catch (GLib.Error e) {}
219                 
220                 
221             }
222             
223             
224             public void updateCompileGroup(string old_target, string new_target) 
225             {
226                 if (old_target == new_target) {
227                         return;
228                 }
229                 if (old_target != "") {
230                         if (this.gproject.compilegroups.has_key(old_target)) {
231                                 var cg = this.gproject.compilegroups.get(old_target);
232                                 if (cg.sources.contains(this.relpath)) {
233                                         cg.sources.remove(this.relpath);
234                                         }
235                                 }
236                         }
237                  if (new_target != "") {
238                         if (this.gproject.compilegroups.has_key(new_target)) {
239                                 var cg = this.gproject.compilegroups.get(new_target);
240                                 if (!cg.sources.contains(this.relpath)) {
241                                         cg.sources.add(this.relpath);
242                                         }
243                                 }
244                         }
245             
246             
247             }
248             
249                 /*
250             valaCompileCmd : function()
251             {
252                 
253                 var fn = '/tmp/' + this.name + '.vala';
254                 print("WRITE : " + fn);
255                 File.write(fn, this.toVala(true));
256                 
257                 
258                 
259                 return ["valac",
260                        "--pkg",  "gio-2.0",
261                        "--pkg" , "posix" ,
262                        "--pkg" , "gtk+-3.0",
263                        "--pkg",  "libnotify",
264                        "--pkg",  "gtksourceview-3.0",
265                        "--pkg", "libwnck-3.0",
266                        fn ,   "-o", "/tmp/" + this.name];
267                 
268                
269                  
270                 
271             },
272             */
273              
274             public override void  findTransStrings(Node? node )
275                 {
276                         // not yet..
277                 }
278
279                 public override string toGlade() 
280                 {
281                         return  NodeToGlade.mungeFile(this);
282                 }
283                 public   override string language_id() 
284                 {
285                         return "vala";
286                 }
287
288         
289
290         }
291 }
292
293
294