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