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