7991ac62ef3abc7269a7cacbaceeb6252de2b9ea
[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       // code preview...
325        
326        GLib.Timeout.add(100, () => {
327        
328        
329             this.notebook.el.set_current_page(1);
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                 if (event.keyval == Gdk.Key.f && (event.state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
692                     GLib.debug("SAVE: ctrl-f  pressed");
693                         _this.search_entry.el.grab_focus();
694                     return true;
695                 }
696                  
697                 return false;
698             });
699         }
700
701         // user defined functions
702         public void loadFile ( ) {
703             this.loading = true;
704             var buf = this.el.get_buffer();
705             buf.set_text("",0);
706             var sbuf = (Gtk.SourceBuffer) buf;
707         
708             
709         
710             if (_this.file == null || _this.file.xtype != "Gtk") {
711                 print("xtype != Gtk");
712                 this.loading = false;
713                 return;
714             }
715             
716             var valafn = "";
717               try {             
718                    var  regex = new Regex("\\.bjs$");
719                 
720                  
721                     valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
722                  } catch (GLib.RegexError e) {
723                      this.loading = false;
724                     return;
725                 }   
726             
727         
728            if (!FileUtils.test(valafn,FileTest.IS_REGULAR) ) {
729                 print("File path has no errors\n");
730                 this.loading = false;
731                 return  ;
732             }
733             
734             string str;
735             try {
736             
737                 GLib.FileUtils.get_contents (valafn, out str);
738             } catch (Error e) {
739                 this.loading = false;
740                 return  ;
741             }
742         
743         //    print("setting str %d\n", str.length);
744             buf.set_text(str, str.length);
745             var lm = Gtk.SourceLanguageManager.get_default();
746              
747             //?? is javascript going to work as js?
748             
749             ((Gtk.SourceBuffer)(buf)) .set_language(lm.get_language(_this.file.language));
750           
751             
752             Gtk.TextIter start;
753             Gtk.TextIter end;     
754                 
755             sbuf.get_bounds (out start, out end);
756             sbuf.remove_source_marks (start, end, null); // remove all marks..
757             
758             
759             if (_this.main_window.windowstate.last_compile_result != null) {
760                 var obj = _this.main_window.windowstate.last_compile_result;
761                 this.highlightErrorsJson("ERR", obj);
762                 this.highlightErrorsJson("WARN", obj);
763                 this.highlightErrorsJson("DEPR", obj);                  
764             }
765             //while (Gtk.events_pending()) {
766              //   Gtk.main_iteration();
767            // }
768             
769             this.loading = false; 
770         }
771         public void nodeSelected (JsRender.Node? sel, bool scroll) {
772           
773             
774           
775             // this is connected in widnowstate
776             print("Roo-view - node selected\n");
777             var buf = this.el.get_buffer();
778          
779             var sbuf = (Gtk.SourceBuffer) buf;
780         
781            
782             while(Gtk.events_pending()) {
783                 Gtk.main_iteration();
784             }
785             
786            
787             // clear all the marks..
788              Gtk.TextIter start;
789             Gtk.TextIter end;     
790                 
791             sbuf.get_bounds (out start, out end);
792             sbuf.remove_source_marks (start, end, "grey");
793             
794                 this.node_selected = sel;
795              if (sel == null) {
796                 // no highlighting..
797                 return;
798             }
799             Gtk.TextIter iter;   
800             sbuf.get_iter_at_line(out iter,  sel.line_start);
801             
802             
803             Gtk.TextIter cur_iter;
804             sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position);
805             
806             //var cur_line = cur_iter.get_line();
807             //if (cur_line > sel.line_start && cur_line < sel.line_end) {
808             
809             //} else {
810             if (this.allow_node_scroll) {
811                          
812                 this.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);
813                 }
814             
815              
816             
817             for (var i = 0; i < buf.get_line_count();i++) {
818                 if (i < sel.line_start || i > sel.line_end) {
819                    
820                     sbuf.get_iter_at_line(out iter, i);
821                     sbuf.create_source_mark(null, "grey", iter);
822                     
823                 }
824             
825             }
826             
827         
828         }
829         public void highlightErrorsJson (string type, Json.Object obj) {
830               Gtk.TextIter start;
831              Gtk.TextIter end;   
832              
833              var buf =  this.el.get_buffer();
834                var sbuf = (Gtk.SourceBuffer)buf;
835                 buf.get_bounds (out start, out end);
836                 
837                 sbuf.remove_source_marks (start, end, type);
838                          
839              
840              // we should highlight other types of errors..
841             
842             if (!obj.has_member(type)) {
843                 print("Return has no errors\n");
844                 return  ;
845             }
846             var err = obj.get_object_member(type);
847             
848             if (_this.file == null) { 
849                 return; // just in case the file has not loaded yet?
850             }
851          
852         
853             var valafn = "";
854               try {             
855                    var  regex = new Regex("\\.bjs$");
856                 
857                  
858                     valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
859                  } catch (GLib.RegexError e) {
860                     return;
861                 }   
862         
863            if (!err.has_member(valafn)) {
864                 print("File path has no errors\n");
865                 return  ;
866             }
867             var lines = err.get_object_member(valafn);
868             
869            
870             
871             var tlines = buf.get_line_count () +1;
872             
873             lines.foreach_member((obj, line, node) => {
874                 
875                      Gtk.TextIter iter;
876             //        print("get inter\n");
877                     var eline = int.parse(line) -1  ;
878                     print("GOT ERROR on line %s -- converted to %d\n", line,eline);
879                     
880                     
881                     if (eline > tlines || eline < 0) {
882                         return;
883                     }
884                     sbuf.get_iter_at_line( out iter, eline);
885                     //print("mark line\n");
886                     var msg  = type + " on line: %d - %s".printf(eline+1, valafn);
887                     var ar = lines.get_array_member(line);
888                     for (var i = 0 ; i < ar.get_length(); i++) {
889                             msg += (msg.length > 0) ? "\n" : "";
890                             msg += ar.get_string_element(i);
891                     }
892                     
893                     
894                     sbuf.create_source_mark(msg, type, iter);
895                 } );
896                 return  ;
897             
898          
899         
900         
901         }
902         public string toString () {
903            Gtk.TextIter s;
904             Gtk.TextIter e;
905             this.el.get_buffer().get_start_iter(out s);
906             this.el.get_buffer().get_end_iter(out e);
907             var ret = this.el.get_buffer().get_text(s,e,true);
908             //print("TO STRING? " + ret);
909             return ret;
910         }
911     }
912     public class Xcls_buffer : Object
913     {
914         public Gtk.SourceBuffer el;
915         private Xcls_GtkView  _this;
916
917
918             // my vars (def)
919         public int error_line;
920         public bool dirty;
921
922         // ctor
923         public Xcls_buffer(Xcls_GtkView _owner )
924         {
925             _this = _owner;
926             _this.buffer = this;
927             this.el = new Gtk.SourceBuffer( null );
928
929             // my vars (dec)
930             this.error_line = -1;
931             this.dirty = false;
932
933             // set gobject values
934         }
935
936         // user defined functions
937     }
938
939
940
941     public class Xcls_Box12 : Object
942     {
943         public Gtk.Box el;
944         private Xcls_GtkView  _this;
945
946
947             // my vars (def)
948
949         // ctor
950         public Xcls_Box12(Xcls_GtkView _owner )
951         {
952             _this = _owner;
953             this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
954
955             // my vars (dec)
956
957             // set gobject values
958             this.el.homogeneous = false;
959             this.el.vexpand = false;
960             var child_0 = new Xcls_search_entry( _this );
961             child_0.ref();
962             this.el.add(  child_0.el );
963             var child_1 = new Xcls_MenuBar14( _this );
964             child_1.ref();
965             this.el.add (  child_1.el  );
966             var child_2 = new Xcls_nextBtn( _this );
967             child_2.ref();
968             this.el.add(  child_2.el );
969             var child_3 = new Xcls_backBtn( _this );
970             child_3.ref();
971             this.el.add(  child_3.el );
972             var child_4 = new Xcls_MenuButton20( _this );
973             child_4.ref();
974             this.el.add(  child_4.el );
975         }
976
977         // user defined functions
978     }
979     public class Xcls_search_entry : Object
980     {
981         public Gtk.SearchEntry el;
982         private Xcls_GtkView  _this;
983
984
985             // my vars (def)
986
987         // ctor
988         public Xcls_search_entry(Xcls_GtkView _owner )
989         {
990             _this = _owner;
991             _this.search_entry = this;
992             this.el = new Gtk.SearchEntry();
993
994             // my vars (dec)
995
996             // set gobject values
997             this.el.width_request = 300;
998             this.el.hexpand = true;
999             this.el.placeholder_text = "Press enter to search";
1000
1001             // init method
1002
1003             var description =   Pango.FontDescription.from_string("monospace");
1004                 description.set_size(8000);
1005                  this.el.override_font(description);
1006
1007             //listeners
1008             this.el.key_press_event.connect( (event) => {
1009                  if (event.keyval == Gdk.Key.g && (event.state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1010                     GLib.debug("SAVE: ctrl-g  pressed");
1011                         _this.forwardSearch(true);
1012                     return true;
1013                 }
1014                 
1015               
1016                 if (event.keyval == Gdk.Key.Return && this.el.text.length > 0) {
1017                         var res = _this.search(this.el.text);
1018                          _this.search_results.updateResults();
1019             
1020                         GLib.Timeout.add_seconds(2,() => {
1021                                  _this.search_results.updateResults();
1022                                  return false;
1023                          });
1024                  
1025                         
1026                     return true;
1027             
1028                 }    
1029                // print(event.key.keyval)
1030                
1031                 return false;
1032             
1033             });
1034             this.el.changed.connect( () => {
1035                 /*
1036                 if (this.el.text == "") {
1037                         _this.search_results.el.hide();
1038                         return;
1039                 }
1040                 var res = 0;
1041                 switch(_this.windowstate.state) {
1042                         case WindowState.State.CODEONLY:
1043                         ///case WindowState.State.CODE:
1044                                 // search the code being edited..
1045                                 res = _this.windowstate.code_editor_tab.search(this.el.text);
1046                                 
1047                                 break;
1048                         case WindowState.State.PREVIEW:
1049                                 if (_this.windowstate.file.xtype == "Gtk") {
1050                                          res = _this.windowstate.window_gladeview.search(this.el.text);
1051                                 } else { 
1052                                          res = _this.windowstate.window_rooview.search(this.el.text);                   
1053                                 }
1054                         
1055                         
1056                                 break;
1057                 }
1058                 _this.search_results.el.show();
1059                 if (res > 0) {
1060                         _this.search_results.el.label = "%d Matches".printf(res);
1061                 } else {
1062                         _this.search_results.el.label = "No Matches";
1063                 }
1064                         
1065                 */
1066                 
1067             });
1068         }
1069
1070         // user defined functions
1071         public void forwardSearch (bool change_focus) {
1072         
1073         
1074                 _this.forwardSearch(change_focus);
1075         
1076         /*
1077         
1078                 switch(_this.windowstate.state) {
1079                         case WindowState.State.CODEONLY:
1080                         //case WindowState.State.CODE:
1081                                 // search the code being edited..
1082                                 _this.windowstate.code_editor_tab.forwardSearch(change_focus);
1083                                  
1084                                 break;
1085                         case WindowState.State.PREVIEW:
1086                                 if (_this.windowstate.file.xtype == "Gtk") {
1087                                         _this.windowstate.window_gladeview.forwardSearch(change_focus);
1088                                 } else { 
1089                                          _this.windowstate.window_rooview.forwardSearch(change_focus);
1090                                 }
1091                         
1092                                 break;
1093                 }
1094                 */
1095                 
1096         }
1097     }
1098
1099     public class Xcls_MenuBar14 : Object
1100     {
1101         public Gtk.MenuBar el;
1102         private Xcls_GtkView  _this;
1103
1104
1105             // my vars (def)
1106
1107         // ctor
1108         public Xcls_MenuBar14(Xcls_GtkView _owner )
1109         {
1110             _this = _owner;
1111             this.el = new Gtk.MenuBar();
1112
1113             // my vars (dec)
1114
1115             // set gobject values
1116             var child_0 = new Xcls_search_results( _this );
1117             child_0.ref();
1118             this.el.add (  child_0.el  );
1119         }
1120
1121         // user defined functions
1122     }
1123     public class Xcls_search_results : Object
1124     {
1125         public Gtk.ImageMenuItem el;
1126         private Xcls_GtkView  _this;
1127
1128
1129             // my vars (def)
1130
1131         // ctor
1132         public Xcls_search_results(Xcls_GtkView _owner )
1133         {
1134             _this = _owner;
1135             _this.search_results = this;
1136             this.el = new Gtk.ImageMenuItem();
1137
1138             // my vars (dec)
1139
1140             // set gobject values
1141             this.el.always_show_image = true;
1142             this.el.visible = false;
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
1407             // init method
1408
1409             {
1410                 this.el.show();
1411             }
1412         }
1413
1414         // user defined functions
1415     }
1416
1417     public class Xcls_regex : Object
1418     {
1419         public Gtk.CheckMenuItem el;
1420         private Xcls_GtkView  _this;
1421
1422
1423             // my vars (def)
1424
1425         // ctor
1426         public Xcls_regex(Xcls_GtkView _owner )
1427         {
1428             _this = _owner;
1429             _this.regex = this;
1430             this.el = new Gtk.CheckMenuItem();
1431
1432             // my vars (dec)
1433
1434             // set gobject values
1435             this.el.label = "Regex";
1436
1437             // init method
1438
1439             {
1440                 this.el.show();
1441             }
1442         }
1443
1444         // user defined functions
1445     }
1446
1447     public class Xcls_multiline : Object
1448     {
1449         public Gtk.CheckMenuItem el;
1450         private Xcls_GtkView  _this;
1451
1452
1453             // my vars (def)
1454
1455         // ctor
1456         public Xcls_multiline(Xcls_GtkView _owner )
1457         {
1458             _this = _owner;
1459             _this.multiline = this;
1460             this.el = new Gtk.CheckMenuItem();
1461
1462             // my vars (dec)
1463
1464             // set gobject values
1465             this.el.label = "Multi-line (add \\n)";
1466
1467             // init method
1468
1469             {
1470                 this.el.show();
1471             }
1472         }
1473
1474         // user defined functions
1475     }
1476
1477
1478
1479
1480
1481
1482 }