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