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