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