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