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_compile_tree compile_tree;
17     public Xcls_compile_result_store compile_result_store;
18     public Xcls_renderer renderer;
19
20         // my vars (def)
21     public Xcls_MainWindow window;
22     public bool active;
23     public JsRender.JsRender? file;
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         this.active = false;
34
35         // set gobject values
36         this.el.width_request = 900;
37         this.el.height_request = 800;
38         this.el.modal = false;
39         this.el.position = Gtk.PositionType.TOP;
40         var child_0 = new Xcls_compile_view( _this );
41         child_0.ref();
42         this.el.add (  child_0.el  );
43
44         //listeners
45         this.el.closed.connect( () => {
46           /*  if (this.active) {
47                 this.el.show();
48                 return;
49             }
50            */
51         });
52     }
53
54     // user defined functions
55     public void show (Json.Object tree, Gtk.Widget onbtn) {
56     
57             
58             this.file = null;
59             this.notices = tree;
60            
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(250, 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     
116         if (this.el.relative_to == null) {
117             this.el.set_relative_to(onbtn);
118         }
119         this.el.show_all();
120        
121         while(Gtk.events_pending()) { 
122                 Gtk.main_iteration();
123         }       
124      //   this.hpane.el.set_position( 0);
125     }
126     public class Xcls_compile_view : Object
127     {
128         public Gtk.VBox el;
129         private Xcls_ValaCompileErrors  _this;
130
131
132             // my vars (def)
133
134         // ctor
135         public Xcls_compile_view(Xcls_ValaCompileErrors _owner )
136         {
137             _this = _owner;
138             _this.compile_view = this;
139             this.el = new Gtk.VBox( false, 0 );
140
141             // my vars (dec)
142
143             // set gobject values
144             var child_0 = new Xcls_HBox3( _this );
145             child_0.ref();
146             this.el.pack_start (  child_0.el , false,false,0 );
147             var child_1 = new Xcls_ScrolledWindow5( _this );
148             child_1.ref();
149             this.el.add (  child_1.el  );
150         }
151
152         // user defined functions
153     }
154     public class Xcls_HBox3 : Object
155     {
156         public Gtk.HBox el;
157         private Xcls_ValaCompileErrors  _this;
158
159
160             // my vars (def)
161
162         // ctor
163         public Xcls_HBox3(Xcls_ValaCompileErrors _owner )
164         {
165             _this = _owner;
166             this.el = new Gtk.HBox( true, 0 );
167
168             // my vars (dec)
169
170             // set gobject values
171             var child_0 = new Xcls_Button4( _this );
172             child_0.ref();
173             this.el.pack_start (  child_0.el , true,true,0 );
174         }
175
176         // user defined functions
177     }
178     public class Xcls_Button4 : Object
179     {
180         public Gtk.Button el;
181         private Xcls_ValaCompileErrors  _this;
182
183
184             // my vars (def)
185
186         // ctor
187         public Xcls_Button4(Xcls_ValaCompileErrors _owner )
188         {
189             _this = _owner;
190             this.el = new Gtk.Button();
191
192             // my vars (dec)
193
194             // set gobject values
195             this.el.label = "Compile and Run ";
196         }
197
198         // user defined functions
199     }
200
201
202     public class Xcls_ScrolledWindow5 : Object
203     {
204         public Gtk.ScrolledWindow el;
205         private Xcls_ValaCompileErrors  _this;
206
207
208             // my vars (def)
209
210         // ctor
211         public Xcls_ScrolledWindow5(Xcls_ValaCompileErrors _owner )
212         {
213             _this = _owner;
214             this.el = new Gtk.ScrolledWindow( null, null );
215
216             // my vars (dec)
217
218             // set gobject values
219             var child_0 = new Xcls_compile_tree( _this );
220             child_0.ref();
221             this.el.add (  child_0.el  );
222
223             // init method
224
225             {
226              this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
227              
228             
229             }
230         }
231
232         // user defined functions
233     }
234     public class Xcls_compile_tree : Object
235     {
236         public Gtk.TreeView el;
237         private Xcls_ValaCompileErrors  _this;
238
239
240             // my vars (def)
241
242         // ctor
243         public Xcls_compile_tree(Xcls_ValaCompileErrors _owner )
244         {
245             _this = _owner;
246             _this.compile_tree = this;
247             this.el = new Gtk.TreeView();
248
249             // my vars (dec)
250
251             // set gobject values
252             var child_0 = new Xcls_compile_result_store( _this );
253             child_0.ref();
254             this.el.set_model (  child_0.el  );
255             var child_1 = new Xcls_column( _this );
256             child_1.ref();
257             this.el.append_column (  child_1.el  );
258
259             // init method
260
261             {
262              var description = new Pango.FontDescription();
263                 description.set_size(8000);
264                 this.el.modify_font(description);
265             
266             }
267
268             //listeners
269             this.el.button_press_event.connect( ( ev)  => {
270              
271                 Gtk.TreeViewColumn col;
272                 int cell_x;
273                 int cell_y;
274                 Gtk.TreePath path;
275                 if (!this.el.get_path_at_pos((int)ev.x, (int) ev.y, out path, out col, out cell_x, out cell_y )) {
276                     print("nothing selected on click");
277                     
278                     return false; //not on a element.
279                 }
280                 
281                  
282                  // right click.
283                  if (ev.type != Gdk.EventType.2BUTTON_PRESS  || ev.button != 1  ) {    
284                     // show popup!.   
285                         
286                      
287                     return false;
288                 }
289                 
290                 Gtk.TreeIter iter;
291                  Gtk.TreeModel mod;
292                 sel.get_selected(out mod, out iter);
293                  
294                 
295                 
296                 
297                 // var val = "";
298                 GLib.Value value;
299                 _this.compile_result_store.el.get_value(iter, 3, out value);
300                 var fname = (string)value;
301                 GLib.Value lvalue;
302                 _this.compile_result_store.el.get_value(iter, 1, out lvalue);
303                 var line = (int) lvalue;
304                 
305                 
306                 
307                 /*
308                  var f = _this.sourceview.curfname;
309                             
310                     Regex regex = new Regex("\\.vala$");
311                 
312                     var bjsf = regex.replace(f,f.length , 0 , ".bjs");
313                     
314                     var p = _this.window.project;
315                     
316                     
317                     
318                     var jsr = p.getByPath(bjsf);
319                     if (jsr != null) {
320                         _this.window.windowstate.fileViewOpen(jsr);
321                         
322                         return;
323                     
324                     }
325                 
326                 
327               });
328             this.el.cursor_changed.connect( () => {
329                 var sel = this.el.get_selection();
330             
331                 if (sel.count_selected_rows() < 1) {
332             
333                     print("selected rows < 1\n");
334                     //??this.mo 
335                     return  ;
336                 }
337                     
338                     //console.log('changed');
339                  
340                  Gtk.TreeIter iter;
341                  Gtk.TreeModel mod;
342                 sel.get_selected(out mod, out iter);
343                  
344                 
345                 
346                 
347                 // var val = "";
348                 GLib.Value value;
349                 _this.compile_result_store.el.get_value(iter, 3, out value);
350                 var fname = (string)value;
351                 GLib.Value lvalue;
352                 _this.compile_result_store.el.get_value(iter, 1, out lvalue);
353                 var line = (int) lvalue;
354                 
355                 
356                 
357              
358                 
359                 
360                 print ("loadfile %s : %d", fname,line);
361                 
362                // _this.sourceview.loadFile(fname, line);
363                 /*
364                     var f = _this.sourceview.curfname;
365                             
366                     Regex regex = new Regex("\\.vala$");
367                 
368                     var bjsf = regex.replace(f,f.length , 0 , ".bjs");
369                     
370                     var p = _this.window.project;
371                     
372                     
373                     
374                     var jsr = p.getByPath(bjsf);
375                     if (jsr != null) {
376                         _this.window.windowstate.fileViewOpen(jsr);
377                         
378                         return;
379                     
380                     }
381                      */   
382                         
383             });
384         }
385
386         // user defined functions
387     }
388     public class Xcls_compile_result_store : Object
389     {
390         public Gtk.TreeStore el;
391         private Xcls_ValaCompileErrors  _this;
392
393
394             // my vars (def)
395
396         // ctor
397         public Xcls_compile_result_store(Xcls_ValaCompileErrors _owner )
398         {
399             _this = _owner;
400             _this.compile_result_store = this;
401             this.el = new Gtk.TreeStore( 4,   typeof(string), typeof(int), typeof(string), typeof(string)  );
402
403             // my vars (dec)
404
405             // set gobject values
406         }
407
408         // user defined functions
409     }
410
411     public class Xcls_column : Object
412     {
413         public Gtk.TreeViewColumn el;
414         private Xcls_ValaCompileErrors  _this;
415
416
417             // my vars (def)
418
419         // ctor
420         public Xcls_column(Xcls_ValaCompileErrors _owner )
421         {
422             _this = _owner;
423             this.el = new Gtk.TreeViewColumn();
424
425             // my vars (dec)
426
427             // set gobject values
428             this.el.title = "Compile output";
429             var child_0 = new Xcls_renderer( _this );
430             child_0.ref();
431             this.el.pack_start (  child_0.el , true );
432
433             // init method
434
435             {
436               this.el.add_attribute(_this.renderer.el , "markup", 2 );
437              
438             }
439         }
440
441         // user defined functions
442     }
443     public class Xcls_renderer : Object
444     {
445         public Gtk.CellRendererText el;
446         private Xcls_ValaCompileErrors  _this;
447
448
449             // my vars (def)
450
451         // ctor
452         public Xcls_renderer(Xcls_ValaCompileErrors _owner )
453         {
454             _this = _owner;
455             _this.renderer = this;
456             this.el = new Gtk.CellRendererText();
457
458             // my vars (dec)
459
460             // set gobject values
461         }
462
463         // user defined functions
464     }
465
466
467
468
469
470 }