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