src/Builder4/Editor.bjs
[roobuilder] / src / Builder4 / Editor.vala
1 static Editor  _Editor;
2
3 public class Editor : Object
4 {
5         public Gtk.Box el;
6         private Editor  _this;
7
8         public static Editor singleton()
9         {
10                 if (_Editor == null) {
11                     _Editor= new Editor();
12                 }
13                 return _Editor;
14         }
15         public Xcls_save_button save_button;
16         public Xcls_helper helper;
17         public Xcls_close_btn close_btn;
18         public Xcls_RightEditor RightEditor;
19         public Xcls_view view;
20         public Xcls_buffer buffer;
21         public Xcls_keystate keystate;
22         public Xcls_search_entry search_entry;
23         public Xcls_search_results search_results;
24         public Xcls_nextBtn nextBtn;
25         public Xcls_backBtn backBtn;
26         public Xcls_search_settings search_settings;
27         public Xcls_case_sensitive case_sensitive;
28         public Xcls_regex regex;
29         public Xcls_multiline multiline;
30         public Xcls_navigationwindow navigationwindow;
31         public Xcls_navigation navigation;
32         public Xcls_navigationselmodel navigationselmodel;
33         public Xcls_navigationsort navigationsort;
34         public Xcls_navliststore navliststore;
35
36                 // my vars (def)
37         public int pos_root_x;
38         public Xcls_MainWindow window;
39         public bool dirty;
40         public int pos_root_y;
41         public bool pos;
42         public int last_error_counter;
43         public GtkSource.SearchContext searchcontext;
44         public int last_search_end;
45         public signal void save ();
46         public JsRender.JsRender? file;
47         public JsRender.Node node;
48         public JsRender.NodeProp? prop;
49         public string activeEditor;
50
51         // ctor
52         public Editor()
53         {
54                 _this = this;
55                 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
56
57                 // my vars (dec)
58                 this.window = null;
59                 this.dirty = false;
60                 this.pos = false;
61                 this.last_error_counter = 0;
62                 this.searchcontext = null;
63                 this.last_search_end = 0;
64                 this.file = null;
65                 this.node = null;
66                 this.prop = null;
67                 this.activeEditor = "\"\"";
68
69                 // set gobject values
70                 this.el.homogeneous = false;
71                 this.el.hexpand = true;
72                 this.el.vexpand = true;
73                 var child_1 = new Xcls_Paned1( _this );
74                 child_1.ref();
75                 this.el.append( child_1.el );
76         }
77
78         // user defined functions
79         public bool saveContents ()  {
80             
81             
82             if (_this.file == null) {
83                 return true;
84             }
85             
86              
87              
88              var str = _this.buffer.toString();
89              
90              _this.buffer.checkSyntax();
91              
92              
93              
94              // LeftPanel.model.changed(  str , false);
95              _this.dirty = false;
96              _this.save_button.el.sensitive = false;
97              
98             // find the text for the node..
99             if (_this.file.xtype != "PlainFile") {
100                // in theory these properties have to exist!?!
101                 this.prop.val = str;
102                 //this.window.windowstate.left_props.reload();
103             } else {
104                 _this.file.setSource(  str );
105              }
106             
107             // call the signal..
108             this.save();
109             
110             return true;
111         
112         }
113         public void forwardSearch (bool change_focus) {
114         
115                 if (this.searchcontext == null) {
116                         return;
117                 } 
118         
119                 Gtk.TextIter beg, st,en;
120                  bool has_wrapped_around;
121                 this.buffer.el.get_iter_at_offset(out beg, this.last_search_end);
122                 if (!this.searchcontext.forward(beg, out st, out en, out has_wrapped_around)) {
123                 
124                         this.last_search_end = 0; // not sure if this should happen
125                 } else {
126                         if (has_wrapped_around) {
127                                 return;
128                         }
129                 
130                         this.last_search_end = en.get_offset();
131                         if (change_focus) {
132                                 this.view.el.grab_focus();
133                         }
134                         this.buffer.el.place_cursor(st);
135                         this.view.el.scroll_to_iter(st,  0.1f, true, 0.0f, 0.5f);
136                 }
137          
138         }
139         public void show (JsRender.JsRender file, JsRender.Node? node, JsRender.NodeProp? prop)
140         {
141             this.reset();
142             if (this.file != null) {
143                 this.file.navigation_tree_updated.disconnect(
144                         _this.navigation.show
145                 );
146             }
147             this.file = file;    
148             this.file.navigation_tree_updated.connect(
149                         _this.navigation.show
150                 );
151             if (file.xtype != "PlainFile") {
152                 this.prop = prop;
153                 this.node = node;
154         
155                 // find the text for the node..
156                 this.view.load( prop.val );
157                 this.updateErrorMarks();
158                 
159                 
160                 
161                 this.close_btn.el.show();       
162             
163             } else {
164                 this.view.load(        file.toSource() );
165                 this.updateErrorMarks();
166                 this.close_btn.el.hide();
167                 var ls = file.getLanguageServer();
168                 ls.queueDocumentSymbols(file);
169                 ////ls.documentSymbols.begin(file, (a,o) => {
170                 //      _this.navigation.show(ls.documentSymbols.end(o)); 
171                //});
172                 //documentSymbols
173                 
174             }
175          
176         }
177         public void backSearch (bool change_focus) {
178         
179                 if (this.searchcontext == null) {
180                         return;
181                 }
182                 
183                 Gtk.TextIter beg, st,en;
184                 bool has_wrapped_around;
185                 this.buffer.el.get_iter_at_offset(out beg, this.last_search_end -1 );
186                 
187                 if (!this.searchcontext.backward(beg, out st, out en, out has_wrapped_around)) {
188                         this.last_search_end = 0;
189                 } else {
190                         this.last_search_end = en.get_offset();
191                         if (change_focus) {
192                                 this.view.el.grab_focus();
193                         }
194                         this.buffer.el.place_cursor(st);
195                         this.view.el.scroll_to_iter(st,  0.1f, true, 0.0f, 0.5f);
196                 }
197         
198         }
199         public string tempFileContents () {
200            
201            
202            if (_this.file == null) {
203                return "";
204            }
205                 var str= this.buffer.toString();
206                 if (_this.file.xtype == "PlainFile") {
207             
208                 return str;
209             
210             }
211           
212               
213              
214             GLib.debug("calling validate");    
215             // clear the buttons.
216                 if (_this.prop.name == "xns" || _this.prop.name == "xtype") {
217                         return this.file.toSource(); ;
218                 }
219                 
220                 var oldcode  = _this.prop.val;
221                 _this.prop.val = str;
222             var ret = _this.file.toSource();
223             _this.prop.val = oldcode;
224             return ret;
225             
226         }
227         public void reset () {
228                  this.file = null;    
229              
230             this.node = null;
231             this.prop = null;
232                 this.searchcontext = null;
233           
234         }
235         public int search (string in_txt) {
236         
237                 var s = new GtkSource.SearchSettings();
238                 s.case_sensitive = _this.case_sensitive.el.active;
239                 s.regex_enabled = _this.regex.el.active;        
240                 s.wrap_around = false;
241                 
242                 this.searchcontext = new GtkSource.SearchContext(this.buffer.el,s);
243                 this.searchcontext.set_highlight(true);
244                 var txt = in_txt;
245                 
246                 if (_this.multiline.el.active) {
247                         txt = in_txt.replace("\\n", "\n");
248                 }
249                 
250                 s.set_search_text(txt);
251                 Gtk.TextIter beg, st,en;
252                  
253                 this.buffer.el.get_start_iter(out beg);
254                 bool has_wrapped_around;
255                 this.searchcontext.forward(beg, out st, out en, out has_wrapped_around);
256                 this.last_search_end = 0;
257                 
258                 return this.searchcontext.get_occurrences_count();
259         
260          
261            
262         
263         }
264         public void updateErrorMarks () {
265                 
266          
267         
268                 var buf = _this.buffer.el;
269                 Gtk.TextIter start;
270                 Gtk.TextIter end;     
271                 buf.get_bounds (out start, out end);
272         
273                 
274         
275          
276                 //GLib.debug("highlight errors");                
277         
278                  // we should highlight other types of errors..
279         
280                 if (_this.window.windowstate.state != WindowState.State.CODEONLY 
281                         &&
282                         _this.window.windowstate.state != WindowState.State.CODE
283                         ) {
284                         //GLib.debug("windowstate != CODEONLY?");
285                         
286                         return;
287                 } 
288         
289                  
290                 if (_this.file == null) {
291                         GLib.debug("file is null?");
292                         return;
293         
294                 }
295                 var ar = this.file.getErrors();
296                 if (ar.size < 1) {
297                         buf.remove_source_marks (start, end, "ERR");
298                         buf.remove_source_marks (start, end, "WARN");
299                         buf.remove_source_marks (start, end, "DEPR");
300                         buf.remove_tag_by_name ("ERR", start, end);
301                         buf.remove_tag_by_name ("WARN", start, end);
302                         buf.remove_tag_by_name ("DEPR", start, end);
303                         this.last_error_counter = file.error_counter ;
304                         //GLib.debug("highlight %s :  %s has no errors", this.file.relpath, category);
305                         return;
306                 }
307                 
308         
309          // basicaly check if there is no change, then we do not do any update..
310          // we can do this by just using an error counter?
311          // if that's changed then we will do an update, otherwise dont bother.
312                   
313                 
314                 var offset = 0;
315                 var hoffset = 0;
316         
317                 var tlines = buf.get_line_count () +1;
318                 
319                 if (_this.prop != null) {
320                         // this still seems flaky...
321         
322                         tlines = _this.prop.end_line;
323                         offset = _this.prop.start_line;
324                         hoffset = _this.node.node_pad.length + 2; //shift it left  by 2 ? ..
325                         
326                          
327                 } else {
328                         // no update...
329                         if (this.last_error_counter == file.error_counter) {
330                         
331                                 return;
332                         }
333                 
334                 }
335                 buf.remove_source_marks (start, end, "ERR");
336                 buf.remove_source_marks (start, end, "WARN");
337                 buf.remove_source_marks (start, end, "DEPR");
338                 buf.remove_tag_by_name ("ERR", start, end);
339                 buf.remove_tag_by_name ("WARN", start, end);
340                 buf.remove_tag_by_name ("DEPR", start, end);
341                 
342                 foreach(var diag in ar) { 
343                      Gtk.TextIter iter;
344         //        print("get inter\n");
345                     var eline = (int)diag.range.start.line - offset;
346                     var eline_to = (int)diag.range.end.line - offset;
347                     //var eline =  diag.range.end_line - offset;
348                     //GLib.debug("GOT ERROR on line %d -- converted to %d  (offset = %d)",
349                     //  err.line ,eline, offset);
350                     
351                     
352                     if (eline > tlines || eline < 0) {
353                         continue;
354                     }
355                     
356                     buf.get_iter_at_line( out iter, eline);
357                         var msg = "Line: %d %s : %s".printf(eline+1, diag.category, diag.message);
358                     buf.create_source_mark( msg, diag.category, iter);
359                     
360                     var spos = (int)diag.range.start.character - hoffset;
361                     if (spos < 0) { spos =0 ; }
362                     if (spos > iter.get_chars_in_line()) {
363                         spos = iter.get_chars_in_line();
364                 }
365                         buf.get_iter_at_line( out iter, eline_to);
366                         var epos = (int)diag.range.end.character - hoffset;
367                     if (epos < 0) { epos =0 ; }
368                     if (epos > iter.get_chars_in_line()) {
369                         epos = iter.get_chars_in_line();
370                 }
371                      
372                     
373                     buf.get_iter_at_line_offset( out start, eline, spos); 
374                    
375                     buf.get_iter_at_line_offset( out end, eline_to,epos); 
376                         
377                     buf.apply_tag_by_name(diag.category, start, end);
378                     
379                    // GLib.debug("set line %d to %s", eline, msg);
380                     //this.marks.set(eline, msg);
381                 }
382                 this.last_error_counter = file.error_counter ;
383         
384         
385         
386          
387         
388         }
389         public void scroll_to_line (int line) {
390         
391                 GLib.Timeout.add(500, () => {
392            
393                         var buf = this.view.el.get_buffer();
394         
395                         var sbuf = (GtkSource.Buffer) buf;
396         
397         
398                         Gtk.TextIter iter;   
399                         sbuf.get_iter_at_line(out iter,  line);
400                         this.view.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);
401                         return false;
402                 });   
403         }
404         public class Xcls_Paned1 : Object
405         {
406                 public Gtk.Paned el;
407                 private Editor  _this;
408
409
410                         // my vars (def)
411
412                 // ctor
413                 public Xcls_Paned1(Editor _owner )
414                 {
415                         _this = _owner;
416                         this.el = new Gtk.Paned( Gtk.Orientation.HORIZONTAL );
417
418                         // my vars (dec)
419
420                         // set gobject values
421                         var child_1 = new Xcls_Box2( _this );
422                         child_1.ref();
423                         this.el.start_child = child_1.el;
424                         var child_2 = new Xcls_Box27( _this );
425                         child_2.ref();
426                         this.el.end_child = child_2.el;
427                 }
428
429                 // user defined functions
430         }
431         public class Xcls_Box2 : Object
432         {
433                 public Gtk.Box el;
434                 private Editor  _this;
435
436
437                         // my vars (def)
438
439                 // ctor
440                 public Xcls_Box2(Editor _owner )
441                 {
442                         _this = _owner;
443                         this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
444
445                         // my vars (dec)
446
447                         // set gobject values
448                         var child_1 = new Xcls_Box3( _this );
449                         child_1.ref();
450                         this.el.append( child_1.el );
451                         new Xcls_RightEditor( _this );
452                         this.el.append( _this.RightEditor.el );
453                         var child_3 = new Xcls_Box15( _this );
454                         child_3.ref();
455                         this.el.append ( child_3.el  );
456                 }
457
458                 // user defined functions
459         }
460         public class Xcls_Box3 : Object
461         {
462                 public Gtk.Box el;
463                 private Editor  _this;
464
465
466                         // my vars (def)
467
468                 // ctor
469                 public Xcls_Box3(Editor _owner )
470                 {
471                         _this = _owner;
472                         this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
473
474                         // my vars (dec)
475
476                         // set gobject values
477                         this.el.homogeneous = false;
478                         this.el.hexpand = true;
479                         new Xcls_save_button( _this );
480                         this.el.append( _this.save_button.el );
481                         new Xcls_helper( _this );
482                         this.el.append( _this.helper.el );
483                         var child_3 = new Xcls_Scale6( _this );
484                         child_3.ref();
485                         this.el.append( child_3.el );
486                         new Xcls_close_btn( _this );
487                         this.el.append( _this.close_btn.el );
488                 }
489
490                 // user defined functions
491         }
492         public class Xcls_save_button : Object
493         {
494                 public Gtk.Button el;
495                 private Editor  _this;
496
497
498                         // my vars (def)
499
500                 // ctor
501                 public Xcls_save_button(Editor _owner )
502                 {
503                         _this = _owner;
504                         _this.save_button = this;
505                         this.el = new Gtk.Button();
506
507                         // my vars (dec)
508
509                         // set gobject values
510                         this.el.vexpand = true;
511                         this.el.label = "Save";
512
513                         //listeners
514                         this.el.clicked.connect( () => { 
515                             _this.saveContents();
516                         });
517                 }
518
519                 // user defined functions
520         }
521
522         public class Xcls_helper : Object
523         {
524                 public Gtk.Label el;
525                 private Editor  _this;
526
527
528                         // my vars (def)
529
530                 // ctor
531                 public Xcls_helper(Editor _owner )
532                 {
533                         _this = _owner;
534                         _this.helper = this;
535                         this.el = new Gtk.Label( null );
536
537                         // my vars (dec)
538
539                         // set gobject values
540                         this.el.margin_end = 4;
541                         this.el.margin_start = 4;
542                         this.el.hexpand = true;
543                 }
544
545                 // user defined functions
546         }
547
548         public class Xcls_Scale6 : Object
549         {
550                 public Gtk.Scale el;
551                 private Editor  _this;
552
553
554                         // my vars (def)
555
556                 // ctor
557                 public Xcls_Scale6(Editor _owner )
558                 {
559                         _this = _owner;
560                         this.el = new Gtk.Scale.with_range (Gtk.Orientation.HORIZONTAL,6, 30, 1);
561
562                         // my vars (dec)
563
564                         // set gobject values
565                         this.el.width_request = 200;
566                         this.el.has_origin = true;
567                         this.el.draw_value = false;
568                         this.el.digits = 0;
569                         this.el.sensitive = true;
570
571                         // init method
572
573                         {
574                                 //this.el.set_range(6,30);
575                                 this.el.set_value ( BuilderApplication.settings.editor_font_size);
576                                 BuilderApplication.settings.editor_font_size_updated.connect(
577                                         () => {
578                                                 BuilderApplication.settings.editor_font_size_inchange = true;
579                                         //      GLib.debug("update range");
580                                                 this.el.set_value (BuilderApplication.settings.editor_font_size);
581                                                 BuilderApplication.settings.editor_font_size_inchange = false;
582                                         }
583                                 );
584                                 
585                          
586                         }
587
588                         //listeners
589                         this.el.change_value.connect( (st, val ) => {
590                                 if (BuilderApplication.settings.editor_font_size_inchange) {
591                                         return false;
592                                 }
593                                 BuilderApplication.settings.editor_font_size = val;
594                                 return false;
595                         });
596                 }
597
598                 // user defined functions
599         }
600
601         public class Xcls_close_btn : Object
602         {
603                 public Gtk.Button el;
604                 private Editor  _this;
605
606
607                         // my vars (def)
608
609                 // ctor
610                 public Xcls_close_btn(Editor _owner )
611                 {
612                         _this = _owner;
613                         _this.close_btn = this;
614                         this.el = new Gtk.Button();
615
616                         // my vars (dec)
617
618                         // set gobject values
619                         this.el.icon_name = "window-close";
620                         var child_1 = new Xcls_Image8( _this );
621                         child_1.ref();
622                         this.el.child = child_1.el;
623
624                         //listeners
625                         this.el.clicked.connect( () => { 
626                             _this.saveContents();
627                             _this.window.windowstate.switchState(WindowState.State.PREVIEW);
628                         });
629                 }
630
631                 // user defined functions
632         }
633         public class Xcls_Image8 : Object
634         {
635                 public Gtk.Image el;
636                 private Editor  _this;
637
638
639                         // my vars (def)
640
641                 // ctor
642                 public Xcls_Image8(Editor _owner )
643                 {
644                         _this = _owner;
645                         this.el = new Gtk.Image();
646
647                         // my vars (dec)
648
649                         // set gobject values
650                         this.el.icon_name = "window-close";
651                         this.el.icon_size = Gtk.IconSize.NORMAL;
652                 }
653
654                 // user defined functions
655         }
656
657
658
659         public class Xcls_RightEditor : Object
660         {
661                 public Gtk.ScrolledWindow el;
662                 private Editor  _this;
663
664
665                         // my vars (def)
666
667                 // ctor
668                 public Xcls_RightEditor(Editor _owner )
669                 {
670                         _this = _owner;
671                         _this.RightEditor = this;
672                         this.el = new Gtk.ScrolledWindow();
673
674                         // my vars (dec)
675
676                         // set gobject values
677                         this.el.vscrollbar_policy = Gtk.PolicyType.AUTOMATIC;
678                         this.el.vexpand = true;
679                         this.el.overlay_scrolling = false;
680                         this.el.hscrollbar_policy = Gtk.PolicyType.AUTOMATIC;
681                         new Xcls_view( _this );
682                         this.el.child = _this.view.el;
683                 }
684
685                 // user defined functions
686         }
687         public class Xcls_view : Object
688         {
689                 public GtkSource.View el;
690                 private Editor  _this;
691
692
693                         // my vars (def)
694                 public Gtk.CssProvider css;
695
696                 // ctor
697                 public Xcls_view(Editor _owner )
698                 {
699                         _this = _owner;
700                         _this.view = this;
701                         this.el = new GtkSource.View();
702
703                         // my vars (dec)
704                         this.css = null;
705
706                         // set gobject values
707                         this.el.auto_indent = true;
708                         this.el.indent_width = 4;
709                         this.el.name = "editor-view";
710                         this.el.show_line_marks = true;
711                         this.el.insert_spaces_instead_of_tabs = true;
712                         this.el.show_line_numbers = true;
713                         this.el.hexpand = true;
714                         this.el.vexpand = true;
715                         this.el.has_tooltip = true;
716                         this.el.css_classes = { "code-editor" };
717                         this.el.tab_width = 4;
718                         this.el.highlight_current_line = true;
719                         new Xcls_buffer( _this );
720                         this.el.buffer = _this.buffer.el;
721                         new Xcls_keystate( _this );
722                         this.el.add_controller(  _this.keystate.el );
723                         var child_3 = new Xcls_EventControllerScroll13( _this );
724                         child_3.ref();
725                         this.el.add_controller(  child_3.el );
726                         var child_4 = new Xcls_GestureClick14( _this );
727                         child_4.ref();
728                         this.el.add_controller(  child_4.el );
729
730                         // init method
731
732                         this.el.completion.add_provider(
733                                 new Palete.CompletionProvider(_this)
734                         );
735                         
736                         // hover seems pretty useless.. - ??
737                         //var hover = this.el.get_hover();
738                         //hover.add_provider(new Palete.HoverProvider(_this));
739                         
740                         //this.el.completion.unblock_interactive();
741                         this.el.completion.select_on_show = true; // select
742                         //this.el.completion.remember_info_visibility    = true;
743                         
744                         
745                         var attrs = new GtkSource.MarkAttributes();
746                         
747                         attrs.set_icon_name ( "process-stop");    
748                         attrs.query_tooltip_text.connect(( mark) => {
749                              GLib.debug("tooltip query? %s", mark.name);
750                             return strdup( mark.name);
751                         });
752                          attrs.query_tooltip_markup.connect(( mark) => {
753                              GLib.debug("tooltip query? %s", mark.name);
754                             return strdup( mark.name);
755                         });
756                         this.el.set_mark_attributes ("ERR", attrs, 1);
757                         attrs.ref();
758                         
759                         
760                         var wattrs = new GtkSource.MarkAttributes();
761                         wattrs.set_icon_name ( "process-stop");    
762                         wattrs.query_tooltip_text.connect(( mark) => {
763                              GLib.debug("tooltip query? %s", mark.name);
764                             return strdup(mark.name);
765                         });
766                         wattrs.query_tooltip_markup.connect(( mark) => {
767                              GLib.debug("tooltip query? %s", mark.name);
768                             return strdup(mark.name);
769                         });
770                         this.el.set_mark_attributes ("WARN", wattrs, 1);
771                         wattrs.ref();
772                         
773                          
774                         var dattrs = new GtkSource.MarkAttributes();
775                          
776                         dattrs.set_icon_name ( "process-stop"); 
777                         
778                         dattrs.query_tooltip_text.connect(( mark) => {
779                                 GLib.debug("tooltip query? %s", mark.name);
780                             return strdup(mark.name);
781                         });
782                         //dattrs.query_tooltip_markup.connect(( mark) => {
783                         //      GLib.debug("tooltip query? %s", mark.name);
784                          //   return strdup(mark.name);
785                         //});
786                         this.el.set_mark_attributes ("DEPR", dattrs, 1);
787                         dattrs.ref();    
788                         
789                          this.el.get_space_drawer().set_matrix(null);
790                          this.el.get_space_drawer().set_types_for_locations( 
791                                 GtkSource.SpaceLocationFlags.ALL,
792                                 GtkSource.SpaceTypeFlags.ALL
793                         );
794                         this.el.get_space_drawer().set_enable_matrix(true);
795
796                         //listeners
797                         this.el.query_tooltip.connect( (x, y, keyboard_tooltip, tooltip) => {
798                                 
799                                 //GLib.debug("query tooltip");
800                                 Gtk.TextIter iter;
801                                 int trailing;
802                                 
803                                 var yoff = (int) _this.RightEditor.el.vadjustment.value;
804                                 
805                                 // I think this is problematic - if it's compliing  / updating at same time as query.
806                                 
807                                 //if (_this.window.statusbar_compile_spinner.el.spinning) {
808                                 //      return false;
809                                 //}
810                                 
811                                 this.el.get_iter_at_position (out iter, out trailing,  x,  y + yoff);
812                                  
813                                 var l = iter.get_line();
814                         
815                                 
816                                  
817                                 // GLib.debug("query tooltip line %d", (int) l);
818                                 if (l < 0) {
819                         
820                                         return false;
821                                 }
822                                 /*
823                                 if (_this.buffer.marks != null && _this.buffer.marks.has_key(l)) {
824                                         GLib.debug("line %d setting tip to %s", l,  _this.buffer.marks.get(l));
825                                         tooltip.set_text(_this.buffer.marks.get(l).dup());
826                                         return true;
827                                 }
828                          
829                                 return false;
830                                 */
831                                 
832                                   
833                                 // this crashes?? - not sure why.
834                                 var marks = _this.buffer.el.get_source_marks_at_line(l, "ERR");
835                                 if (marks.is_empty()) {
836                                         marks = _this.buffer.el.get_source_marks_at_line(l, "WARN");
837                                 }
838                                 if (marks.is_empty()) {
839                                         marks = _this.buffer.el.get_source_marks_at_line(l, "DEPR");
840                                 }
841                                 
842                                 // GLib.debug("query tooltip line %d marks %d", (int)l, (int) marks.length());
843                                 var str = "";
844                                 marks.@foreach((m) => { 
845                                         //GLib.debug("got mark %s", m.name);
846                                         str += (str.length > 0 ? "\n" : "") + m.category + ": " + m.name;
847                                 });
848                                 // true if there is a mark..
849                                 if (str.length > 0 ) {
850                                         tooltip.set_text( str );
851                                 }
852                                 return str.length > 0 ? true : false;
853                                  
854                         });
855                 }
856
857                 // user defined functions
858                 public void load (string str) {
859                 
860                 // show the help page for the active node..
861                    //this.get('/Help').show();
862                  
863                   // this.get('/BottomPane').el.set_current_page(0);
864                         GLib.debug("load called - Reset undo buffer");
865                         
866                     var buf = (GtkSource.Buffer)this.el.get_buffer();
867                     buf.begin_irreversible_action();
868                     buf.set_text(str, str.length);
869                     buf.end_irreversible_action();
870                     
871                     var lm = GtkSource.LanguageManager.get_default();
872                     var lang = "vala";
873                     if (_this.file != null) {
874                          lang = _this.file.language;
875                     }
876                     print("lang=%s, content_type = %s\n", lang, _this.file.content_type);
877                     var lg = _this.file.content_type.length > 0  ?
878                             lm.guess_language(_this.file.path, _this.file.content_type) :
879                             lm.get_language(lang);
880                      
881                    
882                     ((GtkSource.Buffer)(this.el.get_buffer())) .set_language(lg); 
883                 
884                     this.el.insert_spaces_instead_of_tabs = true;
885                     if (lg != null) {
886                                 print("sourcelanguage  = %s\n", lg.name);
887                                 if (lg.name == "Vala") {
888                                     this.el.insert_spaces_instead_of_tabs = false;
889                                 }
890                      }
891                     _this.dirty = false;
892                     this.el.grab_focus();
893                     _this.save_button.el.sensitive = false;
894                     _this.last_error_counter = -1;
895                 }
896         }
897         public class Xcls_buffer : Object
898         {
899                 public GtkSource.Buffer el;
900                 private Editor  _this;
901
902
903                         // my vars (def)
904                 public int error_line;
905                 public Gee.HashMap<int,string>? xmarks;
906                 public bool check_queued;
907
908                 // ctor
909                 public Xcls_buffer(Editor _owner )
910                 {
911                         _this = _owner;
912                         _this.buffer = this;
913                         this.el = new GtkSource.Buffer( null );
914
915                         // my vars (dec)
916                         this.error_line = -1;
917                         this.xmarks = null;
918                         this.check_queued = false;
919
920                         // set gobject values
921                         this.el.highlight_syntax = true;
922                         this.el.highlight_matching_brackets = true;
923                         this.el.enable_undo = true;
924
925                         // init method
926
927                         var buf = this.el;
928                         buf.create_tag ("bold", "weight", Pango.Weight.BOLD);
929                         buf.create_tag ("type", "weight", Pango.Weight.BOLD, "foreground", "#204a87");
930                         buf.create_tag ("keyword", "weight", Pango.Weight.BOLD, "foreground", "#a40000");
931                         buf.create_tag ("text", "weight", Pango.Weight.NORMAL, "foreground", "#729fcf");
932                         buf.create_tag ("number", "weight", Pango.Weight.BOLD, "foreground", "#ad7fa8");
933                         buf.create_tag ("method", "weight", Pango.Weight.BOLD, "foreground", "#729fcf");
934                         buf.create_tag ("property", "weight", Pango.Weight.BOLD, "foreground", "#BC1F51");
935                         buf.create_tag ("variable", "weight", Pango.Weight.BOLD, "foreground", "#A518B5");
936                         
937                         
938                         buf.create_tag ("ERR", "weight", Pango.Weight.BOLD, "background", "pink");
939                         buf.create_tag ("WARN", "weight", Pango.Weight.BOLD, "background", "#ABF4EB");
940                         buf.create_tag ("DEPR", "weight", Pango.Weight.BOLD, "background", "#EEA9FF");
941
942                         //listeners
943                         this.el.cursor_moved.connect( ( ) => {
944                         
945                                 Gtk.TextIter iter;
946                                 this.el.get_iter_at_offset (
947                                                 out iter, this.el.cursor_position);
948                         
949                                 _this.navigation.updateSelectedLine(
950                                                 (uint)iter.get_line(),
951                                                 (uint)iter.get_line_offset()
952                                         );
953                         
954                         
955                         });
956                         this.el.changed.connect( () => {
957                             // check syntax??
958                             // ??needed..??
959                             _this.save_button.el.sensitive = true;
960                             print("EDITOR CHANGED");
961                             this.checkSyntax();
962                            
963                             _this.dirty = true;
964                         
965                             // this.get('/LeftPanel.model').changed(  str , false);
966                             return ;
967                         });
968                 }
969
970                 // user defined functions
971                 public bool OLDhighlightErrorsJson (string type, Json.Object obj) {
972                         Gtk.TextIter start;
973                         Gtk.TextIter end;     
974                         this.el.get_bounds (out start, out end);
975                 
976                         this.el.remove_source_marks (start, end, type);
977                         GLib.debug("highlight errors");          
978                 
979                          // we should highlight other types of errors..
980                 
981                         if (!obj.has_member(type)) {
982                                 GLib.debug("Return has no errors\n");
983                                 return true;
984                         }
985                 
986                         if (_this.window.windowstate.state != WindowState.State.CODEONLY 
987                                 &&
988                                 _this.window.windowstate.state != WindowState.State.CODE
989                                 ) {
990                                 GLib.debug("windowstate != CODEONLY?");
991                                 
992                                 return true;
993                         } 
994                 
995                         //this.marks = new Gee.HashMap<int,string>();
996                         var err = obj.get_object_member(type);
997                  
998                         if (_this.file == null) {
999                                 GLib.debug("file is null?");
1000                                 return true;
1001                 
1002                         }
1003                         var valafn = _this.file.path;
1004                 
1005                         if (_this.file.xtype != "PlainFile") {
1006                 
1007                                 valafn = "";
1008                                 try {             
1009                                         var  regex = new Regex("\\.bjs$");
1010                                         // should not happen
1011                                         valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
1012                                 } catch (GLib.RegexError e) {
1013                                         return true;
1014                                 }   
1015                 
1016                 
1017                 
1018                         }
1019                         if (!err.has_member(valafn)) {
1020                                 GLib.debug("File path has no errors");
1021                                 return  true;
1022                         }
1023                 
1024                         var lines = err.get_object_member(valafn);
1025                         
1026                         var offset = 1;
1027                         if (obj.has_member("line_offset")) { // ?? why??
1028                                 offset = (int)obj.get_int_member("line_offset") + 1;
1029                         }
1030                 
1031                 
1032                         var tlines = this.el.get_line_count () +1;
1033                         
1034                         if (_this.prop != null) {
1035                         
1036                                 tlines = _this.prop.end_line + 1;
1037                                 offset = _this.prop.start_line + 1;
1038                         
1039                         }
1040                         
1041                 
1042                 
1043                         lines.foreach_member((obj, line, node) => {
1044                                 
1045                              Gtk.TextIter iter;
1046                 //        print("get inter\n");
1047                             var eline = int.parse(line) - offset;
1048                             GLib.debug("GOT ERROR on line %s -- converted to %d  (offset = %d)\n", line,eline, offset);
1049                             
1050                             
1051                             if (eline > tlines || eline < 0) {
1052                                 return;
1053                             }
1054                            
1055                             
1056                             this.el.get_iter_at_line( out iter, eline);
1057                             //print("mark line\n");
1058                             var msg  = "";
1059                             var ar = lines.get_array_member(line);
1060                             for (var i = 0 ; i < ar.get_length(); i++) {
1061                                 if (ar.get_string_element(i) == "Success") {
1062                                         continue;
1063                                 }
1064                                         msg += (msg.length > 0) ? "\n" : "";
1065                                         msg += ar.get_string_element(i);
1066                                 }
1067                                 if (msg == "") {
1068                                         return;
1069                                 }
1070                                 msg = "Line: %d".printf(eline+1) +  " " + msg;
1071                             this.el.create_source_mark(msg, type, iter);
1072                             GLib.debug("set line %d to %m", eline, msg);
1073                            // this.marks.set(eline, msg);
1074                         } );
1075                         return false;
1076                 
1077                 
1078                 
1079                 
1080                 
1081                         }
1082                 public bool checkSyntax () {
1083                  
1084                     
1085                     var str = this.toString();
1086                     
1087                     // needed???
1088                     if (this.error_line > 0) {
1089                          Gtk.TextIter start;
1090                          Gtk.TextIter end;     
1091                         this.el.get_bounds (out start, out end);
1092                 
1093                         this.el.remove_source_marks (start, end, null);
1094                     }
1095                     if (str.length < 1) {
1096                         print("checkSyntax - empty string?\n");
1097                         return true;
1098                     }
1099                     
1100                     // bit presumptiona
1101                     if (_this.file.xtype == "PlainFile") {
1102                     
1103                         // assume it's gtk...
1104                          var  oldcode =_this.file.toSource();
1105                         _this.file.setSource(str);
1106                             BuilderApplication.showSpinner("appointment soon","document change pending");
1107                         _this.file.getLanguageServer().document_change(_this.file);
1108                                 _this.file.getLanguageServer().queueDocumentSymbols(_this.file);
1109                         _this.file.setSource(oldcode);
1110                         
1111                                  
1112                         return true;
1113                     
1114                     }
1115                    if (_this.file == null) {
1116                        return true;
1117                    }
1118                  
1119                     
1120                 
1121                       
1122                      
1123                     GLib.debug("calling validate");    
1124                     // clear the buttons.
1125                         if (_this.prop.name == "xns" || _this.prop.name == "xtype") {
1126                                 return true ;
1127                         }
1128                         var oldcode  = _this.prop.val;
1129                         
1130                         _this.prop.val = str;
1131                         _this.node.updated_count++;
1132                     _this.file.getLanguageServer().document_change(_this.file);
1133                     _this.node.updated_count++;
1134                     _this.prop.val = oldcode;
1135                     
1136                     
1137                     //print("done mark line\n");
1138                      
1139                     return true; // at present allow saving - even if it's invalid..
1140                 }
1141                 public bool highlightErrors ( Gee.HashMap<int,string> validate_res) {
1142                          
1143                         this.error_line = validate_res.size;
1144                 
1145                         if (this.error_line < 1) {
1146                                 return true;
1147                         }
1148                         var tlines = this.el.get_line_count ();
1149                         Gtk.TextIter iter;
1150                         var valiter = validate_res.map_iterator();
1151                         while (valiter.next()) {
1152                 
1153                         //        print("get inter\n");
1154                                 var eline = valiter.get_key();
1155                                 if (eline > tlines) {
1156                                         continue;
1157                                 }
1158                                 this.el.get_iter_at_line( out iter, eline);
1159                                 //print("mark line\n");
1160                                 this.el.create_source_mark(valiter.get_value(), "ERR", iter);
1161                         }   
1162                         return false;
1163                 }
1164                 public string toString () {
1165                     
1166                     Gtk.TextIter s;
1167                     Gtk.TextIter e;
1168                     this.el.get_start_iter(out s);
1169                     this.el.get_end_iter(out e);
1170                     var ret = this.el.get_text(s,e,true);
1171                     //print("TO STRING? " + ret);
1172                     return ret;
1173                 }
1174         }
1175
1176         public class Xcls_keystate : Object
1177         {
1178                 public Gtk.EventControllerKey el;
1179                 private Editor  _this;
1180
1181
1182                         // my vars (def)
1183                 public bool is_control;
1184
1185                 // ctor
1186                 public Xcls_keystate(Editor _owner )
1187                 {
1188                         _this = _owner;
1189                         _this.keystate = this;
1190                         this.el = new Gtk.EventControllerKey();
1191
1192                         // my vars (dec)
1193                         this.is_control = false;
1194
1195                         // set gobject values
1196
1197                         //listeners
1198                         this.el.key_released.connect( (keyval, keycode, state) => {
1199                         
1200                                  if (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) {
1201                                         this.is_control = false;
1202                                 }
1203                             if (keyval == Gdk.Key.s && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1204                                 GLib.debug("SAVE: ctrl-S  pressed");
1205                                 _this.saveContents();
1206                                 return;
1207                             }
1208                             
1209                             if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1210                                     GLib.debug("SAVE: ctrl-g  pressed");
1211                                         _this.forwardSearch(true);
1212                                     return;
1213                                 }
1214                                 if (keyval == Gdk.Key.f && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1215                                     GLib.debug("SAVE: ctrl-f  pressed");
1216                                         _this.search_entry.el.grab_focus();
1217                                         _this.search_entry.el.select_region(0,-1);
1218                                     return;
1219                                 }
1220                                 if (keyval == Gdk.Key.space && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1221                                         _this.view.el.show_completion();
1222                                 }
1223                                 
1224                                 Gtk.TextIter iter;
1225                                 _this.buffer.el.get_iter_at_offset( out iter, _this.buffer.el.cursor_position);  
1226                                 var line  = iter.get_line();
1227                                 var offset = iter.get_line_offset();
1228                                 GLib.debug("line  %d  off %d", line ,offset);
1229                                 if (_this.prop != null) {
1230                                         line += _this.prop.start_line + 1; // i think..
1231                                         offset += 12; // should probably be 8 without namespaced 
1232                                         GLib.debug("guess line  %d  off %d", line ,offset);
1233                                 } 
1234                             //_this.view.el.show_completion();
1235                            // print(event.key.keyval)
1236                             
1237                             
1238                             return;
1239                          
1240                          
1241                         });
1242                         this.el.key_pressed.connect( (keyval, keycode, state) => {
1243                         
1244                                 if (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) {
1245                                         this.is_control = true;
1246                                 }
1247                                 return false;
1248                         });
1249                 }
1250
1251                 // user defined functions
1252         }
1253
1254         public class Xcls_EventControllerScroll13 : Object
1255         {
1256                 public Gtk.EventControllerScroll el;
1257                 private Editor  _this;
1258
1259
1260                         // my vars (def)
1261                 public double distance;
1262
1263                 // ctor
1264                 public Xcls_EventControllerScroll13(Editor _owner )
1265                 {
1266                         _this = _owner;
1267                         this.el = new Gtk.EventControllerScroll( Gtk.EventControllerScrollFlags.VERTICAL );
1268
1269                         // my vars (dec)
1270                         this.distance = 0.0f;
1271
1272                         // set gobject values
1273
1274                         //listeners
1275                         this.el.scroll.connect( (dx, dy) => {
1276                                 if (!_this.keystate.is_control) {
1277                                         return false;
1278                                 }
1279                                  //GLib.debug("scroll %f",  dy);
1280                                 
1281                                 this.distance += dy;
1282                                 
1283                                 //GLib.debug("scroll %f / %f",  dy, this.distance);
1284                          
1285                                  if (this.distance < -1) {
1286                          
1287                                         BuilderApplication.settings.editor_font_size ++;
1288                                         this.distance = 0;
1289                                 }
1290                                 if (this.distance > 1) {
1291                                         BuilderApplication.settings.editor_font_size --;
1292                                         this.distance = 0;
1293                                 }
1294                                  
1295                                 return true;
1296                         });
1297                 }
1298
1299                 // user defined functions
1300         }
1301
1302         public class Xcls_GestureClick14 : Object
1303         {
1304                 public Gtk.GestureClick el;
1305                 private Editor  _this;
1306
1307
1308                         // my vars (def)
1309
1310                 // ctor
1311                 public Xcls_GestureClick14(Editor _owner )
1312                 {
1313                         _this = _owner;
1314                         this.el = new Gtk.GestureClick();
1315
1316                         // my vars (dec)
1317
1318                         // set gobject values
1319
1320                         //listeners
1321                         this.el.pressed.connect( (n_press, x, y) => {
1322                                 Gtk.TextIter iter;
1323                                 int  buffer_x, buffer_y;
1324                                 var gut = _this.view.el.get_gutter(Gtk.TextWindowType.LEFT);
1325                                 
1326                                  _this.view.el.window_to_buffer_coords (Gtk.TextWindowType.TEXT,
1327                                         (int)x - gut.get_width(),  (int)y,
1328                                         out  buffer_x, out  buffer_y);
1329                                 _this.view.el.get_iter_at_location (out  iter,  
1330                                                 buffer_x,  buffer_y);;
1331                                 
1332                                 
1333                                 if (_this.buffer.el.iter_has_context_class(iter, "comment") ||
1334                                         _this.buffer.el.iter_has_context_class(iter, "string")
1335                                 ) { 
1336                                         return ;
1337                                 }
1338                                 var back = iter.copy();
1339                                 back.backward_char();
1340                                 
1341                                 var forward = iter.copy();
1342                                 forward.forward_char();
1343                                 
1344                                 // what's the character at the iter?
1345                                 var str = back.get_text(iter);
1346                                 str += iter.get_text(forward);
1347                                 if (str.strip().length < 1) {
1348                                         return;
1349                                 }
1350                                 var offset = iter.get_line_offset();
1351                                 var line = iter.get_line();
1352                                 if (_this.prop != null) {
1353                                                         // 
1354                                         line += _this.prop.start_line ; 
1355                                                                 // this is based on Gtk using tabs (hence 1/2 chars);
1356                                         offset += _this.node.node_pad.length;
1357                                                                 // javascript listeners are indented 2 more spaces.
1358                                         if (_this.prop.ptype == JsRender.NodePropType.LISTENER) {
1359                                                 offset += 2;
1360                                         }
1361                                 } 
1362                                 
1363                                 var ls = _this.file.getLanguageServer();
1364                                 ls.hover.begin(
1365                                         _this.file, line, offset,
1366                                         ( a, o)  => {
1367                                                 var res = ls.hover.end(o );
1368                                                 
1369                                         });
1370                                         
1371                                         /*
1372                                                 things that can ber returned..
1373                                                 "int" (type only)
1374                          
1375                                                 Editor xxxx._thisJ
1376                                                 Jsrennder.jsrender Editor.file 
1377                                                 Palete.LanguageClient? JsRender.JsRender.getLanguageServer ()
1378                                                 Palete.LanguageClient? ls = _this.file.getLanguageServer()
1379                                                 async Lsp.Hover Palete.LanguageClient.hover (JsRender.JsRender file, int line, int offset) throws GLib.Error
1380                                                 .string JsRender.Node.node_pad = \"\" 
1381                                                 Gtk.TextIter iter
1382                                                 
1383                                           string Gtk.TextIter.get_text (Gtk.TextIter end)
1384                              
1385                         
1386                                         */
1387                                         
1388                                          // could never get this to work anywhere..
1389                                          // looks like its probably for calling stuff..
1390                                          // but always returns null..
1391                                          /*
1392                                 ls.signatureHelp.begin(
1393                                         _this.file, iter.get_line(), iter.get_line_offset(),
1394                                         ( a, o)  => {
1395                                                 var res = ls.signatureHelp.end(o );
1396                                                 
1397                                         });     
1398                         
1399                         */
1400                         });
1401                 }
1402
1403                 // user defined functions
1404         }
1405
1406
1407
1408         public class Xcls_Box15 : Object
1409         {
1410                 public Gtk.Box el;
1411                 private Editor  _this;
1412
1413
1414                         // my vars (def)
1415
1416                 // ctor
1417                 public Xcls_Box15(Editor _owner )
1418                 {
1419                         _this = _owner;
1420                         this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
1421
1422                         // my vars (dec)
1423
1424                         // set gobject values
1425                         this.el.homogeneous = false;
1426                         this.el.vexpand = false;
1427                         new Xcls_search_entry( _this );
1428                         this.el.append( _this.search_entry.el );
1429                         new Xcls_search_results( _this );
1430                         this.el.append( _this.search_results.el );
1431                         new Xcls_nextBtn( _this );
1432                         this.el.append( _this.nextBtn.el );
1433                         new Xcls_backBtn( _this );
1434                         this.el.append( _this.backBtn.el );
1435                         var child_5 = new Xcls_MenuButton21( _this );
1436                         child_5.ref();
1437                         this.el.append( child_5.el );
1438                 }
1439
1440                 // user defined functions
1441         }
1442         public class Xcls_search_entry : Object
1443         {
1444                 public Gtk.SearchEntry el;
1445                 private Editor  _this;
1446
1447
1448                         // my vars (def)
1449                 public Gtk.CssProvider css;
1450
1451                 // ctor
1452                 public Xcls_search_entry(Editor _owner )
1453                 {
1454                         _this = _owner;
1455                         _this.search_entry = this;
1456                         this.el = new Gtk.SearchEntry();
1457
1458                         // my vars (dec)
1459
1460                         // set gobject values
1461                         this.el.name = "editor-search-entry";
1462                         this.el.hexpand = true;
1463                         this.el.placeholder_text = "Press enter to search";
1464                         this.el.search_delay = 3;
1465                         var child_1 = new Xcls_EventControllerKey17( _this );
1466                         child_1.ref();
1467                         this.el.add_controller(  child_1.el );
1468
1469                         //listeners
1470                         this.el.search_changed.connect( ( ) => {
1471                         
1472                         _this.search(_this.search_entry.el.text);
1473                                  _this.search_results.updateResults();
1474                         
1475                                 GLib.Timeout.add_seconds(1,() => {
1476                                          _this.search_results.updateResults();
1477                                          return false;
1478                                  });
1479                         });
1480                 }
1481
1482                 // user defined functions
1483                 public void forwardSearch (bool change_focus) {
1484                 
1485                 
1486                         _this.forwardSearch(change_focus);
1487                 
1488                 /*
1489                 
1490                         switch(_this.windowstate.state) {
1491                                 case WindowState.State.CODEONLY:
1492                                 //case WindowState.State.CODE:
1493                                         // search the code being edited..
1494                                         _this.windowstate.code_editor_tab.forwardSearch(change_focus);
1495                                          
1496                                         break;
1497                                 case WindowState.State.PREVIEW:
1498                                         if (_this.windowstate.file.xtype == "Gtk") {
1499                                                 _this.windowstate.window_gladeview.forwardSearch(change_focus);
1500                                         } else { 
1501                                                  _this.windowstate.window_rooview.forwardSearch(change_focus);
1502                                         }
1503                                 
1504                                         break;
1505                         }
1506                         */
1507                         
1508                 }
1509         }
1510         public class Xcls_EventControllerKey17 : Object
1511         {
1512                 public Gtk.EventControllerKey el;
1513                 private Editor  _this;
1514
1515
1516                         // my vars (def)
1517
1518                 // ctor
1519                 public Xcls_EventControllerKey17(Editor _owner )
1520                 {
1521                         _this = _owner;
1522                         this.el = new Gtk.EventControllerKey();
1523
1524                         // my vars (dec)
1525
1526                         // set gobject values
1527
1528                         //listeners
1529                         this.el.key_pressed.connect( (keyval, keycode, state) => {
1530                         
1531                                 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1532                                     GLib.debug("SAVE: ctrl-g  pressed");
1533                                         _this.forwardSearch(true);
1534                                     return true;
1535                                 }
1536                             
1537                           
1538                                 if (keyval == Gdk.Key.Return && _this.search_entry.el.text.length > 0) {
1539                                         _this.forwardSearch(true);
1540                                         
1541                                         
1542                                     return true;
1543                         
1544                                 }    
1545                            // print(event.key.keyval)
1546                            
1547                             return false;
1548                         });
1549                 }
1550
1551                 // user defined functions
1552         }
1553
1554
1555         public class Xcls_search_results : Object
1556         {
1557                 public Gtk.Label el;
1558                 private Editor  _this;
1559
1560
1561                         // my vars (def)
1562
1563                 // ctor
1564                 public Xcls_search_results(Editor _owner )
1565                 {
1566                         _this = _owner;
1567                         _this.search_results = this;
1568                         this.el = new Gtk.Label( "No Results" );
1569
1570                         // my vars (dec)
1571
1572                         // set gobject values
1573                         this.el.margin_end = 4;
1574                         this.el.margin_start = 4;
1575                 }
1576
1577                 // user defined functions
1578                 public void updateResults () {
1579                         this.el.visible = true;
1580                         
1581                         var res = _this.searchcontext.get_occurrences_count();
1582                         if (res < 0) {
1583                                 _this.search_results.el.label = "??? Matches";          
1584                                 return;
1585                         }
1586                 
1587                         _this.nextBtn.el.sensitive = false;
1588                         _this.backBtn.el.sensitive = false;     
1589                 
1590                         if (res > 0) {
1591                                 _this.search_results.el.label = "%d Matches".printf(res);
1592                                 _this.nextBtn.el.sensitive = true;
1593                                 _this.backBtn.el.sensitive = true;
1594                                 return;
1595                         } 
1596                         _this.search_results.el.label = "No Matches";
1597                         
1598                 }
1599         }
1600
1601         public class Xcls_nextBtn : Object
1602         {
1603                 public Gtk.Button el;
1604                 private Editor  _this;
1605
1606
1607                         // my vars (def)
1608                 public bool always_show_image;
1609
1610                 // ctor
1611                 public Xcls_nextBtn(Editor _owner )
1612                 {
1613                         _this = _owner;
1614                         _this.nextBtn = this;
1615                         this.el = new Gtk.Button();
1616
1617                         // my vars (dec)
1618                         this.always_show_image = true;
1619
1620                         // set gobject values
1621                         this.el.icon_name = "go-down";
1622                         this.el.sensitive = false;
1623
1624                         //listeners
1625                         this.el.clicked.connect( (event) => {
1626                         
1627                                 _this.forwardSearch(true);
1628                                 
1629                                  
1630                         });
1631                 }
1632
1633                 // user defined functions
1634         }
1635
1636         public class Xcls_backBtn : Object
1637         {
1638                 public Gtk.Button el;
1639                 private Editor  _this;
1640
1641
1642                         // my vars (def)
1643                 public bool always_show_image;
1644
1645                 // ctor
1646                 public Xcls_backBtn(Editor _owner )
1647                 {
1648                         _this = _owner;
1649                         _this.backBtn = this;
1650                         this.el = new Gtk.Button();
1651
1652                         // my vars (dec)
1653                         this.always_show_image = true;
1654
1655                         // set gobject values
1656                         this.el.icon_name = "go-up";
1657                         this.el.sensitive = false;
1658
1659                         //listeners
1660                         this.el.clicked.connect( (event) => {
1661                         
1662                                 _this.backSearch(true);
1663                                  
1664                         });
1665                 }
1666
1667                 // user defined functions
1668         }
1669
1670         public class Xcls_MenuButton21 : Object
1671         {
1672                 public Gtk.MenuButton el;
1673                 private Editor  _this;
1674
1675
1676                         // my vars (def)
1677                 public bool always_show_image;
1678
1679                 // ctor
1680                 public Xcls_MenuButton21(Editor _owner )
1681                 {
1682                         _this = _owner;
1683                         this.el = new Gtk.MenuButton();
1684
1685                         // my vars (dec)
1686                         this.always_show_image = true;
1687
1688                         // set gobject values
1689                         this.el.icon_name = "emblem-system";
1690                         this.el.always_show_arrow = true;
1691                         new Xcls_search_settings( _this );
1692                         this.el.popover = _this.search_settings.el;
1693                 }
1694
1695                 // user defined functions
1696         }
1697         public class Xcls_search_settings : Object
1698         {
1699                 public Gtk.Popover el;
1700                 private Editor  _this;
1701
1702
1703                         // my vars (def)
1704
1705                 // ctor
1706                 public Xcls_search_settings(Editor _owner )
1707                 {
1708                         _this = _owner;
1709                         _this.search_settings = this;
1710                         this.el = new Gtk.Popover();
1711
1712                         // my vars (dec)
1713
1714                         // set gobject values
1715                         var child_1 = new Xcls_Box23( _this );
1716                         child_1.ref();
1717                         this.el.child = child_1.el;
1718                 }
1719
1720                 // user defined functions
1721         }
1722         public class Xcls_Box23 : Object
1723         {
1724                 public Gtk.Box el;
1725                 private Editor  _this;
1726
1727
1728                         // my vars (def)
1729
1730                 // ctor
1731                 public Xcls_Box23(Editor _owner )
1732                 {
1733                         _this = _owner;
1734                         this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
1735
1736                         // my vars (dec)
1737
1738                         // set gobject values
1739                         new Xcls_case_sensitive( _this );
1740                         this.el.append( _this.case_sensitive.el );
1741                         new Xcls_regex( _this );
1742                         this.el.append( _this.regex.el );
1743                         new Xcls_multiline( _this );
1744                         this.el.append( _this.multiline.el );
1745                 }
1746
1747                 // user defined functions
1748         }
1749         public class Xcls_case_sensitive : Object
1750         {
1751                 public Gtk.CheckButton el;
1752                 private Editor  _this;
1753
1754
1755                         // my vars (def)
1756
1757                 // ctor
1758                 public Xcls_case_sensitive(Editor _owner )
1759                 {
1760                         _this = _owner;
1761                         _this.case_sensitive = this;
1762                         this.el = new Gtk.CheckButton();
1763
1764                         // my vars (dec)
1765
1766                         // set gobject values
1767                         this.el.label = "Case Sensitive";
1768
1769                         // init method
1770
1771                         {
1772                                 this.el.show();
1773                         }
1774                 }
1775
1776                 // user defined functions
1777         }
1778
1779         public class Xcls_regex : Object
1780         {
1781                 public Gtk.CheckButton el;
1782                 private Editor  _this;
1783
1784
1785                         // my vars (def)
1786
1787                 // ctor
1788                 public Xcls_regex(Editor _owner )
1789                 {
1790                         _this = _owner;
1791                         _this.regex = this;
1792                         this.el = new Gtk.CheckButton();
1793
1794                         // my vars (dec)
1795
1796                         // set gobject values
1797                         this.el.label = "Regex";
1798
1799                         // init method
1800
1801                         {
1802                                 this.el.show();
1803                         }
1804                 }
1805
1806                 // user defined functions
1807         }
1808
1809         public class Xcls_multiline : Object
1810         {
1811                 public Gtk.CheckButton el;
1812                 private Editor  _this;
1813
1814
1815                         // my vars (def)
1816
1817                 // ctor
1818                 public Xcls_multiline(Editor _owner )
1819                 {
1820                         _this = _owner;
1821                         _this.multiline = this;
1822                         this.el = new Gtk.CheckButton();
1823
1824                         // my vars (dec)
1825
1826                         // set gobject values
1827                         this.el.label = "Multi-line (add \\n)";
1828                 }
1829
1830                 // user defined functions
1831         }
1832
1833
1834
1835
1836
1837
1838         public class Xcls_Box27 : Object
1839         {
1840                 public Gtk.Box el;
1841                 private Editor  _this;
1842
1843
1844                         // my vars (def)
1845
1846                 // ctor
1847                 public Xcls_Box27(Editor _owner )
1848                 {
1849                         _this = _owner;
1850                         this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
1851
1852                         // my vars (dec)
1853
1854                         // set gobject values
1855                         this.el.hexpand = true;
1856                         this.el.vexpand = true;
1857                         var child_1 = new Xcls_Box28( _this );
1858                         child_1.ref();
1859                         this.el.append( child_1.el );
1860                         new Xcls_navigationwindow( _this );
1861                         this.el.append( _this.navigationwindow.el );
1862                 }
1863
1864                 // user defined functions
1865         }
1866         public class Xcls_Box28 : Object
1867         {
1868                 public Gtk.Box el;
1869                 private Editor  _this;
1870
1871
1872                         // my vars (def)
1873
1874                 // ctor
1875                 public Xcls_Box28(Editor _owner )
1876                 {
1877                         _this = _owner;
1878                         this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
1879
1880                         // my vars (dec)
1881
1882                         // set gobject values
1883                 }
1884
1885                 // user defined functions
1886         }
1887
1888         public class Xcls_navigationwindow : Object
1889         {
1890                 public Gtk.ScrolledWindow el;
1891                 private Editor  _this;
1892
1893
1894                         // my vars (def)
1895
1896                 // ctor
1897                 public Xcls_navigationwindow(Editor _owner )
1898                 {
1899                         _this = _owner;
1900                         _this.navigationwindow = this;
1901                         this.el = new Gtk.ScrolledWindow();
1902
1903                         // my vars (dec)
1904
1905                         // set gobject values
1906                         this.el.hexpand = true;
1907                         this.el.vexpand = true;
1908                         this.el.visible = false;
1909                         new Xcls_navigation( _this );
1910                         this.el.child = _this.navigation.el;
1911                 }
1912
1913                 // user defined functions
1914         }
1915         public class Xcls_navigation : Object
1916         {
1917                 public Gtk.ColumnView el;
1918                 private Editor  _this;
1919
1920
1921                         // my vars (def)
1922                 public int last_selected_line;
1923                 public Gtk.Widget? selected_row;
1924
1925                 // ctor
1926                 public Xcls_navigation(Editor _owner )
1927                 {
1928                         _this = _owner;
1929                         _this.navigation = this;
1930                         new Xcls_navigationselmodel( _this );
1931                         this.el = new Gtk.ColumnView( _this.navigationselmodel.el );
1932
1933                         // my vars (dec)
1934                         this.last_selected_line = -1;
1935                         this.selected_row = null;
1936
1937                         // set gobject values
1938                         this.el.name = "editor-navigation";
1939                         var child_2 = new Xcls_ColumnViewColumn31( _this );
1940                         child_2.ref();
1941                         this.el.append_column( child_2.el );
1942                         var child_3 = new Xcls_GestureClick40( _this );
1943                         child_3.ref();
1944                         this.el.add_controller(  child_3.el );
1945                 }
1946
1947                 // user defined functions
1948                 public Gtk.Widget? getRowWidgetAt (double x,  double  y, out string pos) {
1949                 
1950                         pos = "";
1951                         var w = this.el.pick(x, y, Gtk.PickFlags.DEFAULT);
1952                         //GLib.debug("got widget %s", w == null ? "nothing" : w.get_type().name());
1953                         if (w == null) {
1954                                 return null;
1955                         }
1956                         
1957                         var row= w.get_ancestor(GLib.Type.from_name("GtkColumnViewRowWidget"));
1958                         if (row == null) {
1959                                 return null;
1960                         }
1961                         
1962                         //GLib.debug("got colview %s", row == null ? "nothing" : row.get_type().name());
1963                          
1964                  
1965                         
1966                         //GLib.debug("row number is %d", rn);
1967                         //GLib.debug("click %d, %d", (int)x, (int)y);
1968                         // above or belw
1969                         Graphene.Rect  bounds;
1970                         row.compute_bounds(this.el, out bounds);
1971                         //GLib.debug("click x=%d, y=%d, w=%d, h=%d", 
1972                         //      (int)bounds.get_x(), (int)bounds.get_y(),
1973                         //      (int)bounds.get_width(), (int)bounds.get_height()
1974                         //      );
1975                         var ypos = y - bounds.get_y();
1976                         //GLib.debug("rel ypos = %d", (int)ypos);       
1977                         var rpos = 100.0 * (ypos / bounds.get_height());
1978                         //GLib.debug("rel pos = %d %%", (int)rpos);
1979                         pos = "over";
1980                         
1981                         if (rpos > 80) {
1982                                 pos = "below";
1983                         } else if (rpos < 20) {
1984                                 pos = "above";
1985                         } 
1986                         return row;
1987                  }
1988                 public void show (Gee.ArrayList<Lsp.DocumentSymbol> syms) {
1989                         _this.navigationwindow.el.show();
1990                         //_this.navliststore.el.remove_all();
1991                         
1992                         
1993                         var ls  = new GLib.ListStore(typeof(Lsp.DocumentSymbol));
1994                         
1995                         foreach(var sym in syms) {
1996                                 ls.append(sym);
1997                         }
1998                         Lsp.DocumentSymbol.copyList(ls, _this.navliststore.el);
1999                         //_this.navliststore.el.append(sym);
2000                         this.last_selected_line = -1;
2001                         GLib.Idle.add(() => {
2002                                 _this.navigationsort.collapseOnLoad();
2003                                 Gtk.TextIter iter;
2004                                 _this.buffer.el.get_iter_at_offset (
2005                                                 out iter, _this.buffer.el.cursor_position);
2006                                 
2007                                 GLib.debug("idle update scroll %d, %d", iter.get_line(),
2008                                                 iter.get_line_offset());
2009                                 this.updateSelectedLine(
2010                                                 (uint)iter.get_line(),
2011                                                 (uint)iter.get_line_offset()
2012                                 );
2013                                 return false;
2014                         });
2015                 
2016                 }
2017                 public int getRowAt (double x,  double  y, out string pos) {
2018                 
2019                         pos = "";
2020                         var w = this.el.pick(x, y, Gtk.PickFlags.DEFAULT);
2021                         //GLib.debug("got widget %s", w == null ? "nothing" : w.get_type().name());
2022                         if (w == null) {
2023                                 return -1;
2024                         }
2025                         
2026                         var row= w.get_ancestor(GLib.Type.from_name("GtkColumnViewRowWidget"));
2027                         if (row == null) {
2028                                 return -1;
2029                         }
2030                         
2031                         //GLib.debug("got colview %s", row == null ? "nothing" : row.get_type().name());
2032                          
2033                         var rn = 0;
2034                         var cr = row;
2035                          
2036                         while (cr.get_prev_sibling() != null) {
2037                                 rn++;
2038                                 cr = cr.get_prev_sibling();
2039                         }
2040                         
2041                         //GLib.debug("row number is %d", rn);
2042                         //GLib.debug("click %d, %d", (int)x, (int)y);
2043                         // above or belw
2044                         Graphene.Rect  bounds;
2045                         row.compute_bounds(this.el, out bounds);
2046                         //GLib.debug("click x=%d, y=%d, w=%d, h=%d", 
2047                         //      (int)bounds.get_x(), (int)bounds.get_y(),
2048                         //      (int)bounds.get_width(), (int)bounds.get_height()
2049                         //      );
2050                         var ypos = y - bounds.get_y();
2051                         //GLib.debug("rel ypos = %d", (int)ypos);       
2052                         var rpos = 100.0 * (ypos / bounds.get_height());
2053                         //GLib.debug("rel pos = %d %%", (int)rpos);
2054                         pos = "over";
2055                         
2056                         if (rpos > 80) {
2057                                 pos = "below";
2058                         } else if (rpos < 20) {
2059                                 pos = "above";
2060                         } 
2061                         return rn;
2062                  }
2063                 public void updateSelectedLine (uint line, uint chr) {
2064                         if (line == this.last_selected_line) {
2065                                 return;
2066                         }
2067                         GLib.debug("select line %d", (int)line);
2068                         this.last_selected_line = (int)line;
2069                         
2070                         
2071                         var new_row = -1;
2072                         var sym = _this.navliststore.symbolAtLine(line, chr);
2073                         if (sym != null) {
2074                                 new_row = _this.navigationsort.getRowFromSymbol(sym);
2075                                 GLib.debug("select line %d - row found %d", (int)line, new_row);
2076                         } else {
2077                                 GLib.debug(" no symbol found at line %d", (int)line);
2078                         }
2079                         
2080                         if (this.selected_row != null) { 
2081                                 GLib.debug(" remove selected row");
2082                                 this.selected_row.remove_css_class("selected-row");
2083                         }
2084                         this.selected_row  = null;
2085                         if (new_row > -1) {
2086                                 this.el.scroll_to(new_row,null,Gtk.ListScrollFlags.NONE, null);
2087                                 var row = sym.get_data<Gtk.Widget>("widget");
2088                                 if (row != null) {
2089                                         GLib.debug(" Add selected row");
2090                                         
2091                                         row.add_css_class("selected-row");
2092                                         this.selected_row = row;
2093                 
2094                                         
2095                                 } else {
2096                                         GLib.debug("could not find widget on row %d", new_row);
2097                                 }
2098                 
2099                         }
2100                 
2101                 
2102                 }
2103         }
2104         public class Xcls_ColumnViewColumn31 : Object
2105         {
2106                 public Gtk.ColumnViewColumn el;
2107                 private Editor  _this;
2108
2109
2110                         // my vars (def)
2111
2112                 // ctor
2113                 public Xcls_ColumnViewColumn31(Editor _owner )
2114                 {
2115                         _this = _owner;
2116                         var child_1 = new Xcls_SignalListItemFactory32( _this );
2117                         child_1.ref();
2118                         this.el = new Gtk.ColumnViewColumn( "Code Navigation", child_1.el );
2119
2120                         // my vars (dec)
2121
2122                         // set gobject values
2123                         this.el.expand = true;
2124                 }
2125
2126                 // user defined functions
2127         }
2128         public class Xcls_SignalListItemFactory32 : Object
2129         {
2130                 public Gtk.SignalListItemFactory el;
2131                 private Editor  _this;
2132
2133
2134                         // my vars (def)
2135
2136                 // ctor
2137                 public Xcls_SignalListItemFactory32(Editor _owner )
2138                 {
2139                         _this = _owner;
2140                         this.el = new Gtk.SignalListItemFactory();
2141
2142                         // my vars (dec)
2143
2144                         // set gobject values
2145
2146                         //listeners
2147                         this.el.setup.connect( (listitem) => {
2148                                 
2149                                 var expand = new Gtk.TreeExpander();
2150                                  
2151                                 expand.set_indent_for_depth(true);
2152                                 expand.set_indent_for_icon(true);
2153                                 var hbox = new Gtk.Box(Gtk.Orientation.HORIZONTAL,0);
2154                                 var icon = new Gtk.Image();
2155                                 var lbl = new Gtk.Label("");
2156                                 lbl.use_markup = true;
2157                                 lbl.ellipsize = Pango.EllipsizeMode.END;
2158                                 
2159                                 icon.margin_end = 4;
2160                                 lbl.justify = Gtk.Justification.LEFT;
2161                                 lbl.xalign = 0;
2162                         
2163                         //      listitem.activatable = true; ??
2164                                 
2165                                 hbox.append(icon);
2166                                 hbox.append(lbl);
2167                                 expand.set_child(hbox);
2168                                 ((Gtk.ListItem)listitem).set_child(expand);
2169                                 
2170                         });
2171                         this.el.bind.connect( (listitem) => {
2172                                  
2173                                 // GLib.debug("listitme is is %s", ((Gtk.ListItem)listitem).get_type().name());
2174                                 
2175                                 //var expand = (Gtk.TreeExpander) ((Gtk.ListItem)listitem).get_child();
2176                                 var expand = (Gtk.TreeExpander)  ((Gtk.ListItem)listitem).get_child();
2177                                  
2178                                  
2179                                 var hbox = (Gtk.Box) expand.child;
2180                          
2181                                 
2182                                 var img = (Gtk.Image) hbox.get_first_child();
2183                                 var lbl = (Gtk.Label) img.get_next_sibling();
2184                                 
2185                                 var lr = (Gtk.TreeListRow)((Gtk.ListItem)listitem).get_item();
2186                                 var sym = (Lsp.DocumentSymbol) lr.get_item();
2187                                 
2188                                 sym.set_data<Gtk.Widget>("widget", expand.get_parent());
2189                                 expand.get_parent().get_parent().set_data<Lsp.DocumentSymbol>("symbol", sym);
2190                                 
2191                                 //GLib.debug("save sym on %s", expand.get_parent().get_parent().get_type().name());
2192                                 
2193                                 //GLib.debug("got %d children for %s" , (int)sym.children.get_n_items(), sym.name);
2194                             
2195                             expand.set_hide_expander( sym.children.get_n_items()  < 1);
2196                                 expand.set_list_row(lr);
2197                                 //this.in_bind = true;
2198                                 // default is to expand
2199                          
2200                                 //this.in_bind = false;
2201                                 
2202                                 sym.bind_property("symbol_icon",
2203                                             img, "icon_name",
2204                                            GLib.BindingFlags.SYNC_CREATE);
2205                                 
2206                                 hbox.css_classes = { sym.symbol_icon };
2207                                 
2208                                 sym.bind_property("name",
2209                                             lbl, "label",
2210                                            GLib.BindingFlags.SYNC_CREATE);
2211                                 // should be better?- --line no?
2212                                 sym.bind_property("tooltip",
2213                                             lbl, "tooltip_markup",
2214                                            GLib.BindingFlags.SYNC_CREATE);
2215                                 // bind image...
2216                                 
2217                         });
2218                 }
2219
2220                 // user defined functions
2221         }
2222
2223
2224         public class Xcls_navigationselmodel : Object
2225         {
2226                 public Gtk.NoSelection el;
2227                 private Editor  _this;
2228
2229
2230                         // my vars (def)
2231
2232                 // ctor
2233                 public Xcls_navigationselmodel(Editor _owner )
2234                 {
2235                         _this = _owner;
2236                         _this.navigationselmodel = this;
2237                         new Xcls_navigationsort( _this );
2238                         this.el = new Gtk.NoSelection( _this.navigationsort.el );
2239
2240                         // my vars (dec)
2241
2242                         // set gobject values
2243                 }
2244
2245                 // user defined functions
2246         }
2247         public class Xcls_navigationsort : Object
2248         {
2249                 public Gtk.SortListModel el;
2250                 private Editor  _this;
2251
2252
2253                         // my vars (def)
2254
2255                 // ctor
2256                 public Xcls_navigationsort(Editor _owner )
2257                 {
2258                         _this = _owner;
2259                         _this.navigationsort = this;
2260                         var child_1 = new Xcls_TreeListModel35( _this );
2261                         child_1.ref();
2262                         var child_2 = new Xcls_TreeListRowSorter37( _this );
2263                         child_2.ref();
2264                         this.el = new Gtk.SortListModel( child_1.el, child_2.el );
2265
2266                         // my vars (dec)
2267
2268                         // set gobject values
2269                 }
2270
2271                 // user defined functions
2272                 public void collapseOnLoad () {
2273                         for (var i=0;i < this.el.get_n_items(); i++) {
2274                                 var tr = (Gtk.TreeListRow)this.el.get_item(i);
2275                                 var sym =  (Lsp.DocumentSymbol)tr.get_item();
2276                                 switch (sym.kind) {
2277                                         case Lsp.SymbolKind.Enum: 
2278                                                 tr.expanded = false;
2279                                                 break;
2280                                         default:
2281                                                 //tr.expanded = true;
2282                                                 break;
2283                                 }
2284                         }
2285                  
2286                         
2287                 
2288                 
2289                 }
2290                 public int getRowFromSymbol (Lsp.DocumentSymbol sym) {
2291                 
2292                         for (var i=0;i < this.el.get_n_items(); i++) {
2293                                 var tr = (Gtk.TreeListRow)this.el.get_item(i);
2294                            
2295                                 if (sym.equals( (Lsp.DocumentSymbol)tr.get_item())) {
2296                                         return i;
2297                                 }
2298                         }
2299                         return -1;
2300                 }
2301                 public Lsp.DocumentSymbol? getSymbolAt (uint row) {
2302                 
2303                    var tr = (Gtk.TreeListRow)this.el.get_item(row);
2304                    
2305                    var a = tr.get_item();;   
2306                    GLib.debug("get_item (2) = %s", a.get_type().name());
2307                         
2308                    
2309                    return (Lsp.DocumentSymbol)tr.get_item();
2310                          
2311                 }
2312         }
2313         public class Xcls_TreeListModel35 : Object
2314         {
2315                 public Gtk.TreeListModel el;
2316                 private Editor  _this;
2317
2318
2319                         // my vars (def)
2320
2321                 // ctor
2322                 public Xcls_TreeListModel35(Editor _owner )
2323                 {
2324                         _this = _owner;
2325                         new Xcls_navliststore( _this );
2326                         this.el = new Gtk.TreeListModel( _this.navliststore.el, false, true, (item) => {
2327  
2328         return ((Lsp.DocumentSymbol)item).children;
2329 }
2330  );
2331
2332                         // my vars (dec)
2333
2334                         // set gobject values
2335
2336                         //listeners
2337                         this.el.items_changed.connect( (position, removed, added) => {
2338                                 GLib.debug("tree item changed %d , %d , %d",(int) position, (int)removed, (int) added);
2339                                  if (added < 1) { 
2340                                         return;
2341                                 }
2342                                 //var sym = (Lsp.DocumentSymbol) this.el.get_item(position);
2343                                 var row = this.el.get_row(position);
2344                                 
2345                                 GLib.debug("got %s", row.get_item().get_type().name());
2346                                 
2347                         
2348                         });
2349                 }
2350
2351                 // user defined functions
2352         }
2353         public class Xcls_navliststore : Object
2354         {
2355                 public GLib.ListStore el;
2356                 private Editor  _this;
2357
2358
2359                         // my vars (def)
2360
2361                 // ctor
2362                 public Xcls_navliststore(Editor _owner )
2363                 {
2364                         _this = _owner;
2365                         _this.navliststore = this;
2366                         this.el = new GLib.ListStore( typeof(Lsp.DocumentSymbol) );
2367
2368                         // my vars (dec)
2369
2370                         // set gobject values
2371                 }
2372
2373                 // user defined functions
2374                 public Lsp.DocumentSymbol? symbolAtLine (uint line, uint chr) {
2375                  
2376                         
2377                         for(var i = 0; i < this.el.get_n_items();i++) {
2378                                 var el = (Lsp.DocumentSymbol)this.el.get_item(i);
2379                                 //GLib.debug("Check sym %s : %d-%d",
2380                                 //      el.name , (int)el.range.start.line,
2381                                 //      (int)el.range.end.line
2382                                 //);
2383                                 var ret = el.containsLine(line,chr);
2384                                 if (ret != null) {
2385                                         return ret;
2386                                 }
2387                                 
2388                         }
2389                         
2390                         return null;
2391                 }
2392         }
2393
2394
2395         public class Xcls_TreeListRowSorter37 : Object
2396         {
2397                 public Gtk.TreeListRowSorter el;
2398                 private Editor  _this;
2399
2400
2401                         // my vars (def)
2402
2403                 // ctor
2404                 public Xcls_TreeListRowSorter37(Editor _owner )
2405                 {
2406                         _this = _owner;
2407                         var child_1 = new Xcls_StringSorter38( _this );
2408                         child_1.ref();
2409                         this.el = new Gtk.TreeListRowSorter( child_1.el );
2410
2411                         // my vars (dec)
2412
2413                         // set gobject values
2414                 }
2415
2416                 // user defined functions
2417         }
2418         public class Xcls_StringSorter38 : Object
2419         {
2420                 public Gtk.StringSorter el;
2421                 private Editor  _this;
2422
2423
2424                         // my vars (def)
2425
2426                 // ctor
2427                 public Xcls_StringSorter38(Editor _owner )
2428                 {
2429                         _this = _owner;
2430                         var child_1 = new Xcls_PropertyExpression39( _this );
2431                         child_1.ref();
2432                         this.el = new Gtk.StringSorter( child_1.el );
2433
2434                         // my vars (dec)
2435
2436                         // set gobject values
2437                 }
2438
2439                 // user defined functions
2440         }
2441         public class Xcls_PropertyExpression39 : Object
2442         {
2443                 public Gtk.PropertyExpression el;
2444                 private Editor  _this;
2445
2446
2447                         // my vars (def)
2448
2449                 // ctor
2450                 public Xcls_PropertyExpression39(Editor _owner )
2451                 {
2452                         _this = _owner;
2453                         this.el = new Gtk.PropertyExpression( typeof(Lsp.DocumentSymbol), null, "sort_key" );
2454
2455                         // my vars (dec)
2456
2457                         // set gobject values
2458                 }
2459
2460                 // user defined functions
2461         }
2462
2463
2464
2465
2466
2467         public class Xcls_GestureClick40 : Object
2468         {
2469                 public Gtk.GestureClick el;
2470                 private Editor  _this;
2471
2472
2473                         // my vars (def)
2474
2475                 // ctor
2476                 public Xcls_GestureClick40(Editor _owner )
2477                 {
2478                         _this = _owner;
2479                         this.el = new Gtk.GestureClick();
2480
2481                         // my vars (dec)
2482
2483                         // set gobject values
2484
2485                         //listeners
2486                         this.el.pressed.connect( (n_press, x, y) => {
2487                                 string pos;
2488                                 var row = _this.navigation.getRowWidgetAt(x,y, out pos );
2489                         
2490                             if (row == null) {
2491                                     GLib.debug("no row selected items");
2492                                     return;
2493                             }
2494                                 GLib.debug("got click on %s", row.get_type().name());    
2495                             //Lsp.DocumentSymbol
2496                             var sym =  row.get_data<Lsp.DocumentSymbol>("symbol");
2497                             if (sym == null) {
2498                                 return;
2499                                 }
2500                                 /*
2501                                  "range" : {
2502                                       "start" : {
2503                                         "line" : 1410,
2504                                         "character" : 8
2505                                       },
2506                                       "end" : {
2507                                         "line" : 1410,
2508                                         "character" : 39
2509                                       }
2510                                     },
2511                                 */
2512                              GLib.debug("goto line %d",   (int)sym.range.start.line); 
2513                             _this.scroll_to_line((int)sym.range.start.line);
2514                             Gtk.TextIter iter;
2515                             _this.buffer.el.get_iter_at_line_offset(out iter, 
2516                                 (int)sym.range.start.line,
2517                                 (int)sym.range.start.character
2518                                 );
2519                             _this.buffer.el.place_cursor(iter);
2520                                 
2521                         });
2522                 }
2523
2524                 // user defined functions
2525         }
2526
2527
2528
2529
2530
2531 }