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