src/Builder4/WindowRooView.bjs
[app.Builder.js] / src / Builder4 / WindowRooView.vala
index 666263e..c53d05e 100644 (file)
@@ -1031,6 +1031,10 @@ public class Xcls_WindowRooView : Object
             
                return false;
             });
+            this.el.key_press_event.connect( () => {
+               this.onCursorChanged();
+               return false; 
+            });
         }
 
         // user defined functions
@@ -1105,7 +1109,16 @@ public class Xcls_WindowRooView : Object
                 // highlight the node..
         }
         public void clearGreySelection () {
-        
+         // clear all the marks..
+            var sbuf = (Gtk.SourceBuffer)this.el.buffer;
+            
+            Gtk.TextIter start;
+            Gtk.TextIter end;     
+                
+            sbuf.get_bounds (out start, out end);
+            sbuf.remove_source_marks (start, end, "grey");
+            
+            
         }
         public void nodeSelected (JsRender.Node? sel, bool scroll ) {
           
@@ -1120,20 +1133,89 @@ public class Xcls_WindowRooView : Object
             }
             
             this.node_selected = sel;
-        
-            print("node selected\n");
+            
+            this.updateGreySelection(scroll);
+        }
+        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;
         
-           
-            // clear all the marks..
+            
+        
+            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, "grey");
-            
+            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();
+                       _this.buffer.checkSyntax();
+                       return false;
+               });
+                       
+            this.loading = false; 
+            _this.buffer.dirty = false;
+        }
+        public void updateGreySelection (bool scroll) { 
+               var sel = this.node_selected;
+               print("node selected\n");
+            var buf = this.el.get_buffer();
+            var sbuf = (Gtk.SourceBuffer) buf;
+        
+           
+           this.clearGreySelection();
+           
+           
+           
              if (sel == null) {
                     print("no selected node\n");
                 // no highlighting..
@@ -1191,7 +1273,7 @@ public class Xcls_WindowRooView : Object
                                        var first_line  = this.el.buffer.get_text(start_line_iter, end_line_iter, false);
                                        print("first line = %s\n", first_line);
                                        if (first_line.contains(":")) {
-                                               colon_pos = start_line_iter.get_offset() + first_line.index_of(":");
+                                               colon_pos = start_line_iter.get_offset() + first_line.index_of(":") + 1;
                                        }
                                        print("colon_pos  = %d\n", colon_pos);
                                }
@@ -1252,78 +1334,65 @@ public class Xcls_WindowRooView : Object
             
         
         }
-        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;
+        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..
             
-           print("BEFORE LOAD cursor = %d\n", cpos);
-           
-            var vadj_pos = this.el.get_vadjustment().get_value();
-           
+            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?
+            }
          
-            buf.set_text("",0);
-            var sbuf = (Gtk.SourceBuffer) buf;
         
-            
+            print("checking for errors in " + _this.file.path);
         
-            if (_this.file == null || _this.file.xtype != "Roo") {
-                print("xtype != Roo");
-                this.loading = false;
-                return;
+           if (!err.has_member(_this.file.path)) {
+                print("File path has no errors\n");
+                return  ;
             }
+            var lines = err.get_object_member(_this.file.path);
             
-            // 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));
-          
+            var tlines = buf.get_line_count () +1;
             
-            Gtk.TextIter start;
-            Gtk.TextIter end;     
+            lines.foreach_member((obj, line, node) => {
                 
-            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();
-                       _this.buffer.checkSyntax();
-                       return false;
-               });
-                       
-            this.loading = false; 
-            _this.buffer.dirty = false;
-        }
-        public void highlightErrorsJson (string type, Json.Object obj) {
-               // this is a hook for the vala code - it has no value in javascript 
-               // as we only have one error ususally....
+                     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  ".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);
+                               }
+                    
+                    
+                    sbuf.create_source_mark(msg, type, iter);
+                } );
                 return  ;
             
          
@@ -1365,7 +1434,7 @@ public class Xcls_WindowRooView : Object
                }
                
                 print("- PREVIEW EDITOR CHANGED--");
-                
+            
                 this.dirty = true;    
                 if (!this.checkSyntax()) {
                        return;
@@ -1373,7 +1442,7 @@ public class Xcls_WindowRooView : Object
                 
                // what are we editing??
                
-               
+            
             
             
             
@@ -1445,14 +1514,16 @@ public class Xcls_WindowRooView : Object
                }
                
                 
-        
-               return this.highlightErrors(p.validateJavascript(
+         
+               return p.javascriptHasErrors(
+                       _this.main_window.windowstate,
                 str, 
                  "", // _this.key, 
                 "file", //_this.ptype,
                 _this.file,
+                null,
                 null
-            ));    
+            );    
              
         }
     }