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