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