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