fix line numbering issues with vala generator - hopefully fixes completion in node...
[roobuilder] / src / Builder4 / WindowRooView.vala
1     static Xcls_WindowRooView  _WindowRooView;
2
3     public class Xcls_WindowRooView : Object
4     {
5         public Gtk.Box el;
6         private Xcls_WindowRooView  _this;
7
8         public static Xcls_WindowRooView singleton()
9         {
10             if (_WindowRooView == null) {
11                 _WindowRooView= new Xcls_WindowRooView();
12             }
13             return _WindowRooView;
14         }
15         public Xcls_notebook notebook;
16         public Xcls_label_preview label_preview;
17         public Xcls_label_code label_code;
18         public Xcls_paned paned;
19         public Xcls_viewbox viewbox;
20         public Xcls_AutoRedraw AutoRedraw;
21         public Xcls_view view;
22         public Xcls_inspectorcontainer inspectorcontainer;
23         public Xcls_sourceviewscroll sourceviewscroll;
24         public Xcls_sourceview sourceview;
25         public Xcls_buffer buffer;
26         public Xcls_search_entry search_entry;
27         public Xcls_search_results search_results;
28         public Xcls_nextBtn nextBtn;
29         public Xcls_backBtn backBtn;
30         public Xcls_search_settings search_settings;
31         public Xcls_case_sensitive case_sensitive;
32         public Xcls_regex regex;
33         public Xcls_multiline multiline;
34
35             // my vars (def)
36         public Gtk.Widget lastObj;
37         public Xcls_MainWindow main_window;
38         public int last_search_end;
39         public GtkSource.SearchContext searchcontext;
40         public JsRender.JsRender file;
41
42         // ctor
43         public Xcls_WindowRooView()
44         {
45             _this = this;
46             this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
47
48             // my vars (dec)
49             this.lastObj = null;
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
60         // user defined functions
61         public void loadFile (JsRender.JsRender file)
62         {
63             this.file = file;
64             this.view.renderJS(true);
65             this.notebook.el.page = 0;// gtk preview 
66             this.sourceview.loadFile();   
67         }
68         public void highlightNodeAtLine (int ln) {
69         
70         
71                  
72                 // highlight node...
73                 
74                         
75             var node = _this.file.lineToNode(ln+1);
76          
77             if (node == null) {
78                 //print("can not find node\n");
79                 return;
80             }
81             var prop = node.lineToProp(ln+1);
82             print("prop : %s", prop == null ? "???" : prop.name);
83                 
84                 
85             // ---------- this selects the tree's node...
86             
87             var ltree = _this.main_window.windowstate.left_tree;
88            ltree.model.selectNode(node);
89                 
90             //_this.sourceview.allow_node_scroll = false; /// block node scrolling..
91                        
92            
93             //print("changing cursor on tree..\n");
94            
95         
96             
97             // let's try allowing editing on the methods.
98             // a little klunky at present..
99                 _this.sourceview.prop_selected = "";
100                 /*
101             if (prop != null) {
102                         //see if we can find it..
103                         var kv = prop.split(":");
104                         if (kv[0] == "p") {
105                         
106                         //var k = prop.get_key(kv[1]);
107                         // fixme -- need to determine if it's an editable property...
108                         _this.sourceview.prop_selected = prop;
109                         
110                         } else if (kv[0] == "l") {
111                                  _this.sourceview.prop_selected = prop;
112                                 
113                         }
114             }
115             */
116            // ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false); 
117            _this.sourceview.nodeSelected(node,false);
118             
119                     // scrolling is disabled... as node selection calls scroll 10ms after it changes.
120               //      GLib.Timeout.add_full(GLib.Priority.DEFAULT,100 , () => {
121                   //          this.allow_node_scroll = true;
122                   //          return false;
123               //      });
124               //  }
125                         
126                         
127                         
128                         
129                         
130                         
131                         
132                         
133                         
134                          
135         
136         }
137         public void requestRedraw () {
138             this.view.renderJS(false);
139             this.sourceview.loadFile();   
140         }
141         public void forwardSearch (bool change_focus) {
142         
143                 if (this.searchcontext == null) {
144                         return;
145                 }
146                 this.notebook.el.page = 1;
147                 Gtk.TextIter beg, st,en;
148                 bool has_wrapped_around;
149                 var buf = this.sourceview.el.get_buffer();
150                 buf.get_iter_at_offset(out beg, this.last_search_end);
151                 if (!this.searchcontext.forward(beg, out st, out en, out has_wrapped_around)) {
152                         this.last_search_end = 0;
153                         return;
154                 }
155                 this.last_search_end = en.get_offset();
156                 if (change_focus) {
157                         this.sourceview.el.grab_focus();
158                 }
159                 buf.place_cursor(st);
160                 
161          
162                  
163                 this.sourceview.el.scroll_to_iter(st,  0.0f, true, 0.0f, 0.5f);
164                 
165                 
166                 var ln = st.get_line();
167                 
168                 this.highlightNodeAtLine(ln);
169         }
170         public void backSearch (bool change_focus) {
171         
172                 if (this.searchcontext == null) {
173                         return;
174                 } 
175                 
176                 Gtk.TextIter beg, st,en;
177                 bool has_wrapped_around;
178                 this.buffer.el.get_iter_at_offset(out beg, this.last_search_end -1 );
179                 
180                 if (!this.searchcontext.backward(beg, out st, out en, out has_wrapped_around)) {
181                 
182                         this.last_search_end = 0;
183                         return;
184                 }
185                 this.last_search_end = en.get_offset();
186                 if (change_focus) {
187                         this.sourceview.el.grab_focus();
188                 }
189                 this.buffer.el.place_cursor(st);
190                 this.sourceview.el.scroll_to_iter(st,  0.1f, true, 0.0f, 0.5f);
191                 var ln = st.get_line();
192                 this.highlightNodeAtLine(ln);
193                 
194          
195         }
196         public int search (string in_txt) {
197                 this.notebook.el.page = 1;
198                 
199          
200            
201                 var s = new GtkSource.SearchSettings();
202                 s.case_sensitive = _this.case_sensitive.el.active;
203                 s.regex_enabled = _this.regex.el.active;        
204                 s.wrap_around = false;
205                 
206                 this.searchcontext = new GtkSource.SearchContext(this.buffer.el,s);
207                 this.searchcontext.set_highlight(true);
208                 var txt = in_txt;
209                 
210                 if (_this.multiline.el.active) {
211                         txt = in_txt.replace("\\n", "\n");
212                 }
213                 
214                 s.set_search_text(txt);
215                 Gtk.TextIter beg, st,en;
216                 bool has_wrapped_around;
217                 this.buffer.el.get_start_iter(out beg);
218                 this.searchcontext.forward(beg, out st, out en, out has_wrapped_around);
219                 this.last_search_end = 0;
220                 
221                 return this.searchcontext.get_occurrences_count();
222         
223          
224             
225         
226         }
227         public void createThumb () {
228             
229             
230             if (this.file == null) {
231                 return;
232             }
233             
234                 if (this.notebook.el.page > 0 ) {
235                 return;
236             }
237             
238                 this.file.widgetToIcon(this.view.el); 
239         
240             
241              
242             
243              
244         }
245         public void updateErrorMarks (string category) {
246                 
247          
248         
249                 var buf = _this.buffer.el;
250                 Gtk.TextIter start;
251                 Gtk.TextIter end;     
252                 buf.get_bounds (out start, out end);
253         
254                 buf.remove_source_marks (start, end, category);
255          
256                 GLib.debug("highlight errors");          
257         
258                  // we should highlight other types of errors..
259         
260          
261         
262                  
263                 if (_this.file == null) {
264                         GLib.debug("file is null?");
265                         return;
266         
267                 }
268                 var ar = this.file.getErrors(category);
269                 if (ar == null || ar.get_n_items() < 1) {
270                         GLib.debug("higjlight %s has no errors", category);
271                         return;
272                 }
273          
274         
275          
276                 
277                 var offset = 0;
278                  
279         
280                 var tlines = buf.get_line_count () +1;
281                 
282          
283                  
284                 for (var i = 0; i < ar.get_n_items();i++) {
285                         var err = (Palete.CompileError) ar.get_item(i);
286                         
287                      Gtk.TextIter iter;
288         //        print("get inter\n");
289                     var eline = err.line - offset;
290                     GLib.debug("GOT ERROR on line %d -- converted to %d  (offset = %d)",
291                         err.line ,eline, offset);
292                     
293                     
294                     if (eline > tlines || eline < 0) {
295                         return;
296                     }
297                    
298                     
299                     buf.get_iter_at_line( out iter, eline);
300                    
301                    
302                         var msg = "Line: %d %s : %s".printf(eline+1, err.category, err.msg);
303                     buf.create_source_mark( msg, err.category, iter);
304                     GLib.debug("set line %d to %s", eline, msg);
305                     //this.marks.set(eline, msg);
306                 }
307                 return ;
308         
309         
310         
311          
312         
313         }
314         public void scroll_to_line (int line) {
315            // code preview...
316            
317            GLib.Timeout.add(100, () => {
318            
319                         this.notebook.el.set_current_page( 1 );
320                    
321                    
322                           var buf = this.sourceview.el.get_buffer();
323                  
324                         var sbuf = (GtkSource.Buffer) buf;
325         
326         
327                         Gtk.TextIter iter;   
328                         sbuf.get_iter_at_line(out iter,  line);
329                         this.sourceview.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);
330                         return false;
331                 });   
332         
333            
334         }
335         public class Xcls_notebook : Object
336         {
337             public Gtk.Notebook el;
338             private Xcls_WindowRooView  _this;
339
340
341                 // my vars (def)
342
343             // ctor
344             public Xcls_notebook(Xcls_WindowRooView _owner )
345             {
346                 _this = _owner;
347                 _this.notebook = this;
348                 this.el = new Gtk.Notebook();
349
350                 // my vars (dec)
351
352                 // set gobject values
353                 this.el.vexpand = true;
354                 new Xcls_label_preview( _this );
355                 new Xcls_label_code( _this );
356                 new Xcls_paned( _this );
357                 this.el.append_page ( _this.paned.el , _this.label_preview.el );
358                 var child_4 = new Xcls_Box13( _this );
359                 child_4.ref();
360                 this.el.append_page ( child_4.el , _this.label_code.el );
361             }
362
363             // user defined functions
364         }
365         public class Xcls_label_preview : Object
366         {
367             public Gtk.Label el;
368             private Xcls_WindowRooView  _this;
369
370
371                 // my vars (def)
372
373             // ctor
374             public Xcls_label_preview(Xcls_WindowRooView _owner )
375             {
376                 _this = _owner;
377                 _this.label_preview = this;
378                 this.el = new Gtk.Label( "Preview" );
379
380                 // my vars (dec)
381
382                 // set gobject values
383             }
384
385             // user defined functions
386         }
387
388         public class Xcls_label_code : Object
389         {
390             public Gtk.Label el;
391             private Xcls_WindowRooView  _this;
392
393
394                 // my vars (def)
395
396             // ctor
397             public Xcls_label_code(Xcls_WindowRooView _owner )
398             {
399                 _this = _owner;
400                 _this.label_code = this;
401                 this.el = new Gtk.Label( "Preview Generated Code" );
402
403                 // my vars (dec)
404
405                 // set gobject values
406             }
407
408             // user defined functions
409         }
410
411         public class Xcls_paned : Object
412         {
413             public Gtk.Paned el;
414             private Xcls_WindowRooView  _this;
415
416
417                 // my vars (def)
418
419             // ctor
420             public Xcls_paned(Xcls_WindowRooView _owner )
421             {
422                 _this = _owner;
423                 _this.paned = this;
424                 this.el = new Gtk.Paned( Gtk.Orientation.VERTICAL );
425
426                 // my vars (dec)
427
428                 // set gobject values
429                 this.el.vexpand = true;
430                 new Xcls_viewbox( _this );
431                 this.el.set_start_child ( _this.viewbox.el  );
432                 new Xcls_inspectorcontainer( _this );
433                 this.el.set_end_child ( _this.inspectorcontainer.el  );
434             }
435
436             // user defined functions
437         }
438         public class Xcls_viewbox : Object
439         {
440             public Gtk.Box el;
441             private Xcls_WindowRooView  _this;
442
443
444                 // my vars (def)
445
446             // ctor
447             public Xcls_viewbox(Xcls_WindowRooView _owner )
448             {
449                 _this = _owner;
450                 _this.viewbox = this;
451                 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
452
453                 // my vars (dec)
454
455                 // set gobject values
456                 this.el.homogeneous = false;
457                 this.el.vexpand = true;
458                 var child_1 = new Xcls_Box7( _this );
459                 child_1.ref();
460                 this.el.append( child_1.el );
461                 new Xcls_view( _this );
462                 this.el.append( _this.view.el );
463             }
464
465             // user defined functions
466         }
467         public class Xcls_Box7 : Object
468         {
469             public Gtk.Box el;
470             private Xcls_WindowRooView  _this;
471
472
473                 // my vars (def)
474
475             // ctor
476             public Xcls_Box7(Xcls_WindowRooView _owner )
477             {
478                 _this = _owner;
479                 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
480
481                 // my vars (dec)
482
483                 // set gobject values
484                 this.el.homogeneous = true;
485                 this.el.height_request = 20;
486                 this.el.vexpand = false;
487                 var child_1 = new Xcls_Button8( _this );
488                 child_1.ref();
489                 this.el.append( child_1.el );
490                 new Xcls_AutoRedraw( _this );
491                 this.el.append( _this.AutoRedraw.el );
492                 var child_3 = new Xcls_Button10( _this );
493                 child_3.ref();
494                 this.el.append( child_3.el );
495             }
496
497             // user defined functions
498         }
499         public class Xcls_Button8 : Object
500         {
501             public Gtk.Button el;
502             private Xcls_WindowRooView  _this;
503
504
505                 // my vars (def)
506
507             // ctor
508             public Xcls_Button8(Xcls_WindowRooView _owner )
509             {
510                 _this = _owner;
511                 this.el = new Gtk.Button();
512
513                 // my vars (dec)
514
515                 // set gobject values
516                 this.el.label = "Redraw";
517
518                 //listeners
519                 this.el.clicked.connect( ( ) => {
520                     _this.view.renderJS(  true);
521                 });
522             }
523
524             // user defined functions
525         }
526
527         public class Xcls_AutoRedraw : Object
528         {
529             public Gtk.CheckButton el;
530             private Xcls_WindowRooView  _this;
531
532
533                 // my vars (def)
534
535             // ctor
536             public Xcls_AutoRedraw(Xcls_WindowRooView _owner )
537             {
538                 _this = _owner;
539                 _this.AutoRedraw = this;
540                 this.el = new Gtk.CheckButton();
541
542                 // my vars (dec)
543
544                 // set gobject values
545                 this.el.active = true;
546                 this.el.label = "Auto Redraw On";
547
548                 //listeners
549                 this.el.toggled.connect( (state) => {
550                     this.el.set_label(this.el.active  ? "Auto Redraw On" : "Auto Redraw Off");
551                 });
552             }
553
554             // user defined functions
555         }
556
557         public class Xcls_Button10 : Object
558         {
559             public Gtk.Button el;
560             private Xcls_WindowRooView  _this;
561
562
563                 // my vars (def)
564
565             // ctor
566             public Xcls_Button10(Xcls_WindowRooView _owner )
567             {
568                 _this = _owner;
569                 this.el = new Gtk.Button();
570
571                 // my vars (dec)
572
573                 // set gobject values
574                 this.el.label = "Full Redraw";
575
576                 //listeners
577                 this.el.clicked.connect( () => {
578                   _this.view.redraws = 99;
579                  //   _this.view.el.web_context.clear_cache();  
580                   //_this.view.renderJS(true);
581                   FakeServerCache.clear();
582                   _this.view.reInit();
583                  
584                 });
585             }
586
587             // user defined functions
588         }
589
590
591         public class Xcls_view : Object
592         {
593             public WebKit.WebView el;
594             private Xcls_WindowRooView  _this;
595
596
597                 // my vars (def)
598             public WebKit.WebInspector inspector;
599             public bool pendingRedraw;
600             public int redraws;
601             public bool refreshRequired;
602             public string runjs;
603             public string runhtml;
604             public string renderedData;
605             public GLib.DateTime lastRedraw;
606
607             // ctor
608             public Xcls_view(Xcls_WindowRooView _owner )
609             {
610                 _this = _owner;
611                 _this.view = this;
612                 this.el = new WebKit.WebView();
613
614                 // my vars (dec)
615                 this.pendingRedraw = false;
616                 this.redraws = 0;
617                 this.refreshRequired = false;
618                 this.runjs = "";
619                 this.runhtml = "";
620                 this.renderedData = "";
621                 this.lastRedraw = null;
622
623                 // set gobject values
624                 this.el.vexpand = true;
625
626                 // init method
627
628                 {
629                     // this may not work!?
630                     var settings =  this.el.get_settings();
631                     settings.enable_developer_extras = true;
632                     
633                     
634                     var fs= new FakeServer(this.el);
635                     fs.ref();
636                     // this was an attempt to change the url perms.. did not work..
637                     // settings.enable_file_access_from_file_uris = true;
638                     // settings.enable_offline_web_application_cache - true;
639                     // settings.enable_universal_access_from_file_uris = true;
640                    
641                      
642                     
643                     
644                     
645                 
646                      // FIXME - base url of script..
647                      // we need it so some of the database features work.
648                     this.el.load_html( "Render not ready" , 
649                             //fixme - should be a config option!
650                             // or should we catch stuff and fix it up..
651                             "http://localhost/app.Builder/"
652                     );
653                    
654                         
655                    //this.el.open('file:///' + __script_path__ + '/../builder.html');
656                     /*
657                     Gtk.drag_dest_set
658                     (
659                             this.el,              //
660                             Gtk.DestDefaults.MOTION  | Gtk.DestDefaults.HIGHLIGHT,
661                             null,            // list of targets
662                             Gdk.DragAction.COPY         // what to do with data after dropped 
663                     );
664                                             
665                    // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
666                     Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
667                     */
668                     GLib.Timeout.add_seconds(1,  ()  =>{
669                          //print("run refresh?");
670                          if (this.el == null) {
671                             return false;
672                          }
673                          this.runRefresh(); 
674                          return true;
675                      });
676                     
677                     
678                 }
679
680                 //listeners
681                 this.el.script_dialog.connect( (dialog) => {
682                     
683                     
684                     if (this.el == null) {
685                         return true;
686                     }
687                     
688                      var msg = dialog.get_message();
689                      if (msg.length < 4) {
690                         return false;
691                      }
692                      
693                      GLib.debug("script dialog got %s", msg);
694                      
695                      if (msg.substring(0,4) != "IPC:") {
696                          return false;
697                      }
698                      var ar = msg.split(":", 3);
699                     if (ar.length < 3) {
700                         return false;
701                     }
702                 
703                     switch(ar[1]) {
704                         case "SAVEHTML":
705                                 GLib.debug("GOT saveHTML %d", ar[2].length);
706                             _this.file.saveHTML(ar[2]);
707                             _this.createThumb();
708                             return true;
709                         default:
710                             return false;
711                     }
712                     
713                 });
714                 this.el.ready_to_show.connect( ( ) => {
715                   this.initInspector();
716                 
717                 });
718                 this.el.load_changed.connect( (le) => {
719                     if (le != WebKit.LoadEvent.FINISHED) {
720                         return;
721                     }
722                     if (this.runjs.length < 1) {
723                         return;
724                     }
725                   //  this.el.run_javascript(this.runjs, null);
726                      FakeServerCache.remove(    this.runjs);
727                     this.runjs = "";
728                 });
729             }
730
731             // user defined functions
732             public void initInspector () {
733                 
734              
735                       
736                // this.inspector.open_window.connect(() => {
737                      this.inspector = this.el.get_inspector();
738                      
739                      this.inspector.open_window.connect(() => {
740                     print("inspector attach\n");
741                     var wv = this.inspector.get_web_view();
742                     if (wv != null) {
743                         print("got inspector web view\n");
744                         
745                         var cn = _this.inspectorcontainer.el.get_first_child();
746                         if (cn != null) {
747                              _this.inspectorcontainer.el.remove(cn);
748                          }
749                         
750                         _this.inspectorcontainer.el.append(wv);
751                         wv.show();
752                     } else {
753                          print("got inspector web view FAILED\n");
754                         //this.inspector.close();
755                         
756                         //this.inspector = null;
757                        
758              
759                     }
760                   return true;
761                    
762                });
763                  this.inspector.show();
764                      
765                 
766               
767             }
768             public void renderJS (bool force) {
769             
770                 // this is the public redraw call..
771                 // we refresh in a loop privately..
772                 var autodraw = _this.AutoRedraw.el.active;
773                 if (!autodraw && !force) {
774                     print("Skipping redraw - no force, and autodraw off");
775                     return;
776                 }
777                  
778                 this.refreshRequired  = true;
779             }
780             public void reInit () {
781                print("reInit?");
782                      // if this happens destroy the webkit..
783                      // recreate it..
784                  this.el.stop_loading();
785                      
786                  if (_this.viewbox.el.get_parent() == null) {
787                     return;
788                  }
789                      
790                      /*
791                 _this.viewbox.el.remove(_this.viewcontainer.el);
792                 //_this.paned.el.remove(_this.inspectorcontainer.el);        
793                      
794                      // destory seems to cause problems.
795                      //this.el.destroy();
796                     //_this.viewcontainer.el.destroy();
797                      //_this.inspectorcontainer.el.destroy();
798                  var  inv =new Xcls_inspectorcontainer(_this);
799                   
800                   _this.paned.el.set_end_child(inv.el);
801                   _this.inspectorcontainer = inv;
802                   
803                  this.el = null;         
804                  var nv =new Xcls_viewcontainer(_this);
805                 // nv.ref();
806                  _this.viewbox.el.append(nv.el);
807                      
808                      _this.viewcontainer = nv;
809                  inv.el.show();
810                  nv.el.show();
811                      //while(Gtk.events_pending ()) Gtk.main_iteration ();
812                      //_this.view.renderJS(true); 
813                  _this.view.refreshRequired  = true;
814                  
815                  */
816             }
817             public void runRefresh () 
818             {
819                 // this is run every 2 seconds from the init..
820             
821               
822                 
823                 if (!this.refreshRequired) {
824                    // print("no refresh required");
825                     return;
826                 }
827             
828                 if (this.lastRedraw != null) {
829                    // do not redraw if last redraw was less that 5 seconds ago.
830                    if ((int64)(new DateTime.now_local()).difference(this.lastRedraw) < 5000 ) {
831                         return;
832                     }
833                 }
834                 
835                 if (_this.file == null) {
836                     return;
837                 }
838                 
839                 
840                  this.refreshRequired = false;
841                //  print("HTML RENDERING");
842                  
843                  
844                  //this.get('/BottomPane').el.show();
845                  //this.get('/BottomPane').el.set_current_page(2);// webkit inspector
846                 _this.file.webkit_page_id  = this.el.get_page_id();
847                 
848                 var js = _this.file.toSourcePreview();
849             
850                 if (js.length < 1) {
851                     print("no data");
852                     return;
853                 }
854             //    var  data = js[0];
855                 this.redraws++;
856               
857                 var project = (Project.Roo) _this.file.project;  
858             
859                  //print (project.fn);
860                  // set it to non-empty.
861                  
862             //     runhtml = runhtml.length ?  runhtml : '<script type="text/javascript"></script>'; 
863             
864             
865             //   this.runhtml  = this.runhtml || '';
866              
867              
868                 // then we need to reload the browser using
869                 // load_html_string..
870             
871                 // then trigger a redraw once it's loaded..
872                 this.pendingRedraw = true;
873             
874                 var runhtml = "<script type=\"text/javascript\">\n" ;
875                 string builderhtml;
876                 
877                 try {
878                     GLib.FileUtils.get_contents(BuilderApplication.configDirectory() + "/resources/roo.builder.js", out builderhtml);
879                 } catch (Error e) {
880                     builderhtml = "";
881                 }
882             
883                 runhtml += builderhtml + "\n";
884                 runhtml += "</script>\n" ;
885             
886                 // fix to make sure they are the same..
887                 this.runhtml = project.runhtml;
888                 // need to modify paths
889             
890                 string inhtml;
891                 var base_template = project.base_template;
892                 
893                 if (base_template.length > 0 && !FileUtils.test(
894                     BuilderApplication.configDirectory() + "/resources/" +  base_template, FileTest.EXISTS)  
895                     ) {
896                        print("invalid base_template name - using default:  %s\n", base_template);
897                        base_template = "";
898                 
899                 }
900                 try {
901                     GLib.FileUtils.get_contents(
902                         BuilderApplication.configDirectory() + "/resources/" + 
903                             (base_template.length > 0 ? base_template :  "roo.builder.html")
904                             , out inhtml);
905                 
906                 } catch (Error e) {
907                     inhtml = "";
908                 }    
909                 this.renderedData = js;
910             
911             
912                 string js_src = js + "
913             Roo.onReady(function() {
914             if (" + _this.file.name +".show) {
915                         " + _this.file.name +".show({});
916                         (function() {  
917                                 Builder.saveHTML.defer(100, Builder);
918                         }).defer(100);
919             }
920             Roo.XComponent.build();
921             });\n";
922                 
923                // print("render js: " + js);
924                 //if (!this.ready) {
925               //      console.log('not loaded yet');
926                 //}
927                 this.lastRedraw = new DateTime.now_local();
928             
929             
930                 //this.runjs = js_src;
931                 var fc =    FakeServerCache.factory_with_data(js_src);
932                 this.runjs = fc.fname;
933                 
934                     var html = inhtml.replace("</head>", runhtml + this.runhtml + 
935                         "<script type=\"text/javascript\" src=\"xhttp://localhost" + fc.fname + "\"></script>" +   
936                           //  "<script type=\"text/javascript\">\n" +
937                           //  js_src + "\n" + 
938                           //  "</script>" + 
939                                     
940                     "</head>");
941                     //print("LOAD HTML " + html);
942                     
943                      var rootURL = project.rootURL;
944                
945                     
946                     
947                     this.el.load_html( html , 
948                         //fixme - should be a config option!
949                         (rootURL.length > 0 ? rootURL : "xhttp://localhost/roobuilder/")
950                     );
951                       this.initInspector();   
952                 // force the inspector...        
953                    //   this.initInspector();
954                     
955                     // - no need for this, the builder javascript will call it when build is complete
956                     //GLib.Timeout.add_seconds(1, () => {
957                     //    this.el.run_javascript("Builder.saveHTML()",null);
958                     //    return false;
959                     //});
960             //     print( "before render" +    this.lastRedraw);
961             //    print( "after render" +    (new Date()));
962                 
963             }
964         }
965
966
967         public class Xcls_inspectorcontainer : Object
968         {
969             public Gtk.Box el;
970             private Xcls_WindowRooView  _this;
971
972
973                 // my vars (def)
974
975             // ctor
976             public Xcls_inspectorcontainer(Xcls_WindowRooView _owner )
977             {
978                 _this = _owner;
979                 _this.inspectorcontainer = this;
980                 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
981
982                 // my vars (dec)
983
984                 // set gobject values
985                 this.el.vexpand = true;
986             }
987
988             // user defined functions
989         }
990
991
992         public class Xcls_Box13 : Object
993         {
994             public Gtk.Box el;
995             private Xcls_WindowRooView  _this;
996
997
998                 // my vars (def)
999
1000             // ctor
1001             public Xcls_Box13(Xcls_WindowRooView _owner )
1002             {
1003                 _this = _owner;
1004                 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
1005
1006                 // my vars (dec)
1007
1008                 // set gobject values
1009                 this.el.vexpand = true;
1010                 new Xcls_sourceviewscroll( _this );
1011                 this.el.append( _this.sourceviewscroll.el );
1012                 var child_2 = new Xcls_Box19( _this );
1013                 child_2.ref();
1014                 this.el.append( child_2.el );
1015             }
1016
1017             // user defined functions
1018         }
1019         public class Xcls_sourceviewscroll : Object
1020         {
1021             public Gtk.ScrolledWindow el;
1022             private Xcls_WindowRooView  _this;
1023
1024
1025                 // my vars (def)
1026
1027             // ctor
1028             public Xcls_sourceviewscroll(Xcls_WindowRooView _owner )
1029             {
1030                 _this = _owner;
1031                 _this.sourceviewscroll = this;
1032                 this.el = new Gtk.ScrolledWindow();
1033
1034                 // my vars (dec)
1035
1036                 // set gobject values
1037                 this.el.vexpand = true;
1038                 new Xcls_sourceview( _this );
1039                 this.el.set_child ( _this.sourceview.el  );
1040             }
1041
1042             // user defined functions
1043         }
1044         public class Xcls_sourceview : Object
1045         {
1046             public GtkSource.View el;
1047             private Xcls_WindowRooView  _this;
1048
1049
1050                 // my vars (def)
1051             public int editable_start_pos;
1052             public bool loading;
1053             public bool button_is_pressed;
1054             public string prop_selected;
1055             public bool key_is_pressed;
1056             public Gtk.CssProvider css;
1057             public JsRender.Node? node_selected;
1058
1059             // ctor
1060             public Xcls_sourceview(Xcls_WindowRooView _owner )
1061             {
1062                 _this = _owner;
1063                 _this.sourceview = this;
1064                 this.el = new GtkSource.View();
1065
1066                 // my vars (dec)
1067                 this.editable_start_pos = -1;
1068                 this.loading = true;
1069                 this.button_is_pressed = false;
1070                 this.prop_selected = "";
1071                 this.key_is_pressed = false;
1072                 this.node_selected = null;
1073
1074                 // set gobject values
1075                 this.el.name = "roo-view";
1076                 this.el.editable = false;
1077                 this.el.show_line_marks = true;
1078                 this.el.show_line_numbers = true;
1079                 new Xcls_buffer( _this );
1080                 this.el.set_buffer ( _this.buffer.el  );
1081                 var child_2 = new Xcls_EventControllerKey17( _this );
1082                 child_2.ref();
1083                 this.el.add_controller ( child_2.el  );
1084                 var child_3 = new Xcls_GestureClick18( _this );
1085                 child_3.ref();
1086                 this.el.add_controller(  child_3.el );
1087
1088                 // init method
1089
1090                 {
1091                    
1092                    this.css = new Gtk.CssProvider();
1093                          
1094                         this.css.load_from_string(
1095                                 "#roo-view { 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                          
1105                     
1106                     this.loading = true;
1107                     //var buf = this.el.get_buffer();
1108                     //buf.notify.connect(this.onCursorChanged);
1109                   
1110                   
1111                     var attrs = new GtkSource.MarkAttributes();
1112                     var  pink =   Gdk.RGBA();
1113                     pink.parse ( "pink");
1114                     attrs.set_background ( pink);
1115                     attrs.set_icon_name ( "process-stop");    
1116                     attrs.query_tooltip_text.connect(( mark) => {
1117                         //print("tooltip query? %s\n", mark.name);
1118                         return mark.name;
1119                     });
1120                     
1121                     this.el.set_mark_attributes ("ERR", attrs, 1);
1122                     
1123                      var wattrs = new GtkSource.MarkAttributes();
1124                     var  blue =   Gdk.RGBA();
1125                     blue.parse ( "#ABF4EB");
1126                     wattrs.set_background ( blue);
1127                     wattrs.set_icon_name ( "process-stop");    
1128                     wattrs.query_tooltip_text.connect(( mark) => {
1129                         //print("tooltip query? %s\n", mark.name);
1130                         return mark.name;
1131                     });
1132                     
1133                     this.el.set_mark_attributes ("WARN", wattrs, 1);
1134                     
1135                  
1136                     
1137                      var dattrs = new GtkSource.MarkAttributes();
1138                     var  purple =   Gdk.RGBA();
1139                     purple.parse ( "#EEA9FF");
1140                     dattrs.set_background ( purple);
1141                     dattrs.set_icon_name ( "process-stop");    
1142                     dattrs.query_tooltip_text.connect(( mark) => {
1143                         //print("tooltip query? %s\n", mark.name);
1144                         return mark.name;
1145                     });
1146                     
1147                     this.el.set_mark_attributes ("DEPR", dattrs, 1);
1148                     
1149                     
1150                     var gattrs = new GtkSource.MarkAttributes();
1151                     var  grey =   Gdk.RGBA();
1152                     grey.parse ( "#ccc");
1153                     gattrs.set_background ( grey);
1154                  
1155                     
1156                     this.el.set_mark_attributes ("grey", gattrs, 1);
1157                     
1158                     
1159                     
1160                     
1161                     
1162                     
1163                 }
1164
1165                 //listeners
1166                 this.el.query_tooltip.connect( (x, y, keyboard_tooltip, tooltip) => {
1167                         
1168                         //GLib.debug("query tooltip");
1169                         Gtk.TextIter iter;
1170                         int trailing;
1171                         
1172                         var yoff = (int) _this.sourceviewscroll.el.vadjustment.value;
1173                         
1174                         this.el.get_iter_at_position (out iter, out trailing,  x,  y + yoff);
1175                          
1176                         var l = iter.get_line();
1177                         //GLib.debug("query tooltip line %d", (int) l);
1178                         var marks = _this.buffer.el.get_source_marks_at_line(l, null);
1179                         //GLib.debug("query tooltip line marks %d", (int) marks.length());
1180                         var str = "";
1181                         marks.@foreach((m) => { 
1182                                 //GLib.debug("got mark %s", m.name);
1183                                 str += (str.length > 0 ? "\n" : "") + m.name;
1184                         });
1185                         // true if there is a mark..
1186                         if (str.length > 0 ) {
1187                                         tooltip.set_text( str);
1188                         }
1189                         return str.length > 0 ? true : false;
1190                 
1191                 });
1192             }
1193
1194             // user defined functions
1195             public void loadFile ( ) {
1196                 this.loading = true;
1197                 
1198                 
1199                 // get the cursor and scroll position....
1200                 var buf = this.el.get_buffer();
1201                 var cpos = buf.cursor_position;
1202                 
1203                print("BEFORE LOAD cursor = %d\n", cpos);
1204                
1205                 var vadj_pos = this.el.get_vadjustment().get_value();
1206                
1207                 
1208              
1209                 buf.set_text("",0);
1210                 var sbuf = (GtkSource.Buffer) buf;
1211             
1212                 
1213             
1214                 if (_this.file == null || _this.file.xtype != "Roo") {
1215                     print("xtype != Roo");
1216                     this.loading = false;
1217                     return;
1218                 }
1219                 
1220                 // get the string from the rendered tree...
1221                  
1222                  var str = _this.file.toSource();
1223                  
1224             //    print("setting str %d\n", str.length);
1225                 buf.set_text(str, str.length);
1226                 var lm = GtkSource.LanguageManager.get_default();
1227                  
1228                 //?? is javascript going to work as js?
1229                 
1230                 ((GtkSource.Buffer)(buf)) .set_language(lm.get_language(_this.file.language));
1231               
1232                 
1233                 _this.main_window.windowstate.updateErrorMarksAll();
1234                 
1235                 // what does this do?
1236                  GLib.Timeout.add(500, () => {
1237             
1238                     print("RESORTING cursor to = %d\n", cpos);
1239                         Gtk.TextIter cpos_iter;
1240                         buf.get_iter_at_offset(out cpos_iter, cpos);
1241                         buf.place_cursor(cpos_iter); 
1242                         
1243                         this.el.get_vadjustment().set_value(vadj_pos);;
1244                         
1245             
1246                         this.onCursorChanged();
1247                         
1248                         
1249                         //_this.buffer.checkSyntax();
1250                         return false;
1251                 });
1252                         
1253                 this.loading = false; 
1254                 _this.buffer.dirty = false;
1255             }
1256             public void onCursorChanged (/*ParamSpec ps*/) {
1257             
1258                         if (!this.key_is_pressed && !this.button_is_pressed) {
1259                                 return;
1260                         }
1261             
1262                    if (this.loading) {
1263                         return;
1264                     }
1265                    // if (ps.name != "cursor-position") {
1266                    //     return;
1267                    // }
1268             
1269                     var buf = this.el.get_buffer();
1270                     //print("cursor changed : %d\n", buf.cursor_position);
1271                     Gtk.TextIter cpos;
1272                     buf.get_iter_at_offset(out cpos, buf.cursor_position);
1273                     
1274                     var ln = cpos.get_line();
1275                     
1276                     
1277                     // --- select node at line....
1278                     
1279                     var node = _this.file.lineToNode(ln+1);
1280              
1281                     if (node == null) {
1282                         print("can not find node\n");
1283                         return;
1284                     }
1285                     var prop = node.lineToProp(ln+1);
1286                     print("prop : %s", prop == null ? "???" : prop.name);
1287                     
1288                     
1289                     // ---------- this selects the tree's node...
1290                     
1291                     var ltree = _this.main_window.windowstate.left_tree;
1292                      ltree.model.selectNode(node);
1293                     
1294                        
1295                     //print("changing cursor on tree..\n");
1296                    
1297             
1298                     
1299                     // let's try allowing editing on the methods.
1300                     // a little klunky at present..
1301                     this.prop_selected = "";
1302                     /*
1303                     if (prop != null) {
1304                                 //see if we can find it..
1305                                 var kv = prop.split(":");
1306                                 if (kv[0] == "p") {
1307                                 
1308                                 //var k = prop.get_key(kv[1]);
1309                                 // fixme -- need to determine if it's an editable property...
1310                                 this.prop_selected = prop;
1311                                 
1312                                 } else if (kv[0] == "l") {
1313                                          this.prop_selected = prop;
1314                                         
1315                                 }
1316                     }
1317                    */
1318                        // ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false); 
1319                        //this.nodeSelected(node,false);
1320                         
1321                         // scrolling is disabled... as node selection calls scroll 10ms after it changes.
1322                        
1323                     
1324                     // highlight the node..
1325             }
1326             public void nodeSelected (JsRender.Node? sel, bool scroll ) {
1327               
1328                 
1329                 
1330                 // this is connected in widnowstate
1331             
1332             
1333                 // not sure why....   
1334               //  while(Gtk.events_pending()) {
1335                //     Gtk.main_iteration();
1336              //   }
1337                 
1338                 this.node_selected = sel;
1339                 
1340                // this.updateGreySelection(scroll);
1341                 
1342                 
1343                 
1344             }
1345             public void updateGreySelection (bool scroll) { 
1346                 var sel = this.node_selected;
1347                 print("node selected\n");
1348                 var buf = this.el.get_buffer();
1349                 var sbuf = (GtkSource.Buffer) buf;
1350             
1351                
1352                this.clearGreySelection();
1353                
1354                
1355                
1356                  if (sel == null) {
1357                      print("no selected node\n");
1358                     // no highlighting..
1359                     return;
1360                 }
1361                 
1362                 print("highlight region %d to %d\n", sel.line_start,sel.line_end);
1363                 Gtk.TextIter iter;   
1364                 sbuf.get_iter_at_line(out iter,  sel.line_start);
1365                 
1366                 
1367                 Gtk.TextIter cur_iter;
1368                 sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position);
1369                
1370                 var cursor_at_line = cur_iter.get_line();
1371                 
1372                 
1373                 //var cur_line = cur_iter.get_line();
1374                 //if (cur_line > sel.line_start && cur_line < sel.line_end) {
1375                 
1376                 //} else {
1377                 if (scroll) {
1378                         print("scrolling to node -- should occur on node picking.\n");
1379                         this.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);
1380                 }
1381                 
1382                 var start_line = sel.line_start;
1383                 var end_line = sel.line_end;
1384                 
1385                 
1386                 this.el.editable = false;
1387                 
1388                 //var colon_pos = 0;
1389                 
1390                 this.editable_start_pos = -1;
1391                 
1392                 // now if we have selected a property...
1393                 if (this.prop_selected.length> 0 ) {
1394             
1395                         int nstart, nend;
1396                         if (sel.getPropertyRange(this.prop_selected, out nstart, out nend) && nend > nstart) {
1397                                 start_line = nstart;
1398                                 end_line = nend;
1399                                 // this.el.editable = true; << cant do this!!?
1400                                 print("start line = %d, end line = %d\n", start_line, end_line);
1401                                 
1402                                         // see if we are 'right of ':'
1403                                         // get an iter for the start of the line.
1404                                 Gtk.TextIter start_first_line_iter,end_first_line_iter;
1405                                 this.el.buffer.get_iter_at_line(out start_first_line_iter, start_line -1);
1406                                 this.el.buffer.get_iter_at_line(out end_first_line_iter, start_line -1);
1407                                  
1408                                 
1409                                 
1410                                 
1411                                 if (end_first_line_iter.forward_to_line_end()) {
1412                                         var first_line  = this.el.buffer.get_text(start_first_line_iter, end_first_line_iter, false);
1413                                         
1414                                         print("first line = %s\n", first_line);
1415                                         if (first_line.contains(":")) {
1416                                                 this.editable_start_pos = start_first_line_iter.get_offset() + first_line.index_of(":") + 1;
1417                                                 print("colon_pos  = %d\n", this.editable_start_pos);
1418                                         }
1419                                         
1420             
1421                                         //Gtk.TextIter colon_iter;
1422                                         //sbuf.get_iter_at_offset (out colon_iter, colon_pos);
1423                                         //sbuf.create_source_mark(null, "active_text", colon_iter);
1424                                 }
1425                                 
1426                                 
1427                                 
1428                                 //print("is cursor at line? %d ?= %d\n", start_line -1 , cursor_at_line);
1429                                 //if (start_line - 1 == cursor_at_line) {
1430                                 // should be ok - current_posssion can not be less than '-1'...
1431                                 if (sbuf.cursor_position < this.editable_start_pos) {
1432                                 
1433                                         print("cursor is before start pos.. - turn off editable...\n");
1434                                         //var before_cursor_string = this.el.buffer.get_text(start_line_iter, cur_iter, false);
1435                                         //print("before cursor string =  %s\n", before_cursor_string);
1436                                         //if (!before_cursor_string.contains(":")) {
1437                                                 this.el.editable = false;
1438                                         //}
1439                                         
1440                                 }
1441                                  
1442                                  
1443             
1444                                  
1445                         }
1446                         print("propSelected = %s range  %d -> %d\n", this.prop_selected, start_line, end_line);         
1447                         
1448                         
1449                 }
1450                 
1451                 print("checking selection\n");
1452                 
1453                 
1454                 // check selection - if it's out of 'bounds'
1455                 if (this.el.editable && sbuf.get_has_selection()) {
1456                         Gtk.TextIter sel_start_iter, sel_end_iter;
1457                         sbuf.get_selection_bounds(out sel_start_iter, out sel_end_iter);
1458                         
1459                         if (sel_start_iter.get_line() < start_line || sel_end_iter.get_line() > end_line ||
1460                                 sel_start_iter.get_line() > end_line   || sel_end_iter.get_line() < start_line                  ) {
1461                                 // save?
1462                                 this.el.editable = false;
1463                         }
1464                         if (this.editable_start_pos > 0 &&
1465                                 (sel_start_iter.get_offset() < this.editable_start_pos || sel_end_iter.get_offset() < this.editable_start_pos)
1466                                 
1467                         ) {
1468                                 this.el.editable = false;
1469                         }
1470                         
1471                          
1472                 
1473                 }
1474                 
1475                 
1476                 
1477                 
1478                 for (var i = 0; i < buf.get_line_count();i++) {
1479                     if (i < (start_line -1) || i > (end_line -1)) {
1480                        
1481                         sbuf.get_iter_at_line(out iter, i);
1482                         sbuf.create_source_mark(null, "grey", iter);
1483                         
1484                     }
1485                 
1486                 }
1487                 if (scroll && (cursor_at_line > end_line || cursor_at_line < start_line)) {
1488                     Gtk.TextIter cpos_iter;
1489                         buf.get_iter_at_line(out cpos_iter, start_line);
1490                         
1491                         buf.place_cursor(cpos_iter); 
1492                 }
1493             
1494             
1495             }
1496             public void highlightErrorsJson (string type, Json.Object obj) {
1497                    // this is a hook for the vala code - it has no value in javascript 
1498                    // as we only have one error ususally....
1499                     return  ;
1500                 
1501              
1502             
1503             
1504             }
1505             public void clearGreySelection () {
1506              // clear all the marks..
1507                 var sbuf = (GtkSource.Buffer)this.el.buffer;
1508                 
1509                 Gtk.TextIter start;
1510                 Gtk.TextIter end;     
1511                     
1512                 sbuf.get_bounds (out start, out end);
1513                 sbuf.remove_source_marks (start, end, "grey");
1514                 
1515                 
1516             }
1517             public string toString () {
1518                Gtk.TextIter s;
1519                 Gtk.TextIter e;
1520                 this.el.get_buffer().get_start_iter(out s);
1521                 this.el.get_buffer().get_end_iter(out e);
1522                 var ret = this.el.get_buffer().get_text(s,e,true);
1523                 //print("TO STRING? " + ret);
1524                 return ret;
1525             }
1526         }
1527         public class Xcls_buffer : Object
1528         {
1529             public GtkSource.Buffer el;
1530             private Xcls_WindowRooView  _this;
1531
1532
1533                 // my vars (def)
1534             public int error_line;
1535             public bool dirty;
1536
1537             // ctor
1538             public Xcls_buffer(Xcls_WindowRooView _owner )
1539             {
1540                 _this = _owner;
1541                 _this.buffer = this;
1542                 this.el = new GtkSource.Buffer( null );
1543
1544                 // my vars (dec)
1545                 this.error_line = -1;
1546                 this.dirty = false;
1547
1548                 // set gobject values
1549
1550                 //listeners
1551                 this.el.changed.connect( () => {
1552                   
1553                     // check syntax??
1554                     // ??needed..??
1555                    // _this.save_button.el.sensitive = true;
1556                     ///?? has changed occured during loading?
1557                     
1558                     // only trigger this if 
1559                     
1560                     
1561                     
1562                     
1563                     if (_this.sourceview.loading) {
1564                                 return;
1565                         }
1566                         
1567                 
1568                         
1569                     print("- PREVIEW EDITOR CHANGED--");
1570                 
1571                     this.dirty = true;  
1572                    // this.checkSyntax(); // this calls backs and highlights errors.. in theory...  
1573                 
1574                 
1575                 
1576                         if (!_this.sourceview.button_is_pressed && !_this.sourceview.key_is_pressed) {
1577                                 print("button or key not pressed to generate change?!\n");
1578                                 return;
1579                         }
1580                                 
1581                     
1582                         // what are we editing??
1583                         if (null == _this.sourceview.node_selected || _this.sourceview.prop_selected.length  < 1) {
1584                                 return;
1585                         }
1586                         
1587                         // find the colon on the first line...
1588                         
1589                         if (_this.sourceview.editable_start_pos > -1) {
1590                                 
1591                                 var buf = (GtkSource.Buffer)_this.sourceview.el.get_buffer();
1592                                 
1593                         //print("cursor changed : %d\n", buf.cursor_position);
1594                         Gtk.TextIter spos,epos;
1595                         buf.get_iter_at_offset(out spos, _this.sourceview.editable_start_pos);
1596                         buf.get_iter_at_offset(out epos, _this.sourceview.editable_start_pos); // initialize epos..
1597                         
1598                         var gotit= false;
1599                         var line = spos.get_line();
1600                         var endline = buf.get_line_count();
1601                         while (line < endline) {
1602                                 line++;
1603                                 buf.get_iter_at_line(out epos, line);
1604                                 if (buf.get_source_marks_at_line(line, "grey").length() > 0) {
1605                                         buf.get_iter_at_line(out epos, line);                   
1606                                         gotit=true;
1607                                         break;
1608                                 }
1609                                 }
1610                         
1611                                 if (gotit) {
1612                                         print("End Offset = %d/%d\n", epos.get_line(), epos.get_offset());
1613                                         // get the pos...
1614                                         // in theory the last char will be '}' or '},' .. or ','
1615                                         // we should chop the ',' of the end...
1616                                         var str = buf.get_text(spos, epos, false);
1617                                         print("got string\n%s\n", str);
1618                                 
1619                                 }
1620                         }
1621                     return ;
1622                 });
1623             }
1624
1625             // user defined functions
1626             public bool highlightErrors ( Gee.HashMap<int,string> validate_res) {
1627                      
1628                 this.error_line = validate_res.size;
1629                 
1630                 if (this.error_line < 1) {
1631                       return true;
1632                 }
1633                 var tlines = this.el.get_line_count ();
1634                 Gtk.TextIter iter;
1635                 var valiter = validate_res.map_iterator();
1636                 while (valiter.next()) {
1637                 
1638             //        print("get inter\n");
1639                     var eline = valiter.get_key();
1640                     if (eline > tlines) {
1641                         continue;
1642                     }
1643                     this.el.get_iter_at_line( out iter, eline);
1644                     //print("mark line\n");
1645                     this.el.create_source_mark(valiter.get_value(), "ERR", iter);
1646                 }   
1647                 return false;
1648             }
1649             public string toString () {
1650                 
1651                 Gtk.TextIter s;
1652                 Gtk.TextIter e;
1653                 this.el.get_start_iter(out s);
1654                 this.el.get_end_iter(out e);
1655                 var ret = this.el.get_text(s,e,true);
1656                 //print("TO STRING? " + ret);
1657                 return ret;
1658             }
1659         }
1660
1661         public class Xcls_EventControllerKey17 : Object
1662         {
1663             public Gtk.EventControllerKey el;
1664             private Xcls_WindowRooView  _this;
1665
1666
1667                 // my vars (def)
1668
1669             // ctor
1670             public Xcls_EventControllerKey17(Xcls_WindowRooView _owner )
1671             {
1672                 _this = _owner;
1673                 this.el = new Gtk.EventControllerKey();
1674
1675                 // my vars (dec)
1676
1677                 // set gobject values
1678
1679                 //listeners
1680                 this.el.key_pressed.connect( (keyval, keycode, state) => {
1681                 
1682                  
1683                     
1684                         if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1685                             GLib.debug("SAVE: ctrl-g  pressed");
1686                                 _this.forwardSearch(true);
1687                             return false;
1688                         }
1689                         if (keyval == Gdk.Key.f && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1690                             GLib.debug("SAVE: ctrl-f  pressed");
1691                                 _this.search_entry.el.grab_focus();
1692                             return false ;
1693                         }
1694                     
1695                         //this.button_is_pressed = true;
1696                         //return false;
1697                    // print(event.key.keyval)
1698                     
1699                     return false;
1700                  
1701                  
1702                 });
1703             }
1704
1705             // user defined functions
1706         }
1707
1708         public class Xcls_GestureClick18 : Object
1709         {
1710             public Gtk.GestureClick el;
1711             private Xcls_WindowRooView  _this;
1712
1713
1714                 // my vars (def)
1715
1716             // ctor
1717             public Xcls_GestureClick18(Xcls_WindowRooView _owner )
1718             {
1719                 _this = _owner;
1720                 this.el = new Gtk.GestureClick();
1721
1722                 // my vars (dec)
1723
1724                 // set gobject values
1725
1726                 //listeners
1727                 this.el.released.connect( (n_press, x, y) => {
1728                 
1729                         print("BUTTON RELEASE EVENT\n");
1730                         _this.sourceview.onCursorChanged();
1731                         //this.button_is_pressed = false;
1732                          
1733                 });
1734             }
1735
1736             // user defined functions
1737         }
1738
1739
1740
1741         public class Xcls_Box19 : Object
1742         {
1743             public Gtk.Box el;
1744             private Xcls_WindowRooView  _this;
1745
1746
1747                 // my vars (def)
1748
1749             // ctor
1750             public Xcls_Box19(Xcls_WindowRooView _owner )
1751             {
1752                 _this = _owner;
1753                 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
1754
1755                 // my vars (dec)
1756
1757                 // set gobject values
1758                 this.el.homogeneous = false;
1759                 this.el.vexpand = false;
1760                 new Xcls_search_entry( _this );
1761                 this.el.append( _this.search_entry.el );
1762                 new Xcls_search_results( _this );
1763                 this.el.append( _this.search_results.el );
1764                 new Xcls_nextBtn( _this );
1765                 this.el.append( _this.nextBtn.el );
1766                 new Xcls_backBtn( _this );
1767                 this.el.append( _this.backBtn.el );
1768                 var child_5 = new Xcls_MenuButton25( _this );
1769                 child_5.ref();
1770                 this.el.append( child_5.el );
1771             }
1772
1773             // user defined functions
1774         }
1775         public class Xcls_search_entry : Object
1776         {
1777             public Gtk.SearchEntry el;
1778             private Xcls_WindowRooView  _this;
1779
1780
1781                 // my vars (def)
1782             public Gtk.CssProvider css;
1783
1784             // ctor
1785             public Xcls_search_entry(Xcls_WindowRooView _owner )
1786             {
1787                 _this = _owner;
1788                 _this.search_entry = this;
1789                 this.el = new Gtk.SearchEntry();
1790
1791                 // my vars (dec)
1792
1793                 // set gobject values
1794                 this.el.name = "roo-search-entry";
1795                 this.el.hexpand = true;
1796                 this.el.placeholder_text = "Press enter to search";
1797                 var child_1 = new Xcls_EventControllerKey21( _this );
1798                 child_1.ref();
1799                 this.el.add_controller(  child_1.el );
1800
1801                 // init method
1802
1803                 this.css = new Gtk.CssProvider();
1804                  
1805                 this.css.load_from_string(
1806                         "#roo-search-entry { background-color: #ccc; }"
1807                 );
1808                  
1809                 Gtk.StyleContext.add_provider_for_display(
1810                         this.el.get_display(),
1811                         this.css,
1812                         Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
1813                 );
1814
1815                 //listeners
1816                 this.el.search_changed.connect( ( ) => {
1817                 
1818                 _this.search(_this.search_entry.el.text);
1819                          _this.search_results.updateResults();
1820                 
1821                         GLib.Timeout.add_seconds(1,() => {
1822                                  _this.search_results.updateResults();
1823                                  return false;
1824                          });
1825                 });
1826             }
1827
1828             // user defined functions
1829             public void forwardSearch (bool change_focus) {
1830             
1831             
1832                 _this.forwardSearch(change_focus);
1833             
1834             /*
1835             
1836                 switch(_this.windowstate.state) {
1837                         case WindowState.State.CODEONLY:
1838                         //case WindowState.State.CODE:
1839                                 // search the code being edited..
1840                                 _this.windowstate.code_editor_tab.forwardSearch(change_focus);
1841                                  
1842                                 break;
1843                         case WindowState.State.PREVIEW:
1844                                 if (_this.windowstate.file.xtype == "Gtk") {
1845                                         _this.windowstate.window_gladeview.forwardSearch(change_focus);
1846                                 } else { 
1847                                          _this.windowstate.window_rooview.forwardSearch(change_focus);
1848                                 }
1849                         
1850                                 break;
1851                 }
1852                 */
1853                 
1854             }
1855         }
1856         public class Xcls_EventControllerKey21 : Object
1857         {
1858             public Gtk.EventControllerKey el;
1859             private Xcls_WindowRooView  _this;
1860
1861
1862                 // my vars (def)
1863
1864             // ctor
1865             public Xcls_EventControllerKey21(Xcls_WindowRooView _owner )
1866             {
1867                 _this = _owner;
1868                 this.el = new Gtk.EventControllerKey();
1869
1870                 // my vars (dec)
1871
1872                 // set gobject values
1873
1874                 //listeners
1875                 this.el.key_pressed.connect( (keyval, keycode, state) => {
1876                 
1877                         if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1878                             GLib.debug("SAVE: ctrl-g  pressed");
1879                                 _this.forwardSearch(true);
1880                             return true;
1881                         }
1882                     
1883                   
1884                         if (keyval == Gdk.Key.Return) {
1885                                 _this.forwardSearch(true);
1886                                 
1887                                 
1888                             return true;
1889                 
1890                         }    
1891                    // print(event.key.keyval)
1892                    
1893                     return false;
1894                 });
1895             }
1896
1897             // user defined functions
1898         }
1899
1900
1901         public class Xcls_search_results : Object
1902         {
1903             public Gtk.Label el;
1904             private Xcls_WindowRooView  _this;
1905
1906
1907                 // my vars (def)
1908
1909             // ctor
1910             public Xcls_search_results(Xcls_WindowRooView _owner )
1911             {
1912                 _this = _owner;
1913                 _this.search_results = this;
1914                 this.el = new Gtk.Label( "No Results" );
1915
1916                 // my vars (dec)
1917
1918                 // set gobject values
1919                 this.el.margin_end = 4;
1920                 this.el.margin_start = 4;
1921             }
1922
1923             // user defined functions
1924             public void updateResults () {
1925                 this.el.visible = true;
1926                 
1927                 var res = _this.searchcontext.get_occurrences_count();
1928                 if (res < 0) {
1929                         _this.search_results.el.label = "??? Matches";          
1930                         return;
1931                 }
1932             
1933                 _this.nextBtn.el.sensitive = false;
1934                 _this.backBtn.el.sensitive = false;     
1935             
1936                 if (res > 0) {
1937                         _this.search_results.el.label = "%d Matches".printf(res);
1938                         _this.nextBtn.el.sensitive = true;
1939                         _this.backBtn.el.sensitive = true;
1940                         return;
1941                 } 
1942                 _this.search_results.el.label = "No Matches";
1943                 
1944             }
1945         }
1946
1947         public class Xcls_nextBtn : Object
1948         {
1949             public Gtk.Button el;
1950             private Xcls_WindowRooView  _this;
1951
1952
1953                 // my vars (def)
1954             public bool always_show_image;
1955
1956             // ctor
1957             public Xcls_nextBtn(Xcls_WindowRooView _owner )
1958             {
1959                 _this = _owner;
1960                 _this.nextBtn = this;
1961                 this.el = new Gtk.Button();
1962
1963                 // my vars (dec)
1964                 this.always_show_image = true;
1965
1966                 // set gobject values
1967                 this.el.icon_name = "go-down";
1968                 this.el.sensitive = false;
1969
1970                 //listeners
1971                 this.el.clicked.connect( (event) => {
1972                 
1973                         _this.forwardSearch(true);
1974                          
1975                 });
1976             }
1977
1978             // user defined functions
1979         }
1980
1981         public class Xcls_backBtn : Object
1982         {
1983             public Gtk.Button el;
1984             private Xcls_WindowRooView  _this;
1985
1986
1987                 // my vars (def)
1988             public bool always_show_image;
1989
1990             // ctor
1991             public Xcls_backBtn(Xcls_WindowRooView _owner )
1992             {
1993                 _this = _owner;
1994                 _this.backBtn = this;
1995                 this.el = new Gtk.Button();
1996
1997                 // my vars (dec)
1998                 this.always_show_image = true;
1999
2000                 // set gobject values
2001                 this.el.icon_name = "go-up";
2002                 this.el.sensitive = false;
2003
2004                 //listeners
2005                 this.el.clicked.connect( (event) => {
2006                 
2007                         _this.backSearch(true);
2008                         
2009                          
2010                 });
2011             }
2012
2013             // user defined functions
2014         }
2015
2016         public class Xcls_MenuButton25 : Object
2017         {
2018             public Gtk.MenuButton el;
2019             private Xcls_WindowRooView  _this;
2020
2021
2022                 // my vars (def)
2023             public bool always_show_image;
2024
2025             // ctor
2026             public Xcls_MenuButton25(Xcls_WindowRooView _owner )
2027             {
2028                 _this = _owner;
2029                 this.el = new Gtk.MenuButton();
2030
2031                 // my vars (dec)
2032                 this.always_show_image = true;
2033
2034                 // set gobject values
2035                 this.el.icon_name = "emblem-system";
2036                 new Xcls_search_settings( _this );
2037                 this.el.popover = _this.search_settings.el;
2038             }
2039
2040             // user defined functions
2041         }
2042         public class Xcls_search_settings : Object
2043         {
2044             public Gtk.Popover el;
2045             private Xcls_WindowRooView  _this;
2046
2047
2048                 // my vars (def)
2049
2050             // ctor
2051             public Xcls_search_settings(Xcls_WindowRooView _owner )
2052             {
2053                 _this = _owner;
2054                 _this.search_settings = this;
2055                 this.el = new Gtk.Popover();
2056
2057                 // my vars (dec)
2058
2059                 // set gobject values
2060                 var child_1 = new Xcls_Box27( _this );
2061                 this.el.child = child_1.el;
2062             }
2063
2064             // user defined functions
2065         }
2066         public class Xcls_Box27 : Object
2067         {
2068             public Gtk.Box el;
2069             private Xcls_WindowRooView  _this;
2070
2071
2072                 // my vars (def)
2073
2074             // ctor
2075             public Xcls_Box27(Xcls_WindowRooView _owner )
2076             {
2077                 _this = _owner;
2078                 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
2079
2080                 // my vars (dec)
2081
2082                 // set gobject values
2083                 new Xcls_case_sensitive( _this );
2084                 this.el.append( _this.case_sensitive.el );
2085                 new Xcls_regex( _this );
2086                 this.el.append( _this.regex.el );
2087                 new Xcls_multiline( _this );
2088                 this.el.append( _this.multiline.el );
2089             }
2090
2091             // user defined functions
2092         }
2093         public class Xcls_case_sensitive : Object
2094         {
2095             public Gtk.CheckButton el;
2096             private Xcls_WindowRooView  _this;
2097
2098
2099                 // my vars (def)
2100
2101             // ctor
2102             public Xcls_case_sensitive(Xcls_WindowRooView _owner )
2103             {
2104                 _this = _owner;
2105                 _this.case_sensitive = this;
2106                 this.el = new Gtk.CheckButton();
2107
2108                 // my vars (dec)
2109
2110                 // set gobject values
2111                 this.el.label = "Case Sensitive";
2112
2113                 // init method
2114
2115                 {
2116                         this.el.show();
2117                 }
2118             }
2119
2120             // user defined functions
2121         }
2122
2123         public class Xcls_regex : Object
2124         {
2125             public Gtk.CheckButton el;
2126             private Xcls_WindowRooView  _this;
2127
2128
2129                 // my vars (def)
2130
2131             // ctor
2132             public Xcls_regex(Xcls_WindowRooView _owner )
2133             {
2134                 _this = _owner;
2135                 _this.regex = this;
2136                 this.el = new Gtk.CheckButton();
2137
2138                 // my vars (dec)
2139
2140                 // set gobject values
2141                 this.el.label = "Regex";
2142
2143                 // init method
2144
2145                 {
2146                         this.el.show();
2147                 }
2148             }
2149
2150             // user defined functions
2151         }
2152
2153         public class Xcls_multiline : Object
2154         {
2155             public Gtk.CheckButton el;
2156             private Xcls_WindowRooView  _this;
2157
2158
2159                 // my vars (def)
2160
2161             // ctor
2162             public Xcls_multiline(Xcls_WindowRooView _owner )
2163             {
2164                 _this = _owner;
2165                 _this.multiline = this;
2166                 this.el = new Gtk.CheckButton();
2167
2168                 // my vars (dec)
2169
2170                 // set gobject values
2171                 this.el.label = "Multi-line (add \\n)";
2172
2173                 // init method
2174
2175                 {
2176                         this.el.show();
2177                 }
2178             }
2179
2180             // user defined functions
2181         }
2182
2183
2184
2185
2186
2187
2188
2189     }