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