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