b567e929f7cd5df4280e9b27d455ea9cf640100f
[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        // code preview...
260        
261        GLib.Timeout.add(100, () => {
262        
263                 this.notebook.el.set_current_page( 1 );
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                 if (event.keyval == Gdk.Key.f && (event.state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1205                     GLib.debug("SAVE: ctrl-f  pressed");
1206                         _this.search_entry.el.grab_focus();
1207                     return true;
1208                 }
1209                 
1210                 this.button_is_pressed = true;
1211                 return false;
1212             });
1213             this.el.key_release_event.connect( () => { 
1214                 this.key_is_pressed = false;
1215                 return false;
1216             });
1217         }
1218
1219         // user defined functions
1220         public void loadFile ( ) {
1221             this.loading = true;
1222             
1223             
1224             // get the cursor and scroll position....
1225             var buf = this.el.get_buffer();
1226                 var cpos = buf.cursor_position;
1227             
1228            print("BEFORE LOAD cursor = %d\n", cpos);
1229            
1230             var vadj_pos = this.el.get_vadjustment().get_value();
1231            
1232             
1233          
1234             buf.set_text("",0);
1235             var sbuf = (Gtk.SourceBuffer) buf;
1236         
1237             
1238         
1239             if (_this.file == null || _this.file.xtype != "Roo") {
1240                 print("xtype != Roo");
1241                 this.loading = false;
1242                 return;
1243             }
1244             
1245             // get the string from the rendered tree...
1246              
1247              var str = _this.file.toSource();
1248              
1249         //    print("setting str %d\n", str.length);
1250             buf.set_text(str, str.length);
1251             var lm = Gtk.SourceLanguageManager.get_default();
1252              
1253             //?? is javascript going to work as js?
1254             
1255             ((Gtk.SourceBuffer)(buf)) .set_language(lm.get_language(_this.file.language));
1256           
1257             
1258             Gtk.TextIter start;
1259             Gtk.TextIter end;     
1260                 
1261             sbuf.get_bounds (out start, out end);
1262             sbuf.remove_source_marks (start, end, null); // remove all marks..
1263             
1264              GLib.Timeout.add(500, () => {
1265         
1266                 print("RESORTING cursor to = %d\n", cpos);
1267                         Gtk.TextIter cpos_iter;
1268                         buf.get_iter_at_offset(out cpos_iter, cpos);
1269                         buf.place_cursor(cpos_iter); 
1270                         
1271                         this.el.get_vadjustment().set_value(vadj_pos);;
1272                         
1273         
1274                         this.onCursorChanged();
1275                         
1276                         
1277                         _this.buffer.checkSyntax();
1278                         return false;
1279                 });
1280                         
1281             this.loading = false; 
1282             _this.buffer.dirty = false;
1283         }
1284         public void onCursorChanged (/*ParamSpec ps*/) {
1285         
1286                         if (!this.key_is_pressed && !this.button_is_pressed) {
1287                                 return;
1288                         }
1289         
1290                    if (this.loading) {
1291                     return;
1292                 }
1293                // if (ps.name != "cursor-position") {
1294                //     return;
1295                // }
1296         
1297                 var buf = this.el.get_buffer();
1298                 //print("cursor changed : %d\n", buf.cursor_position);
1299                 Gtk.TextIter cpos;
1300                 buf.get_iter_at_offset(out cpos, buf.cursor_position);
1301                 
1302                 var ln = cpos.get_line();
1303                 
1304                 
1305                 // --- select node at line....
1306                 
1307                 var node = _this.file.lineToNode(ln+1);
1308          
1309                 if (node == null) {
1310                     print("can not find node\n");
1311                     return;
1312                 }
1313                 var prop = node.lineToProp(ln+1);
1314                 print("prop : %s", prop == null ? "???" : prop);
1315                 
1316                 
1317                 // ---------- this selects the tree's node...
1318                 
1319                 var ltree = _this.main_window.windowstate.left_tree;
1320                 var tp = ltree.model.treePathFromNode(node);
1321                 print("got tree path %s\n", tp);
1322                 if (tp != "") {
1323                          
1324                        
1325                         //print("changing cursor on tree..\n");
1326                        
1327          
1328                     
1329                     // let's try allowing editing on the methods.
1330                     // a little klunky at present..
1331                     this.prop_selected = "";
1332                     if (prop != null) {
1333                                 //see if we can find it..
1334                                 var kv = prop.split(":");
1335                                 if (kv[0] == "p") {
1336                                 
1337                                         //var k = prop.get_key(kv[1]);
1338                                         // fixme -- need to determine if it's an editable property...
1339                                         this.prop_selected = prop;
1340                                         
1341                                 } else if (kv[0] == "l") {
1342                                          this.prop_selected = prop;
1343                                         
1344                                 }
1345                     }
1346                     ltree.view.setCursor(tp, "editor");
1347                    // ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false); 
1348                    //this.nodeSelected(node,false);
1349                     
1350                     // scrolling is disabled... as node selection calls scroll 10ms after it changes.
1351                      
1352                 }
1353                 
1354                 // highlight the node..
1355         }
1356         public void nodeSelected (JsRender.Node? sel, bool scroll ) {
1357           
1358             
1359                 
1360             // this is connected in widnowstate
1361         
1362         
1363                 // not sure why....   
1364             while(Gtk.events_pending()) {
1365                 Gtk.main_iteration();
1366             }
1367             
1368             this.node_selected = sel;
1369             
1370            // this.updateGreySelection(scroll);
1371             
1372             
1373             
1374         }
1375         public void updateGreySelection (bool scroll) { 
1376                 var sel = this.node_selected;
1377                 print("node selected\n");
1378             var buf = this.el.get_buffer();
1379             var sbuf = (Gtk.SourceBuffer) buf;
1380         
1381            
1382            this.clearGreySelection();
1383            
1384            
1385            
1386              if (sel == null) {
1387                      print("no selected node\n");
1388                 // no highlighting..
1389                 return;
1390             }
1391             
1392             print("highlight region %d to %d\n", sel.line_start,sel.line_end);
1393             Gtk.TextIter iter;   
1394             sbuf.get_iter_at_line(out iter,  sel.line_start);
1395             
1396             
1397             Gtk.TextIter cur_iter;
1398             sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position);
1399            
1400             var cursor_at_line = cur_iter.get_line();
1401             
1402             
1403             //var cur_line = cur_iter.get_line();
1404             //if (cur_line > sel.line_start && cur_line < sel.line_end) {
1405             
1406             //} else {
1407             if (scroll) {
1408                         print("scrolling to node -- should occur on node picking.\n");
1409                 this.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);
1410                 }
1411             
1412             var start_line = sel.line_start;
1413             var end_line = sel.line_end;
1414             
1415             
1416             this.el.editable = false;
1417             
1418             //var colon_pos = 0;
1419             
1420             this.editable_start_pos = -1;
1421             
1422             // now if we have selected a property...
1423             if (this.prop_selected.length> 0 ) {
1424         
1425                         int nstart, nend;
1426                         if (sel.getPropertyRange(this.prop_selected, out nstart, out nend) && nend > nstart) {
1427                                 start_line = nstart;
1428                                 end_line = nend;
1429                                 // this.el.editable = true; << cant do this!!?
1430                                 print("start line = %d, end line = %d\n", start_line, end_line);
1431                                 
1432                                         // see if we are 'right of ':'
1433                                         // get an iter for the start of the line.
1434                                 Gtk.TextIter start_first_line_iter,end_first_line_iter;
1435                                 this.el.buffer.get_iter_at_line(out start_first_line_iter, start_line -1);
1436                                 this.el.buffer.get_iter_at_line(out end_first_line_iter, start_line -1);
1437                                  
1438                                 
1439                                 
1440                                 
1441                                 if (end_first_line_iter.forward_to_line_end()) {
1442                                         var first_line  = this.el.buffer.get_text(start_first_line_iter, end_first_line_iter, false);
1443                                         
1444                                         print("first line = %s\n", first_line);
1445                                         if (first_line.contains(":")) {
1446                                                 this.editable_start_pos = start_first_line_iter.get_offset() + first_line.index_of(":") + 1;
1447                                                 print("colon_pos  = %d\n", this.editable_start_pos);
1448                                         }
1449                                         
1450         
1451                                         //Gtk.TextIter colon_iter;
1452                                         //sbuf.get_iter_at_offset (out colon_iter, colon_pos);
1453                                         //sbuf.create_source_mark(null, "active_text", colon_iter);
1454                                 }
1455                                 
1456                                 
1457                                 
1458                                 //print("is cursor at line? %d ?= %d\n", start_line -1 , cursor_at_line);
1459                                 //if (start_line - 1 == cursor_at_line) {
1460                                 // should be ok - current_posssion can not be less than '-1'...
1461                                 if (sbuf.cursor_position < this.editable_start_pos) {
1462                                 
1463                                         print("cursor is before start pos.. - turn off editable...\n");
1464                                         //var before_cursor_string = this.el.buffer.get_text(start_line_iter, cur_iter, false);
1465                                         //print("before cursor string =  %s\n", before_cursor_string);
1466                                         //if (!before_cursor_string.contains(":")) {
1467                                                 this.el.editable = false;
1468                                         //}
1469                                         
1470                                 }
1471                                  
1472                                  
1473         
1474                                  
1475                         }
1476                         print("propSelected = %s range  %d -> %d\n", this.prop_selected, start_line, end_line);         
1477                         
1478                         
1479             }
1480             
1481                 print("checking selection\n");
1482             
1483             
1484             // check selection - if it's out of 'bounds'
1485             if (this.el.editable && sbuf.get_has_selection()) {
1486                         Gtk.TextIter sel_start_iter, sel_end_iter;
1487                         sbuf.get_selection_bounds(out sel_start_iter, out sel_end_iter);
1488                         
1489                         if (sel_start_iter.get_line() < start_line || sel_end_iter.get_line() > end_line ||
1490                                 sel_start_iter.get_line() > end_line   || sel_end_iter.get_line() < start_line                  ) {
1491                                 // save?
1492                                 this.el.editable = false;
1493                         }
1494                         if (this.editable_start_pos > 0 &&
1495                                 (sel_start_iter.get_offset() < this.editable_start_pos || sel_end_iter.get_offset() < this.editable_start_pos)
1496                                 
1497                         ) {
1498                                 this.el.editable = false;
1499                         }
1500                         
1501                          
1502             
1503             }
1504             
1505             
1506             
1507             
1508             for (var i = 0; i < buf.get_line_count();i++) {
1509                 if (i < (start_line -1) || i > (end_line -1)) {
1510                    
1511                     sbuf.get_iter_at_line(out iter, i);
1512                     sbuf.create_source_mark(null, "grey", iter);
1513                     
1514                 }
1515             
1516             }
1517             if (scroll && (cursor_at_line > end_line || cursor_at_line < start_line)) {
1518                     Gtk.TextIter cpos_iter;
1519                         buf.get_iter_at_line(out cpos_iter, start_line);
1520                         
1521                         buf.place_cursor(cpos_iter); 
1522                 }
1523         
1524         
1525         }
1526         public void highlightErrorsJson (string type, Json.Object obj) {
1527                // this is a hook for the vala code - it has no value in javascript 
1528                // as we only have one error ususally....
1529                 return  ;
1530             
1531          
1532         
1533         
1534         }
1535         public string toString () {
1536            Gtk.TextIter s;
1537             Gtk.TextIter e;
1538             this.el.get_buffer().get_start_iter(out s);
1539             this.el.get_buffer().get_end_iter(out e);
1540             var ret = this.el.get_buffer().get_text(s,e,true);
1541             //print("TO STRING? " + ret);
1542             return ret;
1543         }
1544         public void clearGreySelection () {
1545          // clear all the marks..
1546             var sbuf = (Gtk.SourceBuffer)this.el.buffer;
1547             
1548             Gtk.TextIter start;
1549             Gtk.TextIter end;     
1550                 
1551             sbuf.get_bounds (out start, out end);
1552             sbuf.remove_source_marks (start, end, "grey");
1553             
1554             
1555         }
1556     }
1557     public class Xcls_buffer : Object
1558     {
1559         public Gtk.SourceBuffer el;
1560         private Xcls_WindowRooView  _this;
1561
1562
1563             // my vars (def)
1564         public int error_line;
1565         public bool dirty;
1566
1567         // ctor
1568         public Xcls_buffer(Xcls_WindowRooView _owner )
1569         {
1570             _this = _owner;
1571             _this.buffer = this;
1572             this.el = new Gtk.SourceBuffer( null );
1573
1574             // my vars (dec)
1575             this.error_line = -1;
1576             this.dirty = false;
1577
1578             // set gobject values
1579
1580             //listeners
1581             this.el.changed.connect( () => {
1582              
1583             
1584                 // check syntax??
1585                 // ??needed..??
1586                // _this.save_button.el.sensitive = true;
1587                 ///?? has changed occured during loading?
1588                 
1589                 // only trigger this if 
1590                 
1591                 
1592                 
1593                 
1594                 if (_this.sourceview.loading) {
1595                         return;
1596                 }
1597                 
1598             
1599                 
1600                 print("- PREVIEW EDITOR CHANGED--");
1601             
1602                 this.dirty = true;  
1603                 this.checkSyntax(); // this calls backs and highlights errors.. in theory...  
1604             
1605             
1606             
1607                 if (!_this.sourceview.button_is_pressed && !_this.sourceview.key_is_pressed) {
1608                         print("button or key not pressed to generate change?!\n");
1609                         return;
1610                 }
1611                         
1612                 
1613                 // what are we editing??
1614                 if (null == _this.sourceview.node_selected || _this.sourceview.prop_selected.length  < 1) {
1615                         return;
1616                 }
1617                 
1618                 // find the colon on the first line...
1619                 
1620                 if (_this.sourceview.editable_start_pos > -1) {
1621                         
1622                         var buf = (Gtk.SourceBuffer)_this.sourceview.el.get_buffer();
1623                         
1624                     //print("cursor changed : %d\n", buf.cursor_position);
1625                     Gtk.TextIter spos,epos;
1626                     buf.get_iter_at_offset(out spos, _this.sourceview.editable_start_pos);
1627                     buf.get_iter_at_offset(out epos, _this.sourceview.editable_start_pos); // initialize epos..
1628                     
1629                     var gotit= false;
1630                     var line = spos.get_line();
1631                     var endline = buf.get_line_count();
1632                     while (line < endline) {
1633                                 line++;
1634                         buf.get_iter_at_line(out epos, line);
1635                         if (buf.get_source_marks_at_line(line, "grey").length() > 0) {
1636                                 buf.get_iter_at_line(out epos, line);                   
1637                                 gotit=true;
1638                                 break;
1639                                 }
1640                         }
1641                     
1642                         if (gotit) {
1643                                 print("End Offset = %d/%d\n", epos.get_line(), epos.get_offset());
1644                                 // get the pos...
1645                                 // in theory the last char will be '}' or '},' .. or ','
1646                                 // we should chop the ',' of the end...
1647                                 var str = buf.get_text(spos, epos, false);
1648                                 print("got string\n%s\n", str);
1649                         
1650                         }
1651                 }
1652                 return ;
1653             });
1654         }
1655
1656         // user defined functions
1657         public bool checkSyntax () {
1658          
1659            
1660             var str = this.toString();
1661             
1662             // needed???
1663             if (this.error_line > 0) {
1664                  Gtk.TextIter start;
1665                  Gtk.TextIter end;     
1666                 this.el.get_bounds (out start, out end);
1667         
1668                 this.el.remove_source_marks (start, end, "WARN");
1669                 this.el.remove_source_marks (start, end, "ERR");        
1670         
1671             }
1672             
1673             if (str.length < 1) {
1674                 print("checkSyntax - empty string?\n");
1675                 return false;
1676             }
1677             
1678            if (_this.file == null) {
1679                return false;
1680            }
1681             var p = _this.file.project.palete;
1682             
1683          
1684             if (_this.file.language != "js") {
1685                         return false; // fake syntax error.
1686                 }
1687                 
1688             //Gee.HashMap<int,string> ret_x;
1689         
1690                 return p.javascriptHasErrors(
1691                         _this.main_window.windowstate,
1692                 str, 
1693                 null, // prop - not relivant.
1694                 _this.file, 
1695                 null
1696             );    
1697              
1698         }
1699         public bool highlightErrors ( Gee.HashMap<int,string> validate_res) {
1700                  
1701             this.error_line = validate_res.size;
1702                 
1703             if (this.error_line < 1) {
1704                   return true;
1705             }
1706             var tlines = this.el.get_line_count ();
1707             Gtk.TextIter iter;
1708             var valiter = validate_res.map_iterator();
1709             while (valiter.next()) {
1710             
1711         //        print("get inter\n");
1712                 var eline = valiter.get_key();
1713                 if (eline > tlines) {
1714                     continue;
1715                 }
1716                 this.el.get_iter_at_line( out iter, eline);
1717                 //print("mark line\n");
1718                 this.el.create_source_mark(valiter.get_value(), "ERR", iter);
1719             }   
1720             return false;
1721         }
1722         public string toString () {
1723             
1724             Gtk.TextIter s;
1725             Gtk.TextIter e;
1726             this.el.get_start_iter(out s);
1727             this.el.get_end_iter(out e);
1728             var ret = this.el.get_text(s,e,true);
1729             //print("TO STRING? " + ret);
1730             return ret;
1731         }
1732     }
1733
1734
1735
1736     public class Xcls_Box18 : Object
1737     {
1738         public Gtk.Box el;
1739         private Xcls_WindowRooView  _this;
1740
1741
1742             // my vars (def)
1743
1744         // ctor
1745         public Xcls_Box18(Xcls_WindowRooView _owner )
1746         {
1747             _this = _owner;
1748             this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
1749
1750             // my vars (dec)
1751
1752             // set gobject values
1753             this.el.homogeneous = false;
1754             this.el.vexpand = false;
1755             var child_0 = new Xcls_search_entry( _this );
1756             child_0.ref();
1757             this.el.add(  child_0.el );
1758             var child_1 = new Xcls_MenuBar20( _this );
1759             child_1.ref();
1760             this.el.add (  child_1.el  );
1761             var child_2 = new Xcls_nextBtn( _this );
1762             child_2.ref();
1763             this.el.add(  child_2.el );
1764             var child_3 = new Xcls_backBtn( _this );
1765             child_3.ref();
1766             this.el.add(  child_3.el );
1767             var child_4 = new Xcls_MenuButton26( _this );
1768             child_4.ref();
1769             this.el.add(  child_4.el );
1770         }
1771
1772         // user defined functions
1773     }
1774     public class Xcls_search_entry : Object
1775     {
1776         public Gtk.SearchEntry el;
1777         private Xcls_WindowRooView  _this;
1778
1779
1780             // my vars (def)
1781
1782         // ctor
1783         public Xcls_search_entry(Xcls_WindowRooView _owner )
1784         {
1785             _this = _owner;
1786             _this.search_entry = this;
1787             this.el = new Gtk.SearchEntry();
1788
1789             // my vars (dec)
1790
1791             // set gobject values
1792             this.el.width_request = 300;
1793             this.el.hexpand = true;
1794             this.el.placeholder_text = "Press enter to search";
1795
1796             // init method
1797
1798             var description =   Pango.FontDescription.from_string("monospace");
1799                 description.set_size(8000);
1800                  this.el.override_font(description);
1801
1802             //listeners
1803             this.el.key_press_event.connect( (event) => {
1804                  if (event.keyval == Gdk.Key.g && (event.state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1805                     GLib.debug("SAVE: ctrl-g  pressed");
1806                         _this.forwardSearch(true);
1807                     return true;
1808                 }
1809                 
1810               
1811                 if (event.keyval == Gdk.Key.Return && this.el.text.length > 0) {
1812                         var res = _this.search(this.el.text);
1813                          _this.search_results.updateResults();
1814             
1815                         GLib.Timeout.add_seconds(2,() => {
1816                                  _this.search_results.updateResults();
1817                                  return false;
1818                          });
1819                  
1820                         
1821                     return true;
1822             
1823                 }    
1824                // print(event.key.keyval)
1825                
1826                 return false;
1827             
1828             });
1829             this.el.changed.connect( () => {
1830                 /*
1831                 if (this.el.text == "") {
1832                         _this.search_results.el.hide();
1833                         return;
1834                 }
1835                 var res = 0;
1836                 switch(_this.windowstate.state) {
1837                         case WindowState.State.CODEONLY:
1838                         ///case WindowState.State.CODE:
1839                                 // search the code being edited..
1840                                 res = _this.windowstate.code_editor_tab.search(this.el.text);
1841                                 
1842                                 break;
1843                         case WindowState.State.PREVIEW:
1844                                 if (_this.windowstate.file.xtype == "Gtk") {
1845                                          res = _this.windowstate.window_gladeview.search(this.el.text);
1846                                 } else { 
1847                                          res = _this.windowstate.window_rooview.search(this.el.text);                   
1848                                 }
1849                         
1850                         
1851                                 break;
1852                 }
1853                 _this.search_results.el.show();
1854                 if (res > 0) {
1855                         _this.search_results.el.label = "%d Matches".printf(res);
1856                 } else {
1857                         _this.search_results.el.label = "No Matches";
1858                 }
1859                         
1860                 */
1861                 
1862             });
1863         }
1864
1865         // user defined functions
1866         public void forwardSearch (bool change_focus) {
1867         
1868         
1869                 _this.forwardSearch(change_focus);
1870         
1871         /*
1872         
1873                 switch(_this.windowstate.state) {
1874                         case WindowState.State.CODEONLY:
1875                         //case WindowState.State.CODE:
1876                                 // search the code being edited..
1877                                 _this.windowstate.code_editor_tab.forwardSearch(change_focus);
1878                                  
1879                                 break;
1880                         case WindowState.State.PREVIEW:
1881                                 if (_this.windowstate.file.xtype == "Gtk") {
1882                                         _this.windowstate.window_gladeview.forwardSearch(change_focus);
1883                                 } else { 
1884                                          _this.windowstate.window_rooview.forwardSearch(change_focus);
1885                                 }
1886                         
1887                                 break;
1888                 }
1889                 */
1890                 
1891         }
1892     }
1893
1894     public class Xcls_MenuBar20 : Object
1895     {
1896         public Gtk.MenuBar el;
1897         private Xcls_WindowRooView  _this;
1898
1899
1900             // my vars (def)
1901
1902         // ctor
1903         public Xcls_MenuBar20(Xcls_WindowRooView _owner )
1904         {
1905             _this = _owner;
1906             this.el = new Gtk.MenuBar();
1907
1908             // my vars (dec)
1909
1910             // set gobject values
1911             var child_0 = new Xcls_search_results( _this );
1912             child_0.ref();
1913             this.el.add (  child_0.el  );
1914         }
1915
1916         // user defined functions
1917     }
1918     public class Xcls_search_results : Object
1919     {
1920         public Gtk.ImageMenuItem el;
1921         private Xcls_WindowRooView  _this;
1922
1923
1924             // my vars (def)
1925
1926         // ctor
1927         public Xcls_search_results(Xcls_WindowRooView _owner )
1928         {
1929             _this = _owner;
1930             _this.search_results = this;
1931             this.el = new Gtk.ImageMenuItem();
1932
1933             // my vars (dec)
1934
1935             // set gobject values
1936             this.el.always_show_image = true;
1937             this.el.visible = false;
1938
1939             //listeners
1940             this.el.button_press_event.connect( () => {
1941             /*
1942                 if (this.popup == null) {
1943                     this.popup = new Xcls_ValaCompileErrors();
1944                     this.popup.window = _this;
1945                 }
1946                
1947                 
1948                 this.popup.show(this.notices, this.el);
1949                 */
1950                 return true;
1951             });
1952         }
1953
1954         // user defined functions
1955         public void updateResults () {
1956                 this.el.visible = true;
1957                 
1958                 var res = _this.searchcontext.get_occurrences_count();
1959                 if (res < 0) {
1960                         _this.search_results.el.label = "??? Matches";          
1961                         return;
1962                 }
1963         
1964                 _this.nextBtn.el.sensitive = false;
1965                 _this.backBtn.el.sensitive = false;     
1966         
1967                 if (res > 0) {
1968                         _this.search_results.el.label = "%d Matches".printf(res);
1969                         _this.nextBtn.el.sensitive = true;
1970                         _this.backBtn.el.sensitive = true;
1971                         return;
1972                 } 
1973                 _this.search_results.el.label = "No Matches";
1974                 
1975         }
1976     }
1977
1978
1979     public class Xcls_nextBtn : Object
1980     {
1981         public Gtk.Button el;
1982         private Xcls_WindowRooView  _this;
1983
1984
1985             // my vars (def)
1986
1987         // ctor
1988         public Xcls_nextBtn(Xcls_WindowRooView _owner )
1989         {
1990             _this = _owner;
1991             _this.nextBtn = this;
1992             this.el = new Gtk.Button();
1993
1994             // my vars (dec)
1995
1996             // set gobject values
1997             this.el.always_show_image = true;
1998             this.el.label = "Next";
1999             this.el.sensitive = false;
2000             var child_0 = new Xcls_Image23( _this );
2001             child_0.ref();
2002             this.el.image = child_0.el;
2003
2004             //listeners
2005             this.el.button_press_event.connect( (event) => {
2006             
2007                 _this.forwardSearch(true);
2008                 
2009                 return true;
2010             });
2011         }
2012
2013         // user defined functions
2014     }
2015     public class Xcls_Image23 : Object
2016     {
2017         public Gtk.Image el;
2018         private Xcls_WindowRooView  _this;
2019
2020
2021             // my vars (def)
2022
2023         // ctor
2024         public Xcls_Image23(Xcls_WindowRooView _owner )
2025         {
2026             _this = _owner;
2027             this.el = new Gtk.Image();
2028
2029             // my vars (dec)
2030
2031             // set gobject values
2032             this.el.icon_name = "go-down";
2033         }
2034
2035         // user defined functions
2036     }
2037
2038
2039     public class Xcls_backBtn : Object
2040     {
2041         public Gtk.Button el;
2042         private Xcls_WindowRooView  _this;
2043
2044
2045             // my vars (def)
2046
2047         // ctor
2048         public Xcls_backBtn(Xcls_WindowRooView _owner )
2049         {
2050             _this = _owner;
2051             _this.backBtn = this;
2052             this.el = new Gtk.Button();
2053
2054             // my vars (dec)
2055
2056             // set gobject values
2057             this.el.always_show_image = true;
2058             this.el.label = "Previous";
2059             this.el.sensitive = false;
2060             var child_0 = new Xcls_Image25( _this );
2061             child_0.ref();
2062             this.el.image = child_0.el;
2063
2064             //listeners
2065             this.el.button_press_event.connect( (event) => {
2066             
2067                 _this.backSearch(true);
2068                 
2069                 return true;
2070             });
2071         }
2072
2073         // user defined functions
2074     }
2075     public class Xcls_Image25 : Object
2076     {
2077         public Gtk.Image el;
2078         private Xcls_WindowRooView  _this;
2079
2080
2081             // my vars (def)
2082
2083         // ctor
2084         public Xcls_Image25(Xcls_WindowRooView _owner )
2085         {
2086             _this = _owner;
2087             this.el = new Gtk.Image();
2088
2089             // my vars (dec)
2090
2091             // set gobject values
2092             this.el.icon_name = "go-up";
2093         }
2094
2095         // user defined functions
2096     }
2097
2098
2099     public class Xcls_MenuButton26 : Object
2100     {
2101         public Gtk.MenuButton el;
2102         private Xcls_WindowRooView  _this;
2103
2104
2105             // my vars (def)
2106
2107         // ctor
2108         public Xcls_MenuButton26(Xcls_WindowRooView _owner )
2109         {
2110             _this = _owner;
2111             this.el = new Gtk.MenuButton();
2112
2113             // my vars (dec)
2114
2115             // set gobject values
2116             this.el.always_show_image = true;
2117             this.el.label = "Settings";
2118             var child_0 = new Xcls_Image27( _this );
2119             child_0.ref();
2120             this.el.image = child_0.el;
2121             var child_1 = new Xcls_search_settings( _this );
2122             child_1.ref();
2123             this.el.popup = child_1.el;
2124         }
2125
2126         // user defined functions
2127     }
2128     public class Xcls_Image27 : Object
2129     {
2130         public Gtk.Image el;
2131         private Xcls_WindowRooView  _this;
2132
2133
2134             // my vars (def)
2135
2136         // ctor
2137         public Xcls_Image27(Xcls_WindowRooView _owner )
2138         {
2139             _this = _owner;
2140             this.el = new Gtk.Image();
2141
2142             // my vars (dec)
2143
2144             // set gobject values
2145             this.el.icon_name = "emblem-system";
2146         }
2147
2148         // user defined functions
2149     }
2150
2151     public class Xcls_search_settings : Object
2152     {
2153         public Gtk.Menu el;
2154         private Xcls_WindowRooView  _this;
2155
2156
2157             // my vars (def)
2158
2159         // ctor
2160         public Xcls_search_settings(Xcls_WindowRooView _owner )
2161         {
2162             _this = _owner;
2163             _this.search_settings = this;
2164             this.el = new Gtk.Menu();
2165
2166             // my vars (dec)
2167
2168             // set gobject values
2169             var child_0 = new Xcls_case_sensitive( _this );
2170             child_0.ref();
2171             this.el.append(  child_0.el );
2172             var child_1 = new Xcls_regex( _this );
2173             child_1.ref();
2174             this.el.append(  child_1.el );
2175             var child_2 = new Xcls_multiline( _this );
2176             child_2.ref();
2177             this.el.append(  child_2.el );
2178         }
2179
2180         // user defined functions
2181     }
2182     public class Xcls_case_sensitive : Object
2183     {
2184         public Gtk.CheckMenuItem el;
2185         private Xcls_WindowRooView  _this;
2186
2187
2188             // my vars (def)
2189
2190         // ctor
2191         public Xcls_case_sensitive(Xcls_WindowRooView _owner )
2192         {
2193             _this = _owner;
2194             _this.case_sensitive = this;
2195             this.el = new Gtk.CheckMenuItem();
2196
2197             // my vars (dec)
2198
2199             // set gobject values
2200             this.el.label = "Case Sensitive";
2201
2202             // init method
2203
2204             {
2205                 this.el.show();
2206             }
2207         }
2208
2209         // user defined functions
2210     }
2211
2212     public class Xcls_regex : Object
2213     {
2214         public Gtk.CheckMenuItem el;
2215         private Xcls_WindowRooView  _this;
2216
2217
2218             // my vars (def)
2219
2220         // ctor
2221         public Xcls_regex(Xcls_WindowRooView _owner )
2222         {
2223             _this = _owner;
2224             _this.regex = this;
2225             this.el = new Gtk.CheckMenuItem();
2226
2227             // my vars (dec)
2228
2229             // set gobject values
2230             this.el.label = "Regex";
2231
2232             // init method
2233
2234             {
2235                 this.el.show();
2236             }
2237         }
2238
2239         // user defined functions
2240     }
2241
2242     public class Xcls_multiline : Object
2243     {
2244         public Gtk.CheckMenuItem el;
2245         private Xcls_WindowRooView  _this;
2246
2247
2248             // my vars (def)
2249
2250         // ctor
2251         public Xcls_multiline(Xcls_WindowRooView _owner )
2252         {
2253             _this = _owner;
2254             _this.multiline = this;
2255             this.el = new Gtk.CheckMenuItem();
2256
2257             // my vars (dec)
2258
2259             // set gobject values
2260             this.el.label = "Multi-line (add \\n)";
2261
2262             // init method
2263
2264             {
2265                 this.el.show();
2266             }
2267         }
2268
2269         // user defined functions
2270     }
2271
2272
2273
2274
2275
2276
2277 }