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