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