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