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