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