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