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