X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=src%2FJsRender%2FNode.vala;h=cd101190f84b60f4572a2e350cae2d9021e8df46;hb=HEAD;hp=aeb8d840ca965da558852ab5a979ddf1ec460f47;hpb=b831b51b5e50a9d89cdb5dfe46a1fccfc106d148;p=app.Builder.js diff --git a/src/JsRender/Node.vala b/src/JsRender/Node.vala index aeb8d840c..cd101190f 100644 --- a/src/JsRender/Node.vala +++ b/src/JsRender/Node.vala @@ -60,7 +60,7 @@ * special ID values * +XXXX -- indicates it's a instance property / not glob... * *XXXX -- skip writing glob property (used as classes that can be created...) - * + * _XXXX -- (string) a translatable string. * * * FORMATING? @@ -102,8 +102,15 @@ public class JsRender.Node : Object { public string xvala_cls; public string xvala_xcls; // 'Xcls_' + id; public string xvala_id; // item id or "" - - + + // line markers.. + public int line_start; + public int line_end; + public Gee.ArrayList lines; + public Gee.HashMap line_map; // store of l:xxx or p:.... + public Gee.ArrayList node_lines; + public Gee.HashMap node_lines_map; // store of l:xxx or p:.... + public Node() { @@ -114,8 +121,158 @@ public class JsRender.Node : Object { this.xvala_xcls = ""; this.xvala_id = ""; this.parent = null; + this.line_start = -1; + this.line_end = -1; + this.lines = new Gee.ArrayList(); + this.line_map = new Gee.HashMap(); + this.node_lines = new Gee.ArrayList(); + this.node_lines_map = new Gee.HashMap(); + + } + + public void setNodeLine(int line, Node node) { + //print("Add node @ %d\n", line); + if (this.node_lines_map.has_key(line)) { + return; + } + this.node_lines.add(line); + this.node_lines_map.set(line, node); + } + + public void setLine(int line, string type, string prop) { + if (this.line_map.has_key(line)) { + if (this.line_map.get(line) != "e:" ) { + return; + } + } else { + this.lines.add(line); + } + this.line_map.set(line, type + ":" + prop); + GLib.debug("setLine %d, %s", line, type + ":" + prop); + } + public void sortLines() { + //print("sortLines\n"); + this.lines.sort((a,b) => { + return (int)a-(int)b; + }); + this.node_lines.sort((a,b) => { + return (int)a-(int)b; + }); + } + public Node? lineToNode(int line) + { + //print("Searching for line %d\n",line); + var l = -1; + //foreach(int el in this.node_lines) { + //print("all lines %d\n", el); + //} + + + foreach(int el in this.node_lines) { + //print("?match %d\n", el); + if (el < line) { + + l = el; + //print("LESS\n"); + continue; + } + if (el == line) { + //print("SAME\n"); + l = el; + break; + } + if (l > -1) { + var ret = this.node_lines_map.get(l); + if (line > ret.line_end) { + return null; + } + //print("RETURNING NODE ON LINE %d", l); + return ret; + } + return null; + + } + if (l > -1) { + var ret = this.node_lines_map.get(l); + if (line > ret.line_end) { + return null; + } + //print("RETURNING NODE ON LINE %d", l); + return ret; + } + return null; + + } + public string lineToProp(int line) + { + // assume lineToNode called first... + var l = -1; + //foreach(int el in this.lines) { + // //print("all lines %d\n", el); + // + + + foreach(int el in this.lines) { + //print("?match %d\n", el); + if (el < line) { + + l = el; + //print("LESS\n"); + continue; + } + if (el == line) { + //print("SAME\n"); + l = el; + break; + } + if (l > -1) { + //print("RETURNING NODE ON LINE %d", l); + return this.line_map.get(l); + } + return null; + + } + if (l > -1) { + //print("RETURNING NODE ON LINE %d", l); + return this.line_map.get(l); + } + return null; + + } + + public bool getPropertyRange(string prop, out int start, out int end) + { + start = -1; + foreach(int el in this.lines) { + if (start < 0) { + if (this.line_map.get(el) == prop) { + start = el; + end = el; + } + continue; + } + end = el -1; + break; + } + return start > -1; + + + } + + public void dumpProps(string indent = "") + { + print("%s:\n" , this.fqn()); + foreach(int el in this.lines) { + print("%d: %s%s\n", el, indent, this.line_map.get(el)); + } + foreach(Node n in this.items) { + n.dumpProps(indent + " "); + } + } + + public string uid() { @@ -153,7 +310,7 @@ public class JsRender.Node : Object { this.props.set("xtype", ar[ar.length-1]); var l = name.length - (ar[ar.length-1].length +1); this.props.set("$ xns", name.substring(0, l)); - print("setFQN %s to %s\n", name , this.fqn()); + //print("setFQN %s to %s\n", name , this.fqn()); } @@ -207,7 +364,45 @@ public class JsRender.Node : Object { return ""; } - + public void normalize_key(string key, out string kname, out string kflag, out string ktype) + { + // key formats : XXXX + // XXX - plain + // string XXX - with type + // $ XXX - with flag (no type) + // $ string XXX - with flag + kname = ""; + ktype = ""; // these used to contain '-' ??? + kflag = ""; // these used to contain '-' ??? + var kkv = key.strip().split(" "); + string[] kk = {}; + for (var i = 0; i < kkv.length; i++) { + if (kkv[i].length > 0 ) { + kk+= kkv[i]; + } + } + //print("normalize %s => %s\n", key,string.joinv("=:=",kk)); + + switch(kk.length) { + case 1: + kname = kk[0]; + return; + case 2: + kname = kk[1]; + if (kk[0].length > 1) { + ktype = kk[0]; + } else { + kflag = kk[0]; + } + return; + case 3: + kname = kk[2]; + kflag = kk[0]; + ktype = kk[1]; + return; + } + // everything blank otherwise... + } public void set(string key, string value) { this.props.set(key,value); } @@ -450,35 +645,64 @@ public class JsRender.Node : Object { { var ret = this.nodeTitle(true); var funcs = ""; + var props = ""; + var listen = ""; var iter = this.props.map_iterator(); while (iter.next()) { - var i = iter.get_key(); - //, iter.get_value()); + var i = iter.get_key().strip(); + var val = iter.get_value().strip(); + if (val == null || val.length < 1) { + continue; + } if ( i[0] != '|') { + props += "\n\t" + + GLib.Markup.escape_text(i) +" : " + + GLib.Markup.escape_text(val.split("\n")[0]); + continue; } //if (i == "* init") { // continue; //} - var val = iter.get_value(); + if (Regex.match_simple("^\\s*function", val)) { - funcs += "\n" + - GLib.Markup.escape_text(i.substring(1)) +" : " + + funcs += "\n\t" + + GLib.Markup.escape_text(i.substring(1)).strip() +" : " + GLib.Markup.escape_text(val.split("\n")[0]); continue; } if (Regex.match_simple("^\\s*\\(", val)) { - funcs += "\n" + GLib.Markup.escape_text(i.substring(1)) + + funcs += "\n\t" + GLib.Markup.escape_text(i.substring(1)).strip() + " : " + GLib.Markup.escape_text(val.split("\n")[0]); continue; } } + iter = this.listeners.map_iterator(); + while (iter.next()) { + var i = iter.get_key().strip(); + var val = iter.get_value().strip(); + if (val == null || val.length < 1) { + continue; + } + listen += "\n\t" + + GLib.Markup.escape_text(i) +" : " + + GLib.Markup.escape_text(val.split("\n")[0]); + + } + + + if (props.length > 0) { + ret+="\n\nProperties:" + props; + } if (funcs.length > 0) { ret+="\n\nMethods:" + funcs; } + if (listen.length > 0) { + ret+="\n\nListeners:" + listen; + } return ret; }