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