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