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_save_btn save_btn;
17     public Xcls_hpane hpane;
18     public Xcls_compile_tree compile_tree;
19     public Xcls_compile_result_store compile_result_store;
20     public Xcls_renderer renderer;
21     public Xcls_sourceview sourceview;
22
23         // my vars (def)
24     public Xcls_MainWindow window;
25     public bool active;
26     public JsRender.JsRender? file;
27     public Json.Object notices;
28
29     // ctor 
30     public Xcls_ValaCompileErrors()
31     {
32         _this = this;
33         this.el = new Gtk.Popover( null );
34
35         // my vars (dec)
36         this.active = false;
37
38         // set gobject values
39         this.el.width_request = 900;
40         this.el.height_request = 800;
41         this.el.modal = false;
42         this.el.position = Gtk.PositionType.TOP;
43         var child_0 = new Xcls_compile_view( _this );
44         child_0.ref();
45         this.el.add (  child_0.el  );
46
47         // listeners 
48         this.el.closed.connect( () => {
49             if (this.active) {
50                 this.el.show();
51                 return;
52             }
53            
54         });
55     }
56
57     // user defined functions 
58     public void show (Json.Object tree, Gtk.Widget onbtn) {
59     
60             
61             this.file = null;
62             this.notices = tree;
63             this.active = true;
64              //print("looking for %s\n", id);
65             // loop through parent childnre
66               
67             
68             var store = this.compile_result_store.el;    
69             
70             store.clear();
71          
72             
73             tree.foreach_member((obj, file, node) => {
74                 // id line "display text", file
75                 
76                 var title = GLib.Path.get_basename(GLib.Path.get_dirname( file)) + "/" +  GLib.Path.get_basename( file) ;
77                 Gtk.TreeIter iter;
78                 print("Add file %s", title);
79                 store.append(out iter, null);
80                 var lines = tree.get_object_member(file);
81                 title += " (" + lines.get_size().to_string() + ")";
82                 store.set(iter, 0, file, 1, 0, 2, title, 3, file,-1);
83                 
84                 lines.foreach_member((obja, line, nodea) => {
85                     var msg  = "";
86                     var ar = lines.get_array_member(line);
87                     for (var i = 0 ; i < ar.get_length(); i++) {
88                             msg += (msg.length > 0) ? "\n" : "";
89                             msg += ar.get_string_element(i);
90                 }
91                     Gtk.TreeIter citer;  
92                     print("Add line %s", line);
93                     store.append(out citer, iter);
94                     store.set(citer, 
95                         0, file + ":" + line, 
96                         1, int.parse(line), 
97                         2, GLib.Markup.escape_text(line + ": " + msg), 
98                         3, file,-1);
99                 
100                 });
101                 
102                 
103             
104             });
105             
106         int w,h;
107         this.window.el.get_size(out w, out h);
108         
109         // left tree = 250, editor area = 500?
110         
111         var new_w = int.min(750, w-100);
112         if (new_w > (w-100)) {
113             new_w = w-100;
114         }
115         this.el.set_size_request( int.max(100, new_w), int.max(100, h-120));
116     
117         
118         this.hpane.el.set_position( int.max(100, new_w));
119        if (this.el.relative_to == null) {
120             this.el.set_relative_to(onbtn);
121         }
122         this.el.show_all();
123         this.save_btn.el.hide();          
124     
125     }
126     public class Xcls_compile_view : Object 
127     {
128         public Gtk.VBox el;
129         private Xcls_ValaCompileErrors  _this;
130
131
132             // my vars (def)
133
134         // ctor 
135         public Xcls_compile_view(Xcls_ValaCompileErrors _owner )
136         {
137             _this = _owner;
138             _this.compile_view = this;
139             this.el = new Gtk.VBox( false, 0 );
140
141             // my vars (dec)
142
143             // set gobject values
144             var child_0 = new Xcls_HBox3( _this );
145             child_0.ref();
146             this.el.pack_start (  child_0.el , false,false,0 );
147             var child_1 = new Xcls_hpane( _this );
148             child_1.ref();
149             this.el.pack_start (  child_1.el , true,true,0 );
150         }
151
152         // user defined functions 
153     }
154     public class Xcls_HBox3 : Object 
155     {
156         public Gtk.HBox el;
157         private Xcls_ValaCompileErrors  _this;
158
159
160             // my vars (def)
161
162         // ctor 
163         public Xcls_HBox3(Xcls_ValaCompileErrors _owner )
164         {
165             _this = _owner;
166             this.el = new Gtk.HBox( true, 0 );
167
168             // my vars (dec)
169
170             // set gobject values
171             var child_0 = new Xcls_Button4( _this );
172             child_0.ref();
173             this.el.pack_start (  child_0.el , true,true,0 );
174             var child_1 = new Xcls_Button5( _this );
175             child_1.ref();
176             this.el.pack_start (  child_1.el , true,true,0 );
177             var child_2 = new Xcls_save_btn( _this );
178             child_2.ref();
179             this.el.pack_start (  child_2.el , true,true,0 );
180         }
181
182         // user defined functions 
183     }
184     public class Xcls_Button4 : Object 
185     {
186         public Gtk.Button el;
187         private Xcls_ValaCompileErrors  _this;
188
189
190             // my vars (def)
191
192         // ctor 
193         public Xcls_Button4(Xcls_ValaCompileErrors _owner )
194         {
195             _this = _owner;
196             this.el = new Gtk.Button();
197
198             // my vars (dec)
199
200             // set gobject values
201             this.el.label = "Compile and Run";
202         }
203
204         // user defined functions 
205     }
206     public class Xcls_Button5 : Object 
207     {
208         public Gtk.Button el;
209         private Xcls_ValaCompileErrors  _this;
210
211
212             // my vars (def)
213
214         // ctor 
215         public Xcls_Button5(Xcls_ValaCompileErrors _owner )
216         {
217             _this = _owner;
218             this.el = new Gtk.Button();
219
220             // my vars (dec)
221
222             // set gobject values
223             this.el.label = "Edit";
224
225             // listeners 
226             this.el.clicked.connect( () => {
227                 // is the file managed by the builder?
228                 
229                 var f = _this.sourceview.curfname;
230                 
231                 Regex regex = new Regex("\\.vala$");
232             
233                 var bjsf = regex.replace(f,f.length , 0 , ".bjs");
234                 
235                 var p = _this.window.project;
236                 
237                 
238                 
239                 var jsr = p.getByPath(bjsf);
240                 if (jsr != null) {
241                     _this.window.windowstate.fileViewOpen(jsr);
242                     
243                     return;
244                 
245                 }
246             
247             
248             });
249         }
250
251         // user defined functions 
252     }
253     public class Xcls_save_btn : Object 
254     {
255         public Gtk.Button el;
256         private Xcls_ValaCompileErrors  _this;
257
258
259             // my vars (def)
260
261         // ctor 
262         public Xcls_save_btn(Xcls_ValaCompileErrors _owner )
263         {
264             _this = _owner;
265             _this.save_btn = this;
266             this.el = new Gtk.Button();
267
268             // my vars (dec)
269
270             // set gobject values
271             this.el.label = "Save";
272             this.el.visible = false;
273         }
274
275         // user defined functions 
276     }
277     public class Xcls_hpane : Object 
278     {
279         public Gtk.HPaned el;
280         private Xcls_ValaCompileErrors  _this;
281
282
283             // my vars (def)
284
285         // ctor 
286         public Xcls_hpane(Xcls_ValaCompileErrors _owner )
287         {
288             _this = _owner;
289             _this.hpane = this;
290             this.el = new Gtk.HPaned();
291
292             // my vars (dec)
293
294             // set gobject values
295             var child_0 = new Xcls_ScrolledWindow8( _this );
296             child_0.ref();
297             this.el.add (  child_0.el  );
298             var child_1 = new Xcls_ScrolledWindow13( _this );
299             child_1.ref();
300             this.el.add (  child_1.el  );
301         }
302
303         // user defined functions 
304     }
305     public class Xcls_ScrolledWindow8 : Object 
306     {
307         public Gtk.ScrolledWindow el;
308         private Xcls_ValaCompileErrors  _this;
309
310
311             // my vars (def)
312
313         // ctor 
314         public Xcls_ScrolledWindow8(Xcls_ValaCompileErrors _owner )
315         {
316             _this = _owner;
317             this.el = new Gtk.ScrolledWindow( null, null );
318
319             // my vars (dec)
320
321             // set gobject values
322             var child_0 = new Xcls_compile_tree( _this );
323             child_0.ref();
324             this.el.add (  child_0.el  );
325
326             // init method 
327
328             {
329              this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
330              
331             
332             }
333         }
334
335         // user defined functions 
336     }
337     public class Xcls_compile_tree : Object 
338     {
339         public Gtk.TreeView el;
340         private Xcls_ValaCompileErrors  _this;
341
342
343             // my vars (def)
344
345         // ctor 
346         public Xcls_compile_tree(Xcls_ValaCompileErrors _owner )
347         {
348             _this = _owner;
349             _this.compile_tree = this;
350             this.el = new Gtk.TreeView();
351
352             // my vars (dec)
353
354             // set gobject values
355             var child_0 = new Xcls_compile_result_store( _this );
356             child_0.ref();
357             this.el.set_model (  child_0.el  );
358             var child_1 = new Xcls_column( _this );
359             child_1.ref();
360             this.el.append_column (  child_1.el  );
361
362             // init method 
363
364             {
365              var description = new Pango.FontDescription();
366                 description.set_size(8000);
367                 this.el.modify_font(description);
368             
369             }
370
371             // listeners 
372             this.el.cursor_changed.connect( () => {
373                 var sel = this.el.get_selection();
374             
375                 if (sel.count_selected_rows() < 1) {
376             
377                     print("selected rows < 1\n");
378                     //??this.mo 
379                     return  ;
380                 }
381                     
382                     //console.log('changed');
383                  
384                  Gtk.TreeIter iter;
385                  Gtk.TreeModel mod;
386                 sel.get_selected(out mod, out iter);
387                 /*
388                  store.set(citer, 
389                         0, file + ":" + line, 
390                         1, int.parse(line), 
391                         2, GLib.Markup.escape_text(line + ": " + msg), 
392                         3, file,-1);
393                 
394                 });
395                 */
396                 
397                 
398                 
399                 // var val = "";
400                 GLib.Value value;
401                 _this.compile_result_store.el.get_value(iter, 3, out value);
402                 var fname = (string)value;
403                 GLib.Value lvalue;
404                 _this.compile_result_store.el.get_value(iter, 1, out lvalue);
405                 var line = (int) lvalue;
406                 
407                 
408                 
409              
410                 
411                 
412                 print ("loadfile %s : %d", fname,line);
413                 
414                 _this.sourceview.loadFile(fname, line);
415                 
416                 
417                         
418                         
419             });
420         }
421
422         // user defined functions 
423     }
424     public class Xcls_compile_result_store : Object 
425     {
426         public Gtk.TreeStore el;
427         private Xcls_ValaCompileErrors  _this;
428
429
430             // my vars (def)
431
432         // ctor 
433         public Xcls_compile_result_store(Xcls_ValaCompileErrors _owner )
434         {
435             _this = _owner;
436             _this.compile_result_store = this;
437             this.el = new Gtk.TreeStore( 4,   typeof(string), typeof(int), typeof(string), typeof(string)  );
438
439             // my vars (dec)
440
441             // set gobject values
442         }
443
444         // user defined functions 
445     }
446     public class Xcls_column : Object 
447     {
448         public Gtk.TreeViewColumn el;
449         private Xcls_ValaCompileErrors  _this;
450
451
452             // my vars (def)
453
454         // ctor 
455         public Xcls_column(Xcls_ValaCompileErrors _owner )
456         {
457             _this = _owner;
458             this.el = new Gtk.TreeViewColumn();
459
460             // my vars (dec)
461
462             // set gobject values
463             this.el.title = "Compile output";
464             var child_0 = new Xcls_renderer( _this );
465             child_0.ref();
466             this.el.pack_start (  child_0.el , true );
467
468             // init method 
469
470             {
471               this.el.add_attribute(_this.renderer.el , "markup", 2 );
472              
473             }
474         }
475
476         // user defined functions 
477     }
478     public class Xcls_renderer : Object 
479     {
480         public Gtk.CellRendererText el;
481         private Xcls_ValaCompileErrors  _this;
482
483
484             // my vars (def)
485
486         // ctor 
487         public Xcls_renderer(Xcls_ValaCompileErrors _owner )
488         {
489             _this = _owner;
490             _this.renderer = this;
491             this.el = new Gtk.CellRendererText();
492
493             // my vars (dec)
494
495             // set gobject values
496         }
497
498         // user defined functions 
499     }
500     public class Xcls_ScrolledWindow13 : Object 
501     {
502         public Gtk.ScrolledWindow el;
503         private Xcls_ValaCompileErrors  _this;
504
505
506             // my vars (def)
507
508         // ctor 
509         public Xcls_ScrolledWindow13(Xcls_ValaCompileErrors _owner )
510         {
511             _this = _owner;
512             this.el = new Gtk.ScrolledWindow( null, null );
513
514             // my vars (dec)
515
516             // set gobject values
517             var child_0 = new Xcls_sourceview( _this );
518             child_0.ref();
519             this.el.add (  child_0.el  );
520         }
521
522         // user defined functions 
523     }
524     public class Xcls_sourceview : Object 
525     {
526         public Gtk.SourceView el;
527         private Xcls_ValaCompileErrors  _this;
528
529
530             // my vars (def)
531         public string curfname;
532
533         // ctor 
534         public Xcls_sourceview(Xcls_ValaCompileErrors _owner )
535         {
536             _this = _owner;
537             _this.sourceview = this;
538             this.el = new Gtk.SourceView();
539
540             // my vars (dec)
541
542             // set gobject values
543             this.el.editable = false;
544             this.el.show_line_marks = true;
545             this.el.show_line_numbers = true;
546
547             // init method 
548
549             {
550                 this.curfname = "";
551                    var description =   Pango.FontDescription.from_string("monospace");
552                 description.set_size(8000);
553                 this.el.override_font(description);
554             
555                 var attrs = new Gtk.SourceMarkAttributes();
556                 var  pink = new Gdk.RGBA();
557                 pink.parse ( "pink");
558                 attrs.set_background ( pink);
559                 attrs.set_icon_name ( "process-stop");    
560                 attrs.query_tooltip_text.connect(( mark) => {
561                     //print("tooltip query? %s\n", mark.name);
562                     return mark.name;
563                 });
564                 
565                 this.el.set_mark_attributes ("error", attrs, 1);
566                 
567             }
568         }
569
570         // user defined functions 
571         public void loadFile (string fname, int line ) {
572         
573          
574             
575         
576         
577             var buf = ((Gtk.SourceBuffer)(this.el.get_buffer()));
578               
579             if (this.curfname != fname) {
580                 this.curfname = fname;
581                 
582                 
583                 Regex regex = new Regex("\\.vala$");
584         
585                 var bjsf = regex.replace(fname,fname.length , 0 , ".bjs");
586                 
587                 var p = _this.window.project;
588                 
589                 var jsr = p.getByPath(bjsf);
590                 
591                 if (_this.file != null) {
592                     // remove listeners from the file...
593                 }
594                 
595                 _this.file = null;
596                 
597                 if (jsr != null) {
598                     _this.file = jsr;
599                     
600                     return;
601                 
602                 }
603                 
604                 
605                 
606         
607                 Gtk.TextIter start;
608                 Gtk.TextIter end;     
609                 buf.get_bounds (out start, out end);
610                     
611                 buf.remove_source_marks (start, end, null);
612                      
613                  
614                 
615                 string str;
616                 FileUtils.get_contents(fname, out str);
617                                 
618                 buf.set_text(str, str.length);
619                 var lm = Gtk.SourceLanguageManager.get_default();
620                 
621                
622                 buf.set_language(lm.get_language("vala"));
623              
624                  
625                 this.el.grab_focus();
626         
627         
628                
629                 var lines = _this.notices.get_object_member(fname);
630                  
631                     
632                 lines.foreach_member((obj, line, node) => {
633                     
634                          Gtk.TextIter iter;
635                 //        print("get inter\n");
636                         var eline = int.parse(line) -1 ;
637                          
638                         
639                         buf.get_iter_at_line( out iter, eline);
640                         //print("mark line\n");
641                         var msg  = "Line: %d".printf(eline+1);
642                         var ar = lines.get_array_member(line);
643                         for (var i = 0 ; i < ar.get_length(); i++) {
644                                 msg += (msg.length > 0) ? "\n" : "";
645                                 msg += ar.get_string_element(i);
646                         }
647                         
648                         
649                         buf.create_source_mark(msg, "error", iter);
650                     } );
651             }
652             // jump to the line...
653             Gtk.TextIter liter;
654             buf.get_iter_at_line (out liter,  line);
655             print("Scroll to \n");
656             this.el.scroll_to_iter (liter, 0.0f, false, 0.0f, 0.5f);
657             print("End Scroll to \n");
658         
659         
660         }
661     }
662 }