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