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