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