fix line numbering issues with vala generator - hopefully fixes completion in node...
[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                 var offset = 0;
364                  
365         
366                 var tlines = buf.get_line_count () +1;
367                 
368          
369                  
370                 for (var i = 0; i < ar.get_n_items();i++) {
371                         var err = (Palete.CompileError) ar.get_item(i);
372                         
373                      Gtk.TextIter iter;
374         //        print("get inter\n");
375                     var eline = err.line - offset;
376                     GLib.debug("GOT ERROR on line %d -- converted to %d  (offset = %d)",
377                         err.line ,eline, offset);
378                     
379                     
380                     if (eline > tlines || eline < 0) {
381                         return;
382                     }
383                    
384                     
385                     buf.get_iter_at_line( out iter, eline);
386                    
387                    
388                         var msg = "Line: %d %s : %s".printf(eline+1, err.category, err.msg);
389                     buf.create_source_mark( msg, err.category, iter);
390                     GLib.debug("set line %d to %s", eline, msg);
391                     //this.marks.set(eline, msg);
392                 }
393                 return ;
394         
395         
396         
397          
398         
399         }
400         public void scroll_to_line (int line) {
401           // code preview...
402            
403            GLib.Timeout.add(100, () => {
404            
405            
406                     this.notebook.el.set_current_page(1);
407                    
408                           var buf = this.sourceview.el.get_buffer();
409                  
410                         var sbuf = (GtkSource.Buffer) buf;
411         
412         
413                         Gtk.TextIter iter;   
414                         sbuf.get_iter_at_line(out iter,  line);
415                         this.sourceview.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);
416                         return false;
417                 });   
418         
419            
420         }
421         public class Xcls_notebook : Object
422         {
423             public Gtk.Notebook el;
424             private Xcls_GtkView  _this;
425
426
427                 // my vars (def)
428
429             // ctor
430             public Xcls_notebook(Xcls_GtkView _owner )
431             {
432                 _this = _owner;
433                 _this.notebook = this;
434                 this.el = new Gtk.Notebook();
435
436                 // my vars (dec)
437
438                 // set gobject values
439                 this.el.overflow = Gtk.Overflow.VISIBLE;
440                 new Xcls_label_preview( _this );
441                 new Xcls_label_code( _this );
442                 var child_3 = new Xcls_ScrolledWindow5( _this );
443                 child_3.ref();
444                 this.el.append_page ( child_3.el , _this.label_preview.el );
445                 var child_4 = new Xcls_Box8( _this );
446                 child_4.ref();
447                 this.el.append_page ( child_4.el , _this.label_code.el );
448             }
449
450             // user defined functions
451         }
452         public class Xcls_label_preview : Object
453         {
454             public Gtk.Label el;
455             private Xcls_GtkView  _this;
456
457
458                 // my vars (def)
459
460             // ctor
461             public Xcls_label_preview(Xcls_GtkView _owner )
462             {
463                 _this = _owner;
464                 _this.label_preview = this;
465                 this.el = new Gtk.Label( "Preview" );
466
467                 // my vars (dec)
468
469                 // set gobject values
470             }
471
472             // user defined functions
473         }
474
475         public class Xcls_label_code : Object
476         {
477             public Gtk.Label el;
478             private Xcls_GtkView  _this;
479
480
481                 // my vars (def)
482
483             // ctor
484             public Xcls_label_code(Xcls_GtkView _owner )
485             {
486                 _this = _owner;
487                 _this.label_code = this;
488                 this.el = new Gtk.Label( "Preview Generated Code" );
489
490                 // my vars (dec)
491
492                 // set gobject values
493             }
494
495             // user defined functions
496         }
497
498         public class Xcls_ScrolledWindow5 : Object
499         {
500             public Gtk.ScrolledWindow el;
501             private Xcls_GtkView  _this;
502
503
504                 // my vars (def)
505
506             // ctor
507             public Xcls_ScrolledWindow5(Xcls_GtkView _owner )
508             {
509                 _this = _owner;
510                 this.el = new Gtk.ScrolledWindow();
511
512                 // my vars (dec)
513
514                 // set gobject values
515                 new Xcls_view_layout( _this );
516                 this.el.set_child ( _this.view_layout.el  );
517             }
518
519             // user defined functions
520         }
521         public class Xcls_view_layout : Object
522         {
523             public Gtk.Fixed el;
524             private Xcls_GtkView  _this;
525
526
527                 // my vars (def)
528
529             // ctor
530             public Xcls_view_layout(Xcls_GtkView _owner )
531             {
532                 _this = _owner;
533                 _this.view_layout = this;
534                 this.el = new Gtk.Fixed();
535
536                 // my vars (dec)
537
538                 // set gobject values
539                 this.el.name = "gtkview-view-layout";
540                 new Xcls_container( _this );
541                 this.el.put ( _this.container.el , 10,10 );
542             }
543
544             // user defined functions
545         }
546         public class Xcls_container : Object
547         {
548             public Gtk.Box el;
549             private Xcls_GtkView  _this;
550
551
552                 // my vars (def)
553
554             // ctor
555             public Xcls_container(Xcls_GtkView _owner )
556             {
557                 _this = _owner;
558                 _this.container = this;
559                 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
560
561                 // my vars (dec)
562
563                 // set gobject values
564             }
565
566             // user defined functions
567         }
568
569
570
571         public class Xcls_Box8 : Object
572         {
573             public Gtk.Box el;
574             private Xcls_GtkView  _this;
575
576
577                 // my vars (def)
578
579             // ctor
580             public Xcls_Box8(Xcls_GtkView _owner )
581             {
582                 _this = _owner;
583                 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
584
585                 // my vars (dec)
586
587                 // set gobject values
588                 new Xcls_sourceviewscroll( _this );
589                 this.el.append( _this.sourceviewscroll.el );
590                 var child_2 = new Xcls_Box13( _this );
591                 child_2.ref();
592                 this.el.append( child_2.el );
593             }
594
595             // user defined functions
596         }
597         public class Xcls_sourceviewscroll : Object
598         {
599             public Gtk.ScrolledWindow el;
600             private Xcls_GtkView  _this;
601
602
603                 // my vars (def)
604
605             // ctor
606             public Xcls_sourceviewscroll(Xcls_GtkView _owner )
607             {
608                 _this = _owner;
609                 _this.sourceviewscroll = this;
610                 this.el = new Gtk.ScrolledWindow();
611
612                 // my vars (dec)
613
614                 // set gobject values
615                 this.el.vexpand = true;
616                 new Xcls_sourceview( _this );
617                 this.el.set_child ( _this.sourceview.el  );
618             }
619
620             // user defined functions
621         }
622         public class Xcls_sourceview : Object
623         {
624             public GtkSource.View el;
625             private Xcls_GtkView  _this;
626
627
628                 // my vars (def)
629             public bool loading;
630             public string prop_selected;
631             public bool allow_node_scroll;
632             public Gtk.CssProvider css;
633             public JsRender.Node? node_selected;
634
635             // ctor
636             public Xcls_sourceview(Xcls_GtkView _owner )
637             {
638                 _this = _owner;
639                 _this.sourceview = this;
640                 this.el = new GtkSource.View();
641
642                 // my vars (dec)
643                 this.loading = true;
644                 this.prop_selected = "";
645                 this.allow_node_scroll = true;
646
647                 // set gobject values
648                 this.el.name = "gtkview-view";
649                 this.el.editable = false;
650                 this.el.show_line_marks = true;
651                 this.el.show_line_numbers = true;
652                 new Xcls_buffer( _this );
653                 this.el.set_buffer ( _this.buffer.el  );
654                 var child_2 = new Xcls_EventControllerKey12( _this );
655                 child_2.ref();
656                 this.el.add_controller(  child_2.el );
657
658                 // init method
659
660                 {
661                    
662                    
663                         this.css = new Gtk.CssProvider();
664                          
665                         this.css.load_from_string("#gtkview-view { font: 10px monospace ;}");
666                          
667                         Gtk.StyleContext.add_provider_for_display(
668                                 this.el.get_display(),
669                                 this.css,
670                                 Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
671                         );
672                                 
673                                  
674                     this.loading = true;
675                     
676                   
677                   
678                     var attrs = new GtkSource.MarkAttributes();
679                     var  pink =   Gdk.RGBA();
680                     pink.parse ( "pink");
681                     attrs.set_background ( pink);
682                     attrs.set_icon_name ( "process-stop");    
683                     attrs.query_tooltip_text.connect(( mark) => {
684                         //print("tooltip query? %s\n", mark.name);
685                         return mark.name;
686                     });
687                     
688                     this.el.set_mark_attributes ("ERR", attrs, 1);
689                     
690                      var wattrs = new GtkSource.MarkAttributes();
691                     var  blue =   Gdk.RGBA();
692                     blue.parse ( "#ABF4EB");
693                     wattrs.set_background ( blue);
694                     wattrs.set_icon_name ( "process-stop");    
695                     wattrs.query_tooltip_text.connect(( mark) => {
696                         //print("tooltip query? %s\n", mark.name);
697                         return mark.name;
698                     });
699                     
700                     this.el.set_mark_attributes ("WARN", wattrs, 1);
701                     
702                  
703                     
704                      var dattrs = new GtkSource.MarkAttributes();
705                     var  purple =   Gdk.RGBA();
706                     purple.parse ( "#EEA9FF");
707                     dattrs.set_background ( purple);
708                     dattrs.set_icon_name ( "process-stop");    
709                     dattrs.query_tooltip_text.connect(( mark) => {
710                         //print("tooltip query? %s\n", mark.name);
711                         return mark.name;
712                     });
713                     
714                     this.el.set_mark_attributes ("DEPR", dattrs, 1);
715                     
716                     
717                     var gattrs = new GtkSource.MarkAttributes();
718                     var  grey =   Gdk.RGBA();
719                     grey.parse ( "#ccc");
720                     gattrs.set_background ( grey);
721                  
722                     
723                     this.el.set_mark_attributes ("grey", gattrs, 1);
724                     
725                     
726                     
727                     
728                     
729                     
730                 }
731
732                 //listeners
733                 this.el.query_tooltip.connect( (x, y, keyboard_tooltip, tooltip) => {
734                         
735                         //GLib.debug("query tooltip");
736                         Gtk.TextIter iter;
737                         int trailing;
738                         
739                         var yoff = (int) _this.sourceviewscroll.el.vadjustment.value;
740                         
741                         this.el.get_iter_at_position (out iter, out trailing,  x,  y + yoff);
742                          
743                         var l = iter.get_line();
744                         // GLib.debug("query tooltip line %d", (int) l);
745                         var marks = _this.buffer.el.get_source_marks_at_line(l, "ERR");
746                         if (marks.is_empty()) {
747                                 marks = _this.buffer.el.get_source_marks_at_line(l, "WARN");
748                         }
749                         if (marks.is_empty()) {
750                                 marks = _this.buffer.el.get_source_marks_at_line(l, "DEPR");
751                         }
752                         
753                         // GLib.debug("query tooltip line marks %d", (int) marks.length());
754                         var str = "";
755                         marks.@foreach((m) => { 
756                                 //GLib.debug("got mark %s", m.name);
757                                 str += (str.length > 0 ? "\n" : "") + m.name;
758                         });
759                         
760                         // true if there is a mark..
761                         tooltip.set_text( str);
762                         return str.length > 0 ? true : false;
763                 
764                 });
765             }
766
767             // user defined functions
768             public void loadFile ( ) {
769                 this.loading = true;
770                 var buf = this.el.get_buffer();
771                 buf.set_text("",0);
772                 var sbuf = (GtkSource.Buffer) buf;
773             
774                 
775             
776                 if (_this.file == null || _this.file.xtype != "Gtk") {
777                     print("xtype != Gtk");
778                     this.loading = false;
779                     return;
780                 }
781                 
782                 var valafn = "";
783                   try {             
784                        var  regex = new Regex("\\.bjs$");
785                     
786                      
787                         valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
788                      } catch (GLib.RegexError e) {
789                          this.loading = false;
790                         return;
791                     }   
792                 
793             
794                if (!FileUtils.test(valafn,FileTest.IS_REGULAR) ) {
795                     print("File path has no errors\n");
796                     this.loading = false;
797                     return  ;
798                 }
799                 
800                 string str;
801                 try {
802                 
803                     GLib.FileUtils.get_contents (valafn, out str);
804                 } catch (Error e) {
805                     this.loading = false;
806                     return  ;
807                 }
808             
809             //    print("setting str %d\n", str.length);
810                 buf.set_text(str, str.length);
811                 var lm = GtkSource.LanguageManager.get_default();
812                  
813                 //?? is javascript going to work as js?
814                 
815                 ((GtkSource.Buffer)(buf)) .set_language(lm.get_language(_this.file.language));
816               
817                  
818                _this.main_window.windowstate.updateErrorMarksAll(); 
819                
820               
821                 
822                 this.loading = false; 
823             }
824             public void nodeSelected (JsRender.Node? sel, bool scroll) {
825               
826                 
827                 if (this.loading) {
828                         return;
829                 }
830                 // this is connected in widnowstate
831                 print("Roo-view - node selected\n");
832                 var buf = this.el.get_buffer();
833              
834                 var sbuf = (GtkSource.Buffer) buf;
835             
836                
837                 // while(Gtk.events_pending()) {
838                  //    Gtk.main_iteration();
839                //  }
840                 
841                
842                 // clear all the marks..
843                  Gtk.TextIter start;
844                 Gtk.TextIter end;     
845                     
846                 sbuf.get_bounds (out start, out end);
847                 sbuf.remove_source_marks (start, end, "grey");
848                 
849                     this.node_selected = sel;
850                  if (sel == null) {
851                     // no highlighting..
852                     return;
853                 }
854                 Gtk.TextIter iter;   
855                 sbuf.get_iter_at_line(out iter,  sel.line_start);
856                 
857                 
858                 Gtk.TextIter cur_iter;
859                 sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position);
860                 
861                 //var cur_line = cur_iter.get_line();
862                 //if (cur_line > sel.line_start && cur_line < sel.line_end) {
863                 
864                 //} else {
865                 if (this.allow_node_scroll) {
866                          
867                         this.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);
868                 }
869                 
870                  
871                 
872                 for (var i = 0; i < buf.get_line_count();i++) {
873                     if (i < sel.line_start || i > sel.line_end) {
874                        
875                         sbuf.get_iter_at_line(out iter, i);
876                         sbuf.create_source_mark(null, "grey", iter);
877                         
878                     }
879                 
880                 }
881                 
882             
883             }
884             public string toString () {
885                Gtk.TextIter s;
886                 Gtk.TextIter e;
887                 this.el.get_buffer().get_start_iter(out s);
888                 this.el.get_buffer().get_end_iter(out e);
889                 var ret = this.el.get_buffer().get_text(s,e,true);
890                 //print("TO STRING? " + ret);
891                 return ret;
892             }
893         }
894         public class Xcls_buffer : Object
895         {
896             public GtkSource.Buffer el;
897             private Xcls_GtkView  _this;
898
899
900                 // my vars (def)
901             public int error_line;
902             public bool dirty;
903
904             // ctor
905             public Xcls_buffer(Xcls_GtkView _owner )
906             {
907                 _this = _owner;
908                 _this.buffer = this;
909                 this.el = new GtkSource.Buffer( null );
910
911                 // my vars (dec)
912                 this.error_line = -1;
913                 this.dirty = false;
914
915                 // set gobject values
916
917                 //listeners
918                 this.el.notify["cursor_position"].connect( () => {
919                 
920                 
921                     if (_this.sourceview.loading) {
922                         return;
923                     }
924                    
925                     GLib.debug("cursor changed : %d", this.el.cursor_position);
926                     Gtk.TextIter cpos;
927                     this.el.get_iter_at_offset(out cpos, this.el.cursor_position);
928                     
929                     var ln = cpos.get_line();
930                 
931                     var node = _this.file.lineToNode(ln);
932                 
933                     if (node == null) {
934                         print("can not find node\n");
935                         return;
936                     }
937                     _this.sourceview.loading = true;
938                     var ltree = _this.main_window.windowstate.left_tree;
939                     ltree.model.selectNode(node);
940                     _this.sourceview.loading = false;
941                     
942                     //print("got tree path %s\n", tp);
943                     //if (tp != "") {
944                       // this.allow_node_scroll = false;        
945                      //  print("changing cursor on tree..\n");
946                         //ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);
947                         // scrolling is disabled... as node selection calls scroll 10ms after it changes.
948                         ///GLib.Timeout.add_full(GLib.Priority.DEFAULT,100 , () => {
949                          //   this.allow_node_scroll = true;
950                          //   return false;
951                       //  });
952                    // }
953                     
954                     // highlight the node..
955                     
956                   
957                 
958                  });
959             }
960
961             // user defined functions
962         }
963
964         public class Xcls_EventControllerKey12 : Object
965         {
966             public Gtk.EventControllerKey el;
967             private Xcls_GtkView  _this;
968
969
970                 // my vars (def)
971
972             // ctor
973             public Xcls_EventControllerKey12(Xcls_GtkView _owner )
974             {
975                 _this = _owner;
976                 this.el = new Gtk.EventControllerKey();
977
978                 // my vars (dec)
979
980                 // set gobject values
981
982                 //listeners
983                 this.el.key_pressed.connect( (keyval, keycode, state) => {
984                 
985                         
986                          
987                          if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
988                             GLib.debug("SAVE: ctrl-g  pressed");
989                                 _this.forwardSearch(true);
990                             return true;
991                         }
992                     if (keyval == Gdk.Key.f && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
993                             GLib.debug("SAVE: ctrl-f  pressed");
994                                 _this.search_entry.el.grab_focus();
995                             return true;
996                         }
997                          
998                         return false;
999                 });
1000             }
1001
1002             // user defined functions
1003         }
1004
1005
1006
1007         public class Xcls_Box13 : Object
1008         {
1009             public Gtk.Box el;
1010             private Xcls_GtkView  _this;
1011
1012
1013                 // my vars (def)
1014
1015             // ctor
1016             public Xcls_Box13(Xcls_GtkView _owner )
1017             {
1018                 _this = _owner;
1019                 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
1020
1021                 // my vars (dec)
1022
1023                 // set gobject values
1024                 this.el.homogeneous = false;
1025                 this.el.vexpand = false;
1026                 new Xcls_search_entry( _this );
1027                 this.el.append( _this.search_entry.el );
1028                 new Xcls_search_results( _this );
1029                 this.el.append( _this.search_results.el );
1030                 new Xcls_nextBtn( _this );
1031                 this.el.append( _this.nextBtn.el );
1032                 new Xcls_backBtn( _this );
1033                 this.el.append( _this.backBtn.el );
1034                 var child_5 = new Xcls_MenuButton19( _this );
1035                 child_5.ref();
1036                 this.el.append( child_5.el );
1037             }
1038
1039             // user defined functions
1040         }
1041         public class Xcls_search_entry : Object
1042         {
1043             public Gtk.SearchEntry el;
1044             private Xcls_GtkView  _this;
1045
1046
1047                 // my vars (def)
1048             public Gtk.CssProvider css;
1049
1050             // ctor
1051             public Xcls_search_entry(Xcls_GtkView _owner )
1052             {
1053                 _this = _owner;
1054                 _this.search_entry = this;
1055                 this.el = new Gtk.SearchEntry();
1056
1057                 // my vars (dec)
1058
1059                 // set gobject values
1060                 this.el.name = "gtkview-search-entry";
1061                 this.el.hexpand = true;
1062                 this.el.placeholder_text = "Press enter to search";
1063                 this.el.search_delay = 3;
1064                 var child_1 = new Xcls_EventControllerKey15( _this );
1065                 child_1.ref();
1066                 this.el.add_controller(  child_1.el );
1067
1068                 // init method
1069
1070                 this.css = new Gtk.CssProvider();
1071                 
1072                 this.css.load_from_string("
1073                         #gtkview-search-entry { font: 10px monospace ;}"
1074                 );
1075                 
1076                 Gtk.StyleContext.add_provider_for_display(
1077                         this.el.get_display(),
1078                         this.css,
1079                         Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
1080                 );
1081
1082                 //listeners
1083                 this.el.search_changed.connect( () => {
1084                          
1085                         _this.search(_this.search_entry.el.text);
1086                          _this.search_results.updateResults();
1087                 
1088                         GLib.Timeout.add_seconds(1,() => {
1089                                  _this.search_results.updateResults();
1090                                  return false;
1091                          });
1092                           
1093                    
1094                     
1095                 });
1096             }
1097
1098             // user defined functions
1099             public void forwardSearch (bool change_focus) {
1100             
1101             
1102                 _this.forwardSearch(change_focus);
1103             
1104             /*
1105             
1106                 switch(_this.windowstate.state) {
1107                         case WindowState.State.CODEONLY:
1108                         //case WindowState.State.CODE:
1109                                 // search the code being edited..
1110                                 _this.windowstate.code_editor_tab.forwardSearch(change_focus);
1111                                  
1112                                 break;
1113                         case WindowState.State.PREVIEW:
1114                                 if (_this.windowstate.file.xtype == "Gtk") {
1115                                         _this.windowstate.window_gladeview.forwardSearch(change_focus);
1116                                 } else { 
1117                                          _this.windowstate.window_rooview.forwardSearch(change_focus);
1118                                 }
1119                         
1120                                 break;
1121                 }
1122                 */
1123                 
1124             }
1125         }
1126         public class Xcls_EventControllerKey15 : Object
1127         {
1128             public Gtk.EventControllerKey el;
1129             private Xcls_GtkView  _this;
1130
1131
1132                 // my vars (def)
1133
1134             // ctor
1135             public Xcls_EventControllerKey15(Xcls_GtkView _owner )
1136             {
1137                 _this = _owner;
1138                 this.el = new Gtk.EventControllerKey();
1139
1140                 // my vars (dec)
1141
1142                 // set gobject values
1143
1144                 //listeners
1145                 this.el.key_pressed.connect( (keyval, keycode, state) => {
1146                 
1147                         if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1148                             GLib.debug("SAVE: ctrl-g  pressed");
1149                                 _this.forwardSearch(true);
1150                             return true;
1151                         }
1152                     
1153                   
1154                         if (keyval == Gdk.Key.Return && _this.search_entry.el.text.length > 0) {
1155                                 _this.forwardSearch(true);
1156                                 
1157                                 
1158                             return true;
1159                 
1160                         }    
1161                    // print(event.key.keyval)
1162                    
1163                     return false;
1164                 });
1165             }
1166
1167             // user defined functions
1168         }
1169
1170
1171         public class Xcls_search_results : Object
1172         {
1173             public Gtk.Label el;
1174             private Xcls_GtkView  _this;
1175
1176
1177                 // my vars (def)
1178
1179             // ctor
1180             public Xcls_search_results(Xcls_GtkView _owner )
1181             {
1182                 _this = _owner;
1183                 _this.search_results = this;
1184                 this.el = new Gtk.Label( "No Results" );
1185
1186                 // my vars (dec)
1187
1188                 // set gobject values
1189                 this.el.margin_end = 4;
1190                 this.el.margin_start = 4;
1191             }
1192
1193             // user defined functions
1194             public void updateResults () {
1195                 this.el.visible = true;
1196                 
1197                 var res = _this.searchcontext.get_occurrences_count();
1198                 if (res < 0) {
1199                         _this.search_results.el.label = "??? Matches";          
1200                         return;
1201                 }
1202             
1203                 _this.nextBtn.el.sensitive = false;
1204                 _this.backBtn.el.sensitive = false;     
1205             
1206                 if (res > 0) {
1207                         _this.search_results.el.label = "%d Matches".printf(res);
1208                         _this.nextBtn.el.sensitive = true;
1209                         _this.backBtn.el.sensitive = true;
1210                         return;
1211                 } 
1212                 _this.search_results.el.label = "No Matches";
1213                 
1214             }
1215         }
1216
1217         public class Xcls_nextBtn : Object
1218         {
1219             public Gtk.Button el;
1220             private Xcls_GtkView  _this;
1221
1222
1223                 // my vars (def)
1224             public bool always_show_image;
1225
1226             // ctor
1227             public Xcls_nextBtn(Xcls_GtkView _owner )
1228             {
1229                 _this = _owner;
1230                 _this.nextBtn = this;
1231                 this.el = new Gtk.Button();
1232
1233                 // my vars (dec)
1234                 this.always_show_image = true;
1235
1236                 // set gobject values
1237                 this.el.icon_name = "go-down";
1238                 this.el.sensitive = false;
1239
1240                 //listeners
1241                 this.el.clicked.connect( ( ) => {
1242                 _this.forwardSearch(true);
1243                          
1244                 
1245                 });
1246             }
1247
1248             // user defined functions
1249         }
1250
1251         public class Xcls_backBtn : Object
1252         {
1253             public Gtk.Button el;
1254             private Xcls_GtkView  _this;
1255
1256
1257                 // my vars (def)
1258             public bool always_show_image;
1259
1260             // ctor
1261             public Xcls_backBtn(Xcls_GtkView _owner )
1262             {
1263                 _this = _owner;
1264                 _this.backBtn = this;
1265                 this.el = new Gtk.Button();
1266
1267                 // my vars (dec)
1268                 this.always_show_image = true;
1269
1270                 // set gobject values
1271                 this.el.icon_name = "go-up";
1272                 this.el.sensitive = false;
1273
1274                 //listeners
1275                 this.el.clicked.connect( ( ) => {
1276                 
1277                 _this.backSearch(true);
1278                         
1279                 });
1280             }
1281
1282             // user defined functions
1283         }
1284
1285         public class Xcls_MenuButton19 : Object
1286         {
1287             public Gtk.MenuButton el;
1288             private Xcls_GtkView  _this;
1289
1290
1291                 // my vars (def)
1292             public bool always_show_image;
1293
1294             // ctor
1295             public Xcls_MenuButton19(Xcls_GtkView _owner )
1296             {
1297                 _this = _owner;
1298                 this.el = new Gtk.MenuButton();
1299
1300                 // my vars (dec)
1301                 this.always_show_image = true;
1302
1303                 // set gobject values
1304                 this.el.icon_name = "emblem-system";
1305                 this.el.always_show_arrow = true;
1306                 new Xcls_search_settings( _this );
1307                 this.el.popover = _this.search_settings.el;
1308             }
1309
1310             // user defined functions
1311         }
1312         public class Xcls_search_settings : Object
1313         {
1314             public Gtk.PopoverMenu el;
1315             private Xcls_GtkView  _this;
1316
1317
1318                 // my vars (def)
1319
1320             // ctor
1321             public Xcls_search_settings(Xcls_GtkView _owner )
1322             {
1323                 _this = _owner;
1324                 _this.search_settings = this;
1325                 this.el = new Gtk.PopoverMenu.from_model(null);
1326
1327                 // my vars (dec)
1328
1329                 // set gobject values
1330                 var child_1 = new Xcls_Box21( _this );
1331                 child_1.ref();
1332                 this.el.set_child ( child_1.el  );
1333             }
1334
1335             // user defined functions
1336         }
1337         public class Xcls_Box21 : Object
1338         {
1339             public Gtk.Box el;
1340             private Xcls_GtkView  _this;
1341
1342
1343                 // my vars (def)
1344
1345             // ctor
1346             public Xcls_Box21(Xcls_GtkView _owner )
1347             {
1348                 _this = _owner;
1349                 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
1350
1351                 // my vars (dec)
1352
1353                 // set gobject values
1354                 new Xcls_case_sensitive( _this );
1355                 this.el.append( _this.case_sensitive.el );
1356                 new Xcls_regex( _this );
1357                 this.el.append( _this.regex.el );
1358                 new Xcls_multiline( _this );
1359                 this.el.append( _this.multiline.el );
1360             }
1361
1362             // user defined functions
1363         }
1364         public class Xcls_case_sensitive : Object
1365         {
1366             public Gtk.CheckButton el;
1367             private Xcls_GtkView  _this;
1368
1369
1370                 // my vars (def)
1371
1372             // ctor
1373             public Xcls_case_sensitive(Xcls_GtkView _owner )
1374             {
1375                 _this = _owner;
1376                 _this.case_sensitive = this;
1377                 this.el = new Gtk.CheckButton();
1378
1379                 // my vars (dec)
1380
1381                 // set gobject values
1382                 this.el.label = "Case Sensitive";
1383             }
1384
1385             // user defined functions
1386         }
1387
1388         public class Xcls_regex : Object
1389         {
1390             public Gtk.CheckButton el;
1391             private Xcls_GtkView  _this;
1392
1393
1394                 // my vars (def)
1395
1396             // ctor
1397             public Xcls_regex(Xcls_GtkView _owner )
1398             {
1399                 _this = _owner;
1400                 _this.regex = this;
1401                 this.el = new Gtk.CheckButton();
1402
1403                 // my vars (dec)
1404
1405                 // set gobject values
1406                 this.el.label = "Regex";
1407             }
1408
1409             // user defined functions
1410         }
1411
1412         public class Xcls_multiline : Object
1413         {
1414             public Gtk.CheckButton el;
1415             private Xcls_GtkView  _this;
1416
1417
1418                 // my vars (def)
1419
1420             // ctor
1421             public Xcls_multiline(Xcls_GtkView _owner )
1422             {
1423                 _this = _owner;
1424                 _this.multiline = this;
1425                 this.el = new Gtk.CheckButton();
1426
1427                 // my vars (dec)
1428
1429                 // set gobject values
1430                 this.el.label = "Multi-line (add \\n)";
1431             }
1432
1433             // user defined functions
1434         }
1435
1436
1437
1438
1439
1440
1441
1442     }