Fix #8004 - try and fix start line / end line cached node output
[roobuilder] / src / JsRender / Roo.vala
index dda1b04..c6ba188 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";
             
@@ -61,6 +63,10 @@ namespace JsRender {
                 "header",
                 "placeholder",
                 "fieldLabel",
+                "emptyTitle",
+                "dialogTitle",
+                "modalTitle",
+                "boxLabel"
                 
                 };
             for (var i=0;i<dsp.length;i++) {
@@ -109,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;
 
@@ -132,57 +140,74 @@ 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.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.roo_project.runhtml);                 
+               if (this.roo_project.runhtml == "") {
+                       return;
+               }
                 
                var top = this.tree.fqn();
                GLib.debug ("TOP = " + top + "\n" );
@@ -218,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");
                }
             
@@ -230,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;
                                
@@ -255,6 +281,9 @@ namespace JsRender {
                                return;
                        }               
                        
+                       var named = new Gee.HashMap<string,string>();
+                       var name_prefix = "";
+                       
                        var iter = node.props.map_iterator();
                        while (iter.next()) {
                                // key formats : XXXX
@@ -262,42 +291,53 @@ 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 = prop.val;
+                               if (kname == "name") {
+                                       name_prefix = str;
+                               }
+                               
+                               var chksum = GLib.Checksum.compute_for_string (ChecksumType.MD5, str.strip());
                                
-                               var str = iter.get_value();
                                if (this.doubleStringProps.index_of(kname) > -1) {
-                                       GLib.debug("flag=%s type=%s name=%s : %s\n", kflag,ktype,kname,str);
-                                       this.transStrings.set(str,  
-                                               GLib.Checksum.compute_for_string (ChecksumType.MD5, str.strip())
-                                       );
+                                       //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);
-                                       this.transStrings.set(str,  
-                                               GLib.Checksum.compute_for_string (ChecksumType.MD5, str.strip())
-                                       );
+                                       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 (name_prefix != "") {
+                               var niter = named.map_iterator();
+                               while (niter.next()) {
+                                       this.namedStrings.set(name_prefix + niter.get_key(),niter.get_value());
+                               }
+                        }
 
-                       
+                       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) );
                        }
                
                                
@@ -313,20 +353,35 @@ namespace JsRender {
                        }
                         
                        string[] kvs = {};
+                       
+                       var hash = new Gee.HashMap<string,string>();
                        var iter = this.transStrings.map_iterator();
                        while (iter.next()) {
+                               hash.set(iter.get_value(), iter.get_key());
                                kvs +=  ("  '" + iter.get_value() + "' :" + 
                                        this.tree.quoteString(iter.get_key())
                                        );
                        }
-                       return " _strings : {\n" + string.joinv(",\n", kvs) + "\n" + 
-                               " },";
-                               
-                
-              
                        
-               }
-                 
+                       var ret = " _strings : {\n" + string.joinv(",\n", kvs) + "\n },";
+
+                       
+                       string[] ns = {};
+                       var niter = this.namedStrings.map_iterator();
+                       while (niter.next()) {
+                               var otext = hash.get(niter.get_value());
+                               var com = " /* " + (otext.replace("*/", "* - /") + " */ ");
+
+                       
+                               ns +=  ("  '" + niter.get_key() + "' : '" + niter.get_value() + "'" + com); 
+                       }
+                       if (ns.length > 0 ) {
+                               ret += "\n _named_strings : {\n" + string.joinv(",\n", ns) + "\n },";
+                       }
+                       return ret;
+               }       
+                
+             
         /**
         * javascript used in Webkit preview 
          */
@@ -335,7 +390,7 @@ namespace JsRender {
         {
                        print("toSourcePreview() - reset transStrings\n");
                        this.transStrings = new Gee.HashMap<string,string>();
-                       
+                       this.namedStrings = new Gee.HashMap<string,string>();
                
                        print("to source preview\n");
                        if (this.tree == null) {
@@ -351,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) {}
                                        
                                }
 
@@ -386,7 +442,9 @@ namespace JsRender {
                        if (top.contains("Modal")) {
                                return prefix_data + this.toSourceModal(true);
                        }
-
+                       if (top.contains("Popover")) {
+                               return prefix_data + this.toSourceModal(true);
+                       }
                        return prefix_data + this.toSourceLayout(true);
                                
                                
@@ -404,6 +462,7 @@ namespace JsRender {
         public override string toSourceCode() 
         {
                        this.transStrings = new Gee.HashMap<string,string>();
+                       this.namedStrings = new Gee.HashMap<string,string>();
                        this.findTransStrings(this.tree);
                        return this.toSource();
                }
@@ -428,6 +487,7 @@ namespace JsRender {
             
             // get the translatable strings.. = we reload them again so calling methods get the right data...
             this.transStrings = new Gee.HashMap<string,string>();
+            this.namedStrings = new Gee.HashMap<string,string>();
                        this.findTransStrings(this.tree);
             
             
@@ -438,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);
             
             /*
@@ -468,17 +533,11 @@ namespace JsRender {
                        if (this.tree == null) {
                                return "";
                        }
-                       var x = new NodeToJs(this.tree, this.doubleStringProps, pad, null);
-                       x.renderer = this;
-                       x.cur_line = prefix.split("\n").length;
-                       
+
+                       var x = new NodeToJs( this,  this.tree,   pad , null, this.doubleStringProps);
+                       x.addMultiLine(prefix, false); 
                        var ret = x.munge();
-                       //var nret = x.ret;
-                       
-                       // output both files.. so we can diff them...
-                       //this.writeFile("/tmp/old.js", ret);
-                       //this.writeFile("/tmp/new.js", nret);                  
-                       return prefix +  ret + suffix;
+                       return  ret + suffix;
                        
                    
                }
@@ -533,7 +592,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);",
@@ -604,7 +663,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);",
@@ -729,47 +788,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";
+               }
      
     }
 }