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