fix #7968 - language server support for syntax check and completion
[roobuilder] / src / JsRender / Roo.vala
index 5946e86..582984d 100644 (file)
@@ -18,13 +18,15 @@ namespace JsRender {
    
     class Roo : JsRender 
     {
-        string region;
+         
         bool disabled;
 
  
         
-        public Roo(Project.Project project, string path) {
+        public Roo(Project.Roo project, string path) 
+        {
             base( project, path);
             this.xtype = "Roo";
              this.language = "js";
             
@@ -113,7 +115,9 @@ namespace JsRender {
                        this.permname = this.jsonHasOrEmpty(obj, "permname");
                        this.title = this.jsonHasOrEmpty(obj, "title");
                        this.modOrder = this.jsonHasOrEmpty(obj, "modOrder");
-
+                       if (obj.has_member("gen_extended")) { // should check type really..
+                               this.gen_extended = obj.get_boolean_member("gen_extended");
+                       }
                        var bjs_version_str = this.jsonHasOrEmpty(obj, "bjs-version");
                        bjs_version_str = bjs_version_str == "" ? "1" : bjs_version_str;
 
@@ -136,60 +140,72 @@ namespace JsRender {
             
         }
         
-        
-       public  override  void save()
-       {
-            
-               GLib.debug("--- JsRender.Roo.save");
-               GLib.debug("save() - reset transStrings\n");
-               this.transStrings = new Gee.HashMap<string,string>();
-               this.namedStrings = new Gee.HashMap<string,string>();
-               this.findTransStrings(this.tree);
-               
-               this.saveBJS();
+               public override string targetName()
+               {
+                       string js;
+                       try {
+                               Regex regex = new Regex("\\.(bjs|js)$");
 
-               // no tree..
-               if (this.tree == null) {
-                       return;
+                               js = regex.replace(this.path,this.path.length , 0 , ".js");
+                               return js;
+                       } catch (RegexError e) {
+                               this.name = "???";
+                               print("count not make filename from path");
+                               return this.name + ".js";
+                       }
+                       
                }
-               // now write the js file..
-               string js;
-               try {
-                       Regex regex = new Regex("\\.(bjs|js)$");
+               public  override  void save()
+               {
+                       
+                       GLib.debug("--- JsRender.Roo.save");
+                       GLib.debug("save() - reset transStrings\n");
+                       this.transStrings = new Gee.HashMap<string,string>();
+                       this.namedStrings = new Gee.HashMap<string,string>();
+                       this.findTransStrings(this.tree);
+                       
+                       this.saveBJS();
 
-                       js = regex.replace(this.path,this.path.length , 0 , ".js");
-               } catch (RegexError e) {
-                       this.name = "???";
-                       print("count not make filename from path");
-                       return;
-               }
+                       // no tree..
+                       if (this.tree == null) {
+                               return;
+                       }
+                       // now write the js file..
+                       var  js = this.targetName();
+                        
 
 
-               //var d = new Date();
-               var js_src = this.toSource();            
-               //print("TO SOURCE in " + ((new Date()) - d) + "ms");
-               try {
-                       this.writeFile(js, js_src);            
-               } catch (FileError e ) {
-                       print("Save failed\n");
+                       //var d = new Date();
+                       var js_src = this.toSource();            
+                       //print("TO SOURCE in " + ((new Date()) - d) + "ms");
+                       try {
+                               this.writeFile(js, js_src);            
+                       } catch (GLib.Error e ) {
+                               print("Save failed\n");
+                       }
+                       // for bootstrap - we can write the HTML to the templates directory..
+                                
+                       //var top = this.guessName(this.items[0]);
+                       //print ("TOP = " + top)
+                        
+                       
+                       
+                       
                }
-               // for bootstrap - we can write the HTML to the templates directory..
-                
-            //var top = this.guessName(this.items[0]);
-            //print ("TOP = " + top)
-             
-            
-            
-            
-       }
 
-        
+        public Project.Roo roo_project {
+               set {}  
+               get { 
+                       return (Project.Roo) this.project;
+               }
+       }
+                       
 
         
        public override void saveHTML ( string html )
        {
-               GLib.debug ("SAVEHTML %s\n",  this.project.runhtml);             
-               if (this.project.runhtml == "") {
+               GLib.debug ("SAVEHTML %s\n",  this.roo_project.runhtml);                 
+               if (this.roo_project.runhtml == "") {
                        return;
                }
                 
@@ -227,7 +243,7 @@ namespace JsRender {
           print("SAVE HTML (%d) -- %s\n",html.length, targetdir + "/" +  bn);
                try {
                        this.writeFile(targetdir + "/" +  bn , html);            
-               } catch (FileError e ) {
+               } catch (GLib.Error e ) {
                        print("SaveHtml failed\n");
                }
             
@@ -239,10 +255,11 @@ namespace JsRender {
                {
                        
                        if (node.props.has_key("* xinclude")) {
-                               ret.add(node.props.get("* xinclude"));
+                               ret.add(node.props.get("* xinclude").val);
                        }
-                       for (var i =0; i < node.items.size; i++) {
-                               this.findxincludes(node.items.get(i), ret);
+                       var items = node.readItems();
+                       for (var i =0; i < items.size; i++) {
+                               this.findxincludes(items.get(i), ret);
                        }
                        return ret;
                                
@@ -274,18 +291,21 @@ namespace JsRender {
                                // string XXX - with type
                                // $ XXX - with flag (no type)
                                // $ string XXX - with flag
-                               string kname;
-                               string ktype;
-                               string kflag;
-                               node.normalize_key(iter.get_key(), out kname, out kflag, out ktype);
-                               if (kflag == "$") {
+                               
+                               
+                               var prop = iter.get_value();
+                               var kname = prop.name;
+                               var ktype = prop.rtype;
+
+
+                               if (prop.ptype == NodePropType.RAW) {
                                        continue;
                                }
                                // skip cms-id nodes...
                                if (kname == "html" && node.has("cms-id")) { 
                                        continue;
                                }
-                               var str = iter.get_value();                             
+                               var str = prop.val;
                                if (kname == "name") {
                                        name_prefix = str;
                                }
@@ -293,14 +313,14 @@ namespace JsRender {
                                var chksum = GLib.Checksum.compute_for_string (ChecksumType.MD5, str.strip());
                                
                                if (this.doubleStringProps.index_of(kname) > -1) {
-                                       GLib.debug("flag=%s type=%s name=%s : %s\n", kflag,ktype,kname,str);
+                                       //GLib.debug("flag=%s type=%s name=%s : %s\n", prop.ptype.to_string(),ktype,kname,str);
                                        this.transStrings.set(str,  chksum);
                                        named.set("_" + kname, chksum);
                                        continue;
                                }
                                
                                if (ktype.down() == "string" && kname[0] == '_') {
-                                       GLib.debug("flag=%s type=%s name=%s : %s\n", kflag,ktype,kname,str);
+                                       GLib.debug("flag=%s type=%s name=%s : %s\n", prop.ptype.to_string(),ktype,kname,str);
                                        this.transStrings.set(str,   chksum);
                                        named.set(kname, chksum);
                                        continue;
@@ -314,10 +334,10 @@ namespace JsRender {
                                }
                         }
 
-                       
+                       var items = node.readItems();
                        // iterate children..
-                       for (var i =0; i < node.items.size; i++) {
-                               this.findTransStrings(node.items.get(i) );
+                       for (var i =0; i < items.size; i++) {
+                               this.findTransStrings(items.get(i) );
                        }
                
                                
@@ -386,19 +406,20 @@ namespace JsRender {
                        if (xinc.size > 0 ) {
                                for(var i = 0; i < xinc.size; i++) {
                                        print("check xinclude:  %s\n", xinc.get(i));
-                                       var sf = this.project.getByName(xinc.get(i));
+                                       var sf = this.project.getByRelPath(xinc.get(i));
                                        if (sf == null) {
                                                print("Failed to find file by name?\n");
                                                continue;
                                        }
-
-                                       sf.loadItems();
-                                       sf.findTransStrings(sf.tree);
-                                       var xinc_str = sf.toSource();
-                                       
-                                       //string xinc_str;
-                                       //FileUtils.get_contents(js, out xinc_str);
-                                       prefix_data += "\n" + xinc_str + "\n";
+                                       try {
+                                               sf.loadItems();
+                                               sf.findTransStrings(sf.tree);
+                                               var xinc_str = sf.toSource();
+                                               
+                                               //string xinc_str;
+                                               //FileUtils.get_contents(js, out xinc_str);
+                                               prefix_data += "\n" + xinc_str + "\n";
+                                       } catch (GLib.Error e) {}
                                        
                                }
 
@@ -477,6 +498,11 @@ namespace JsRender {
             if (top.contains("Modal")) {
                 return this.toSourceModal(false);
             }
+            
+            if (top.contains("Popover")) {
+                return this.toSourceModal(false);
+            }
+            
             return this.toSourceLayout(false);
             
             /*
@@ -572,7 +598,7 @@ namespace JsRender {
                 "",
                 "  this.callback = cb;",
                 "  this.data = data;",
-                "  this.dialog.show(this.data._el);",
+                "  this.dialog.show.apply(this.dialog,  Array.prototype.slice.call(arguments).slice(2));",
                 "  if (this.form) {",
                 "   this.form.reset();",
                 "   this.form.setValues(data);",
@@ -643,7 +669,7 @@ namespace JsRender {
                 "",
                 "  this.callback = cb;",
                 "  this.data = data;",
-                "  this.dialog.show(this.data._el);",
+                "  this.dialog.show.apply(this.dialog,  Array.prototype.slice.call(arguments).slice(2));",
                 "  if (this.form) {",
                 "   this.form.reset();",
                 "   this.form.setValues(data);",
@@ -768,47 +794,15 @@ namespace JsRender {
               
         }
             
-        public new string? guessName (Node? ar) // turns the object into full name.
-        {
-             // eg. xns: Roo, xtype: XXX -> Roo.xxx
-            if (ar == null) {
-                return null;
-            }
-            
-            string[] ret = {} ;
-            ret += (ar.get("|xns").length < 1 ? "Roo": ar.get("|xns"));
-             
-            
-            if ( ar.get("xtype").length < 1) {
-                return null;
-            }
-                    
-            var xtype = ar.get("xtype");
-
-            if (xtype[0] == '*') { // prefixes????
-                xtype  = xtype.substring(1);
-            }
-            if (! Regex.match_simple("^Roo", xtype)) {
-                
-                // already starts with roo...
-                ret = {};
-            }
-            ret += xtype;
-            var str =  string.joinv(".", ret);
-            
-            return str;
-           // 
-            //Palete.Palete.factory("Roo").guessName(str);
-            
-                            
-                                 
-        }
         
-        string getHelpUrl(string cls)
-        {
-            return "http://www.roojs.com/roojs1/docs/symbols/" + cls + ".html";
-        }
-                
+                public override string toGlade() 
+               {
+                       return "Roo files do not convert to glade";
+               }
+               public   override string language_id() 
+               {
+                       return "javascript";
+               }
      
     }
 }