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