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