src/Builder4/WindowRooView.bjs
[app.Builder.js] / src / Builder4 / WindowRooView.vala
index 91904e3..6906c41 100644 (file)
@@ -933,6 +933,7 @@ public class Xcls_WindowRooView : Object
             // my vars (def)
         public bool loading;
         public bool allow_node_scroll;
+        public JsRender.Node? node;
         public string propSelected;
 
         // ctor
@@ -945,6 +946,7 @@ public class Xcls_WindowRooView : Object
             // my vars (dec)
             this.loading = true;
             this.allow_node_scroll = true;
+            this.node = null;
             this.propSelected = "";
 
             // set gobject values
@@ -1105,18 +1107,20 @@ public class Xcls_WindowRooView : Object
         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;
         
-           
+        
+               // not sure why....   
             while(Gtk.events_pending()) {
                 Gtk.main_iteration();
             }
             
+        
+            print("node selected\n");
+            var buf = this.el.get_buffer();
+            var sbuf = (Gtk.SourceBuffer) buf;
+        
            
             // clear all the marks..
             Gtk.TextIter start;
@@ -1139,6 +1143,9 @@ public class Xcls_WindowRooView : Object
             
             Gtk.TextIter cur_iter;
             sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position);
+           
+            var cursor_at_line = cur_iter.get_line();
+            
             
             //var cur_line = cur_iter.get_line();
             //if (cur_line > sel.line_start && cur_line < sel.line_end) {
@@ -1154,6 +1161,9 @@ public class Xcls_WindowRooView : Object
             
             
             this.el.editable = false;
+            
+            var colon_pos = 0;
+            
             // now if we have selected a property...
             if (this.propSelected.length> 0 ) {
         
@@ -1162,12 +1172,46 @@ public class Xcls_WindowRooView : Object
                                start_line = nstart;
                                end_line = nend;
                                this.el.editable = true;
+                               print("start line = %d, end line = %d\n", start_line, end_line);
+                               
+                                       // see if we are 'right of ':'
+                                       // get an iter for the start of the line.
+                               Gtk.TextIter start_line_iter,end_line_iter;
+                               this.el.buffer.get_iter_at_line(out start_line_iter, start_line -1);
+                               this.el.buffer.get_iter_at_line(out end_line_iter, start_line -1);
+                                
+                               
+                               
+                               
+                               if (end_line_iter.forward_to_line_end()) {
+                                       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(":");
+                                       }
+                                       print("colon_pos  = %d\n", colon_pos);
+                               }
+                               print("is cursor at line? %d ?= %d\n", start_line -1 , cursor_at_line);
+                               if (start_line - 1 == cursor_at_line) {
+                                       print("cursor is on current line.\n");
+                                       var before_cursor_string = this.el.buffer.get_text(start_line_iter, cur_iter, false);
+                                       print("before cursor string =  %s\n", before_cursor_string);
+                                       if (!before_cursor_string.contains(":")) {
+                                               this.el.editable = false;
+                                       }
+                                       
+                               }
+                               
+                               
                        }
                        print("propSelected = %s range  %d -> %d\n", this.propSelected, start_line, end_line);          
                        
                        
             }
             
+               print("checking selection\n");
+            
+            
             // check selection - if it's out of 'bounds'
             if (this.el.editable && sbuf.get_has_selection()) {
                        Gtk.TextIter sel_start_iter, sel_end_iter;
@@ -1178,6 +1222,14 @@ public class Xcls_WindowRooView : Object
                                // save?
                                this.el.editable = false;
                        }
+                       if (colon_pos > 0 &&
+                               (sel_start_iter.get_offset() < colon_pos || sel_end_iter.get_offset() < colon_pos)
+                               
+                       ) {
+                               this.el.editable = false;
+                       }
+                       
+                        
             
             }
             
@@ -1310,10 +1362,15 @@ public class Xcls_WindowRooView : Object
                
                 print("- PREVIEW EDITOR CHANGED--");
                 
+                this.dirty = true;    
+                if (!this.checkSyntax()) {
+                       return;
+               }               
                 
-                 this.checkSyntax();
+               // what are we editing??
                
-                this.dirty = true;
+               
+            
             
             
                 return ;
@@ -1370,40 +1427,29 @@ public class Xcls_WindowRooView : Object
             
             if (str.length < 1) {
                 print("checkSyntax - empty string?\n");
-                return true;
+                return false;
             }
             
            if (_this.file == null) {
-               return true;
+               return false;
            }
             var p = Palete.factory(_this.file.xtype);  // returns Roo | Gtk  | PlainFile 
             
          
             if (_this.file.language != "js") {
-                       return;
+                       return false; // fake syntax error.
                }
                
                 
         
-               var res =  this.highlightErrors(p.validateJavascript(
+               return this.highlightErrors(p.validateJavascript(
                 str, 
                  "", // _this.key, 
                 "file", //_this.ptype,
                 _this.file,
                 null
             ));    
-                
-            if (!res) { // an error in the code.. don't save it..
-                   return; 
-            }
-            
-            
-            
-                
-        
-            
              
-            return true; // at present allow saving - even if it's invalid..
         }
     }