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