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