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