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