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