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 = true;
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
45     // user defined functions
46     public void show (Json.Object tree, Gtk.Widget onbtn) {
47     
48             
49             this.file = null;
50             this.notices = tree;
51            
52              //print("looking for %s\n", id);
53             // loop through parent childnre
54               
55             
56             var store = this.compile_result_store.el;    
57             
58             store.clear();
59          
60             
61             tree.foreach_member((obj, file, node) => {
62                 // id line "display text", file
63                 
64                 var title = GLib.Path.get_basename(GLib.Path.get_dirname( file)) + "/" +  GLib.Path.get_basename( file) ;
65                 Gtk.TreeIter iter;
66                 print("Add file %s", title);
67                 store.append(out iter, null);
68                 var lines = tree.get_object_member(file);
69                 title += " (" + lines.get_size().to_string() + ")";
70                 store.set(iter, 0, file, 1, 0, 2, title, 3, file,-1);
71                 
72                 lines.foreach_member((obja, line, nodea) => {
73                     var msg  = "";
74                     var ar = lines.get_array_member(line);
75                     for (var i = 0 ; i < ar.get_length(); i++) {
76                             msg += (msg.length > 0) ? "\n" : "";
77                             msg += ar.get_string_element(i);
78                 }
79                     Gtk.TreeIter citer;  
80                     print("Add line %s", line);
81                     store.append(out citer, iter);
82                     store.set(citer, 
83                         0, file + ":" + line, 
84                         1, int.parse(line), 
85                         2, GLib.Markup.escape_text(line + ": " + msg), 
86                         3, file,-1);
87                 
88                 });
89                 
90                 
91             
92             });
93             
94         int w,h;
95         this.window.el.get_size(out w, out h);
96         
97         // left tree = 250, editor area = 500?
98         
99         var new_w = int.min(250, w-100);
100         if (new_w > (w-100)) {
101             new_w = w-100;
102         }
103         this.el.set_size_request( int.max(100, new_w), int.max(100, h-120));
104     
105         
106     
107         if (this.el.relative_to == null) {
108             this.el.set_relative_to(onbtn);
109         }
110         this.el.show_all();
111        
112         while(Gtk.events_pending()) { 
113                 Gtk.main_iteration();
114         }       
115      //   this.hpane.el.set_position( 0);
116     }
117     public class Xcls_compile_view : Object
118     {
119         public Gtk.VBox el;
120         private Xcls_ValaCompileErrors  _this;
121
122
123             // my vars (def)
124
125         // ctor
126         public Xcls_compile_view(Xcls_ValaCompileErrors _owner )
127         {
128             _this = _owner;
129             _this.compile_view = this;
130             this.el = new Gtk.VBox( false, 0 );
131
132             // my vars (dec)
133
134             // set gobject values
135             var child_0 = new Xcls_HBox3( _this );
136             child_0.ref();
137             this.el.pack_start (  child_0.el , false,false,0 );
138             var child_1 = new Xcls_ScrolledWindow5( _this );
139             child_1.ref();
140             this.el.add (  child_1.el  );
141         }
142
143         // user defined functions
144     }
145     public class Xcls_HBox3 : Object
146     {
147         public Gtk.HBox el;
148         private Xcls_ValaCompileErrors  _this;
149
150
151             // my vars (def)
152
153         // ctor
154         public Xcls_HBox3(Xcls_ValaCompileErrors _owner )
155         {
156             _this = _owner;
157             this.el = new Gtk.HBox( true, 0 );
158
159             // my vars (dec)
160
161             // set gobject values
162             var child_0 = new Xcls_Button4( _this );
163             child_0.ref();
164             this.el.pack_start (  child_0.el , true,true,0 );
165         }
166
167         // user defined functions
168     }
169     public class Xcls_Button4 : Object
170     {
171         public Gtk.Button el;
172         private Xcls_ValaCompileErrors  _this;
173
174
175             // my vars (def)
176
177         // ctor
178         public Xcls_Button4(Xcls_ValaCompileErrors _owner )
179         {
180             _this = _owner;
181             this.el = new Gtk.Button();
182
183             // my vars (dec)
184
185             // set gobject values
186             this.el.label = "Compile and Run ";
187         }
188
189         // user defined functions
190     }
191
192
193     public class Xcls_ScrolledWindow5 : Object
194     {
195         public Gtk.ScrolledWindow el;
196         private Xcls_ValaCompileErrors  _this;
197
198
199             // my vars (def)
200
201         // ctor
202         public Xcls_ScrolledWindow5(Xcls_ValaCompileErrors _owner )
203         {
204             _this = _owner;
205             this.el = new Gtk.ScrolledWindow( null, null );
206
207             // my vars (dec)
208
209             // set gobject values
210             var child_0 = new Xcls_compile_tree( _this );
211             child_0.ref();
212             this.el.add (  child_0.el  );
213
214             // init method
215
216             {
217              this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
218              
219             
220             }
221         }
222
223         // user defined functions
224     }
225     public class Xcls_compile_tree : Object
226     {
227         public Gtk.TreeView el;
228         private Xcls_ValaCompileErrors  _this;
229
230
231             // my vars (def)
232
233         // ctor
234         public Xcls_compile_tree(Xcls_ValaCompileErrors _owner )
235         {
236             _this = _owner;
237             _this.compile_tree = this;
238             this.el = new Gtk.TreeView();
239
240             // my vars (dec)
241
242             // set gobject values
243             var child_0 = new Xcls_compile_result_store( _this );
244             child_0.ref();
245             this.el.set_model (  child_0.el  );
246             var child_1 = new Xcls_column( _this );
247             child_1.ref();
248             this.el.append_column (  child_1.el  );
249
250             // init method
251
252             {
253              var description = new Pango.FontDescription();
254                 description.set_size(8000);
255                 this.el.modify_font(description);
256             
257             }
258
259             //listeners
260             this.el.button_press_event.connect( ( ev)  => {
261              
262                 Gtk.TreeViewColumn col;
263                 int cell_x;
264                 int cell_y;
265                 Gtk.TreePath path;
266                 if (!this.el.get_path_at_pos((int)ev.x, (int) ev.y, out path, out col, out cell_x, out cell_y )) {
267                     print("nothing selected on click");
268                     
269                     return false; //not on a element.
270                 }
271                 
272                  
273                  // right click.
274                  if (ev.type != Gdk.EventType.2BUTTON_PRESS  || ev.button != 1  ) {    
275                     // show popup!.   
276                         
277                      
278                     return false;
279                 }
280                 Gtk.TreeIter iter;
281                  var mod = _this.compile_result_store.el;
282                 mod.get_iter (out iter, path);
283                 
284                  
285                 
286                 
287                 
288                 // var val = "";
289                 GLib.Value value;
290                 _this.compile_result_store.el.get_value(iter, 3, out value);
291                 var fname = (string)value;
292                 //GLib.Value lvalue;
293                 //_this.compile_result_store.el.get_value(iter, 1, out lvalue);
294                 //var line = (int) lvalue;
295                 
296                 
297                var  bjsf = "";
298                 try {             
299                    var  regex = new Regex("\\.vala$");
300                 
301                  
302                     bjsf = regex.replace(fname,fname.length , 0 , ".bjs");
303                  } catch (GLib.RegexError e) {
304                     return false;
305                 }   
306                 var p = _this.window.project;
307                     
308                     
309                     
310                 var jsr = p.getByPath(bjsf);
311                 if (jsr != null) {
312                     _this.window.windowstate.fileViewOpen(jsr);
313                     
314                     return false;
315                 
316                 }
317                  return false;
318                 
319               });
320         }
321
322         // user defined functions
323     }
324     public class Xcls_compile_result_store : Object
325     {
326         public Gtk.TreeStore el;
327         private Xcls_ValaCompileErrors  _this;
328
329
330             // my vars (def)
331
332         // ctor
333         public Xcls_compile_result_store(Xcls_ValaCompileErrors _owner )
334         {
335             _this = _owner;
336             _this.compile_result_store = this;
337             this.el = new Gtk.TreeStore( 4,   typeof(string), typeof(int), typeof(string), typeof(string)  );
338
339             // my vars (dec)
340
341             // set gobject values
342         }
343
344         // user defined functions
345     }
346
347     public class Xcls_column : Object
348     {
349         public Gtk.TreeViewColumn el;
350         private Xcls_ValaCompileErrors  _this;
351
352
353             // my vars (def)
354
355         // ctor
356         public Xcls_column(Xcls_ValaCompileErrors _owner )
357         {
358             _this = _owner;
359             this.el = new Gtk.TreeViewColumn();
360
361             // my vars (dec)
362
363             // set gobject values
364             this.el.title = "Compile output";
365             var child_0 = new Xcls_renderer( _this );
366             child_0.ref();
367             this.el.pack_start (  child_0.el , true );
368
369             // init method
370
371             {
372               this.el.add_attribute(_this.renderer.el , "markup", 2 );
373              
374             }
375         }
376
377         // user defined functions
378     }
379     public class Xcls_renderer : Object
380     {
381         public Gtk.CellRendererText el;
382         private Xcls_ValaCompileErrors  _this;
383
384
385             // my vars (def)
386
387         // ctor
388         public Xcls_renderer(Xcls_ValaCompileErrors _owner )
389         {
390             _this = _owner;
391             _this.renderer = this;
392             this.el = new Gtk.CellRendererText();
393
394             // my vars (dec)
395
396             // set gobject values
397         }
398
399         // user defined functions
400     }
401
402
403
404
405
406 }