resources/RooUsage.txt
[app.Builder.js] / src / JsRender / JsRender.vala
index 92a8e48..db19fe2 100644 (file)
@@ -27,6 +27,7 @@ namespace JsRender {
 
                public string permname;
                public string language;
+               public string content_type;
                public string modOrder;
                public string xtype;
                public uint64 webkit_page_id; // set by webkit view - used to extract extension/etc..
@@ -40,11 +41,15 @@ namespace JsRender {
 
                public bool hasParent; 
                
+               public bool loaded;
+               
                public Gee.HashMap<string,string> transStrings; // map of md5 -> string.
                
 
                public signal void changed (Node? node, string source); 
-
+               
+                
+               public signal void compile_notice(string type, string file, int line, string message);
                /**
                 * UI componenets
                 * 
@@ -66,8 +71,10 @@ namespace JsRender {
                        this.permname = "";
                        this.modOrder = "";
                        this.language = "";
+                       this.content_type = "";
                        this.build_module = "";
-                       print("JsRender.cto() - reset transStrings\n");
+                       this.loaded = false;
+                       //print("JsRender.cto() - reset transStrings\n");
                        this.transStrings = new Gee.HashMap<string,string> ();
                        
                        // should use basename reallly...
@@ -78,7 +85,7 @@ namespace JsRender {
                                Regex regex = new Regex ("\\.(bjs|js)$");
 
                                this.name = ar.length > 0 ? regex.replace(ar[ar.length-1],ar[ar.length-1].length, 0 , "") : "";
-                       } catch (Error e) {
+                       } catch (GLib.Error e) {
                                this.name = "???";
                        }
                        this.fullname = (this.parent.length > 0 ? (this.parent + ".") : "" ) + this.name;
@@ -87,9 +94,11 @@ namespace JsRender {
 
                }
                
-               public void renameTo(string name) 
+               public void renameTo(string name) throws  Error
                {
-                       
+                       if (this.xtype == "PlainFile") {
+                               return;
+                       }
                        var bjs = GLib.Path.get_dirname(this.path) +"/" +  name + ".bjs";
                        if (FileUtils.test(bjs, FileTest.EXISTS)) {
                                throw new Error.RENAME_FILE_EXISTS("File exists %s\n",name);
@@ -107,7 +116,7 @@ namespace JsRender {
                
                // not sure why xt is needed... -> project contains xtype..
                
-               public static JsRender factory(string xt, Project.Project project, string path)
+               public static JsRender factory(string xt, Project.Project project, string path) throws Error
                {
         
                        switch (xt) {
@@ -115,13 +124,18 @@ namespace JsRender {
                                        return new Gtk(project, path);
                                case "Roo":
                                        return new Roo(project, path);
+                               case "PlainFile":
+                                       return new PlainFile(project, path);
                        }
                        throw new Error.INVALID_FORMAT("JsRender Factory called with xtype=%s", xt);
-                       return null;    
+                       //return null;    
                }
 
                public string toJsonString()
                {
+                       if (this.xtype == "PlainFile") {
+                               return "";
+                       }
                        var generator = new Json.Generator ();
                        generator.indent = 4;
                        generator.pretty = true;
@@ -155,8 +169,12 @@ namespace JsRender {
                        var m5 = GLib.Checksum.compute_for_string(GLib.ChecksumType.MD5,this.path); 
 
                        var dir = GLib.Environment.get_home_dir() + "/.Builder/icons";
-                       if (!FileUtils.test(dir, FileTest.IS_DIR)) {
-                                File.new_for_path(dir).make_directory();
+                       try {
+                               if (!FileUtils.test(dir, FileTest.IS_DIR)) {
+                                        File.new_for_path(dir).make_directory();
+                               }
+                       } catch (GLib.Error e) {
+                               // eakk.. what to do here...
                        }
                        var fname = dir + "/" + m5 + ".png";
                        
@@ -178,7 +196,12 @@ namespace JsRender {
 
                public void saveBJS()
                {
-                    
+                   if (!this.loaded) {
+                           return;
+                   }
+                   if (this.xtype == "PlainFile") {
+                           return;
+                   }
                    var generator = new Json.Generator ();
                    generator.indent = 1;
                    generator.pretty = true;
@@ -198,64 +221,10 @@ namespace JsRender {
                 
 
                public abstract void loadItems() throws GLib.Error;
-               
-               /**
-                *
-                * load from a javascript file.. rather than bjs..
-                * 
-                *
-                */
-                /*
-               _loadItems : function(cb)
-               {
-                   // already loaded..
-                   if (this.items !== false) {
-                       return false;
-                   }
-                     
-                   
-                   
-                   var tr = new  TokenReader(  { 
-                       keepDocs :true, 
-                       keepWhite : true,  
-                       keepComments : true, 
-                       sepIdents : false,
-                       collapseWhite : false,
-                       filename : args[0],
-                       ignoreBadGrammer: true
-                   });
-                   
-                   var str = File.read(this.path);
-                   var toks = tr.tokenize(new TextStream(str));  
-                   var rf = new JsParser(toks);
-                   rf.parse();
-                   var cfg = rf.cfg;
-                   
-                   this.modOrder = cfg.modOrder || '001';
-                   this.name = cfg.name.replace(/\.bjs/, ''); // BC!
-                   this.parent =  cfg.parent;
-                   this.permname =  cfg.permname || '';
-                   this.title =  cfg.title || cfg.name;;
-                   this.items = cfg.items || []; 
-                   //???
-                   //this.fixItems(_this, false);
-                   cb();
-                   return true;    
-                       
-               },
-               */
-                   /**
-                    * accepts:
-                    * { success : , failure : , scope : }
-                    * 
-                    * 
-                    * 
-                    */
-               /*     
-               void getTree ( o ) {
-                   print("File.getTree tree called on base object?!?!");
-               }
-       */
+                
+                
+                
+                 
                public string jsonHasOrEmpty(Json.Object obj, string key) {
                        return obj.has_member(key) ? 
                                                obj.get_string_member(key) : "";
@@ -267,6 +236,10 @@ namespace JsRender {
                    
                    
                        var ret = new Json.Object();
+                       if (this.xtype == "PlainFile") {
+                               return ret;
+                       }
+                       
                        //ret.set_string_member("id", this.id); // not relivant..
                        ret.set_string_member("name", this.name);
                        ret.set_string_member("parent", this.parent == null ? "" : this.parent);
@@ -275,7 +248,7 @@ namespace JsRender {
                        //ret.set_string_member("items", this.items);
                        ret.set_string_member("permname", this.permname  == null ? "" : this.permname);
                        ret.set_string_member("modOrder", this.modOrder  == null ? "" : this.modOrder);
-                       if (this.xtype == "Gtk") {
+                       if (this.project.xtype == "Gtk") {
                                ret.set_string_member("build_module", this.build_module  == null ? "" : this.build_module);
                        }
                        
@@ -330,7 +303,8 @@ namespace JsRender {
 
                public Palete.Palete palete()
                {
-                       return Palete.factory(this.xtype);
+                       // error on plainfile?
+                       return Palete.factory(this.project.xtype);
 
                }
                
@@ -359,48 +333,25 @@ namespace JsRender {
                        data_out.put_string(contents, null);
                        data_out.close(null);
                }
-               /*
-               copyTo: function(path, cb)
-               {
-                   var _this = this;
-                   this.loadItems(function() {
-                       
-                       _this.path = path;
-                       cb();
-                   });
-                   
-               },
-               */
+                
                
-               /**
-                * 
-                * munge JSON tree into Javascript code.
-                *
-                * NOTE - needs a deep copy of original tree, before starting..
-                *     - so that it does not modify current..
-                * 
-                * FIXME: + or / prefixes to properties hide it from renderer.
-                * FIXME: '*props' - not supported by this.. ?? - upto rendering code..
-                * FIXME: needs to understand what properties might be translatable (eg. double quotes)
-                * 
-                * @arg {object} obj the object or array to munge..
-                * @arg {boolean} isListener - is the array being sent a listener..
-                * @arg {string} pad - the padding to indent with. 
-                */
                
-               public string mungeToString(string pad)
+               public  Node? lineToNode(int line)
                {
                        if (this.tree == null) {
-                               return "";
+                               return null;
                        }
-                       var x = new NodeToJs(this.tree, this.doubleStringProps, pad);
-                       return x.munge();
+                       return this.tree.lineToNode(line);
+                       
                        
-                   
                }
+               
+               
                public abstract void save();
                public abstract void saveHTML(string html);
                public abstract string toSource() ;
+               public abstract string toSourceCode() ; // used by commandline tester..
+               public abstract void setSource(string str);
                public abstract string toSourcePreview() ;
                public abstract void removeFiles() ;
                 public abstract void  findTransStrings(Node? node );