src/Builder4/WindowRooView.bjs
[app.Builder.js] / src / Builder4 / WindowRooView.vala
index 37fca66..cb9228a 100644 (file)
@@ -2,7 +2,7 @@ static Xcls_WindowRooView  _WindowRooView;
 
 public class Xcls_WindowRooView : Object
 {
-    public Gtk.Paned el;
+    public Gtk.Box el;
     private Xcls_WindowRooView  _this;
 
     public static Xcls_WindowRooView singleton()
@@ -12,37 +12,68 @@ public class Xcls_WindowRooView : Object
         }
         return _WindowRooView;
     }
+    public Xcls_notebook notebook;
+    public Xcls_label_preview label_preview;
+    public Xcls_label_code label_code;
+    public Xcls_paned paned;
     public Xcls_viewbox viewbox;
     public Xcls_AutoRedraw AutoRedraw;
     public Xcls_viewcontainer viewcontainer;
     public Xcls_view view;
     public Xcls_inspectorcontainer inspectorcontainer;
+    public Xcls_sourceview sourceview;
+    public Xcls_buffer buffer;
 
         // my vars (def)
+    public Gtk.Widget lastObj;
+    public int width;
+    public int last_search_end;
+    public Gtk.SourceSearchContext searchcontext;
     public JsRender.JsRender file;
+    public int height;
+    public Xcls_MainWindow main_window;
 
     // ctor
     public Xcls_WindowRooView()
     {
         _this = this;
-        this.el = new Gtk.Paned( Gtk.Orientation.VERTICAL );
+        this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
 
         // my vars (dec)
+        this.lastObj = null;
+        this.width = 0;
+        this.last_search_end = 0;
+        this.file = null;
+        this.height = 0;
 
         // set gobject values
-        var child_0 = new Xcls_viewbox( _this );
+        this.el.hexpand = true;
+        var child_0 = new Xcls_notebook( _this );
         child_0.ref();
-        this.el.pack1 (  child_0.el , true,true );
-        var child_1 = new Xcls_inspectorcontainer( _this );
-        child_1.ref();
-        this.el.pack2 (  child_1.el , true,true );
+        this.el.pack_start (  child_0.el , true,true,0 );
     }
 
     // user defined functions
-    public void loadFile (JsRender.JsRender file)
-    {
-        this.file = file;
-        this.view.renderJS(true);
+    public void scroll_to_line (int line) {
+       this.notebook.el.page = 1;// code preview...
+       
+       GLib.Timeout.add(500, () => {
+       
+       
+          
+          
+                 var buf = this.sourceview.el.get_buffer();
+        
+               var sbuf = (Gtk.SourceBuffer) buf;
+    
+    
+               Gtk.TextIter iter;   
+               sbuf.get_iter_at_line(out iter,  line);
+               this.sourceview.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);
+               return false;
+       });   
+    
+       
     }
     public void createThumb () {
         
@@ -50,28 +81,186 @@ public class Xcls_WindowRooView : Object
         if (this.file == null) {
             return;
         }
+       if (this.notebook.el.page > 0 ) {
+            return;
+        }
+        
         var filename = this.file.getIconFileName(false);
         
         var  win = this.el.get_parent_window();
         var width = win.get_width();
       //  var height = win.get_height();
         try { 
-            Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, this.el.position);
+            Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, this.paned.el.position);
             screenshot.save(filename,"png");
-        } catch(e) {
+        } catch(Error e) {
             //noop
         }
     
         
+         
         
+         
+    }
+    public void loadFile (JsRender.JsRender file)
+    {
+        this.file = file;
+        this.view.renderJS(true);
+        this.notebook.el.page = 0;// gtk preview 
+        this.sourceview.loadFile();   
         
+    }
+    public int search (string txt) {
+       this.notebook.el.page = 1;
+       var s = new Gtk.SourceSearchSettings();
+       var buf = (Gtk.SourceBuffer) this.sourceview.el.get_buffer();
+       this.searchcontext = new Gtk.SourceSearchContext(buf,s);
+       this.searchcontext.set_highlight(true);
+       s.set_search_text(txt);
+       
+       Gtk.TextIter beg, st,en;
+        
+       buf.get_start_iter(out beg);
+       this.searchcontext.forward(beg, out st, out en);
+       this.last_search_end  = 0;
+       return this.searchcontext.get_occurrences_count();
     
-    
-        
-         
+       
     }
     public void requestRedraw () {
         this.view.renderJS(false);
+        this.sourceview.loadFile();   
+    }
+    public void forwardSearch (bool change_focus) {
+    
+       if (this.searchcontext == null) {
+               return;
+       }
+       this.notebook.el.page = 1;
+       Gtk.TextIter beg, st,en, stl;
+       
+       var buf = this.sourceview.el.get_buffer();
+       buf.get_iter_at_offset(out beg, this.last_search_end);
+       if (!this.searchcontext.forward(beg, out st, out en)) {
+               this.last_search_end = 0;
+       } else { 
+               this.last_search_end = en.get_offset();
+               if (change_focus) {
+                       this.sourceview.el.grab_focus();
+               }
+               buf.place_cursor(st);
+               var ln = st.get_line();
+               buf.get_iter_at_line(out stl,ln);
+                
+               this.sourceview.el.scroll_to_iter(stl,  0.0f, true, 0.0f, 0.5f);
+       }
+    
+    }
+    public class Xcls_notebook : Object
+    {
+        public Gtk.Notebook el;
+        private Xcls_WindowRooView  _this;
+
+
+            // my vars (def)
+
+        // ctor
+        public Xcls_notebook(Xcls_WindowRooView _owner )
+        {
+            _this = _owner;
+            _this.notebook = this;
+            this.el = new Gtk.Notebook();
+
+            // my vars (dec)
+
+            // set gobject values
+            var child_0 = new Xcls_label_preview( _this );
+            child_0.ref();
+            var child_1 = new Xcls_label_code( _this );
+            child_1.ref();
+            var child_2 = new Xcls_paned( _this );
+            child_2.ref();
+            this.el.add (  child_2.el  );
+            var child_3 = new Xcls_ScrolledWindow14( _this );
+            child_3.ref();
+            this.el.append_page (  child_3.el , _this.label_code.el );
+        }
+
+        // user defined functions
+    }
+    public class Xcls_label_preview : Object
+    {
+        public Gtk.Label el;
+        private Xcls_WindowRooView  _this;
+
+
+            // my vars (def)
+
+        // ctor
+        public Xcls_label_preview(Xcls_WindowRooView _owner )
+        {
+            _this = _owner;
+            _this.label_preview = this;
+            this.el = new Gtk.Label( "Preview" );
+
+            // my vars (dec)
+
+            // set gobject values
+        }
+
+        // user defined functions
+    }
+
+    public class Xcls_label_code : Object
+    {
+        public Gtk.Label el;
+        private Xcls_WindowRooView  _this;
+
+
+            // my vars (def)
+
+        // ctor
+        public Xcls_label_code(Xcls_WindowRooView _owner )
+        {
+            _this = _owner;
+            _this.label_code = this;
+            this.el = new Gtk.Label( "Preview Generated Code" );
+
+            // my vars (dec)
+
+            // set gobject values
+        }
+
+        // user defined functions
+    }
+
+    public class Xcls_paned : Object
+    {
+        public Gtk.Paned el;
+        private Xcls_WindowRooView  _this;
+
+
+            // my vars (def)
+
+        // ctor
+        public Xcls_paned(Xcls_WindowRooView _owner )
+        {
+            _this = _owner;
+            _this.paned = this;
+            this.el = new Gtk.Paned( Gtk.Orientation.VERTICAL );
+
+            // my vars (dec)
+
+            // set gobject values
+            var child_0 = new Xcls_viewbox( _this );
+            child_0.ref();
+            this.el.pack1 (  child_0.el , true,true );
+            var child_1 = new Xcls_inspectorcontainer( _this );
+            child_1.ref();
+            this.el.pack2 (  child_1.el , true,true );
+        }
+
+        // user defined functions
     }
     public class Xcls_viewbox : Object
     {
@@ -92,7 +281,7 @@ public class Xcls_WindowRooView : Object
 
             // set gobject values
             this.el.homogeneous = false;
-            var child_0 = new Xcls_Box3( _this );
+            var child_0 = new Xcls_Box7( _this );
             child_0.ref();
             this.el.pack_start (  child_0.el , false,true,0 );
             var child_1 = new Xcls_viewcontainer( _this );
@@ -102,7 +291,7 @@ public class Xcls_WindowRooView : Object
 
         // user defined functions
     }
-    public class Xcls_Box3 : Object
+    public class Xcls_Box7 : Object
     {
         public Gtk.Box el;
         private Xcls_WindowRooView  _this;
@@ -111,7 +300,7 @@ public class Xcls_WindowRooView : Object
             // my vars (def)
 
         // ctor
-        public Xcls_Box3(Xcls_WindowRooView _owner )
+        public Xcls_Box7(Xcls_WindowRooView _owner )
         {
             _this = _owner;
             this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
@@ -122,20 +311,20 @@ public class Xcls_WindowRooView : Object
             this.el.homogeneous = true;
             this.el.height_request = 20;
             this.el.vexpand = false;
-            var child_0 = new Xcls_Button4( _this );
+            var child_0 = new Xcls_Button8( _this );
             child_0.ref();
             this.el.pack_start (  child_0.el , false,false,0 );
             var child_1 = new Xcls_AutoRedraw( _this );
             child_1.ref();
             this.el.pack_start (  child_1.el , false,false,0 );
-            var child_2 = new Xcls_Button6( _this );
+            var child_2 = new Xcls_Button10( _this );
             child_2.ref();
             this.el.pack_start (  child_2.el , false,false,0 );
         }
 
         // user defined functions
     }
-    public class Xcls_Button4 : Object
+    public class Xcls_Button8 : Object
     {
         public Gtk.Button el;
         private Xcls_WindowRooView  _this;
@@ -144,7 +333,7 @@ public class Xcls_WindowRooView : Object
             // my vars (def)
 
         // ctor
-        public Xcls_Button4(Xcls_WindowRooView _owner )
+        public Xcls_Button8(Xcls_WindowRooView _owner )
         {
             _this = _owner;
             this.el = new Gtk.Button();
@@ -193,7 +382,7 @@ public class Xcls_WindowRooView : Object
         // user defined functions
     }
 
-    public class Xcls_Button6 : Object
+    public class Xcls_Button10 : Object
     {
         public Gtk.Button el;
         private Xcls_WindowRooView  _this;
@@ -202,7 +391,7 @@ public class Xcls_WindowRooView : Object
             // my vars (def)
 
         // ctor
-        public Xcls_Button6(Xcls_WindowRooView _owner )
+        public Xcls_Button10(Xcls_WindowRooView _owner )
         {
             _this = _owner;
             this.el = new Gtk.Button();
@@ -422,7 +611,7 @@ public class Xcls_WindowRooView : Object
                  
                  
             _this.viewbox.el.remove(_this.viewcontainer.el);
-            _this.el.remove(_this.inspectorcontainer.el);        
+            _this.paned.el.remove(_this.inspectorcontainer.el);        
                  
                  // destory seems to cause problems.
                  //this.el.destroy();
@@ -430,7 +619,7 @@ public class Xcls_WindowRooView : Object
                  //_this.inspectorcontainer.el.destroy();
              var  inv =new Xcls_inspectorcontainer(_this);
               inv.ref();
-              _this.el.pack2(inv.el,true,true);
+              _this.paned.el.pack2(inv.el,true,true);
               
               
              this.el = null;         
@@ -710,4 +899,714 @@ public class Xcls_WindowRooView : Object
         // user defined functions
     }
 
+
+    public class Xcls_ScrolledWindow14 : Object
+    {
+        public Gtk.ScrolledWindow el;
+        private Xcls_WindowRooView  _this;
+
+
+            // my vars (def)
+
+        // ctor
+        public Xcls_ScrolledWindow14(Xcls_WindowRooView _owner )
+        {
+            _this = _owner;
+            this.el = new Gtk.ScrolledWindow( null, null );
+
+            // my vars (dec)
+
+            // set gobject values
+            var child_0 = new Xcls_sourceview( _this );
+            child_0.ref();
+            this.el.add (  child_0.el  );
+        }
+
+        // user defined functions
+    }
+    public class Xcls_sourceview : Object
+    {
+        public Gtk.SourceView el;
+        private Xcls_WindowRooView  _this;
+
+
+            // my vars (def)
+        public bool loading;
+        public bool allow_node_scroll;
+        public string propSelected;
+
+        // ctor
+        public Xcls_sourceview(Xcls_WindowRooView _owner )
+        {
+            _this = _owner;
+            _this.sourceview = this;
+            this.el = new Gtk.SourceView();
+
+            // my vars (dec)
+            this.loading = true;
+            this.allow_node_scroll = true;
+            this.propSelected = "";
+
+            // set gobject values
+            this.el.editable = false;
+            this.el.show_line_marks = true;
+            this.el.show_line_numbers = true;
+            var child_0 = new Xcls_buffer( _this );
+            child_0.ref();
+            this.el.set_buffer (  child_0.el  );
+
+            // init method
+
+            {
+               
+                var description =   Pango.FontDescription.from_string("monospace");
+                description.set_size(8000);
+                this.el.override_font(description);
+            
+                this.loading = true;
+                //var buf = this.el.get_buffer();
+                //buf.notify.connect(this.onCursorChanged);
+              
+              
+              
+                var attrs = new Gtk.SourceMarkAttributes();
+                var  pink =   Gdk.RGBA();
+                pink.parse ( "pink");
+                attrs.set_background ( pink);
+                attrs.set_icon_name ( "process-stop");    
+                attrs.query_tooltip_text.connect(( mark) => {
+                    //print("tooltip query? %s\n", mark.name);
+                    return mark.name;
+                });
+                
+                this.el.set_mark_attributes ("ERR", attrs, 1);
+                
+                 var wattrs = new Gtk.SourceMarkAttributes();
+                var  blue =   Gdk.RGBA();
+                blue.parse ( "#ABF4EB");
+                wattrs.set_background ( blue);
+                wattrs.set_icon_name ( "process-stop");    
+                wattrs.query_tooltip_text.connect(( mark) => {
+                    //print("tooltip query? %s\n", mark.name);
+                    return mark.name;
+                });
+                
+                this.el.set_mark_attributes ("WARN", wattrs, 1);
+                
+             
+                
+                 var dattrs = new Gtk.SourceMarkAttributes();
+                var  purple =   Gdk.RGBA();
+                purple.parse ( "#EEA9FF");
+                dattrs.set_background ( purple);
+                dattrs.set_icon_name ( "process-stop");    
+                dattrs.query_tooltip_text.connect(( mark) => {
+                    //print("tooltip query? %s\n", mark.name);
+                    return mark.name;
+                });
+                
+                this.el.set_mark_attributes ("DEPR", dattrs, 1);
+                
+                
+                var gattrs = new Gtk.SourceMarkAttributes();
+                var  grey =   Gdk.RGBA();
+                grey.parse ( "#ccc");
+                gattrs.set_background ( grey);
+             
+                
+                this.el.set_mark_attributes ("grey", gattrs, 1);
+                
+                
+                
+                
+                
+                
+            }
+
+            //listeners
+            this.el.button_release_event.connect( () => {
+               this.onCursorChanged();
+            
+               return false;
+            });
+        }
+
+        // user defined functions
+        public void onCursorChanged (/*ParamSpec ps*/) {
+                 if (this.loading) {
+                    return;
+                }
+               // if (ps.name != "cursor-position") {
+               //     return;
+               // }
+        
+                var buf = this.el.get_buffer();
+                print("cursor changed : %d\n", buf.cursor_position);
+                Gtk.TextIter cpos;
+                buf.get_iter_at_offset(out cpos, buf.cursor_position);
+                
+                var ln = cpos.get_line();
+                       print("cursor changed line : %d\n", ln);
+                var node = _this.file.lineToNode(ln+1);
+         
+                if (node == null) {
+                    print("can not find node\n");
+                    return;
+                }
+                var prop = node.lineToProp(ln+1);
+                print("prop : %s", prop == null ? "???" : prop);
+                
+                
+                
+                
+                
+                
+                var ltree = _this.main_window.windowstate.left_tree;
+                var tp = ltree.model.treePathFromNode(node);
+                print("got tree path %s\n", tp);
+                if (tp != "") {
+                      this.allow_node_scroll = false; /// block node scrolling..
+                      
+                      
+                       //print("changing cursor on tree..\n");
+                      
+         
+                    
+                    // let's try allowing editing on the methods.
+                    // a little klunky at present..
+                    this.propSelected = "";
+                    if (prop != null) {
+                               //see if we can find it..
+                               var kv = prop.split(":");
+                               if (kv[0] == "p") {
+                               
+                                       //var k = prop.get_key(kv[1]);
+                                       // fixme -- need to determine if it's an editable property...
+                                       this.propSelected = prop;
+                                       
+                               } else if (kv[0] == "l") {
+                                        this.propSelected = prop;
+                                       
+                               }
+                    }
+                    ltree.view.setCursor(tp, "editor");
+                   // ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false); 
+                   this.nodeSelected(node,false);
+                    
+                    // scrolling is disabled... as node selection calls scroll 10ms after it changes.
+                    GLib.Timeout.add_full(GLib.Priority.DEFAULT,100 , () => {
+                           this.allow_node_scroll = true;
+                           return false;
+                    });
+                }
+                
+                // highlight the node..
+        }
+        public void nodeSelected (JsRender.Node? sel, bool scroll ) {
+          
+            
+          
+            // this is connected in widnowstate
+            print("node selected\n");
+            var buf = this.el.get_buffer();
+         
+            var sbuf = (Gtk.SourceBuffer) buf;
+        
+           
+            while(Gtk.events_pending()) {
+                Gtk.main_iteration();
+            }
+            
+           
+            // clear all the marks..
+            Gtk.TextIter start;
+            Gtk.TextIter end;     
+                
+            sbuf.get_bounds (out start, out end);
+            sbuf.remove_source_marks (start, end, "grey");
+            
+            
+             if (sel == null) {
+                    print("no selected node\n");
+                // no highlighting..
+                return;
+            }
+            
+            print("highlight region %d to %d\n", sel.line_start,sel.line_end);
+            Gtk.TextIter iter;   
+            sbuf.get_iter_at_line(out iter,  sel.line_start);
+            
+            
+            Gtk.TextIter cur_iter;
+            sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position);
+            
+            //var cur_line = cur_iter.get_line();
+            //if (cur_line > sel.line_start && cur_line < sel.line_end) {
+            
+            //} else {
+            if (scroll) {
+                        
+               this.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);
+               }
+            
+            var start_line = sel.line_start;
+            var end_line = sel.line_end;
+            
+            
+            this.el.editable = false;
+            // now if we have selected a property...
+            if (this.propSelected.length> 0 ) {
+        
+                       int nstart, nend;
+                       if (sel.getPropertyRange(this.propSelected, out nstart, out nend) && nend > nstart) {
+                               start_line = nstart;
+                               end_line = nend;
+                               this.el.editable = true;
+                       }
+                       print("propSelected = %s range  %d -> %d\n", this.propSelected, start_line, end_line);          
+                       
+                       
+            }
+            
+            // check selection - if it's out of 'bounds'
+            if (this.el.editable && sbuf.get_has_selection()) {
+                       Gtk.TextIter sel_start_iter, sel_end_iter;
+                       sbuf.get_selection_bounds(out sel_start_iter, out sel_end_iter);
+                       
+                       if (sel_start_iter.get_line() < start_line || sel_end_iter.get_line() > end_line ||
+                               sel_start_iter.get_line() > end_line   || sel_end_iter.get_line() < start_line                  ) {
+                               // save?
+                               this.el.editable = false;
+                       }
+            
+            }
+            
+            
+            
+            
+            for (var i = 0; i < buf.get_line_count();i++) {
+                if (i < (start_line -1) || i > (end_line -1)) {
+                   
+                    sbuf.get_iter_at_line(out iter, i);
+                    sbuf.create_source_mark(null, "grey", iter);
+                    
+                }
+            
+            }
+            
+        
+        }
+        public string toString () {
+           Gtk.TextIter s;
+            Gtk.TextIter e;
+            this.el.get_buffer().get_start_iter(out s);
+            this.el.get_buffer().get_end_iter(out e);
+            var ret = this.el.get_buffer().get_text(s,e,true);
+            //print("TO STRING? " + ret);
+            return ret;
+        }
+        public void loadFile ( ) {
+            this.loading = true;
+            
+            
+            // get the cursor and scroll position....
+            var buf = this.el.get_buffer();
+               var cpos = buf.cursor_position;
+            
+           print("BEFORE LOAD cursor = %d\n", cpos);
+           
+            var vadj_pos = this.el.get_vadjustment().get_value();
+           
+            
+         
+            buf.set_text("",0);
+            var sbuf = (Gtk.SourceBuffer) buf;
+        
+            
+        
+            if (_this.file == null || _this.file.xtype != "Roo") {
+                print("xtype != Roo");
+                this.loading = false;
+                return;
+            }
+            
+            // get the string from the rendered tree...
+             
+             var str = _this.file.toSource();
+             
+        //    print("setting str %d\n", str.length);
+            buf.set_text(str, str.length);
+            var lm = Gtk.SourceLanguageManager.get_default();
+             
+            //?? is javascript going to work as js?
+            
+            ((Gtk.SourceBuffer)(buf)) .set_language(lm.get_language(_this.file.language));
+          
+            
+            Gtk.TextIter start;
+            Gtk.TextIter end;     
+                
+            sbuf.get_bounds (out start, out end);
+            sbuf.remove_source_marks (start, end, null); // remove all marks..
+            
+             GLib.Timeout.add(500, () => {
+               
+               print("RESORTING cursor to = %d\n", cpos);
+                       Gtk.TextIter cpos_iter;
+                       buf.get_iter_at_offset(out cpos_iter, cpos);
+                       buf.place_cursor(cpos_iter); 
+                       
+                       this.el.get_vadjustment().set_value(vadj_pos);;
+                       this.onCursorChanged();
+                       return false;
+               });
+                       
+            this.loading = false; 
+        }
+        public void highlightErrorsJson (string type, Json.Object obj) {
+              Gtk.TextIter start;
+             Gtk.TextIter end;   
+             
+             var buf =  this.el.get_buffer();
+               var sbuf = (Gtk.SourceBuffer)buf;
+                buf.get_bounds (out start, out end);
+                
+                sbuf.remove_source_marks (start, end, type);
+                         
+             
+             // we should highlight other types of errors..
+            
+            if (!obj.has_member(type)) {
+                print("Return has no errors\n");
+                return  ;
+            }
+            var err = obj.get_object_member(type);
+            
+            if (_this.file == null) { 
+                return; // just in case the file has not loaded yet?
+            }
+         
+        
+            var valafn = "";
+              try {             
+                   var  regex = new Regex("\\.bjs$");
+                
+                 
+                    valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
+                 } catch (GLib.RegexError e) {
+                    return;
+                }   
+        
+           if (!err.has_member(valafn)) {
+                print("File path has no errors\n");
+                return  ;
+            }
+            var lines = err.get_object_member(valafn);
+            
+           
+            
+            var tlines = buf.get_line_count () +1;
+            
+            lines.foreach_member((obj, line, node) => {
+                
+                     Gtk.TextIter iter;
+            //        print("get inter\n");
+                    var eline = int.parse(line) -1  ;
+                    print("GOT ERROR on line %s -- converted to %d\n", line,eline);
+                    
+                    
+                    if (eline > tlines || eline < 0) {
+                        return;
+                    }
+                    sbuf.get_iter_at_line( out iter, eline);
+                    //print("mark line\n");
+                    var msg  = type + " on line: %d - %s".printf(eline+1, valafn);
+                    var ar = lines.get_array_member(line);
+                    for (var i = 0 ; i < ar.get_length(); i++) {
+                           msg += (msg.length > 0) ? "\n" : "";
+                           msg += ar.get_string_element(i);
+                   }
+                    
+                    
+                    sbuf.create_source_mark(msg, type, iter);
+                } );
+                return  ;
+            
+         
+        
+        
+        }
+    }
+    public class Xcls_buffer : Object
+    {
+        public Gtk.SourceBuffer el;
+        private Xcls_WindowRooView  _this;
+
+
+            // my vars (def)
+        public bool check_queued;
+        public int error_line;
+        public bool check_running;
+
+        // ctor
+        public Xcls_buffer(Xcls_WindowRooView _owner )
+        {
+            _this = _owner;
+            _this.buffer = this;
+            this.el = new Gtk.SourceBuffer( null );
+
+            // my vars (dec)
+            this.check_queued = false;
+            this.error_line = -1;
+            this.check_running = false;
+
+            // set gobject values
+
+            //listeners
+            this.el.changed.connect( () => {
+                // check syntax??
+                // ??needed..??
+                _this.save_button.el.sensitive = true;
+                print("EDITOR CHANGED");
+                
+                
+                //this.checkSyntax();
+               
+                _this.dirty = true;
+            
+                // this.get('/LeftPanel.model').changed(  str , false);
+                return ;
+            });
+        }
+
+        // user defined functions
+        public bool highlightErrors ( Gee.HashMap<int,string> validate_res) {
+                 
+                this.error_line = validate_res.size;
+        
+                if (this.error_line < 1) {
+                      return true;
+                }
+                var tlines = this.el.get_line_count ();
+                Gtk.TextIter iter;
+                var valiter = validate_res.map_iterator();
+                while (valiter.next()) {
+                
+            //        print("get inter\n");
+                    var eline = valiter.get_key();
+                    if (eline > tlines) {
+                        continue;
+                    }
+                    this.el.get_iter_at_line( out iter, eline);
+                    //print("mark line\n");
+                    this.el.create_source_mark(valiter.get_value(), "ERR", iter);
+                }   
+                return false;
+            }
+        public   string toString () {
+            
+            Gtk.TextIter s;
+            Gtk.TextIter e;
+            this.el.get_start_iter(out s);
+            this.el.get_end_iter(out e);
+            var ret = this.el.get_text(s,e,true);
+            //print("TO STRING? " + ret);
+            return ret;
+        }
+        public   bool checkSyntax () {
+         
+            if (this.check_running) {
+                print("Check is running\n");
+                if (this.check_queued) { 
+                    print("Check is already queued");
+                    return true;
+                }
+                this.check_queued = true;
+                print("Adding queued Check ");
+                GLib.Timeout.add_seconds(1, () => {
+                    this.check_queued = false;
+                    
+                    this.checkSyntax();
+                    return false;
+                });
+            
+        
+                return true;
+            }
+            var str = this.toString();
+            
+            // needed???
+            if (this.error_line > 0) {
+                 Gtk.TextIter start;
+                 Gtk.TextIter end;     
+                this.el.get_bounds (out start, out end);
+        
+                this.el.remove_source_marks (start, end, null);
+            }
+            if (str.length < 1) {
+                print("checkSyntax - empty string?\n");
+                return true;
+            }
+            
+            if (_this.file.xtype == "PlainFile") {
+            
+                // assume it's gtk...
+                   this.check_running = true;
+         
+                 if (!_this.window.windowstate.valasource.checkPlainFileSpawn(
+                  _this.file,
+                   str
+                )) {
+                    this.check_running = false;
+                }
+               
+                return true;
+            
+            }
+           if (_this.file == null) {
+               return true;
+           }
+            var p = Palete.factory(_this.file.xtype);   
+            
+        
+             
+            this.check_running = true;
+            
+            
+            if (_this.file.language == "js") {
+                this.check_running = false;
+                print("calling validate javascript\n"); 
+                return this.highlightErrors(p.validateJavascript(
+                    str, 
+                     _this.key, 
+                    _this.ptype,
+                    _this.file,
+                    _this.node
+                ));    
+                
+            }
+                
+                
+            print("calling validate vala\n");    
+            // clear the buttons.
+         
+            
+           if (! _this.window.windowstate.valasource.checkFileWithNodePropChange(
+                _this.file,
+                _this.node,
+                 _this.key,        
+                 _this.ptype,
+                    str
+                )) {
+                this.check_running = false;
+            } 
+             
+            
+            
+            //print("done mark line\n");
+             
+            return true; // at present allow saving - even if it's invalid..
+        }
+        public bool highlightErrorsJson (string type, Json.Object obj) {
+              Gtk.TextIter start;
+             Gtk.TextIter end;     
+                this.el.get_bounds (out start, out end);
+                
+                this.el.remove_source_marks (start, end, type);
+                         
+             
+             // we should highlight other types of errors..
+            
+            if (!obj.has_member(type)) {
+                print("Return has no errors\n");
+                return true;
+            }
+            
+            if (_this.window.windowstate.state != WindowState.State.CODEONLY && 
+                _this.window.windowstate.state != WindowState.State.CODE
+                ) {
+                return true;
+            } 
+            
+            
+            var err = obj.get_object_member(type);
+            
+            
+            if (_this.file == null) {
+                return true;
+            
+            }
+            var valafn = _this.file.path;
+         
+            if (_this.file.xtype != "PlainFile") {
+        
+        
+                
+                
+                 valafn = "";
+                  try {             
+                       var  regex = new Regex("\\.bjs$");
+                       // should not happen
+                      
+                     
+                        valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
+                     } catch (GLib.RegexError e) {
+                        return true;
+                    }   
+        
+        
+        
+              }
+               if (!err.has_member(valafn)) {
+                    print("File path has no errors\n");
+                    return  true;
+                }
+        
+                var lines = err.get_object_member(valafn);
+                
+                var offset = 1;
+                if (obj.has_member("line_offset")) {
+                    offset = (int)obj.get_int_member("line_offset") + 1;
+                }
+            
+        
+             
+            
+            var tlines = this.el.get_line_count () +1;
+            
+            lines.foreach_member((obj, line, node) => {
+                
+                     Gtk.TextIter iter;
+            //        print("get inter\n");
+                    var eline = int.parse(line) - offset;
+                    print("GOT ERROR on line %s -- converted to %d\n", line,eline);
+                    
+                    
+                    if (eline > tlines || eline < 0) {
+                        return;
+                    }
+                    this.el.get_iter_at_line( out iter, eline);
+                    //print("mark line\n");
+                    var msg  = "Line: %d".printf(eline+1);
+                    var ar = lines.get_array_member(line);
+                    for (var i = 0 ; i < ar.get_length(); i++) {
+                           msg += (msg.length > 0) ? "\n" : "";
+                           msg += ar.get_string_element(i);
+                   }
+                    
+                    
+                    this.el.create_source_mark(msg, type, iter);
+                } );
+                return false;
+            
+        
+        
+        
+        
+        }
+    }
+
+
+
+
 }