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