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