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