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