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