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