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