295f01cc0d9896200e878ba1080a43ad421697bc
[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_tree tree;
17         public Xcls_selmodel selmodel;
18         public Xcls_sortmodel sortmodel;
19         public Xcls_model model;
20
21             // my vars (def)
22         public Xcls_MainWindow window;
23         public GLib.ListStore notices;
24
25         // ctor
26         public Xcls_ValaCompileErrors()
27         {
28             _this = this;
29             this.el = new Gtk.Popover();
30
31             // my vars (dec)
32
33             // set gobject values
34             this.el.width_request = 900;
35             this.el.height_request = 800;
36             this.el.autohide = true;
37             this.el.position = Gtk.PositionType.TOP;
38             new Xcls_compile_view( _this );
39             this.el.set_child ( _this.compile_view.el  );
40         }
41
42         // user defined functions
43         public void show ( GLib.ListStore ls , Gtk.Widget onbtn) {
44         
45             
46                 //this.el.present();
47             //this.el.popup();
48             this.notices = ls;
49            
50              //print("looking for %s\n", id);
51             // loop through parent childnre
52               
53             
54               this.tree.el.hide(); //<< very important!!!
55               
56            // store.set_sort_column_id(0,Gtk.SortType.ASCENDING);
57          
58             var win = this.window.el;
59             var  w = win.get_width();
60             var h = win.get_height();
61         
62           
63              
64             // left tree = 250, editor area = 500?
65             
66             // min 450?
67             var new_w = int.min(650, w-100);
68             if (new_w > (w-100)) {
69                 new_w = w-100;
70             }
71             this.el.set_size_request( int.max(100, new_w), int.max(100, h-120));
72          
73         
74            // this.el.set_relative_to(onbtn);
75                 //Gtk.Allocation rect;
76                 //onbtn.get_allocation(out rect);
77             //this.el.set_pointing_to(rect);
78                 this.el.present();
79             this.el.popup();
80            
81          
82                 var tm = new Gtk.TreeListModel(
83                         ls, //..... << that's our store..
84                         false, // passthru
85                         false, // autexpand
86                         (item) => {
87                         
88                                  return ((Palete.CompileError)item).lines;
89                         
90                         }
91                 );
92          
93             _this.model.el = tm;
94             _this.sortmodel.el.set_model(tm);
95          
96                  this.tree.el.show();   
97            
98                 //if (expand != null) {
99             //  _this.compile_tree.el.expand_row(   store.get_path(expand) , true);
100         //      }
101             
102          //   this.hpane.el.set_position( 0);
103         }
104         public class Xcls_compile_view : Object
105         {
106             public Gtk.Box el;
107             private Xcls_ValaCompileErrors  _this;
108
109
110                 // my vars (def)
111
112             // ctor
113             public Xcls_compile_view(Xcls_ValaCompileErrors _owner )
114             {
115                 _this = _owner;
116                 _this.compile_view = this;
117                 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
118
119                 // my vars (dec)
120
121                 // set gobject values
122                 this.el.homogeneous = false;
123                 this.el.hexpand = false;
124                 var child_1 = new Xcls_ScrolledWindow3( _this );
125                 child_1.ref();
126                 this.el.append( child_1.el );
127             }
128
129             // user defined functions
130         }
131         public class Xcls_ScrolledWindow3 : Object
132         {
133             public Gtk.ScrolledWindow el;
134             private Xcls_ValaCompileErrors  _this;
135
136
137                 // my vars (def)
138
139             // ctor
140             public Xcls_ScrolledWindow3(Xcls_ValaCompileErrors _owner )
141             {
142                 _this = _owner;
143                 this.el = new Gtk.ScrolledWindow();
144
145                 // my vars (dec)
146
147                 // set gobject values
148                 new Xcls_tree( _this );
149                 this.el.set_child ( _this.tree.el  );
150
151                 // init method
152
153                 {
154                  this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
155                  
156                 
157                 }
158             }
159
160             // user defined functions
161         }
162         public class Xcls_tree : Object
163         {
164             public Gtk.ColumnView el;
165             private Xcls_ValaCompileErrors  _this;
166
167
168                 // my vars (def)
169
170             // ctor
171             public Xcls_tree(Xcls_ValaCompileErrors _owner )
172             {
173                 _this = _owner;
174                 _this.tree = this;
175                 new Xcls_selmodel( _this );
176                 this.el = new Gtk.ColumnView( _this.selmodel.el );
177
178                 // my vars (dec)
179
180                 // set gobject values
181                 this.el.hexpand = true;
182                 this.el.vexpand = true;
183                 var child_2 = new Xcls_ColumnViewColumn8( _this );
184                 child_2.ref();
185                 this.el.append_column ( child_2.el  );
186                 var child_3 = new Xcls_GestureClick10( _this );
187                 child_3.ref();
188                 this.el.add_controller(  child_3.el );
189             }
190
191             // user defined functions
192         }
193         public class Xcls_selmodel : Object
194         {
195             public Gtk.SingleSelection el;
196             private Xcls_ValaCompileErrors  _this;
197
198
199                 // my vars (def)
200
201             // ctor
202             public Xcls_selmodel(Xcls_ValaCompileErrors _owner )
203             {
204                 _this = _owner;
205                 _this.selmodel = this;
206                 new Xcls_sortmodel( _this );
207                 this.el = new Gtk.SingleSelection( _this.sortmodel.el );
208
209                 // my vars (dec)
210
211                 // set gobject values
212             }
213
214             // user defined functions
215             public Json.Object getNodeAt (uint row) {
216             
217                var tr = (Gtk.TreeListRow)this.el.get_item(row);
218                
219                var a = tr.get_item();;   
220                GLib.debug("get_item (2) = %s", a.get_type().name());
221                 
222                return (Json.Object)tr.get_item();
223                  
224             }
225         }
226         public class Xcls_sortmodel : Object
227         {
228             public Gtk.SortListModel el;
229             private Xcls_ValaCompileErrors  _this;
230
231
232                 // my vars (def)
233
234             // ctor
235             public Xcls_sortmodel(Xcls_ValaCompileErrors _owner )
236             {
237                 _this = _owner;
238                 _this.sortmodel = this;
239                 new Xcls_model( _this );
240                 this.el = new Gtk.SortListModel( _this.model.el, null );
241
242                 // my vars (dec)
243
244                 // set gobject values
245             }
246
247             // user defined functions
248             public Json.Object getNodeAt (uint row) {
249             
250                var tr = (Gtk.TreeListRow)this.el.get_item(row);
251                
252               
253               // GLib.debug("get_item (2) = %s", a.get_type().name());
254                 
255                
256                return (Json.Object)tr.get_item();
257                  
258             }
259         }
260         public class Xcls_model : Object
261         {
262             public Gtk.TreeListModel el;
263             private Xcls_ValaCompileErrors  _this;
264
265
266                 // my vars (def)
267
268             // ctor
269             public Xcls_model(Xcls_ValaCompileErrors _owner )
270             {
271                 _this = _owner;
272                 _this.model = this;
273                 this.el = new Gtk.TreeListModel(
274     new GLib.ListStore(typeof(Palete.CompileError)), //..... << that's our store..
275     false, // passthru
276     false, // autexpand
277     (item) => {
278     
279          
280          return ((Palete.CompileError)item).lines;
281     
282     }
283     
284     
285 );
286
287                 // my vars (dec)
288
289                 // set gobject values
290             }
291
292             // user defined functions
293         }
294
295
296
297         public class Xcls_ColumnViewColumn8 : Object
298         {
299             public Gtk.ColumnViewColumn el;
300             private Xcls_ValaCompileErrors  _this;
301
302
303                 // my vars (def)
304
305             // ctor
306             public Xcls_ColumnViewColumn8(Xcls_ValaCompileErrors _owner )
307             {
308                 _this = _owner;
309                 var child_1 = new Xcls_SignalListItemFactory9( _this );
310                 child_1.ref();
311                 this.el = new Gtk.ColumnViewColumn( "Compile Result", child_1.el );
312
313                 // my vars (dec)
314
315                 // set gobject values
316                 this.el.expand = true;
317                 this.el.resizable = true;
318             }
319
320             // user defined functions
321         }
322         public class Xcls_SignalListItemFactory9 : Object
323         {
324             public Gtk.SignalListItemFactory el;
325             private Xcls_ValaCompileErrors  _this;
326
327
328                 // my vars (def)
329
330             // ctor
331             public Xcls_SignalListItemFactory9(Xcls_ValaCompileErrors _owner )
332             {
333                 _this = _owner;
334                 this.el = new Gtk.SignalListItemFactory();
335
336                 // my vars (dec)
337
338                 // set gobject values
339
340                 //listeners
341                 this.el.setup.connect( (listitem) => {
342                         
343                         var expand = new Gtk.TreeExpander();
344                          
345                         expand.set_indent_for_depth(true);
346                         expand.set_indent_for_icon(true);
347                          
348                         var lbl = new Gtk.Label("");
349                         lbl.use_markup = true;
350                         
351                         
352                         lbl.justify = Gtk.Justification.LEFT;
353                         lbl.xalign = 0;
354                 
355                  
356                         expand.set_child(lbl);
357                         ((Gtk.ListItem)listitem).set_child(expand);
358                         ((Gtk.ListItem)listitem).activatable = false;
359                 });
360                 this.el.bind.connect( (listitem) => {
361                          //GLib.debug("listitme is is %s", ((Gtk.ListItem)listitem).get_type().name());
362                         
363                         
364                         
365                         //var expand = (Gtk.TreeExpander) ((Gtk.ListItem)listitem).get_child();
366                         var expand = (Gtk.TreeExpander)  ((Gtk.ListItem)listitem).get_child();
367                           
368                  
369                         var lbl = (Gtk.Label) expand.child;
370                         
371                          if (lbl.label != "") { // do not update
372                                 return;
373                         }
374                         
375                 
376                         var lr = (Gtk.TreeListRow)((Gtk.ListItem)listitem).get_item();
377                         var np = (Palete.CompileError) lr.get_item();
378                         
379                         
380                         //GLib.debug("change  %s to %s", lbl.label, np.name);
381                         lbl.label = np.line_msg;
382                         //lbl.tooltip_markup = np.to_property_option_tooltip();
383                          
384                     expand.set_hide_expander(  np.lines.n_items < 1);
385                         expand.set_list_row(lr);
386                  
387                         // expand current file.
388                         if (_this.window.windowstate.file.path == np.file.path) {
389                                 lr.expanded = true;
390                         }
391                          
392                         // bind image...
393                         
394                 });
395             }
396
397             // user defined functions
398         }
399
400
401         public class Xcls_GestureClick10 : Object
402         {
403             public Gtk.GestureClick el;
404             private Xcls_ValaCompileErrors  _this;
405
406
407                 // my vars (def)
408
409             // ctor
410             public Xcls_GestureClick10(Xcls_ValaCompileErrors _owner )
411             {
412                 _this = _owner;
413                 this.el = new Gtk.GestureClick();
414
415                 // my vars (dec)
416
417                 // set gobject values
418                 this.el.button = 0;
419
420                 //listeners
421                 this.el.pressed.connect( (n_press, x, y) => {
422                         
423                         if (n_press < 2) { /// doubleclick?
424                                 return;
425                         }
426                  
427                         
428                         
429                         // use selection?!
430                         var tr = (Gtk.TreeListRow)_this.selmodel.el.selected_item;
431                         //GLib.debug("SELECTED = %s", tr.item.get_type().name());
432                         var ce = (Palete.CompileError) tr.item;
433                 
434                         if (ce.line < 0) {
435                                 // did not click on a line.
436                                 return;
437                         }
438                          
439                          
440                     var fname  = ce.parent.file;
441                         var line = ce.line;  
442                     GLib.debug("open %s @ %d\n", ce.parent.file.path, ce.line);
443                     
444                     
445                    var  bjsf = "";
446                     try {             
447                        var  regex = new Regex("\\.vala$");
448                     
449                      
450                         bjsf = regex.replace(fname.path,fname.path.length , 0 , ".bjs");
451                      } catch (GLib.RegexError e) {
452                         return;
453                     }   
454                     var p = _this.window.project;
455                         
456                         
457                         
458                     var jsr = p.getByPath(bjsf);
459                     if (jsr != null) {
460                         _this.window.windowstate.fileViewOpen(jsr, true, line);
461                         
462                         if (jsr.path == _this.window.windowstate.file.path) {
463                                 _this.el.hide();
464                         }
465                         
466                         
467                         return;
468                     
469                     }
470                     try {
471                                 var pf = JsRender.JsRender.factory("PlainFile", p, fname.path);
472                                 _this.window.windowstate.fileViewOpen(pf, true, line);
473                     } catch (JsRender.Error e) {}
474                     // try hiding the left nav..
475                  
476                     return;
477                 
478                 });
479             }
480
481             // user defined functions
482         }
483
484
485
486
487     }