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