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                 Gtk.TreeIter iter;
290                  var mod = _this.compile_result_store.el;
291                 mod.get_iter (out iter, path);
292                 
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                  var f = fname;
307                  Regex regex;
308                 try {             
309                     regex = new Regex("\\.vala$");
310                 } catch (Error e) {
311                     return false;
312                 }
313                 
314                 var bjsf = regex.replace(f,f.length , 0 , ".bjs");
315                     
316                 var p = _this.window.project;
317                     
318                     
319                     
320                 var jsr = p.getByPath(bjsf);
321                 if (jsr != null) {
322                     _this.window.windowstate.fileViewOpen(jsr);
323                     
324                     return false;
325                 
326                 }
327                  return false;
328                 
329               });
330             this.el.cursor_changed.connect( () => {
331                 var sel = this.el.get_selection();
332             
333                 if (sel.count_selected_rows() < 1) {
334             
335                     print("selected rows < 1\n");
336                     //??this.mo 
337                     return  ;
338                 }
339                     
340                     //console.log('changed');
341                  
342                  Gtk.TreeIter iter;
343                  Gtk.TreeModel mod;
344                 sel.get_selected(out mod, out iter);
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                 
358                 
359              
360                 
361                 
362                 print ("loadfile %s : %d", fname,line);
363                 
364                // _this.sourceview.loadFile(fname, line);
365                 /*
366                     var f = _this.sourceview.curfname;
367                             
368                     Regex regex = new Regex("\\.vala$");
369                 
370                     var bjsf = regex.replace(f,f.length , 0 , ".bjs");
371                     
372                     var p = _this.window.project;
373                     
374                     
375                     
376                     var jsr = p.getByPath(bjsf);
377                     if (jsr != null) {
378                         _this.window.windowstate.fileViewOpen(jsr);
379                         
380                         return;
381                     
382                     }
383                      */   
384                         
385             });
386         }
387
388         // user defined functions
389     }
390     public class Xcls_compile_result_store : Object
391     {
392         public Gtk.TreeStore el;
393         private Xcls_ValaCompileErrors  _this;
394
395
396             // my vars (def)
397
398         // ctor
399         public Xcls_compile_result_store(Xcls_ValaCompileErrors _owner )
400         {
401             _this = _owner;
402             _this.compile_result_store = this;
403             this.el = new Gtk.TreeStore( 4,   typeof(string), typeof(int), typeof(string), typeof(string)  );
404
405             // my vars (dec)
406
407             // set gobject values
408         }
409
410         // user defined functions
411     }
412
413     public class Xcls_column : Object
414     {
415         public Gtk.TreeViewColumn el;
416         private Xcls_ValaCompileErrors  _this;
417
418
419             // my vars (def)
420
421         // ctor
422         public Xcls_column(Xcls_ValaCompileErrors _owner )
423         {
424             _this = _owner;
425             this.el = new Gtk.TreeViewColumn();
426
427             // my vars (dec)
428
429             // set gobject values
430             this.el.title = "Compile output";
431             var child_0 = new Xcls_renderer( _this );
432             child_0.ref();
433             this.el.pack_start (  child_0.el , true );
434
435             // init method
436
437             {
438               this.el.add_attribute(_this.renderer.el , "markup", 2 );
439              
440             }
441         }
442
443         // user defined functions
444     }
445     public class Xcls_renderer : Object
446     {
447         public Gtk.CellRendererText el;
448         private Xcls_ValaCompileErrors  _this;
449
450
451             // my vars (def)
452
453         // ctor
454         public Xcls_renderer(Xcls_ValaCompileErrors _owner )
455         {
456             _this = _owner;
457             _this.renderer = this;
458             this.el = new Gtk.CellRendererText();
459
460             // my vars (dec)
461
462             // set gobject values
463         }
464
465         // user defined functions
466     }
467
468
469
470
471
472 }