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