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