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