fix init output
authorAlan <alan@roojs.com>
Thu, 9 Jun 2022 09:10:12 +0000 (17:10 +0800)
committerAlan <alan@roojs.com>
Thu, 9 Jun 2022 09:10:12 +0000 (17:10 +0800)
src/Builder4/Editor.bjs
src/Builder4/Editor.vala
src/Builder4/PopoverProperty.bjs
src/Builder4/PopoverProperty.vala
src/JsRender/NodeToVala.vala

index 53fe88d..09b381e 100644 (file)
     },
     {
      "$ xns" : "Gtk",
-     "* init" : "this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);",
+     "* init" : [
+      "this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);",
+      ""
+     ],
      "* pack" : "pack_end,true,true",
      "id" : "RightEditor",
      "items" : [
           ]
          },
          "xtype" : "SourceBuffer",
-         "| bool checkSyntax" : [
+         "|   bool checkSyntax" : [
           " () {",
           " ",
           "    if (this.check_running) {",
           "}",
           ""
          ],
+         "|   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;",
+          "}",
+          " "
+         ],
          "| bool highlightErrors" : [
           "( Gee.HashMap<int,string> validate_res) {",
           "         ",
           "",
           "}",
           ""
-         ],
-         "| 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;",
-          "}",
-          " "
          ]
         }
        ],
        },
        "uint tab_width" : 4,
        "xtype" : "SourceView",
-       "| void load" : [
+       "|   void load" : [
         " (string str) {",
         "",
         "// show the help page for the active node..",
      "xtype" : "ScrolledWindow"
     }
    ],
+   "string id" : "Editor",
    "xtype" : "Box",
+   "|   void show" : [
+    "(JsRender.JsRender file, JsRender.Node? node, JsRender.NodeProp? prop)",
+    "{",
+    "    this.reset();",
+    "    this.file = file;    ",
+    "    ",
+    "    if (file.xtype != \"PlainFile\") {",
+    "    \tthis.prop = prop;",
+    "        this.node = node;",
+    "",
+    "        // find the text for the node..",
+    "        this.view.load( prop.val );",
+    "        this.key_edit.el.show();",
+    "        this.key_edit.el.text = prop.rtype +  \" \" + prop.name;  ",
+    "    ",
+    "    } else {",
+    "        this.view.load(        file.toSource() );",
+    "        this.key_edit.el.hide();",
+    "    }",
+    " ",
+    "}"
+   ],
    "| bool saveContents" : [
     "  ()  {",
     "    ",
    ],
    "| void forwardSearch" : [
     "(bool change_focus) {",
-    " ",
+    "",
     "\tif (this.searchcontext == null) {",
     "\t\treturn;",
     "\t}",
     "\t});   ",
     "}",
     ""
-   ],
-   "| void show" : [
-    "(JsRender.JsRender file, JsRender.Node? node, JsRender.NodeProp? prop)",
-    "{",
-    "    this.reset();",
-    "    this.file = file;    ",
-    "    ",
-    "    if (file.xtype != \"PlainFile\") {",
-    "    \tthis.prop = prop;",
-    "        this.node = node;",
-    "",
-    "        // find the text for the node..",
-    "        this.view.load( prop.val );",
-    "        this.key_edit.el.show();",
-    "        this.key_edit.el.text = prop.rtype +  \" \" + prop.name;  ",
-    "    ",
-    "    } else {",
-    "        this.view.load(        file.toSource() );",
-    "        this.key_edit.el.hide();",
-    "    }",
-    " ",
-    "}"
    ]
   }
  ],
index 9b4efd1..6e09c4e 100644 (file)
@@ -20,17 +20,17 @@ public class Editor : Object
 
         // my vars (def)
     public Xcls_MainWindow window;
+    public string activeEditor;
+    public JsRender.NodeProp? prop;
     public int pos_root_x;
-    public bool dirty;
+    public JsRender.JsRender? file;
     public int pos_root_y;
-    public bool pos;
-    public Gtk.SourceSearchContext searchcontext;
     public int last_search_end;
-    public JsRender.NodeProp? prop;
-    public JsRender.JsRender? file;
-    public JsRender.Node node;
+    public Gtk.SourceSearchContext searchcontext;
+    public bool pos;
+    public bool dirty;
     public signal void save ();
-    public string activeEditor;
+    public JsRender.Node node;
 
     // ctor
     public Editor()
@@ -40,14 +40,14 @@ public class Editor : Object
 
         // my vars (dec)
         this.window = null;
-        this.dirty = false;
-        this.pos = false;
-        this.searchcontext = null;
-        this.last_search_end = 0;
+        this.activeEditor = "";
         this.prop = null;
         this.file = null;
+        this.last_search_end = 0;
+        this.searchcontext = null;
+        this.pos = false;
+        this.dirty = false;
         this.node = null;
-        this.activeEditor = "";
 
         // set gobject values
         this.el.homogeneous = false;
@@ -62,6 +62,60 @@ public class Editor : Object
     }
 
     // user defined functions
+    public void scroll_to_line (int line) {
+    
+       GLib.Timeout.add(500, () => {
+       
+               var buf = this.view.el.get_buffer();
+    
+               var sbuf = (Gtk.SourceBuffer) buf;
+    
+    
+               Gtk.TextIter iter;   
+               sbuf.get_iter_at_line(out iter,  line);
+               this.view.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);
+               return false;
+       });   
+    }
+    public int search (string txt) {
+    
+       var s = new Gtk.SourceSearchSettings();
+       
+       this.searchcontext = new Gtk.SourceSearchContext(this.buffer.el,s);
+       this.searchcontext .set_highlight(true);
+       s.set_search_text(txt);
+       Gtk.TextIter beg, st,en;
+        
+       this.buffer.el.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 show (JsRender.JsRender file, JsRender.Node? node, JsRender.NodeProp? prop)
+    {
+        this.reset();
+        this.file = file;    
+        
+        if (file.xtype != "PlainFile") {
+               this.prop = prop;
+            this.node = node;
+    
+            // find the text for the node..
+            this.view.load( prop.val );
+            this.key_edit.el.show();
+            this.key_edit.el.text = prop.rtype +  " " + prop.name;  
+        
+        } else {
+            this.view.load(        file.toSource() );
+            this.key_edit.el.hide();
+        }
+     
+    }
     public bool saveContents ()  {
         
         
@@ -97,7 +151,7 @@ public class Editor : Object
     
     }
     public void forwardSearch (bool change_focus) {
-     
+    
        if (this.searchcontext == null) {
                return;
        }
@@ -117,45 +171,6 @@ public class Editor : Object
                this.view.el.scroll_to_iter(st,  0.1f, true, 0.0f, 0.5f);
        }
      
-    }
-    public void show (JsRender.JsRender file, JsRender.Node? node, JsRender.NodeProp? prop)
-    {
-        this.reset();
-        this.file = file;    
-        
-        if (file.xtype != "PlainFile") {
-               this.prop = prop;
-            this.node = node;
-    
-            // find the text for the node..
-            this.view.load( prop.val );
-            this.key_edit.el.show();
-            this.key_edit.el.text = prop.rtype +  " " + prop.name;  
-        
-        } else {
-            this.view.load(        file.toSource() );
-            this.key_edit.el.hide();
-        }
-     
-    }
-    public int search (string txt) {
-    
-       var s = new Gtk.SourceSearchSettings();
-       
-       this.searchcontext = new Gtk.SourceSearchContext(this.buffer.el,s);
-       this.searchcontext .set_highlight(true);
-       s.set_search_text(txt);
-       Gtk.TextIter beg, st,en;
-        
-       this.buffer.el.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 reset () {
         this.file = null;    
@@ -165,21 +180,6 @@ public class Editor : Object
        this.searchcontext = null;
       
     }
-    public void scroll_to_line (int line) {
-    
-       GLib.Timeout.add(500, () => {
-       
-               var buf = this.view.el.get_buffer();
-    
-               var sbuf = (Gtk.SourceBuffer) buf;
-    
-    
-               Gtk.TextIter iter;   
-               sbuf.get_iter_at_line(out iter,  line);
-               this.view.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);
-               return false;
-       });   
-    }
     public class Xcls_Box2 : Object
     {
         public Gtk.Box el;
@@ -287,6 +287,13 @@ public class Editor : Object
             this.el.digits = 0;
             this.el.sensitive = true;
 
+            // init method
+
+            {
+               this.el.set_range(6,30);
+               this.el.set_value(8);
+            }
+
             //listeners
             this.el.change_value.connect( (st, val ) => {
                 
@@ -323,6 +330,10 @@ public class Editor : Object
             var child_0 = new Xcls_view( _this );
             child_0.ref();
             this.el.add (  child_0.el  );
+
+            // init method
+
+            this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
         }
 
         // user defined functions
@@ -357,6 +368,61 @@ public class Editor : Object
             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);
+            
+               try {        
+                       this.el.completion.add_provider(new Palete.CompletionProvider(_this));
+                } catch (GLib.Error  e) {}
+                
+               this.el.completion.unblock_interactive();
+               this.el.completion.select_on_show                       = true; // select
+               this.el.completion.show_headers                 = false;
+               this.el.completion.remember_info_visibility             = true;
+                
+              
+                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);
+
             //listeners
             this.el.key_release_event.connect( (event) => {
                 
@@ -373,7 +439,7 @@ public class Editor : Object
         }
 
         // user defined functions
-        public void load (string str) {
+        public   void load (string str) {
         
         // show the help page for the active node..
            //this.get('/Help').show();
@@ -416,8 +482,8 @@ public class Editor : Object
 
 
             // my vars (def)
-        public int error_line;
         public bool check_queued;
+        public int error_line;
         public bool check_running;
 
         // ctor
@@ -428,8 +494,8 @@ public class Editor : Object
             this.el = new Gtk.SourceBuffer( null );
 
             // my vars (dec)
-            this.error_line = -1;
             this.check_queued = false;
+            this.error_line = -1;
             this.check_running = false;
 
             // set gobject values
@@ -450,7 +516,30 @@ public class Editor : Object
         }
 
         // user defined functions
-        public bool checkSyntax () {
+        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   bool checkSyntax () {
          
             if (this.check_running) {
                 print("Check is running\n");
@@ -545,6 +634,16 @@ public class Editor : Object
              
             return true; // at present allow saving - even if it's invalid..
         }
+        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 highlightErrorsJson (string type, Json.Object obj) {
               Gtk.TextIter start;
              Gtk.TextIter end;     
@@ -641,39 +740,6 @@ public class Editor : Object
         
         
         
-        }
-        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;
         }
     }
 
index dd482eb..a01b8a1 100644 (file)
    "listeners" : {
     "closed" : [
      "() => {",
+     "",
      " \tGLib.debug(\"popover closed\");",
      "\tif (_this.is_new) {",
      "\t\t// dont allow hiding if we are creating a new one.",
index 526b746..87f502d 100644 (file)
@@ -52,6 +52,7 @@ public class Xcls_PopoverProperty : Object
 
         //listeners
         this.el.closed.connect( () => {
+        
                GLib.debug("popover closed");
                if (_this.is_new) {
                        // dont allow hiding if we are creating a new one.
index 770e506..91a91fe 100644 (file)
@@ -730,7 +730,7 @@ public class JsRender.NodeToVala : Object {
        {
 
                
-               if (!this.node.has("init")) {
+               if (!this.node.has("init")) {
                                return;
                }
                this.addLine();
@@ -738,8 +738,10 @@ public class JsRender.NodeToVala : Object {
                this.addLine();
                this.node.setLine(this.cur_line, "p", "init");
                
-               this.addMultiLine(ipad + this.padMultiline(ipad, this.node.get("init")) );
-
+               var init =  this.node.get_prop("* init");
+               init.start_line = this.cur_line;
+               this.addMultiLine(ipad + this.padMultiline(ipad, init.val) );
+               init.end_line = this.cur_line;
         }
         void addListeners()
         {