src/Builder4/ValaCompileErrors.bjs
[app.Builder.js] / src / Builder4 / ValaCompileErrors.vala
1 static Xcls_ValaCompileErrors  _ValaCompileErrors;
2
3 public class Xcls_ValaCompileErrors : Object 
4 {
5     public Gtk.Popover el;
6     private Xcls_ValaCompileErrors  _this;
7
8     public static Xcls_ValaCompileErrors singleton()
9     {
10         if (_ValaCompileErrors == null) {
11             _ValaCompileErrors= new Xcls_ValaCompileErrors();
12         }
13         return _ValaCompileErrors;
14     }
15     public Xcls_compile_view compile_view;
16     public Xcls_hpane hpane;
17     public Xcls_compile_tree compile_tree;
18     public Xcls_compile_result_store compile_result_store;
19     public Xcls_renderer renderer;
20     public Xcls_sourceview sourceview;
21
22         // my vars (def)
23     public Xcls_MainWindow window;
24     public Json.Object notices;
25
26     // ctor 
27     public Xcls_ValaCompileErrors()
28     {
29         _this = this;
30         this.el = new Gtk.Popover( null );
31
32         // my vars (dec)
33
34         // set gobject values
35         this.el.width_request = 900;
36         this.el.height_request = 800;
37         this.el.modal = true;
38         this.el.position = Gtk.PositionType.TOP;
39         var child_0 = new Xcls_compile_view( _this );
40         child_0.ref();
41         this.el.add (  child_0.el  );
42     }
43
44     // user defined functions 
45     public void show (Json.Object tree, Gtk.Widget onbtn) {
46     
47             this.notices = tree;
48              //print("looking for %s\n", id);
49             // loop through parent childnre
50               
51             
52             var store = this.compile_result_store.el;    
53             
54             store.clear();
55          
56             
57             tree.foreach_member((obj, file, node) => {
58                 // id line "display text", file
59                 
60                 var title = GLib.Path.get_basename( file) ;
61                 Gtk.TreeIter iter;
62                 print("Add file %s", title);
63                 store.append(out iter, null);
64                 var lines = tree.get_object_member(file);
65                 title += " (" + lines.get_size().to_string() + ")";
66                 store.set(iter, 0, file, 1, 0, 2, title, 3, file,-1);
67                 
68                 lines.foreach_member((obja, line, nodea) => {
69                     var msg  = "";
70                     var ar = lines.get_array_member(line);
71                     for (var i = 0 ; i < ar.get_length(); i++) {
72                             msg += (msg.length > 0) ? "\n" : "";
73                             msg += ar.get_string_element(i);
74                 }
75                     Gtk.TreeIter citer;  
76                     print("Add line %s", line);
77                     store.append(out citer, iter);
78                     store.set(citer, 
79                         0, file + ":" + line, 
80                         1, int.parse(line), 
81                         2, GLib.Markup.escape_text(line + ": " + msg), 
82                         3, file,-1);
83                 
84                 });
85                 
86                 
87             
88             });
89                
90      
91         
92         this.hpane.el.set_position(250);
93        if (this.el.relative_to == null) {
94             this.el.set_relative_to(onbtn);
95         }
96         this.el.show_all();
97               
98     
99     }
100     public class Xcls_compile_view : Object 
101     {
102         public Gtk.VBox el;
103         private Xcls_ValaCompileErrors  _this;
104
105
106             // my vars (def)
107
108         // ctor 
109         public Xcls_compile_view(Xcls_ValaCompileErrors _owner )
110         {
111             _this = _owner;
112             _this.compile_view = this;
113             this.el = new Gtk.VBox( false, 0 );
114
115             // my vars (dec)
116
117             // set gobject values
118             var child_0 = new Xcls_HBox3( _this );
119             child_0.ref();
120             this.el.pack_start (  child_0.el , false,false,0 );
121             var child_1 = new Xcls_hpane( _this );
122             child_1.ref();
123             this.el.pack_start (  child_1.el , true,true,0 );
124         }
125
126         // user defined functions 
127     }
128     public class Xcls_HBox3 : Object 
129     {
130         public Gtk.HBox el;
131         private Xcls_ValaCompileErrors  _this;
132
133
134             // my vars (def)
135
136         // ctor 
137         public Xcls_HBox3(Xcls_ValaCompileErrors _owner )
138         {
139             _this = _owner;
140             this.el = new Gtk.HBox( true, 0 );
141
142             // my vars (dec)
143
144             // set gobject values
145             var child_0 = new Xcls_Button4( _this );
146             child_0.ref();
147             this.el.pack_start (  child_0.el , true,true,0 );
148         }
149
150         // user defined functions 
151     }
152     public class Xcls_Button4 : Object 
153     {
154         public Gtk.Button el;
155         private Xcls_ValaCompileErrors  _this;
156
157
158             // my vars (def)
159
160         // ctor 
161         public Xcls_Button4(Xcls_ValaCompileErrors _owner )
162         {
163             _this = _owner;
164             this.el = new Gtk.Button();
165
166             // my vars (dec)
167
168             // set gobject values
169             this.el.label = "Compile and Run";
170         }
171
172         // user defined functions 
173     }
174     public class Xcls_hpane : Object 
175     {
176         public Gtk.HPaned el;
177         private Xcls_ValaCompileErrors  _this;
178
179
180             // my vars (def)
181
182         // ctor 
183         public Xcls_hpane(Xcls_ValaCompileErrors _owner )
184         {
185             _this = _owner;
186             _this.hpane = this;
187             this.el = new Gtk.HPaned();
188
189             // my vars (dec)
190
191             // set gobject values
192             var child_0 = new Xcls_ScrolledWindow6( _this );
193             child_0.ref();
194             this.el.add (  child_0.el  );
195             var child_1 = new Xcls_ScrolledWindow11( _this );
196             child_1.ref();
197             this.el.add (  child_1.el  );
198         }
199
200         // user defined functions 
201     }
202     public class Xcls_ScrolledWindow6 : Object 
203     {
204         public Gtk.ScrolledWindow el;
205         private Xcls_ValaCompileErrors  _this;
206
207
208             // my vars (def)
209
210         // ctor 
211         public Xcls_ScrolledWindow6(Xcls_ValaCompileErrors _owner )
212         {
213             _this = _owner;
214             this.el = new Gtk.ScrolledWindow( null, null );
215
216             // my vars (dec)
217
218             // set gobject values
219             var child_0 = new Xcls_compile_tree( _this );
220             child_0.ref();
221             this.el.add (  child_0.el  );
222
223             // init method 
224
225             {
226              this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
227              
228             
229             }
230         }
231
232         // user defined functions 
233     }
234     public class Xcls_compile_tree : Object 
235     {
236         public Gtk.TreeView el;
237         private Xcls_ValaCompileErrors  _this;
238
239
240             // my vars (def)
241
242         // ctor 
243         public Xcls_compile_tree(Xcls_ValaCompileErrors _owner )
244         {
245             _this = _owner;
246             _this.compile_tree = this;
247             this.el = new Gtk.TreeView();
248
249             // my vars (dec)
250
251             // set gobject values
252             var child_0 = new Xcls_compile_result_store( _this );
253             child_0.ref();
254             this.el.set_model (  child_0.el  );
255             var child_1 = new Xcls_column( _this );
256             child_1.ref();
257             this.el.append_column (  child_1.el  );
258
259             // init method 
260
261             {
262              var description = new Pango.FontDescription();
263                 description.set_size(8000);
264                 this.el.modify_font(description);
265             
266             }
267
268             // listeners 
269             this.el.cursor_changed.connect( () => {
270                 var sel = this.el.get_selection();
271              
272                         if (sel.count_selected_rows() < 1) {
273             
274                             print("selected rows < 1\n");
275                             //??this.mo 
276                             return  ;
277                         }
278                             
279                             //console.log('changed');
280                          
281                          Gtk.TreeIter iter;
282                          Gtk.TreeModel mod;
283                         sel.get_selected(out mod, out iter);
284                         /*
285                          store.set(citer, 
286                                 0, file + ":" + line, 
287                                 1, int.parse(line), 
288                                 2, GLib.Markup.escape_text(line + ": " + msg), 
289                                 3, file,-1);
290                         
291                         });
292                         */
293                         
294                         
295                         
296                         // var val = "";
297                         GLib.Value value;
298                         _this.compile_result_store.el.get_value(iter, 3, out value);
299                         var fname = (string)value;
300                         GLib.Value lvalue;
301                         _this.compile_result_store.el.get_value(iter, 1, out lvalue);
302                         var line = (int) lvalue;
303                         
304                         print ("loadfile %s : %d", fname,line);
305                         
306                         _this.sourceview.loadFile(fname, line);
307                         
308                         
309                         
310                         
311             });
312         }
313
314         // user defined functions 
315     }
316     public class Xcls_compile_result_store : Object 
317     {
318         public Gtk.TreeStore el;
319         private Xcls_ValaCompileErrors  _this;
320
321
322             // my vars (def)
323
324         // ctor 
325         public Xcls_compile_result_store(Xcls_ValaCompileErrors _owner )
326         {
327             _this = _owner;
328             _this.compile_result_store = this;
329             this.el = new Gtk.TreeStore( 4,   typeof(string), typeof(int), typeof(string), typeof(string)  );
330
331             // my vars (dec)
332
333             // set gobject values
334         }
335
336         // user defined functions 
337     }
338     public class Xcls_column : Object 
339     {
340         public Gtk.TreeViewColumn el;
341         private Xcls_ValaCompileErrors  _this;
342
343
344             // my vars (def)
345
346         // ctor 
347         public Xcls_column(Xcls_ValaCompileErrors _owner )
348         {
349             _this = _owner;
350             this.el = new Gtk.TreeViewColumn();
351
352             // my vars (dec)
353
354             // set gobject values
355             this.el.title = "Compile output";
356             var child_0 = new Xcls_renderer( _this );
357             child_0.ref();
358             this.el.pack_start (  child_0.el , true );
359
360             // init method 
361
362             {
363               this.el.add_attribute(_this.renderer.el , "markup", 2 );
364              
365             }
366         }
367
368         // user defined functions 
369     }
370     public class Xcls_renderer : Object 
371     {
372         public Gtk.CellRendererText el;
373         private Xcls_ValaCompileErrors  _this;
374
375
376             // my vars (def)
377
378         // ctor 
379         public Xcls_renderer(Xcls_ValaCompileErrors _owner )
380         {
381             _this = _owner;
382             _this.renderer = this;
383             this.el = new Gtk.CellRendererText();
384
385             // my vars (dec)
386
387             // set gobject values
388         }
389
390         // user defined functions 
391     }
392     public class Xcls_ScrolledWindow11 : Object 
393     {
394         public Gtk.ScrolledWindow el;
395         private Xcls_ValaCompileErrors  _this;
396
397
398             // my vars (def)
399
400         // ctor 
401         public Xcls_ScrolledWindow11(Xcls_ValaCompileErrors _owner )
402         {
403             _this = _owner;
404             this.el = new Gtk.ScrolledWindow( null, null );
405
406             // my vars (dec)
407
408             // set gobject values
409             var child_0 = new Xcls_sourceview( _this );
410             child_0.ref();
411             this.el.add (  child_0.el  );
412         }
413
414         // user defined functions 
415     }
416     public class Xcls_sourceview : Object 
417     {
418         public Gtk.SourceView el;
419         private Xcls_ValaCompileErrors  _this;
420
421
422             // my vars (def)
423         public string curfname;
424
425         // ctor 
426         public Xcls_sourceview(Xcls_ValaCompileErrors _owner )
427         {
428             _this = _owner;
429             _this.sourceview = this;
430             this.el = new Gtk.SourceView();
431
432             // my vars (dec)
433
434             // set gobject values
435             this.el.editable = false;
436             this.el.show_line_marks = true;
437             this.el.show_line_numbers = true;
438
439             // init method 
440
441             {
442                 this.curfname = "";
443                    var description =   Pango.FontDescription.from_string("monospace");
444                 description.set_size(8000);
445                 this.el.override_font(description);
446             
447                 var attrs = new Gtk.SourceMarkAttributes();
448                 var  pink = new Gdk.RGBA();
449                 pink.parse ( "pink");
450                 attrs.set_background ( pink);
451                 attrs.set_icon_name ( "process-stop");    
452                 attrs.query_tooltip_text.connect(( mark) => {
453                     //print("tooltip query? %s\n", mark.name);
454                     return mark.name;
455                 });
456                 
457                 this.el.set_mark_attributes ("error", attrs, 1);
458                 
459             }
460         }
461
462         // user defined functions 
463         public void loadFile (string fname, int line ) {
464           var buf = ((Gtk.SourceBuffer)(this.el.get_buffer()));
465               
466             if (this.curfname != fname) {
467                 this.curfname = fname;
468         
469                 Gtk.TextIter start;
470                 Gtk.TextIter end;     
471                 buf.get_bounds (out start, out end);
472                     
473                 buf.remove_source_marks (start, end, null);
474                      
475                  
476                 
477                 string str;
478                 FileUtils.get_contents(fname, out str);
479                                 
480                 buf.set_text(str, str.length);
481                 var lm = Gtk.SourceLanguageManager.get_default();
482                 
483                
484                 buf.set_language(lm.get_language("vala"));
485              
486                  
487                 this.el.grab_focus();
488         
489         
490                
491                 var lines = _this.notices.get_object_member(fname);
492                  
493                     
494                 lines.foreach_member((obj, line, node) => {
495                     
496                          Gtk.TextIter iter;
497                 //        print("get inter\n");
498                         var eline = int.parse(line) -1 ;
499                          
500                         
501                         buf.get_iter_at_line( out iter, eline);
502                         //print("mark line\n");
503                         var msg  = "Line: %d".printf(eline+1);
504                         var ar = lines.get_array_member(line);
505                         for (var i = 0 ; i < ar.get_length(); i++) {
506                                 msg += (msg.length > 0) ? "\n" : "";
507                                 msg += ar.get_string_element(i);
508                         }
509                         
510                         
511                         buf.create_source_mark(msg, "error", iter);
512                     } );
513             }
514             // jump to the line...
515             Gtk.TextIter liter;
516             buf.get_iter_at_line (out liter,  line);
517             print("Scroll to \n");
518             this.el.scroll_to_iter (liter, 0.0f, false, 0.0f, 0.5f);
519             print("End Scroll to \n");
520         
521         
522         }
523     }
524 }