src/Builder4/Editor.bjs
[roobuilder] / src / Builder4 / Editor.vala
1 static Editor  _Editor;
2
3 public class Editor : Object
4 {
5         public Gtk.Box el;
6         private Editor  _this;
7
8         public static Editor singleton()
9         {
10                 if (_Editor == null) {
11                     _Editor= new Editor();
12                 }
13                 return _Editor;
14         }
15         public Xcls_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(iter.get_line());
937                         
938                         
939                         });
940                         this.el.changed.connect( () => {
941                             // check syntax??
942                             // ??needed..??
943                             _this.save_button.el.sensitive = true;
944                             print("EDITOR CHANGED");
945                             this.checkSyntax();
946                            
947                             _this.dirty = true;
948                         
949                             // this.get('/LeftPanel.model').changed(  str , false);
950                             return ;
951                         });
952                 }
953
954                 // user defined functions
955                 public bool OLDhighlightErrorsJson (string type, Json.Object obj) {
956                         Gtk.TextIter start;
957                         Gtk.TextIter end;     
958                         this.el.get_bounds (out start, out end);
959                 
960                         this.el.remove_source_marks (start, end, type);
961                         GLib.debug("highlight errors");          
962                 
963                          // we should highlight other types of errors..
964                 
965                         if (!obj.has_member(type)) {
966                                 GLib.debug("Return has no errors\n");
967                                 return true;
968                         }
969                 
970                         if (_this.window.windowstate.state != WindowState.State.CODEONLY 
971                                 &&
972                                 _this.window.windowstate.state != WindowState.State.CODE
973                                 ) {
974                                 GLib.debug("windowstate != CODEONLY?");
975                                 
976                                 return true;
977                         } 
978                 
979                         //this.marks = new Gee.HashMap<int,string>();
980                         var err = obj.get_object_member(type);
981                  
982                         if (_this.file == null) {
983                                 GLib.debug("file is null?");
984                                 return true;
985                 
986                         }
987                         var valafn = _this.file.path;
988                 
989                         if (_this.file.xtype != "PlainFile") {
990                 
991                                 valafn = "";
992                                 try {             
993                                         var  regex = new Regex("\\.bjs$");
994                                         // should not happen
995                                         valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
996                                 } catch (GLib.RegexError e) {
997                                         return true;
998                                 }   
999                 
1000                 
1001                 
1002                         }
1003                         if (!err.has_member(valafn)) {
1004                                 GLib.debug("File path has no errors");
1005                                 return  true;
1006                         }
1007                 
1008                         var lines = err.get_object_member(valafn);
1009                         
1010                         var offset = 1;
1011                         if (obj.has_member("line_offset")) { // ?? why??
1012                                 offset = (int)obj.get_int_member("line_offset") + 1;
1013                         }
1014                 
1015                 
1016                         var tlines = this.el.get_line_count () +1;
1017                         
1018                         if (_this.prop != null) {
1019                         
1020                                 tlines = _this.prop.end_line + 1;
1021                                 offset = _this.prop.start_line + 1;
1022                         
1023                         }
1024                         
1025                 
1026                 
1027                         lines.foreach_member((obj, line, node) => {
1028                                 
1029                              Gtk.TextIter iter;
1030                 //        print("get inter\n");
1031                             var eline = int.parse(line) - offset;
1032                             GLib.debug("GOT ERROR on line %s -- converted to %d  (offset = %d)\n", line,eline, offset);
1033                             
1034                             
1035                             if (eline > tlines || eline < 0) {
1036                                 return;
1037                             }
1038                            
1039                             
1040                             this.el.get_iter_at_line( out iter, eline);
1041                             //print("mark line\n");
1042                             var msg  = "";
1043                             var ar = lines.get_array_member(line);
1044                             for (var i = 0 ; i < ar.get_length(); i++) {
1045                                 if (ar.get_string_element(i) == "Success") {
1046                                         continue;
1047                                 }
1048                                         msg += (msg.length > 0) ? "\n" : "";
1049                                         msg += ar.get_string_element(i);
1050                                 }
1051                                 if (msg == "") {
1052                                         return;
1053                                 }
1054                                 msg = "Line: %d".printf(eline+1) +  " " + msg;
1055                             this.el.create_source_mark(msg, type, iter);
1056                             GLib.debug("set line %d to %m", eline, msg);
1057                            // this.marks.set(eline, msg);
1058                         } );
1059                         return false;
1060                 
1061                 
1062                 
1063                 
1064                 
1065                         }
1066                 public bool checkSyntax () {
1067                  
1068                     
1069                     var str = this.toString();
1070                     
1071                     // needed???
1072                     if (this.error_line > 0) {
1073                          Gtk.TextIter start;
1074                          Gtk.TextIter end;     
1075                         this.el.get_bounds (out start, out end);
1076                 
1077                         this.el.remove_source_marks (start, end, null);
1078                     }
1079                     if (str.length < 1) {
1080                         print("checkSyntax - empty string?\n");
1081                         return true;
1082                     }
1083                     
1084                     // bit presumptiona
1085                     if (_this.file.xtype == "PlainFile") {
1086                     
1087                         // assume it's gtk...
1088                          var  oldcode =_this.file.toSource();
1089                         _this.file.setSource(str);
1090                             BuilderApplication.showSpinner("appointment soon","document change pending");
1091                         _this.file.getLanguageServer().document_change(_this.file);
1092                 
1093                         _this.file.setSource(oldcode);
1094                         
1095                                  
1096                         return true;
1097                     
1098                     }
1099                    if (_this.file == null) {
1100                        return true;
1101                    }
1102                  
1103                     
1104                 
1105                       
1106                      
1107                     GLib.debug("calling validate");    
1108                     // clear the buttons.
1109                         if (_this.prop.name == "xns" || _this.prop.name == "xtype") {
1110                                 return true ;
1111                         }
1112                         var oldcode  = _this.prop.val;
1113                         
1114                         _this.prop.val = str;
1115                         _this.node.updated_count++;
1116                     _this.file.getLanguageServer().document_change(_this.file);
1117                     _this.node.updated_count++;
1118                     _this.prop.val = oldcode;
1119                     
1120                     
1121                     //print("done mark line\n");
1122                      
1123                     return true; // at present allow saving - even if it's invalid..
1124                 }
1125                 public bool highlightErrors ( Gee.HashMap<int,string> validate_res) {
1126                          
1127                         this.error_line = validate_res.size;
1128                 
1129                         if (this.error_line < 1) {
1130                                 return true;
1131                         }
1132                         var tlines = this.el.get_line_count ();
1133                         Gtk.TextIter iter;
1134                         var valiter = validate_res.map_iterator();
1135                         while (valiter.next()) {
1136                 
1137                         //        print("get inter\n");
1138                                 var eline = valiter.get_key();
1139                                 if (eline > tlines) {
1140                                         continue;
1141                                 }
1142                                 this.el.get_iter_at_line( out iter, eline);
1143                                 //print("mark line\n");
1144                                 this.el.create_source_mark(valiter.get_value(), "ERR", iter);
1145                         }   
1146                         return false;
1147                 }
1148                 public string toString () {
1149                     
1150                     Gtk.TextIter s;
1151                     Gtk.TextIter e;
1152                     this.el.get_start_iter(out s);
1153                     this.el.get_end_iter(out e);
1154                     var ret = this.el.get_text(s,e,true);
1155                     //print("TO STRING? " + ret);
1156                     return ret;
1157                 }
1158         }
1159
1160         public class Xcls_keystate : Object
1161         {
1162                 public Gtk.EventControllerKey el;
1163                 private Editor  _this;
1164
1165
1166                         // my vars (def)
1167                 public bool is_control;
1168
1169                 // ctor
1170                 public Xcls_keystate(Editor _owner )
1171                 {
1172                         _this = _owner;
1173                         _this.keystate = this;
1174                         this.el = new Gtk.EventControllerKey();
1175
1176                         // my vars (dec)
1177                         this.is_control = false;
1178
1179                         // set gobject values
1180
1181                         //listeners
1182                         this.el.key_released.connect( (keyval, keycode, state) => {
1183                         
1184                                  if (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) {
1185                                         this.is_control = false;
1186                                 }
1187                             if (keyval == Gdk.Key.s && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1188                                 GLib.debug("SAVE: ctrl-S  pressed");
1189                                 _this.saveContents();
1190                                 return;
1191                             }
1192                             
1193                             if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1194                                     GLib.debug("SAVE: ctrl-g  pressed");
1195                                         _this.forwardSearch(true);
1196                                     return;
1197                                 }
1198                                 if (keyval == Gdk.Key.f && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1199                                     GLib.debug("SAVE: ctrl-f  pressed");
1200                                         _this.search_entry.el.grab_focus();
1201                                         _this.search_entry.el.select_region(0,-1);
1202                                     return;
1203                                 }
1204                                 if (keyval == Gdk.Key.space && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1205                                         _this.view.el.show_completion();
1206                                 }
1207                                 
1208                                 Gtk.TextIter iter;
1209                                 _this.buffer.el.get_iter_at_offset( out iter, _this.buffer.el.cursor_position);  
1210                                 var line  = iter.get_line();
1211                                 var offset = iter.get_line_offset();
1212                                 GLib.debug("line  %d  off %d", line ,offset);
1213                                 if (_this.prop != null) {
1214                                         line += _this.prop.start_line + 1; // i think..
1215                                         offset += 12; // should probably be 8 without namespaced 
1216                                         GLib.debug("guess line  %d  off %d", line ,offset);
1217                                 } 
1218                             //_this.view.el.show_completion();
1219                            // print(event.key.keyval)
1220                            
1221                            
1222                            
1223                             
1224                             return;
1225                          
1226                          
1227                         });
1228                         this.el.key_pressed.connect( (keyval, keycode, state) => {
1229                         
1230                                 if (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) {
1231                                         this.is_control = true;
1232                                 }
1233                                 return false;
1234                         });
1235                 }
1236
1237                 // user defined functions
1238         }
1239
1240         public class Xcls_EventControllerScroll13 : Object
1241         {
1242                 public Gtk.EventControllerScroll el;
1243                 private Editor  _this;
1244
1245
1246                         // my vars (def)
1247                 public double distance;
1248
1249                 // ctor
1250                 public Xcls_EventControllerScroll13(Editor _owner )
1251                 {
1252                         _this = _owner;
1253                         this.el = new Gtk.EventControllerScroll( Gtk.EventControllerScrollFlags.VERTICAL );
1254
1255                         // my vars (dec)
1256                         this.distance = 0.0f;
1257
1258                         // set gobject values
1259
1260                         //listeners
1261                         this.el.scroll.connect( (dx, dy) => {
1262                                 if (!_this.keystate.is_control) {
1263                                         return false;
1264                                 }
1265                                  //GLib.debug("scroll %f",  dy);
1266                                 
1267                                 this.distance += dy;
1268                                 
1269                                 //GLib.debug("scroll %f / %f",  dy, this.distance);
1270                          
1271                                  if (this.distance < -1) {
1272                          
1273                                         BuilderApplication.settings.editor_font_size ++;
1274                                         this.distance = 0;
1275                                 }
1276                                 if (this.distance > 1) {
1277                                         BuilderApplication.settings.editor_font_size --;
1278                                         this.distance = 0;
1279                                 }
1280                                  
1281                                 return true;
1282                         });
1283                 }
1284
1285                 // user defined functions
1286         }
1287
1288         public class Xcls_GestureClick14 : Object
1289         {
1290                 public Gtk.GestureClick el;
1291                 private Editor  _this;
1292
1293
1294                         // my vars (def)
1295
1296                 // ctor
1297                 public Xcls_GestureClick14(Editor _owner )
1298                 {
1299                         _this = _owner;
1300                         this.el = new Gtk.GestureClick();
1301
1302                         // my vars (dec)
1303
1304                         // set gobject values
1305                 }
1306
1307                 // user defined functions
1308         }
1309
1310
1311
1312         public class Xcls_Box15 : Object
1313         {
1314                 public Gtk.Box el;
1315                 private Editor  _this;
1316
1317
1318                         // my vars (def)
1319
1320                 // ctor
1321                 public Xcls_Box15(Editor _owner )
1322                 {
1323                         _this = _owner;
1324                         this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
1325
1326                         // my vars (dec)
1327
1328                         // set gobject values
1329                         this.el.homogeneous = false;
1330                         this.el.vexpand = false;
1331                         new Xcls_search_entry( _this );
1332                         this.el.append( _this.search_entry.el );
1333                         new Xcls_search_results( _this );
1334                         this.el.append( _this.search_results.el );
1335                         new Xcls_nextBtn( _this );
1336                         this.el.append( _this.nextBtn.el );
1337                         new Xcls_backBtn( _this );
1338                         this.el.append( _this.backBtn.el );
1339                         var child_5 = new Xcls_MenuButton21( _this );
1340                         child_5.ref();
1341                         this.el.append( child_5.el );
1342                 }
1343
1344                 // user defined functions
1345         }
1346         public class Xcls_search_entry : Object
1347         {
1348                 public Gtk.SearchEntry el;
1349                 private Editor  _this;
1350
1351
1352                         // my vars (def)
1353                 public Gtk.CssProvider css;
1354
1355                 // ctor
1356                 public Xcls_search_entry(Editor _owner )
1357                 {
1358                         _this = _owner;
1359                         _this.search_entry = this;
1360                         this.el = new Gtk.SearchEntry();
1361
1362                         // my vars (dec)
1363
1364                         // set gobject values
1365                         this.el.name = "editor-search-entry";
1366                         this.el.hexpand = true;
1367                         this.el.placeholder_text = "Press enter to search";
1368                         this.el.search_delay = 3;
1369                         var child_1 = new Xcls_EventControllerKey17( _this );
1370                         child_1.ref();
1371                         this.el.add_controller(  child_1.el );
1372
1373                         //listeners
1374                         this.el.search_changed.connect( ( ) => {
1375                         
1376                         _this.search(_this.search_entry.el.text);
1377                                  _this.search_results.updateResults();
1378                         
1379                                 GLib.Timeout.add_seconds(1,() => {
1380                                          _this.search_results.updateResults();
1381                                          return false;
1382                                  });
1383                         });
1384                 }
1385
1386                 // user defined functions
1387                 public void forwardSearch (bool change_focus) {
1388                 
1389                 
1390                         _this.forwardSearch(change_focus);
1391                 
1392                 /*
1393                 
1394                         switch(_this.windowstate.state) {
1395                                 case WindowState.State.CODEONLY:
1396                                 //case WindowState.State.CODE:
1397                                         // search the code being edited..
1398                                         _this.windowstate.code_editor_tab.forwardSearch(change_focus);
1399                                          
1400                                         break;
1401                                 case WindowState.State.PREVIEW:
1402                                         if (_this.windowstate.file.xtype == "Gtk") {
1403                                                 _this.windowstate.window_gladeview.forwardSearch(change_focus);
1404                                         } else { 
1405                                                  _this.windowstate.window_rooview.forwardSearch(change_focus);
1406                                         }
1407                                 
1408                                         break;
1409                         }
1410                         */
1411                         
1412                 }
1413         }
1414         public class Xcls_EventControllerKey17 : Object
1415         {
1416                 public Gtk.EventControllerKey el;
1417                 private Editor  _this;
1418
1419
1420                         // my vars (def)
1421
1422                 // ctor
1423                 public Xcls_EventControllerKey17(Editor _owner )
1424                 {
1425                         _this = _owner;
1426                         this.el = new Gtk.EventControllerKey();
1427
1428                         // my vars (dec)
1429
1430                         // set gobject values
1431
1432                         //listeners
1433                         this.el.key_pressed.connect( (keyval, keycode, state) => {
1434                         
1435                                 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1436                                     GLib.debug("SAVE: ctrl-g  pressed");
1437                                         _this.forwardSearch(true);
1438                                     return true;
1439                                 }
1440                             
1441                           
1442                                 if (keyval == Gdk.Key.Return && _this.search_entry.el.text.length > 0) {
1443                                         _this.forwardSearch(true);
1444                                         
1445                                         
1446                                     return true;
1447                         
1448                                 }    
1449                            // print(event.key.keyval)
1450                            
1451                             return false;
1452                         });
1453                 }
1454
1455                 // user defined functions
1456         }
1457
1458
1459         public class Xcls_search_results : Object
1460         {
1461                 public Gtk.Label el;
1462                 private Editor  _this;
1463
1464
1465                         // my vars (def)
1466
1467                 // ctor
1468                 public Xcls_search_results(Editor _owner )
1469                 {
1470                         _this = _owner;
1471                         _this.search_results = this;
1472                         this.el = new Gtk.Label( "No Results" );
1473
1474                         // my vars (dec)
1475
1476                         // set gobject values
1477                         this.el.margin_end = 4;
1478                         this.el.margin_start = 4;
1479                 }
1480
1481                 // user defined functions
1482                 public void updateResults () {
1483                         this.el.visible = true;
1484                         
1485                         var res = _this.searchcontext.get_occurrences_count();
1486                         if (res < 0) {
1487                                 _this.search_results.el.label = "??? Matches";          
1488                                 return;
1489                         }
1490                 
1491                         _this.nextBtn.el.sensitive = false;
1492                         _this.backBtn.el.sensitive = false;     
1493                 
1494                         if (res > 0) {
1495                                 _this.search_results.el.label = "%d Matches".printf(res);
1496                                 _this.nextBtn.el.sensitive = true;
1497                                 _this.backBtn.el.sensitive = true;
1498                                 return;
1499                         } 
1500                         _this.search_results.el.label = "No Matches";
1501                         
1502                 }
1503         }
1504
1505         public class Xcls_nextBtn : Object
1506         {
1507                 public Gtk.Button el;
1508                 private Editor  _this;
1509
1510
1511                         // my vars (def)
1512                 public bool always_show_image;
1513
1514                 // ctor
1515                 public Xcls_nextBtn(Editor _owner )
1516                 {
1517                         _this = _owner;
1518                         _this.nextBtn = this;
1519                         this.el = new Gtk.Button();
1520
1521                         // my vars (dec)
1522                         this.always_show_image = true;
1523
1524                         // set gobject values
1525                         this.el.icon_name = "go-down";
1526                         this.el.sensitive = false;
1527
1528                         //listeners
1529                         this.el.clicked.connect( (event) => {
1530                         
1531                                 _this.forwardSearch(true);
1532                                 
1533                                  
1534                         });
1535                 }
1536
1537                 // user defined functions
1538         }
1539
1540         public class Xcls_backBtn : Object
1541         {
1542                 public Gtk.Button el;
1543                 private Editor  _this;
1544
1545
1546                         // my vars (def)
1547                 public bool always_show_image;
1548
1549                 // ctor
1550                 public Xcls_backBtn(Editor _owner )
1551                 {
1552                         _this = _owner;
1553                         _this.backBtn = this;
1554                         this.el = new Gtk.Button();
1555
1556                         // my vars (dec)
1557                         this.always_show_image = true;
1558
1559                         // set gobject values
1560                         this.el.icon_name = "go-up";
1561                         this.el.sensitive = false;
1562
1563                         //listeners
1564                         this.el.clicked.connect( (event) => {
1565                         
1566                                 _this.backSearch(true);
1567                                  
1568                         });
1569                 }
1570
1571                 // user defined functions
1572         }
1573
1574         public class Xcls_MenuButton21 : Object
1575         {
1576                 public Gtk.MenuButton el;
1577                 private Editor  _this;
1578
1579
1580                         // my vars (def)
1581                 public bool always_show_image;
1582
1583                 // ctor
1584                 public Xcls_MenuButton21(Editor _owner )
1585                 {
1586                         _this = _owner;
1587                         this.el = new Gtk.MenuButton();
1588
1589                         // my vars (dec)
1590                         this.always_show_image = true;
1591
1592                         // set gobject values
1593                         this.el.icon_name = "emblem-system";
1594                         this.el.always_show_arrow = true;
1595                         new Xcls_search_settings( _this );
1596                         this.el.popover = _this.search_settings.el;
1597                 }
1598
1599                 // user defined functions
1600         }
1601         public class Xcls_search_settings : Object
1602         {
1603                 public Gtk.Popover el;
1604                 private Editor  _this;
1605
1606
1607                         // my vars (def)
1608
1609                 // ctor
1610                 public Xcls_search_settings(Editor _owner )
1611                 {
1612                         _this = _owner;
1613                         _this.search_settings = this;
1614                         this.el = new Gtk.Popover();
1615
1616                         // my vars (dec)
1617
1618                         // set gobject values
1619                         var child_1 = new Xcls_Box23( _this );
1620                         child_1.ref();
1621                         this.el.child = child_1.el;
1622                 }
1623
1624                 // user defined functions
1625         }
1626         public class Xcls_Box23 : Object
1627         {
1628                 public Gtk.Box el;
1629                 private Editor  _this;
1630
1631
1632                         // my vars (def)
1633
1634                 // ctor
1635                 public Xcls_Box23(Editor _owner )
1636                 {
1637                         _this = _owner;
1638                         this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
1639
1640                         // my vars (dec)
1641
1642                         // set gobject values
1643                         new Xcls_case_sensitive( _this );
1644                         this.el.append( _this.case_sensitive.el );
1645                         new Xcls_regex( _this );
1646                         this.el.append( _this.regex.el );
1647                         new Xcls_multiline( _this );
1648                         this.el.append( _this.multiline.el );
1649                 }
1650
1651                 // user defined functions
1652         }
1653         public class Xcls_case_sensitive : Object
1654         {
1655                 public Gtk.CheckButton el;
1656                 private Editor  _this;
1657
1658
1659                         // my vars (def)
1660
1661                 // ctor
1662                 public Xcls_case_sensitive(Editor _owner )
1663                 {
1664                         _this = _owner;
1665                         _this.case_sensitive = this;
1666                         this.el = new Gtk.CheckButton();
1667
1668                         // my vars (dec)
1669
1670                         // set gobject values
1671                         this.el.label = "Case Sensitive";
1672
1673                         // init method
1674
1675                         {
1676                                 this.el.show();
1677                         }
1678                 }
1679
1680                 // user defined functions
1681         }
1682
1683         public class Xcls_regex : Object
1684         {
1685                 public Gtk.CheckButton el;
1686                 private Editor  _this;
1687
1688
1689                         // my vars (def)
1690
1691                 // ctor
1692                 public Xcls_regex(Editor _owner )
1693                 {
1694                         _this = _owner;
1695                         _this.regex = this;
1696                         this.el = new Gtk.CheckButton();
1697
1698                         // my vars (dec)
1699
1700                         // set gobject values
1701                         this.el.label = "Regex";
1702
1703                         // init method
1704
1705                         {
1706                                 this.el.show();
1707                         }
1708                 }
1709
1710                 // user defined functions
1711         }
1712
1713         public class Xcls_multiline : Object
1714         {
1715                 public Gtk.CheckButton el;
1716                 private Editor  _this;
1717
1718
1719                         // my vars (def)
1720
1721                 // ctor
1722                 public Xcls_multiline(Editor _owner )
1723                 {
1724                         _this = _owner;
1725                         _this.multiline = this;
1726                         this.el = new Gtk.CheckButton();
1727
1728                         // my vars (dec)
1729
1730                         // set gobject values
1731                         this.el.label = "Multi-line (add \\n)";
1732                 }
1733
1734                 // user defined functions
1735         }
1736
1737
1738
1739
1740
1741
1742         public class Xcls_navigationwindow : Object
1743         {
1744                 public Gtk.ScrolledWindow el;
1745                 private Editor  _this;
1746
1747
1748                         // my vars (def)
1749
1750                 // ctor
1751                 public Xcls_navigationwindow(Editor _owner )
1752                 {
1753                         _this = _owner;
1754                         _this.navigationwindow = this;
1755                         this.el = new Gtk.ScrolledWindow();
1756
1757                         // my vars (dec)
1758
1759                         // set gobject values
1760                         this.el.visible = false;
1761                         new Xcls_navigation( _this );
1762                         this.el.child = _this.navigation.el;
1763                 }
1764
1765                 // user defined functions
1766         }
1767         public class Xcls_navigation : Object
1768         {
1769                 public Gtk.ColumnView el;
1770                 private Editor  _this;
1771
1772
1773                         // my vars (def)
1774                 public int last_selected_line;
1775                 public Gtk.Widget? selected_row;
1776
1777                 // ctor
1778                 public Xcls_navigation(Editor _owner )
1779                 {
1780                         _this = _owner;
1781                         _this.navigation = this;
1782                         new Xcls_navigationselmodel( _this );
1783                         this.el = new Gtk.ColumnView( _this.navigationselmodel.el );
1784
1785                         // my vars (dec)
1786                         this.last_selected_line = -1;
1787                         this.selected_row = null;
1788
1789                         // set gobject values
1790                         this.el.name = "editor-navigation";
1791                         var child_2 = new Xcls_ColumnViewColumn29( _this );
1792                         child_2.ref();
1793                         this.el.append_column( child_2.el );
1794                         var child_3 = new Xcls_GestureClick38( _this );
1795                         child_3.ref();
1796                         this.el.add_controller(  child_3.el );
1797                 }
1798
1799                 // user defined functions
1800                 public Gtk.Widget? getWidgetAtRow (uint row) {
1801                 /*
1802                         
1803                 from            https://discourse.gnome.org/t/gtk4-finding-a-row-data-on-gtkcolumnview/8465
1804                         var colview = gesture.widget;
1805                         var line_no = check_list_widget(colview, x,y);
1806                          if (line_no > -1) {
1807                                 var item = colview.model.get_item(line_no);
1808                                  
1809                         }
1810                         */
1811                                 //GLib.debug("Get Widget At Row %d", (int)row);
1812                         var  child = this.el.get_first_child(); 
1813                         var line_no = -1; 
1814                         var reading_header = true;
1815                          
1816                         while (child != null) {
1817                                         //GLib.debug("Got %s", child.get_type().name());
1818                            
1819                            if (reading_header) {
1820                                                 
1821                 
1822                                                 if (child.get_type().name() != "GtkColumnListView") {
1823                                                    
1824                                                         child = child.get_next_sibling();
1825                                                         continue;
1826                                                 }
1827                                                 // should be columnlistview
1828                                                 child = child.get_first_child(); 
1829                                          
1830                                          
1831                                                 
1832                                                 reading_header = false;
1833                                                 continue;
1834                                     }
1835                                     
1836                                   
1837                             
1838                                     line_no++;
1839                                         if (line_no == row) {
1840                                                 //GLib.debug("Returning widget %s", child.get_type().name());
1841                                             return (Gtk.Widget)child;
1842                                     }
1843                                 child = child.get_next_sibling(); 
1844                         }
1845                                 //GLib.debug("Rturning null");
1846                         return null;
1847                 
1848                  }
1849                 public void show (Gee.ArrayList<Lsp.DocumentSymbol> syms) {
1850                         _this.navigationwindow.el.show();
1851                         _this.navliststore.el.remove_all();
1852                         foreach(var sym in syms) {
1853                                 _this.navliststore.el.append(sym);
1854                         }
1855                         
1856                 
1857                 }
1858                 public int getRowAt (double x,  double  y, out string pos) {
1859                 
1860                         pos = "";
1861                         var w = this.el.pick(x, y, Gtk.PickFlags.DEFAULT);
1862                         //GLib.debug("got widget %s", w == null ? "nothing" : w.get_type().name());
1863                         if (w == null) {
1864                                 return -1;
1865                         }
1866                         
1867                         var row= w.get_ancestor(GLib.Type.from_name("GtkColumnViewRowWidget"));
1868                         if (row == null) {
1869                                 return -1;
1870                         }
1871                         
1872                         //GLib.debug("got colview %s", row == null ? "nothing" : row.get_type().name());
1873                          
1874                         var rn = 0;
1875                         var cr = row;
1876                          
1877                         while (cr.get_prev_sibling() != null) {
1878                                 rn++;
1879                                 cr = cr.get_prev_sibling();
1880                         }
1881                         
1882                         //GLib.debug("row number is %d", rn);
1883                         //GLib.debug("click %d, %d", (int)x, (int)y);
1884                         // above or belw
1885                         Graphene.Rect  bounds;
1886                         row.compute_bounds(this.el, out bounds);
1887                         //GLib.debug("click x=%d, y=%d, w=%d, h=%d", 
1888                         //      (int)bounds.get_x(), (int)bounds.get_y(),
1889                         //      (int)bounds.get_width(), (int)bounds.get_height()
1890                         //      );
1891                         var ypos = y - bounds.get_y();
1892                         //GLib.debug("rel ypos = %d", (int)ypos);       
1893                         var rpos = 100.0 * (ypos / bounds.get_height());
1894                         //GLib.debug("rel pos = %d %%", (int)rpos);
1895                         pos = "over";
1896                         
1897                         if (rpos > 80) {
1898                                 pos = "below";
1899                         } else if (rpos < 20) {
1900                                 pos = "above";
1901                         } 
1902                         return rn;
1903                  }
1904                 public void updateSelectedLine (uint line, uint chr) {
1905                         if (line == this.last_selected_line) {
1906                                 return;
1907                         }
1908                         GLib.debug("select line %d", (int)ine);
1909                         this.last_selected_line = (int)line;
1910                         
1911                         
1912                         var new_row = -1;
1913                         var sym = _this.navliststore.symbolAtLine(line, chr);
1914                         if (sym != null) {
1915                                 new_row = _this.navigationsort.getRowFromSymbol(sym);
1916                                 GLib.debug("select line %d - row found %d", (int)line, new_row);
1917                         } else {
1918                                 GLib.debug(" no symbol found at line %d", (int)line);
1919                         }
1920                         
1921                         if (this.selected_row != null) { 
1922                                 GLib.debug(" remove selected row");
1923                                 this.selected_row.remove_css_class("selected-row");
1924                         }
1925                         this.selected_row  = null;
1926                         if (new_row > -1) {
1927                                 var row = this.getWidgetAtRow(new_row);
1928                                 if (row != null) {
1929                                         GLib.debug(" Add selected row");
1930                                         
1931                                         row.add_css_class("selected-row");
1932                                         this.selected_row = row;
1933                                         this.el.scroll_to(new_row,null,Gtk.ListScrollFlags.NONE, null);
1934                                         
1935                                 } else {
1936                                         GLib.debug("could not find widget on row %d", new_row);
1937                                 }
1938                 
1939                         }
1940                 
1941                 
1942                 }
1943         }
1944         public class Xcls_ColumnViewColumn29 : Object
1945         {
1946                 public Gtk.ColumnViewColumn el;
1947                 private Editor  _this;
1948
1949
1950                         // my vars (def)
1951
1952                 // ctor
1953                 public Xcls_ColumnViewColumn29(Editor _owner )
1954                 {
1955                         _this = _owner;
1956                         var child_1 = new Xcls_SignalListItemFactory30( _this );
1957                         child_1.ref();
1958                         this.el = new Gtk.ColumnViewColumn( "Code Navigation", child_1.el );
1959
1960                         // my vars (dec)
1961
1962                         // set gobject values
1963                         this.el.expand = true;
1964                 }
1965
1966                 // user defined functions
1967         }
1968         public class Xcls_SignalListItemFactory30 : Object
1969         {
1970                 public Gtk.SignalListItemFactory el;
1971                 private Editor  _this;
1972
1973
1974                         // my vars (def)
1975
1976                 // ctor
1977                 public Xcls_SignalListItemFactory30(Editor _owner )
1978                 {
1979                         _this = _owner;
1980                         this.el = new Gtk.SignalListItemFactory();
1981
1982                         // my vars (dec)
1983
1984                         // set gobject values
1985
1986                         //listeners
1987                         this.el.setup.connect( (listitem) => {
1988                                 
1989                                 var expand = new Gtk.TreeExpander();
1990                                  
1991                                 expand.set_indent_for_depth(true);
1992                                 expand.set_indent_for_icon(true);
1993                                 var hbox = new Gtk.Box(Gtk.Orientation.HORIZONTAL,0);
1994                                 var icon = new Gtk.Image();
1995                                 var lbl = new Gtk.Label("");
1996                                 lbl.use_markup = true;
1997                                 lbl.ellipsize = Pango.EllipsizeMode.END;
1998                                 
1999                                 icon.margin_end = 4;
2000                                 lbl.justify = Gtk.Justification.LEFT;
2001                                 lbl.xalign = 0;
2002                         
2003                         //      listitem.activatable = true; ??
2004                                 
2005                                 hbox.append(icon);
2006                                 hbox.append(lbl);
2007                                 expand.set_child(hbox);
2008                                 ((Gtk.ListItem)listitem).set_child(expand);
2009                                 
2010                         });
2011                         this.el.bind.connect( (listitem) => {
2012                                 // GLib.debug("listitme is is %s", ((Gtk.ListItem)listitem).get_type().name());
2013                                 
2014                                 //var expand = (Gtk.TreeExpander) ((Gtk.ListItem)listitem).get_child();
2015                                 var expand = (Gtk.TreeExpander)  ((Gtk.ListItem)listitem).get_child();
2016                                  
2017                                  
2018                                 var hbox = (Gtk.Box) expand.child;
2019                          
2020                                 
2021                                 var img = (Gtk.Image) hbox.get_first_child();
2022                                 var lbl = (Gtk.Label) img.get_next_sibling();
2023                                 
2024                                 var lr = (Gtk.TreeListRow)((Gtk.ListItem)listitem).get_item();
2025                                 var sym = (Lsp.DocumentSymbol) lr.get_item();
2026                                 
2027                                 GLib.debug("got %d children for %s" , (int)sym.children.get_n_items(), sym.name);
2028                             
2029                             expand.set_hide_expander( sym.children.get_n_items()  < 1);
2030                                 expand.set_list_row(lr);
2031                                 
2032                                 sym.bind_property("symbol_icon",
2033                                             img, "icon_name",
2034                                            GLib.BindingFlags.SYNC_CREATE);
2035                                 
2036                                 hbox.add_css_class(sym.symbol_icon);
2037                                 
2038                                 sym.bind_property("name",
2039                                             lbl, "label",
2040                                            GLib.BindingFlags.SYNC_CREATE);
2041                                 // should be better?- --line no?
2042                                 sym.bind_property("tooltip",
2043                                             lbl, "tooltip_markup",
2044                                            GLib.BindingFlags.SYNC_CREATE);
2045                                 // bind image...
2046                                 
2047                         });
2048                 }
2049
2050                 // user defined functions
2051         }
2052
2053
2054         public class Xcls_navigationselmodel : Object
2055         {
2056                 public Gtk.NoSelection el;
2057                 private Editor  _this;
2058
2059
2060                         // my vars (def)
2061
2062                 // ctor
2063                 public Xcls_navigationselmodel(Editor _owner )
2064                 {
2065                         _this = _owner;
2066                         _this.navigationselmodel = this;
2067                         new Xcls_navigationsort( _this );
2068                         this.el = new Gtk.NoSelection( _this.navigationsort.el );
2069
2070                         // my vars (dec)
2071
2072                         // set gobject values
2073                 }
2074
2075                 // user defined functions
2076                 public int getRowFromSymbolx (Lsp.DocumentSymbol sym) {
2077                 
2078                         for (var i=0;i < this.el.get_n_items(); i++) {
2079                                 var tr = (Gtk.TreeListRow)this.el.get_item(i);
2080                            
2081                                 if (sym.equals( (Lsp.DocumentSymbol)tr.get_item())) {
2082                                         return i;
2083                                 }
2084                         }
2085                         return -1;
2086                 }
2087                 public Lsp.DocumentSymbol? getSymbollAtOLD (uint row) {
2088                 
2089                    var tr = (Gtk.TreeListRow)this.el.get_item(row);
2090                    
2091                    var a = tr.get_item();;   
2092                    GLib.debug("get_item (2) = %s", a.get_type().name());
2093                         
2094                    
2095                    return (Lsp.DocumentSymbol)tr.get_item();
2096                          
2097                 }
2098         }
2099         public class Xcls_navigationsort : Object
2100         {
2101                 public Gtk.SortListModel el;
2102                 private Editor  _this;
2103
2104
2105                         // my vars (def)
2106
2107                 // ctor
2108                 public Xcls_navigationsort(Editor _owner )
2109                 {
2110                         _this = _owner;
2111                         _this.navigationsort = this;
2112                         var child_1 = new Xcls_TreeListModel33( _this );
2113                         child_1.ref();
2114                         var child_2 = new Xcls_TreeListRowSorter35( _this );
2115                         child_2.ref();
2116                         this.el = new Gtk.SortListModel( child_1.el, child_2.el );
2117
2118                         // my vars (dec)
2119
2120                         // set gobject values
2121                 }
2122
2123                 // user defined functions
2124                 public int getRowFromSymbol (Lsp.DocumentSymbol sym) {
2125                 
2126                         for (var i=0;i < this.el.get_n_items(); i++) {
2127                                 var tr = (Gtk.TreeListRow)this.el.get_item(i);
2128                            
2129                                 if (sym.equals( (Lsp.DocumentSymbol)tr.get_item())) {
2130                                         return i;
2131                                 }
2132                         }
2133                         return -1;
2134                 }
2135                 public Lsp.DocumentSymbol? getSymbolAt (uint row) {
2136                 
2137                    var tr = (Gtk.TreeListRow)this.el.get_item(row);
2138                    
2139                    var a = tr.get_item();;   
2140                    GLib.debug("get_item (2) = %s", a.get_type().name());
2141                         
2142                    
2143                    return (Lsp.DocumentSymbol)tr.get_item();
2144                          
2145                 }
2146         }
2147         public class Xcls_TreeListModel33 : Object
2148         {
2149                 public Gtk.TreeListModel el;
2150                 private Editor  _this;
2151
2152
2153                         // my vars (def)
2154
2155                 // ctor
2156                 public Xcls_TreeListModel33(Editor _owner )
2157                 {
2158                         _this = _owner;
2159                         new Xcls_navliststore( _this );
2160                         this.el = new Gtk.TreeListModel( _this.navliststore.el, false, true, (item) => {
2161  
2162         return ((Lsp.DocumentSymbol)item).children;
2163 }
2164  );
2165
2166                         // my vars (dec)
2167
2168                         // set gobject values
2169                 }
2170
2171                 // user defined functions
2172         }
2173         public class Xcls_navliststore : Object
2174         {
2175                 public GLib.ListStore el;
2176                 private Editor  _this;
2177
2178
2179                         // my vars (def)
2180
2181                 // ctor
2182                 public Xcls_navliststore(Editor _owner )
2183                 {
2184                         _this = _owner;
2185                         _this.navliststore = this;
2186                         this.el = new GLib.ListStore( typeof(Lsp.DocumentSymbol) );
2187
2188                         // my vars (dec)
2189
2190                         // set gobject values
2191                 }
2192
2193                 // user defined functions
2194                 public Lsp.DocumentSymbol? symbolAtLine (uint line, uint chr) {
2195                  
2196                         
2197                         for(var i = 0; i < this.el.get_n_items();i++) {
2198                                 var el = (Lsp.DocumentSymbol)this.el.get_item(i);
2199                                 //GLib.debug("Check sym %s : %d-%d",
2200                                 //      el.name , (int)el.range.start.line,
2201                                 //      (int)el.range.end.line
2202                                 //);
2203                                 var ret = el.containsLine(line,chr);
2204                                 if (ret != null) {
2205                                         return ret;
2206                                 }
2207                                 
2208                         }
2209                         
2210                         return null;
2211                 }
2212         }
2213
2214
2215         public class Xcls_TreeListRowSorter35 : Object
2216         {
2217                 public Gtk.TreeListRowSorter el;
2218                 private Editor  _this;
2219
2220
2221                         // my vars (def)
2222
2223                 // ctor
2224                 public Xcls_TreeListRowSorter35(Editor _owner )
2225                 {
2226                         _this = _owner;
2227                         var child_1 = new Xcls_StringSorter36( _this );
2228                         child_1.ref();
2229                         this.el = new Gtk.TreeListRowSorter( child_1.el );
2230
2231                         // my vars (dec)
2232
2233                         // set gobject values
2234                 }
2235
2236                 // user defined functions
2237         }
2238         public class Xcls_StringSorter36 : Object
2239         {
2240                 public Gtk.StringSorter el;
2241                 private Editor  _this;
2242
2243
2244                         // my vars (def)
2245
2246                 // ctor
2247                 public Xcls_StringSorter36(Editor _owner )
2248                 {
2249                         _this = _owner;
2250                         var child_1 = new Xcls_PropertyExpression37( _this );
2251                         child_1.ref();
2252                         this.el = new Gtk.StringSorter( child_1.el );
2253
2254                         // my vars (dec)
2255
2256                         // set gobject values
2257                 }
2258
2259                 // user defined functions
2260         }
2261         public class Xcls_PropertyExpression37 : Object
2262         {
2263                 public Gtk.PropertyExpression el;
2264                 private Editor  _this;
2265
2266
2267                         // my vars (def)
2268
2269                 // ctor
2270                 public Xcls_PropertyExpression37(Editor _owner )
2271                 {
2272                         _this = _owner;
2273                         this.el = new Gtk.PropertyExpression( typeof(Lsp.DocumentSymbol), null, "sort_key" );
2274
2275                         // my vars (dec)
2276
2277                         // set gobject values
2278                 }
2279
2280                 // user defined functions
2281         }
2282
2283
2284
2285
2286
2287         public class Xcls_GestureClick38 : Object
2288         {
2289                 public Gtk.GestureClick el;
2290                 private Editor  _this;
2291
2292
2293                         // my vars (def)
2294
2295                 // ctor
2296                 public Xcls_GestureClick38(Editor _owner )
2297                 {
2298                         _this = _owner;
2299                         this.el = new Gtk.GestureClick();
2300
2301                         // my vars (dec)
2302
2303                         // set gobject values
2304
2305                         //listeners
2306                         this.el.pressed.connect( (n_press, x, y) => {
2307                                 string pos;
2308                                 var row = _this.navigation.getRowAt(x,y, out pos );
2309                             if (row < 0) {
2310                                     GLib.debug("no row selected items");
2311                                     return;
2312                             }
2313                             //Lsp.DocumentSymbol
2314                             var sym =   _this.navigationsort.getSymbolAt(row);
2315                             if (sym == null) {
2316                                 return;
2317                                 }
2318                                 /*
2319                                  "range" : {
2320                                       "start" : {
2321                                         "line" : 1410,
2322                                         "character" : 8
2323                                       },
2324                                       "end" : {
2325                                         "line" : 1410,
2326                                         "character" : 39
2327                                       }
2328                                     },
2329                                 */
2330                              GLib.debug("goto line %d",   (int)sym.range.start.line); 
2331                             _this.scroll_to_line((int)sym.range.start.line);
2332                                 
2333                         });
2334                 }
2335
2336                 // user defined functions
2337         }
2338
2339
2340
2341
2342 }