Fix #8089 - phase 1 - code ast navigation
[roobuilder] / src / Builder4 / GtkView.vala
1 static Xcls_GtkView  _GtkView;
2
3 public class Xcls_GtkView : Object
4 {
5         public Gtk.Box el;
6         private Xcls_GtkView  _this;
7
8         public static Xcls_GtkView singleton()
9         {
10                 if (_GtkView == null) {
11                     _GtkView= new Xcls_GtkView();
12                 }
13                 return _GtkView;
14         }
15         public Xcls_notebook notebook;
16         public Xcls_label_preview label_preview;
17         public Xcls_label_code label_code;
18         public Xcls_view_layout view_layout;
19         public Xcls_container container;
20         public Xcls_sourceviewscroll sourceviewscroll;
21         public Xcls_sourceview sourceview;
22         public Xcls_buffer buffer;
23         public Xcls_keystate keystate;
24         public Xcls_search_entry search_entry;
25         public Xcls_search_results search_results;
26         public Xcls_nextBtn nextBtn;
27         public Xcls_backBtn backBtn;
28         public Xcls_search_settings search_settings;
29         public Xcls_case_sensitive case_sensitive;
30         public Xcls_regex regex;
31         public Xcls_multiline multiline;
32
33                 // my vars (def)
34         public Gtk.Widget lastObj;
35         public Xcls_MainWindow main_window;
36         public int last_error_counter;
37         public int last_search_end;
38         public GtkSource.SearchContext searchcontext;
39         public JsRender.JsRender file;
40
41         // ctor
42         public Xcls_GtkView()
43         {
44                 _this = this;
45                 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
46
47                 // my vars (dec)
48                 this.lastObj = null;
49                 this.last_error_counter = 0;
50                 this.last_search_end = 0;
51                 this.file = null;
52
53                 // set gobject values
54                 this.el.hexpand = true;
55                 this.el.vexpand = true;
56                 new Xcls_notebook( _this );
57                 this.el.append( _this.notebook.el );
58         }
59
60         // user defined functions
61         public void loadFile (JsRender.JsRender file) 
62         {
63                 this.file = null;
64                 
65                 if (file.tree == null) {
66                     return;
67                 }
68                 this.last_error_counter = -1;
69                 this.notebook.el.page = 0;// gtk preview 
70            
71           
72                 
73                this.file = file;     
74                 this.sourceview.loadFile();
75                
76                 this.searchcontext = null;
77                 this.last_error_counter = -1;
78                         this.updateErrorMarks();
79                 if (this.lastObj != null) {
80                     this.container.el.remove(this.lastObj);
81                 }
82                 
83                 // hide the compile view at present..
84                   
85                 
86                 var w = this.el.get_width();
87                 var h = this.el.get_height();
88                 
89                 print("ALLOC SET SIZES %d, %d\n", w,h); 
90                 
91                 // set the container size min to 500/500 or 20 px less than max..
92                 w = int.max (w-20, 500);
93                 h = int.max (h-20, 500); 
94                 
95                 print("SET SIZES %d, %d\n", w,h);       
96                 _this.container.el.set_size_request(w,h);
97                 
98                 _this.view_layout.el.set_size_request(w,h); 
99                 // should be baded on calc.. -- see update_scrolled.
100                
101                var fc = this.container.el.get_first_child();
102                if (fc != null) {
103                         this.container.el.remove(fc);
104                         }
105                 
106                         var xmlstr = JsRender.NodeToGlade.mungeFile( file);
107                         var builder = new Gtk.Builder();
108                         try {
109                                 if (!builder.add_from_string(xmlstr, xmlstr.length)) {
110                                         return;
111                                 }
112                         } catch(GLib.Error e) {
113                                 GLib.debug(e.message);
114                                 return;
115                         }
116                         
117         
118                         var obj = (Gtk.Widget) builder.get_object("w"+ file.tree.oid.to_string());
119                          this.container.el.append(obj);
120                     obj.show();
121                 this.createThumb();
122                  
123                          
124                
125                 
126         }
127         public void highlightNodeAtLine (int ln) {
128         
129                 // this is done from clicking on the editor..
130                  
131                 // highlight node...
132                 
133                         
134             var node = _this.file.lineToNode(ln+1);
135          
136             if (node == null) {
137                 //print("can not find node\n");
138                 return;
139             }
140             var prop = node.lineToProp(ln+1);
141             print("prop : %s", prop == null ? "???" : prop.name);
142                 
143                 
144             // ---------- this selects the tree's node...
145             
146             var ltree = _this.main_window.windowstate.left_tree;
147             ltree.model.selectNode(node);
148             //var tp = ltree.model.treePathFromNode(node);
149             
150             //print("got tree path %s\n", tp);
151             //if (tp == "") {
152                 //      return;
153                 //}
154             //_this.sourceview.allow_node_scroll = false; /// block node scrolling..
155                        
156            
157             //print("changing cursor on tree..\n");
158            
159         
160             
161             // let's try allowing editing on the methods.
162             // a little klunky at present..
163                 _this.sourceview.prop_selected = "";
164                 /*
165             if (prop != null) {
166                         //see if we can find it..
167                         var kv = prop.split(":");
168                         if (kv[0] == "p") {
169                         
170                         //var k = prop.get_key(kv[1]);
171                         // fixme -- need to determine if it's an editable property...
172                         _this.sourceview.prop_selected = prop;
173                         
174                         } else if (kv[0] == "l") {
175                                  _this.sourceview.prop_selected = prop;
176                                 
177                         }
178             }
179             */
180             //ltree.view.setCursor(tp, "editor");
181            // ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false); 
182            _this.sourceview.nodeSelected(node,false);
183             
184                     // scrolling is disabled... as node selection calls scroll 10ms after it changes.
185               //      GLib.Timeout.add_full(GLib.Priority.DEFAULT,100 , () => {
186                   //          this.allow_node_scroll = true;
187                   //          return false;
188               //      });
189               //  }
190                         
191                         
192                         
193                         
194                         
195                         
196                         
197                         
198                         
199                          
200         
201         }
202         public void forwardSearch (bool change_focus) {
203         
204                 if (this.searchcontext == null) {
205                         return;
206                 }
207                 this.notebook.el.page = 1;
208                 Gtk.TextIter beg, st,en;
209                 bool has_wrapped_around;
210                 var buf = this.sourceview.el.get_buffer();
211                 buf.get_iter_at_offset(out beg, this.last_search_end);
212                 if (!this.searchcontext.forward(beg, out st, out en, out has_wrapped_around)) {
213                         this.last_search_end = 0;
214                         return;
215                 }
216                 this.last_search_end = en.get_offset();
217                 if (change_focus) {
218                         this.sourceview.el.grab_focus();
219                 }
220                 buf.place_cursor(st);
221                 
222          
223                  
224                 this.sourceview.el.scroll_to_iter(st,  0.0f, true, 0.0f, 0.5f);
225                 
226                 
227                 var ln = st.get_line();
228                 
229                 this.highlightNodeAtLine(ln);
230         }
231         public void backSearch (bool change_focus) {
232         
233                 if (this.searchcontext == null) {
234                         return;
235                 } 
236                 
237                 Gtk.TextIter beg, st,en;
238                 bool has_wrapped_around;
239                 this.buffer.el.get_iter_at_offset(out beg, this.last_search_end -1 );
240                 
241                 if (!this.searchcontext.backward(beg, out st, out en, out has_wrapped_around)) {
242                 
243                         this.last_search_end = 0;
244                         return;
245                 }
246                 this.last_search_end = en.get_offset();
247                 if (change_focus) {
248                         this.sourceview.el.grab_focus();
249                 }
250                 this.buffer.el.place_cursor(st);
251                 this.sourceview.el.scroll_to_iter(st,  0.1f, true, 0.0f, 0.5f);
252                 var ln = st.get_line();
253                 this.highlightNodeAtLine(ln);
254                  
255         }
256         public int search (string in_txt) {
257                 this.notebook.el.page = 1;
258                 
259          
260            
261                 var s = new GtkSource.SearchSettings();
262                 s.case_sensitive = _this.case_sensitive.el.active;
263                 s.regex_enabled = _this.regex.el.active;        
264                 s.wrap_around = false;
265                 
266                 this.searchcontext = new GtkSource.SearchContext(this.buffer.el,s);
267                 this.searchcontext.set_highlight(true);
268                 var txt = in_txt;
269                 
270                 if (_this.multiline.el.active) {
271                         txt = in_txt.replace("\\n", "\n");
272                 }
273                 
274                 s.set_search_text(txt);
275                 Gtk.TextIter beg, st,en;
276                 bool has_wrapped_around;
277                 this.buffer.el.get_start_iter(out beg);
278                 this.searchcontext.forward(beg, out st, out en, out has_wrapped_around);
279                 this.last_search_end = 0;
280                 
281                 return this.searchcontext.get_occurrences_count();
282         
283          
284             
285         
286         }
287         public void createThumb () {
288             
289             
290             if (this.file == null) {
291                 return;
292             }
293             // only screenshot the gtk preview..
294             if (this.notebook.el.page > 0 ) {
295                 return;
296             }
297             
298             
299                 this.file.widgetToIcon(this.container.el); 
300         
301             
302             return;
303             
304             
305              
306              
307             
308             // should we hold until it's printed...
309              
310         
311             
312              
313         }
314         public void updateErrorMarks () {
315                 
316          
317         
318                 var buf = _this.buffer.el;
319                 Gtk.TextIter start;
320                 Gtk.TextIter end;     
321                 buf.get_bounds (out start, out end);
322         
323         
324          
325                 //GLib.debug("highlight errors");                
326         
327                  // we should highlight other types of errors..
328         
329          
330         
331                  
332                 if (_this.file == null) {
333                         GLib.debug("file is null?");
334                         return;
335         
336                 }
337                 var ar = this.file.getErrors();
338                 if (ar.size < 1) {
339                         buf.remove_tag_by_name ("ERR", start, end);
340                         buf.remove_tag_by_name ("WARN", start, end);
341                         buf.remove_tag_by_name ("DEPR", start, end);
342                         buf.remove_source_marks (start, end, "ERR");
343                         buf.remove_source_marks (start, end, "WARN");
344                         buf.remove_source_marks (start, end, "DEPR");
345                         this.last_error_counter = file.error_counter ;
346                         //GLib.debug("higjlight has no errors");
347                         return;
348                 }
349                 if (this.last_error_counter == file.error_counter) {
350                         return;
351                 }
352                 
353         
354          
355                  
356         
357                 var tlines = buf.get_line_count () +1;
358                 
359          
360                  
361                 buf.remove_source_marks (start, end, "ERR");
362                 buf.remove_source_marks (start, end, "WARN");
363                 buf.remove_source_marks (start, end, "DEPR");
364                 buf.remove_tag_by_name ("ERR", start, end);
365                 buf.remove_tag_by_name ("WARN", start, end);
366                 buf.remove_tag_by_name ("DEPR", start, end);
367                 foreach(var diag in ar) { 
368                 
369                         
370                      Gtk.TextIter iter;
371         //        print("get inter\n");
372                     var eline = (int)diag.range.start.line ;
373                     var eline_to = (int)diag.range.end.line;
374                     if (eline > tlines || eline < 0) {
375                         return;
376                     }
377                    
378                     
379                     buf.get_iter_at_line( out iter, eline);
380                    
381                          buf.get_iter_at_line_offset( out start, 
382                         eline, (int)diag.range.start.character); 
383                     buf.get_iter_at_line_offset( out end, 
384                         eline_to, (int)diag.range.end.character); 
385                         
386                     buf.apply_tag_by_name(diag.category, start, end);
387                    
388                    
389                         var msg = "Line: %d %s : %s".printf(eline+1, diag.category, diag.message);
390                     buf.create_source_mark( msg, diag.category, iter);
391                     GLib.debug("set line %d to %s", eline, msg);
392                     //this.marks.set(eline, msg);
393                 }
394                 this.last_error_counter = file.error_counter ;
395         
396         
397         
398          
399         
400         }
401         public void scroll_to_line (int line) {
402           // code preview...
403            
404            GLib.Timeout.add(100, () => {
405            
406            
407                     this.notebook.el.set_current_page(1);
408                    
409                           var buf = this.sourceview.el.get_buffer();
410                  
411                         var sbuf = (GtkSource.Buffer) buf;
412         
413         
414                         Gtk.TextIter iter;   
415                         sbuf.get_iter_at_line(out iter,  line);
416                         this.sourceview.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);
417                         return false;
418                 });   
419         
420            
421         }
422         public class Xcls_notebook : Object
423         {
424                 public Gtk.Notebook el;
425                 private Xcls_GtkView  _this;
426
427
428                         // my vars (def)
429
430                 // ctor
431                 public Xcls_notebook(Xcls_GtkView _owner )
432                 {
433                         _this = _owner;
434                         _this.notebook = this;
435                         this.el = new Gtk.Notebook();
436
437                         // my vars (dec)
438
439                         // set gobject values
440                         this.el.overflow = Gtk.Overflow.VISIBLE;
441                         new Xcls_label_preview( _this );
442                         new Xcls_label_code( _this );
443                         var child_3 = new Xcls_ScrolledWindow4( _this );
444                         child_3.ref();
445                         this.el.append_page ( child_3.el , _this.label_preview.el );
446                         var child_4 = new Xcls_Box7( _this );
447                         child_4.ref();
448                         this.el.append_page ( child_4.el , _this.label_code.el );
449                 }
450
451                 // user defined functions
452         }
453         public class Xcls_label_preview : Object
454         {
455                 public Gtk.Label el;
456                 private Xcls_GtkView  _this;
457
458
459                         // my vars (def)
460
461                 // ctor
462                 public Xcls_label_preview(Xcls_GtkView _owner )
463                 {
464                         _this = _owner;
465                         _this.label_preview = this;
466                         this.el = new Gtk.Label( "Preview" );
467
468                         // my vars (dec)
469
470                         // set gobject values
471                 }
472
473                 // user defined functions
474         }
475
476         public class Xcls_label_code : Object
477         {
478                 public Gtk.Label el;
479                 private Xcls_GtkView  _this;
480
481
482                         // my vars (def)
483
484                 // ctor
485                 public Xcls_label_code(Xcls_GtkView _owner )
486                 {
487                         _this = _owner;
488                         _this.label_code = this;
489                         this.el = new Gtk.Label( "Preview Generated Code" );
490
491                         // my vars (dec)
492
493                         // set gobject values
494                 }
495
496                 // user defined functions
497         }
498
499         public class Xcls_ScrolledWindow4 : Object
500         {
501                 public Gtk.ScrolledWindow el;
502                 private Xcls_GtkView  _this;
503
504
505                         // my vars (def)
506
507                 // ctor
508                 public Xcls_ScrolledWindow4(Xcls_GtkView _owner )
509                 {
510                         _this = _owner;
511                         this.el = new Gtk.ScrolledWindow();
512
513                         // my vars (dec)
514
515                         // set gobject values
516                         new Xcls_view_layout( _this );
517                         this.el.set_child ( _this.view_layout.el  );
518                 }
519
520                 // user defined functions
521         }
522         public class Xcls_view_layout : Object
523         {
524                 public Gtk.Fixed el;
525                 private Xcls_GtkView  _this;
526
527
528                         // my vars (def)
529
530                 // ctor
531                 public Xcls_view_layout(Xcls_GtkView _owner )
532                 {
533                         _this = _owner;
534                         _this.view_layout = this;
535                         this.el = new Gtk.Fixed();
536
537                         // my vars (dec)
538
539                         // set gobject values
540                         this.el.name = "gtkview-view-layout";
541                         new Xcls_container( _this );
542                         this.el.put ( _this.container.el , 10,10 );
543                 }
544
545                 // user defined functions
546         }
547         public class Xcls_container : Object
548         {
549                 public Gtk.Box el;
550                 private Xcls_GtkView  _this;
551
552
553                         // my vars (def)
554
555                 // ctor
556                 public Xcls_container(Xcls_GtkView _owner )
557                 {
558                         _this = _owner;
559                         _this.container = this;
560                         this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
561
562                         // my vars (dec)
563
564                         // set gobject values
565                 }
566
567                 // user defined functions
568         }
569
570
571
572         public class Xcls_Box7 : Object
573         {
574                 public Gtk.Box el;
575                 private Xcls_GtkView  _this;
576
577
578                         // my vars (def)
579
580                 // ctor
581                 public Xcls_Box7(Xcls_GtkView _owner )
582                 {
583                         _this = _owner;
584                         this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
585
586                         // my vars (dec)
587
588                         // set gobject values
589                         new Xcls_sourceviewscroll( _this );
590                         this.el.append( _this.sourceviewscroll.el );
591                         var child_2 = new Xcls_Box13( _this );
592                         child_2.ref();
593                         this.el.append( child_2.el );
594                 }
595
596                 // user defined functions
597         }
598         public class Xcls_sourceviewscroll : Object
599         {
600                 public Gtk.ScrolledWindow el;
601                 private Xcls_GtkView  _this;
602
603
604                         // my vars (def)
605
606                 // ctor
607                 public Xcls_sourceviewscroll(Xcls_GtkView _owner )
608                 {
609                         _this = _owner;
610                         _this.sourceviewscroll = this;
611                         this.el = new Gtk.ScrolledWindow();
612
613                         // my vars (dec)
614
615                         // set gobject values
616                         this.el.vexpand = true;
617                         new Xcls_sourceview( _this );
618                         this.el.set_child ( _this.sourceview.el  );
619                 }
620
621                 // user defined functions
622         }
623         public class Xcls_sourceview : Object
624         {
625                 public GtkSource.View el;
626                 private Xcls_GtkView  _this;
627
628
629                         // my vars (def)
630                 public bool loading;
631                 public string prop_selected;
632                 public JsRender.Node? node_selected;
633
634                 // ctor
635                 public Xcls_sourceview(Xcls_GtkView _owner )
636                 {
637                         _this = _owner;
638                         _this.sourceview = this;
639                         this.el = new GtkSource.View();
640
641                         // my vars (dec)
642                         this.loading = false;
643                         this.prop_selected = "\"\"";
644
645                         // set gobject values
646                         this.el.name = "gtkview-view";
647                         this.el.editable = false;
648                         this.el.show_line_marks = true;
649                         this.el.show_line_numbers = true;
650                         this.el.css_classes = { "code-editor" };
651                         this.el.tab_width = 4;
652                         new Xcls_buffer( _this );
653                         this.el.set_buffer ( _this.buffer.el  );
654                         new Xcls_keystate( _this );
655                         this.el.add_controller(  _this.keystate.el );
656                         var child_3 = new Xcls_EventControllerScroll12( _this );
657                         child_3.ref();
658                         this.el.add_controller(  child_3.el );
659
660                         // init method
661
662                         {
663                         
664                           
665                                 this.loading = true;
666                         
667                          
668                                 var attrs = new GtkSource.MarkAttributes();
669                                  attrs.set_icon_name ( "process-stop");    
670                                 attrs.query_tooltip_text.connect(( mark) => {
671                                         //print("tooltip query? %s\n", mark.name);
672                                         return mark.name;
673                                 });
674                         
675                                 this.el.set_mark_attributes ("ERR", attrs, 1);
676                         
677                                  var wattrs = new GtkSource.MarkAttributes();
678                                   wattrs.set_icon_name ( "process-stop");    
679                                 wattrs.query_tooltip_text.connect(( mark) => {
680                                         //print("tooltip query? %s\n", mark.name);
681                                         return mark.name;
682                                 });
683                         
684                                 this.el.set_mark_attributes ("WARN", wattrs, 1);
685                         
686                         
687                         
688                                  var dattrs = new GtkSource.MarkAttributes();
689                                 dattrs.set_icon_name ( "process-stop");    
690                                 dattrs.query_tooltip_text.connect(( mark) => {
691                                         //print("tooltip query? %s\n", mark.name);
692                                         return mark.name;
693                                 });
694                         
695                                 this.el.set_mark_attributes ("DEPR", dattrs, 1);
696                         
697                         
698                                 var gattrs = new GtkSource.MarkAttributes();
699                                 var  grey =   Gdk.RGBA();
700                                 grey.parse ( "#ccc");
701                                 gattrs.set_background ( grey);
702                         
703                         
704                                 this.el.set_mark_attributes ("grey", gattrs, 1);
705                         
706                         
707                         
708                         
709                         
710                         
711                                 }
712
713                         //listeners
714                         this.el.query_tooltip.connect( (x, y, keyboard_tooltip, tooltip) => {
715                                 
716                                 //GLib.debug("query tooltip");
717                                 Gtk.TextIter iter;
718                                 int trailing;
719                                 
720                                 var yoff = (int) _this.sourceviewscroll.el.vadjustment.value;
721                                 
722                                 this.el.get_iter_at_position (out iter, out trailing,  x,  y + yoff);
723                                  
724                                 var l = iter.get_line();
725                                 // GLib.debug("query tooltip line %d", (int) l);
726                                 var marks = _this.buffer.el.get_source_marks_at_line(l, "ERR");
727                                 if (marks.is_empty()) {
728                                         marks = _this.buffer.el.get_source_marks_at_line(l, "WARN");
729                                 }
730                                 if (marks.is_empty()) {
731                                         marks = _this.buffer.el.get_source_marks_at_line(l, "DEPR");
732                                 }
733                                 
734                                 // GLib.debug("query tooltip line marks %d", (int) marks.length());
735                                 var str = "";
736                                 marks.@foreach((m) => { 
737                                         //GLib.debug("got mark %s", m.name);
738                                         str += (str.length > 0 ? "\n" : "") + m.name;
739                                 });
740                                 
741                                 // true if there is a mark..
742                                 tooltip.set_text( str);
743                                 return str.length > 0 ? true : false;
744                         
745                         });
746                 }
747
748                 // user defined functions
749                 public void loadFile ( ) {
750                     this.loading = true;
751                     var buf = this.el.get_buffer();
752                     buf.set_text("",0);
753                  
754                         var cpos = buf.cursor_position;
755                     
756                         print("BEFORE LOAD cursor = %d\n", cpos);
757                         var vadj_pos = this.el.get_vadjustment().get_value();
758                 
759                     if (_this.file == null || _this.file.xtype != "Gtk") {
760                         print("xtype != Gtk");
761                         this.loading = false;
762                         return;
763                     }
764                     /*
765                     var valafn = "";
766                       try {             
767                            var  regex = new Regex("\\.bjs$");
768                         
769                          
770                             valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
771                          } catch (GLib.RegexError e) {
772                              this.loading = false;
773                             return;
774                         }   
775                     
776                 
777                    if (!FileUtils.test(valafn,FileTest.IS_REGULAR) ) {
778                         print("File path has no errors\n");
779                         this.loading = false;
780                         return  ;
781                     }
782                     
783                     string str;
784                     try {
785                     
786                         GLib.FileUtils.get_contents (valafn, out str);
787                     } catch (Error e) {
788                         this.loading = false;
789                         return  ;
790                     }
791                     */
792                     var str = _this.file.toSource();
793                 
794                 //    print("setting str %d\n", str.length);
795                     buf.set_text(str, str.length);
796                     var lm = GtkSource.LanguageManager.get_default();
797                      
798                     //?? is javascript going to work as js?
799                     
800                     ((GtkSource.Buffer)(buf)) .set_language(lm.get_language(_this.file.language));
801                   
802                      
803                    _this.main_window.windowstate.updateErrorMarksAll(); 
804                    //  restore the cursor position?
805                     // after reloading the contents.
806                      GLib.Timeout.add(500, () => {
807                                 _this.buffer.in_cursor_change = true;
808                         print("RESORTING cursor to = %d\n", cpos);
809                                 Gtk.TextIter cpos_iter;
810                                 buf.get_iter_at_offset(out cpos_iter, cpos);
811                                 buf.place_cursor(cpos_iter); 
812                                 
813                                 this.el.get_vadjustment().set_value(vadj_pos);;
814                                 _this.buffer.in_cursor_change = false;
815                  
816                                 
817                                 
818                                 //_this.buffer.checkSyntax();
819                                 return false;
820                         });
821                   
822                     
823                     this.loading = false; 
824                 }
825                 public void nodeSelected (JsRender.Node? sel, bool scroll) {
826                   
827                     
828                     if (this.loading) {
829                         return;
830                         }
831                     // this is connected in widnowstate
832                     print("Roo-view - node selected\n");
833                     var buf = this.el.get_buffer();
834                  
835                     var sbuf = (GtkSource.Buffer) buf;
836                 
837                    
838                  
839                     
840                    
841                     // clear all the marks..
842                      Gtk.TextIter start;
843                     Gtk.TextIter end;     
844                         
845                     sbuf.get_bounds (out start, out end);
846                     sbuf.remove_source_marks (start, end, "grey");
847                     
848                         this.node_selected = sel;
849                      if (sel == null) {
850                         // no highlighting..
851                         return;
852                     }
853                     Gtk.TextIter iter;   
854                     sbuf.get_iter_at_line(out iter,  sel.line_start);
855                     
856                     
857                     Gtk.TextIter cur_iter;
858                     sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position);
859                     
860                     
861                     if (!_this.buffer.in_cursor_change) {
862                 
863                         this.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);
864                         }  
865                     
866                      
867                     
868                     for (var i = 0; i < buf.get_line_count();i++) {
869                         if (i < sel.line_start || i > sel.line_end) {
870                            
871                             sbuf.get_iter_at_line(out iter, i);
872                             sbuf.create_source_mark(null, "grey", iter);
873                             
874                         }
875                     
876                     }
877                     
878                 
879                 }
880                 public string toString () {
881                    Gtk.TextIter s;
882                     Gtk.TextIter e;
883                     this.el.get_buffer().get_start_iter(out s);
884                     this.el.get_buffer().get_end_iter(out e);
885                     var ret = this.el.get_buffer().get_text(s,e,true);
886                     //print("TO STRING? " + ret);
887                     return ret;
888                 }
889         }
890         public class Xcls_buffer : Object
891         {
892                 public GtkSource.Buffer el;
893                 private Xcls_GtkView  _this;
894
895
896                         // my vars (def)
897                 public int error_line;
898                 public bool in_cursor_change;
899                 public bool dirty;
900                 public int last_line;
901
902                 // ctor
903                 public Xcls_buffer(Xcls_GtkView _owner )
904                 {
905                         _this = _owner;
906                         _this.buffer = this;
907                         this.el = new GtkSource.Buffer( null );
908
909                         // my vars (dec)
910                         this.error_line = -1;
911                         this.in_cursor_change = false;
912                         this.dirty = false;
913                         this.last_line = -1;
914
915                         // set gobject values
916
917                         // init method
918
919                         var buf = this.el;
920                         buf.create_tag ("bold", "weight", Pango.Weight.BOLD);
921                         buf.create_tag ("type", "weight", Pango.Weight.BOLD, "foreground", "#204a87");
922                         buf.create_tag ("keyword", "weight", Pango.Weight.BOLD, "foreground", "#a40000");
923                         buf.create_tag ("text", "weight", Pango.Weight.NORMAL, "foreground", "#729fcf");
924                         buf.create_tag ("number", "weight", Pango.Weight.BOLD, "foreground", "#ad7fa8");
925                         buf.create_tag ("method", "weight", Pango.Weight.BOLD, "foreground", "#729fcf");
926                         buf.create_tag ("property", "weight", Pango.Weight.BOLD, "foreground", "#BC1F51");
927                         buf.create_tag ("variable", "weight", Pango.Weight.BOLD, "foreground", "#A518B5");
928                         
929                         
930                         buf.create_tag ("ERR", "weight", Pango.Weight.BOLD, "background", "pink");
931                         buf.create_tag ("WARN", "weight", Pango.Weight.BOLD, "background", "#ABF4EB");
932                         buf.create_tag ("DEPR", "weight", Pango.Weight.BOLD, "background", "#EEA9FF");
933
934                         //listeners
935                         this.el.cursor_moved.connect( ( ) => {
936                         GLib.debug("cursor moved called");
937                         
938                         
939                                 if (this.in_cursor_change ) {
940                                 GLib.debug("cursor changed : %d [ignoring nested call)", this.el.cursor_position);
941                                 return;
942                             }
943                            
944                             GLib.debug("cursor changed : %d", this.el.cursor_position);
945                             Gtk.TextIter cpos;
946                             this.el.get_iter_at_offset(out cpos, this.el.cursor_position);
947                             
948                             var ln = cpos.get_line();
949                             if (this.last_line == ln ){
950                                 return;
951                                 }
952                                 this.last_line = ln;
953                             var node = _this.file.lineToNode(ln);
954                         
955                             if (node == null) {
956                                 print("can not find node\n");
957                                 return;
958                             }
959                             this.in_cursor_change  = true;
960                             var ltree = _this.main_window.windowstate.left_tree;
961                             ltree.model.selectNode(node);
962                             this.in_cursor_change  = false;
963                         });
964                 }
965
966                 // user defined functions
967         }
968
969         public class Xcls_keystate : Object
970         {
971                 public Gtk.EventControllerKey el;
972                 private Xcls_GtkView  _this;
973
974
975                         // my vars (def)
976                 public bool is_control;
977
978                 // ctor
979                 public Xcls_keystate(Xcls_GtkView _owner )
980                 {
981                         _this = _owner;
982                         _this.keystate = this;
983                         this.el = new Gtk.EventControllerKey();
984
985                         // my vars (dec)
986                         this.is_control = false;
987
988                         // set gobject values
989
990                         //listeners
991                         this.el.key_released.connect( (keyval, keycode, state) => {
992                         
993                                  if (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) {
994                                         this.is_control = false;
995                                 }
996                         });
997                         this.el.key_pressed.connect( (keyval, keycode, state) => {
998                         
999                                 if (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) {
1000                                         this.is_control = true;
1001                                 }
1002                                  
1003                                  if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1004                                     GLib.debug("SAVE: ctrl-g  pressed");
1005                                         _this.forwardSearch(true);
1006                                     return true;
1007                                 }
1008                             if (keyval == Gdk.Key.f && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1009                                     GLib.debug("SAVE: ctrl-f  pressed");
1010                                         _this.search_entry.el.grab_focus();
1011                                     return true;
1012                                 }
1013                                  
1014                                 return false;
1015                         });
1016                 }
1017
1018                 // user defined functions
1019         }
1020
1021         public class Xcls_EventControllerScroll12 : Object
1022         {
1023                 public Gtk.EventControllerScroll el;
1024                 private Xcls_GtkView  _this;
1025
1026
1027                         // my vars (def)
1028                 public double distance;
1029
1030                 // ctor
1031                 public Xcls_EventControllerScroll12(Xcls_GtkView _owner )
1032                 {
1033                         _this = _owner;
1034                         this.el = new Gtk.EventControllerScroll( Gtk.EventControllerScrollFlags.VERTICAL );
1035
1036                         // my vars (dec)
1037                         this.distance = 0.0f;
1038
1039                         // set gobject values
1040
1041                         //listeners
1042                         this.el.scroll.connect( (dx, dy) => {
1043                                 if (!_this.keystate.is_control) {
1044                                         return false;
1045                                 }
1046                                 //GLib.debug("scroll %f",  dy);
1047                                 
1048                                 this.distance += dy;
1049                                  if (this.distance < -1) {
1050                                         BuilderApplication.settings.editor_font_size ++;
1051                                         this.distance = 0;
1052                                 }
1053                                 if (this.distance > 1) {
1054                                         BuilderApplication.settings.editor_font_size --;
1055                                         this.distance = 0;
1056                                 }
1057                         
1058                                 return true;
1059                         });
1060                 }
1061
1062                 // user defined functions
1063         }
1064
1065
1066
1067         public class Xcls_Box13 : Object
1068         {
1069                 public Gtk.Box el;
1070                 private Xcls_GtkView  _this;
1071
1072
1073                         // my vars (def)
1074
1075                 // ctor
1076                 public Xcls_Box13(Xcls_GtkView _owner )
1077                 {
1078                         _this = _owner;
1079                         this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
1080
1081                         // my vars (dec)
1082
1083                         // set gobject values
1084                         this.el.homogeneous = false;
1085                         this.el.vexpand = false;
1086                         new Xcls_search_entry( _this );
1087                         this.el.append( _this.search_entry.el );
1088                         new Xcls_search_results( _this );
1089                         this.el.append( _this.search_results.el );
1090                         new Xcls_nextBtn( _this );
1091                         this.el.append( _this.nextBtn.el );
1092                         new Xcls_backBtn( _this );
1093                         this.el.append( _this.backBtn.el );
1094                         var child_5 = new Xcls_MenuButton19( _this );
1095                         child_5.ref();
1096                         this.el.append( child_5.el );
1097                 }
1098
1099                 // user defined functions
1100         }
1101         public class Xcls_search_entry : Object
1102         {
1103                 public Gtk.SearchEntry el;
1104                 private Xcls_GtkView  _this;
1105
1106
1107                         // my vars (def)
1108                 public Gtk.CssProvider css;
1109
1110                 // ctor
1111                 public Xcls_search_entry(Xcls_GtkView _owner )
1112                 {
1113                         _this = _owner;
1114                         _this.search_entry = this;
1115                         this.el = new Gtk.SearchEntry();
1116
1117                         // my vars (dec)
1118
1119                         // set gobject values
1120                         this.el.name = "gtkview-search-entry";
1121                         this.el.hexpand = true;
1122                         this.el.placeholder_text = "Press enter to search";
1123                         this.el.search_delay = 3;
1124                         var child_1 = new Xcls_EventControllerKey15( _this );
1125                         child_1.ref();
1126                         this.el.add_controller(  child_1.el );
1127
1128                         //listeners
1129                         this.el.search_changed.connect( () => {
1130                                  
1131                                 _this.search(_this.search_entry.el.text);
1132                                  _this.search_results.updateResults();
1133                         
1134                                 GLib.Timeout.add_seconds(1,() => {
1135                                          _this.search_results.updateResults();
1136                                          return false;
1137                                  });
1138                                   
1139                            
1140                             
1141                         });
1142                 }
1143
1144                 // user defined functions
1145                 public void forwardSearch (bool change_focus) {
1146                 
1147                 
1148                         _this.forwardSearch(change_focus);
1149                 
1150                 /*
1151                 
1152                         switch(_this.windowstate.state) {
1153                                 case WindowState.State.CODEONLY:
1154                                 //case WindowState.State.CODE:
1155                                         // search the code being edited..
1156                                         _this.windowstate.code_editor_tab.forwardSearch(change_focus);
1157                                          
1158                                         break;
1159                                 case WindowState.State.PREVIEW:
1160                                         if (_this.windowstate.file.xtype == "Gtk") {
1161                                                 _this.windowstate.window_gladeview.forwardSearch(change_focus);
1162                                         } else { 
1163                                                  _this.windowstate.window_rooview.forwardSearch(change_focus);
1164                                         }
1165                                 
1166                                         break;
1167                         }
1168                         */
1169                         
1170                 }
1171         }
1172         public class Xcls_EventControllerKey15 : Object
1173         {
1174                 public Gtk.EventControllerKey el;
1175                 private Xcls_GtkView  _this;
1176
1177
1178                         // my vars (def)
1179
1180                 // ctor
1181                 public Xcls_EventControllerKey15(Xcls_GtkView _owner )
1182                 {
1183                         _this = _owner;
1184                         this.el = new Gtk.EventControllerKey();
1185
1186                         // my vars (dec)
1187
1188                         // set gobject values
1189
1190                         //listeners
1191                         this.el.key_pressed.connect( (keyval, keycode, state) => {
1192                         
1193                                 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1194                                     GLib.debug("SAVE: ctrl-g  pressed");
1195                                         _this.forwardSearch(true);
1196                                     return true;
1197                                 }
1198                             
1199                           
1200                                 if (keyval == Gdk.Key.Return && _this.search_entry.el.text.length > 0) {
1201                                         _this.forwardSearch(true);
1202                                         
1203                                         
1204                                     return true;
1205                         
1206                                 }    
1207                            // print(event.key.keyval)
1208                            
1209                             return false;
1210                         });
1211                 }
1212
1213                 // user defined functions
1214         }
1215
1216
1217         public class Xcls_search_results : Object
1218         {
1219                 public Gtk.Label el;
1220                 private Xcls_GtkView  _this;
1221
1222
1223                         // my vars (def)
1224
1225                 // ctor
1226                 public Xcls_search_results(Xcls_GtkView _owner )
1227                 {
1228                         _this = _owner;
1229                         _this.search_results = this;
1230                         this.el = new Gtk.Label( "No Results" );
1231
1232                         // my vars (dec)
1233
1234                         // set gobject values
1235                         this.el.margin_end = 4;
1236                         this.el.margin_start = 4;
1237                 }
1238
1239                 // user defined functions
1240                 public void updateResults () {
1241                         this.el.visible = true;
1242                         
1243                         var res = _this.searchcontext.get_occurrences_count();
1244                         if (res < 0) {
1245                                 _this.search_results.el.label = "??? Matches";          
1246                                 return;
1247                         }
1248                 
1249                         _this.nextBtn.el.sensitive = false;
1250                         _this.backBtn.el.sensitive = false;     
1251                 
1252                         if (res > 0) {
1253                                 _this.search_results.el.label = "%d Matches".printf(res);
1254                                 _this.nextBtn.el.sensitive = true;
1255                                 _this.backBtn.el.sensitive = true;
1256                                 return;
1257                         } 
1258                         _this.search_results.el.label = "No Matches";
1259                         
1260                 }
1261         }
1262
1263         public class Xcls_nextBtn : Object
1264         {
1265                 public Gtk.Button el;
1266                 private Xcls_GtkView  _this;
1267
1268
1269                         // my vars (def)
1270                 public bool always_show_image;
1271
1272                 // ctor
1273                 public Xcls_nextBtn(Xcls_GtkView _owner )
1274                 {
1275                         _this = _owner;
1276                         _this.nextBtn = this;
1277                         this.el = new Gtk.Button();
1278
1279                         // my vars (dec)
1280                         this.always_show_image = true;
1281
1282                         // set gobject values
1283                         this.el.icon_name = "go-down";
1284                         this.el.sensitive = false;
1285
1286                         //listeners
1287                         this.el.clicked.connect( ( ) => {
1288                         _this.forwardSearch(true);
1289                                  
1290                         
1291                         });
1292                 }
1293
1294                 // user defined functions
1295         }
1296
1297         public class Xcls_backBtn : Object
1298         {
1299                 public Gtk.Button el;
1300                 private Xcls_GtkView  _this;
1301
1302
1303                         // my vars (def)
1304                 public bool always_show_image;
1305
1306                 // ctor
1307                 public Xcls_backBtn(Xcls_GtkView _owner )
1308                 {
1309                         _this = _owner;
1310                         _this.backBtn = this;
1311                         this.el = new Gtk.Button();
1312
1313                         // my vars (dec)
1314                         this.always_show_image = true;
1315
1316                         // set gobject values
1317                         this.el.icon_name = "go-up";
1318                         this.el.sensitive = false;
1319
1320                         //listeners
1321                         this.el.clicked.connect( ( ) => {
1322                         
1323                         _this.backSearch(true);
1324                                 
1325                         });
1326                 }
1327
1328                 // user defined functions
1329         }
1330
1331         public class Xcls_MenuButton19 : Object
1332         {
1333                 public Gtk.MenuButton el;
1334                 private Xcls_GtkView  _this;
1335
1336
1337                         // my vars (def)
1338                 public bool always_show_image;
1339
1340                 // ctor
1341                 public Xcls_MenuButton19(Xcls_GtkView _owner )
1342                 {
1343                         _this = _owner;
1344                         this.el = new Gtk.MenuButton();
1345
1346                         // my vars (dec)
1347                         this.always_show_image = true;
1348
1349                         // set gobject values
1350                         this.el.icon_name = "emblem-system";
1351                         this.el.always_show_arrow = true;
1352                         new Xcls_search_settings( _this );
1353                         this.el.popover = _this.search_settings.el;
1354                 }
1355
1356                 // user defined functions
1357         }
1358         public class Xcls_search_settings : Object
1359         {
1360                 public Gtk.PopoverMenu el;
1361                 private Xcls_GtkView  _this;
1362
1363
1364                         // my vars (def)
1365
1366                 // ctor
1367                 public Xcls_search_settings(Xcls_GtkView _owner )
1368                 {
1369                         _this = _owner;
1370                         _this.search_settings = this;
1371                         this.el = new Gtk.PopoverMenu.from_model(null);
1372
1373                         // my vars (dec)
1374
1375                         // set gobject values
1376                         var child_1 = new Xcls_Box21( _this );
1377                         child_1.ref();
1378                         this.el.set_child ( child_1.el  );
1379                 }
1380
1381                 // user defined functions
1382         }
1383         public class Xcls_Box21 : Object
1384         {
1385                 public Gtk.Box el;
1386                 private Xcls_GtkView  _this;
1387
1388
1389                         // my vars (def)
1390
1391                 // ctor
1392                 public Xcls_Box21(Xcls_GtkView _owner )
1393                 {
1394                         _this = _owner;
1395                         this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
1396
1397                         // my vars (dec)
1398
1399                         // set gobject values
1400                         new Xcls_case_sensitive( _this );
1401                         this.el.append( _this.case_sensitive.el );
1402                         new Xcls_regex( _this );
1403                         this.el.append( _this.regex.el );
1404                         new Xcls_multiline( _this );
1405                         this.el.append( _this.multiline.el );
1406                 }
1407
1408                 // user defined functions
1409         }
1410         public class Xcls_case_sensitive : Object
1411         {
1412                 public Gtk.CheckButton el;
1413                 private Xcls_GtkView  _this;
1414
1415
1416                         // my vars (def)
1417
1418                 // ctor
1419                 public Xcls_case_sensitive(Xcls_GtkView _owner )
1420                 {
1421                         _this = _owner;
1422                         _this.case_sensitive = this;
1423                         this.el = new Gtk.CheckButton();
1424
1425                         // my vars (dec)
1426
1427                         // set gobject values
1428                         this.el.label = "Case Sensitive";
1429                 }
1430
1431                 // user defined functions
1432         }
1433
1434         public class Xcls_regex : Object
1435         {
1436                 public Gtk.CheckButton el;
1437                 private Xcls_GtkView  _this;
1438
1439
1440                         // my vars (def)
1441
1442                 // ctor
1443                 public Xcls_regex(Xcls_GtkView _owner )
1444                 {
1445                         _this = _owner;
1446                         _this.regex = this;
1447                         this.el = new Gtk.CheckButton();
1448
1449                         // my vars (dec)
1450
1451                         // set gobject values
1452                         this.el.label = "Regex";
1453                 }
1454
1455                 // user defined functions
1456         }
1457
1458         public class Xcls_multiline : Object
1459         {
1460                 public Gtk.CheckButton el;
1461                 private Xcls_GtkView  _this;
1462
1463
1464                         // my vars (def)
1465
1466                 // ctor
1467                 public Xcls_multiline(Xcls_GtkView _owner )
1468                 {
1469                         _this = _owner;
1470                         _this.multiline = this;
1471                         this.el = new Gtk.CheckButton();
1472
1473                         // my vars (dec)
1474
1475                         // set gobject values
1476                         this.el.label = "Multi-line (add \\n)";
1477                 }
1478
1479                 // user defined functions
1480         }
1481
1482
1483
1484
1485
1486
1487
1488 }