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