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