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