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