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