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