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                 
207             
208             
209             
210             });
211         }
212
213         // user defined functions 
214     }
215     public class Xcls_Button6 : Object 
216     {
217         public Gtk.Button el;
218         private Xcls_ValaCompileErrors  _this;
219
220
221             // my vars (def)
222
223         // ctor 
224         public Xcls_Button6(Xcls_ValaCompileErrors _owner )
225         {
226             _this = _owner;
227             this.el = new Gtk.Button();
228
229             // my vars (dec)
230
231             // set gobject values
232             this.el.label = "Save";
233             this.el.visible = false;
234         }
235
236         // user defined functions 
237     }
238     public class Xcls_hpane : Object 
239     {
240         public Gtk.HPaned el;
241         private Xcls_ValaCompileErrors  _this;
242
243
244             // my vars (def)
245
246         // ctor 
247         public Xcls_hpane(Xcls_ValaCompileErrors _owner )
248         {
249             _this = _owner;
250             _this.hpane = this;
251             this.el = new Gtk.HPaned();
252
253             // my vars (dec)
254
255             // set gobject values
256             var child_0 = new Xcls_ScrolledWindow8( _this );
257             child_0.ref();
258             this.el.add (  child_0.el  );
259             var child_1 = new Xcls_ScrolledWindow13( _this );
260             child_1.ref();
261             this.el.add (  child_1.el  );
262         }
263
264         // user defined functions 
265     }
266     public class Xcls_ScrolledWindow8 : Object 
267     {
268         public Gtk.ScrolledWindow el;
269         private Xcls_ValaCompileErrors  _this;
270
271
272             // my vars (def)
273
274         // ctor 
275         public Xcls_ScrolledWindow8(Xcls_ValaCompileErrors _owner )
276         {
277             _this = _owner;
278             this.el = new Gtk.ScrolledWindow( null, null );
279
280             // my vars (dec)
281
282             // set gobject values
283             var child_0 = new Xcls_compile_tree( _this );
284             child_0.ref();
285             this.el.add (  child_0.el  );
286
287             // init method 
288
289             {
290              this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
291              
292             
293             }
294         }
295
296         // user defined functions 
297     }
298     public class Xcls_compile_tree : Object 
299     {
300         public Gtk.TreeView el;
301         private Xcls_ValaCompileErrors  _this;
302
303
304             // my vars (def)
305
306         // ctor 
307         public Xcls_compile_tree(Xcls_ValaCompileErrors _owner )
308         {
309             _this = _owner;
310             _this.compile_tree = this;
311             this.el = new Gtk.TreeView();
312
313             // my vars (dec)
314
315             // set gobject values
316             var child_0 = new Xcls_compile_result_store( _this );
317             child_0.ref();
318             this.el.set_model (  child_0.el  );
319             var child_1 = new Xcls_column( _this );
320             child_1.ref();
321             this.el.append_column (  child_1.el  );
322
323             // init method 
324
325             {
326              var description = new Pango.FontDescription();
327                 description.set_size(8000);
328                 this.el.modify_font(description);
329             
330             }
331
332             // listeners 
333             this.el.cursor_changed.connect( () => {
334                 var sel = this.el.get_selection();
335              
336                         if (sel.count_selected_rows() < 1) {
337             
338                             print("selected rows < 1\n");
339                             //??this.mo 
340                             return  ;
341                         }
342                             
343                             //console.log('changed');
344                          
345                          Gtk.TreeIter iter;
346                          Gtk.TreeModel mod;
347                         sel.get_selected(out mod, out iter);
348                         /*
349                          store.set(citer, 
350                                 0, file + ":" + line, 
351                                 1, int.parse(line), 
352                                 2, GLib.Markup.escape_text(line + ": " + msg), 
353                                 3, file,-1);
354                         
355                         });
356                         */
357                         
358                         
359                         
360                         // var val = "";
361                         GLib.Value value;
362                         _this.compile_result_store.el.get_value(iter, 3, out value);
363                         var fname = (string)value;
364                         GLib.Value lvalue;
365                         _this.compile_result_store.el.get_value(iter, 1, out lvalue);
366                         var line = (int) lvalue;
367                         
368                         print ("loadfile %s : %d", fname,line);
369                         
370                         _this.sourceview.loadFile(fname, line);
371                         
372                         
373                         
374                         
375             });
376         }
377
378         // user defined functions 
379     }
380     public class Xcls_compile_result_store : Object 
381     {
382         public Gtk.TreeStore el;
383         private Xcls_ValaCompileErrors  _this;
384
385
386             // my vars (def)
387
388         // ctor 
389         public Xcls_compile_result_store(Xcls_ValaCompileErrors _owner )
390         {
391             _this = _owner;
392             _this.compile_result_store = this;
393             this.el = new Gtk.TreeStore( 4,   typeof(string), typeof(int), typeof(string), typeof(string)  );
394
395             // my vars (dec)
396
397             // set gobject values
398         }
399
400         // user defined functions 
401     }
402     public class Xcls_column : Object 
403     {
404         public Gtk.TreeViewColumn el;
405         private Xcls_ValaCompileErrors  _this;
406
407
408             // my vars (def)
409
410         // ctor 
411         public Xcls_column(Xcls_ValaCompileErrors _owner )
412         {
413             _this = _owner;
414             this.el = new Gtk.TreeViewColumn();
415
416             // my vars (dec)
417
418             // set gobject values
419             this.el.title = "Compile output";
420             var child_0 = new Xcls_renderer( _this );
421             child_0.ref();
422             this.el.pack_start (  child_0.el , true );
423
424             // init method 
425
426             {
427               this.el.add_attribute(_this.renderer.el , "markup", 2 );
428              
429             }
430         }
431
432         // user defined functions 
433     }
434     public class Xcls_renderer : Object 
435     {
436         public Gtk.CellRendererText el;
437         private Xcls_ValaCompileErrors  _this;
438
439
440             // my vars (def)
441
442         // ctor 
443         public Xcls_renderer(Xcls_ValaCompileErrors _owner )
444         {
445             _this = _owner;
446             _this.renderer = this;
447             this.el = new Gtk.CellRendererText();
448
449             // my vars (dec)
450
451             // set gobject values
452         }
453
454         // user defined functions 
455     }
456     public class Xcls_ScrolledWindow13 : Object 
457     {
458         public Gtk.ScrolledWindow el;
459         private Xcls_ValaCompileErrors  _this;
460
461
462             // my vars (def)
463
464         // ctor 
465         public Xcls_ScrolledWindow13(Xcls_ValaCompileErrors _owner )
466         {
467             _this = _owner;
468             this.el = new Gtk.ScrolledWindow( null, null );
469
470             // my vars (dec)
471
472             // set gobject values
473             var child_0 = new Xcls_sourceview( _this );
474             child_0.ref();
475             this.el.add (  child_0.el  );
476         }
477
478         // user defined functions 
479     }
480     public class Xcls_sourceview : Object 
481     {
482         public Gtk.SourceView el;
483         private Xcls_ValaCompileErrors  _this;
484
485
486             // my vars (def)
487         public string curfname;
488
489         // ctor 
490         public Xcls_sourceview(Xcls_ValaCompileErrors _owner )
491         {
492             _this = _owner;
493             _this.sourceview = this;
494             this.el = new Gtk.SourceView();
495
496             // my vars (dec)
497
498             // set gobject values
499             this.el.editable = false;
500             this.el.show_line_marks = true;
501             this.el.show_line_numbers = true;
502
503             // init method 
504
505             {
506                 this.curfname = "";
507                    var description =   Pango.FontDescription.from_string("monospace");
508                 description.set_size(8000);
509                 this.el.override_font(description);
510             
511                 var attrs = new Gtk.SourceMarkAttributes();
512                 var  pink = new Gdk.RGBA();
513                 pink.parse ( "pink");
514                 attrs.set_background ( pink);
515                 attrs.set_icon_name ( "process-stop");    
516                 attrs.query_tooltip_text.connect(( mark) => {
517                     //print("tooltip query? %s\n", mark.name);
518                     return mark.name;
519                 });
520                 
521                 this.el.set_mark_attributes ("error", attrs, 1);
522                 
523             }
524         }
525
526         // user defined functions 
527         public void loadFile (string fname, int line ) {
528           var buf = ((Gtk.SourceBuffer)(this.el.get_buffer()));
529               
530             if (this.curfname != fname) {
531                 this.curfname = fname;
532         
533                 Gtk.TextIter start;
534                 Gtk.TextIter end;     
535                 buf.get_bounds (out start, out end);
536                     
537                 buf.remove_source_marks (start, end, null);
538                      
539                  
540                 
541                 string str;
542                 FileUtils.get_contents(fname, out str);
543                                 
544                 buf.set_text(str, str.length);
545                 var lm = Gtk.SourceLanguageManager.get_default();
546                 
547                
548                 buf.set_language(lm.get_language("vala"));
549              
550                  
551                 this.el.grab_focus();
552         
553         
554                
555                 var lines = _this.notices.get_object_member(fname);
556                  
557                     
558                 lines.foreach_member((obj, line, node) => {
559                     
560                          Gtk.TextIter iter;
561                 //        print("get inter\n");
562                         var eline = int.parse(line) -1 ;
563                          
564                         
565                         buf.get_iter_at_line( out iter, eline);
566                         //print("mark line\n");
567                         var msg  = "Line: %d".printf(eline+1);
568                         var ar = lines.get_array_member(line);
569                         for (var i = 0 ; i < ar.get_length(); i++) {
570                                 msg += (msg.length > 0) ? "\n" : "";
571                                 msg += ar.get_string_element(i);
572                         }
573                         
574                         
575                         buf.create_source_mark(msg, "error", iter);
576                     } );
577             }
578             // jump to the line...
579             Gtk.TextIter liter;
580             buf.get_iter_at_line (out liter,  line);
581             print("Scroll to \n");
582             this.el.scroll_to_iter (liter, 0.0f, false, 0.0f, 0.5f);
583             print("End Scroll to \n");
584         
585         
586         }
587     }
588 }