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