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