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