basic highlighting of invalid property names (eg. not user defined or not gtk ) ...
[roobuilder] / src / JsRender / Node.vala
1
2 // test..
3 // valac gitlive/app.Builder.js/JsRender/Lang.vala gitlive/app.Builder.js/JsRender/Node.vala --pkg gee-1.0 --pkg=json-glib-1.0 -o /tmp/Lang ;/tmp/Lang
4
5
6 /*
7  * 
8  * props:
9  * 
10  * key value view of properties.
11  * 
12  * Old standard..
13  * XXXXX : YYYYY  -- standard - should be rendered as XXXX : "YYYY" usually.
14  * |XXXXX : YYYYY  -- standard - should be rendered as XXXX : YYYY usually.
15  * |init  -- the initialization...
16  * *prop : a property which is actually an object definition... 
17  * *args : contructor args
18  * .ctor : Full contruct line...  
19  * 
20  * Newer code
21  * ".Gee.ArrayList<Xcls_fileitem>:fileitems" ==> # type  name 
22  * ".signal:void:open": "(JsRender.JsRender file)" ==> @ type name
23  *  "|void:clearFiles": "() .... some code...."  | type name
24  *
25  * 
26  * 
27  * 
28  * 
29  * Standardize this crap...
30  * 
31  * standard properties (use to set)
32  *          If they are long values show the dialog..
33  * 
34  * bool is_xxx  :: can show a pulldown.. (true/false)
35  * string html  
36  * $ string html  = string with value interpolated eg. baseURL + ".." 
37  *  Clutter.ActorAlign x_align  (typed)  -- shows pulldowns if type is ENUM? 
38  * $ untypedvalue = javascript untyped value... 
39  * 
40  * object properties (not part of the GOjbect being wrapped?
41  * # Gee.ArrayList<Xcls_fileitem> fileitems
42  * 
43  * signals
44  * @ void open 
45  * 
46  * methods -- always text editor..
47  * | void clearFiles
48  * | someJSmethod
49  * 
50  * specials
51  * * prop -- string
52  * * args  -- string
53  * * ctor -- string
54  * * init -- big string?
55  * 
56  * event handlers (listeners)
57  *   just shown 
58  * 
59  * -----------------
60  * special ID values
61  *  +XXXX -- indicates it's a instance property / not glob...
62  *  *XXXX -- skip writing glob property (used as classes that can be created...)
63  *  _XXXX -- (string) a translatable string.
64  * 
65  * 
66  *  FORMATING?
67 .method {
68          color : green;
69          font-weight: bold;      
70 }
71 .prop {
72         color : #333;
73 }
74 .prop-code {
75     font-style: italic;
76  }
77 .listener {
78     color: #600;
79     font-weight: bold;   
80 }
81 .special { 
82   color : #00c;    font-weight: bold;    
83
84
85 */
86
87
88
89
90
91
92 public class JsRender.Node : GLib.Object {
93         
94
95         public static int uid_count = 0;
96         
97         public int oid { get; private set; }
98         public Node parent;
99         private Gee.ArrayList<Node> items; // child items..
100         public GLib.ListStore  childstore; // must be kept in sync with items
101         public GLib.ListStore?  propstore; // must be kept in sync with items
102         public string  xvala_cls; // set by node to vala
103         public string xvala_xcls; // 'Xcls_' + id; // set by nodetoVala
104         public string xvala_id; // item id or "" // set by nodetovala
105         
106         // line markers..
107         public int line_start;
108         public int line_end;
109         public Gee.ArrayList<int> lines;
110         public Gee.HashMap<int,string> line_map; // store of l:xxx or p:....  // fixme - not needed as we can store line numbers in props now.
111         public Gee.ArrayList<int> node_lines; 
112         public Gee.HashMap<int,Node> node_lines_map; // store of l:xxx or p:....
113         
114         
115         public string node_pad = "";
116         
117         private int _updated_count = 0;
118         public int updated_count { 
119                 get {
120                         return this._updated_count; 
121                 }
122                 set  {
123                         this.nodeTitleProp = ""; // ?? should trigger set?
124                         this.iconFilename = "";
125                         this._updated_count = value;
126  
127                                 
128                         //GLib.debug("Update Node %d p%d - rev %d", this.oid, this.parent != null ? this.parent.oid : -1, value);
129                         if (this.parent != null) {
130                                 this.parent.updated_count++;
131                         }  else {
132                                 //GLib.debug("UNDO top node is %d", value);
133                                 this.version_changed();
134                         }
135                 }
136  
137         } // changes to this trigger updates on the tree..
138         
139         public string as_source = "";
140         public int as_source_version = -1;
141         public int as_source_start_line = -1;
142          
143         
144         
145         public signal void  version_changed();
146         
147         public Node()
148         {
149                 this.items = new Gee.ArrayList<Node>();
150                 //this._props = new Gee.HashMap<string,NodeProp>();
151                 //this._listeners = new Gee.HashMap<string,NodeProp>(); // Nodeprop can include line numbers..
152                 this.propstore = new GLib.ListStore(typeof(NodeProp)); // Nodeprop can include line numbers..
153                 this.xvala_cls = "";
154                 this.xvala_xcls = "";
155                 this.xvala_id = "";
156                 this.parent = null;
157                 this.line_start = -1;
158                 this.line_end = -1;             
159                 this.lines = new Gee.ArrayList<int>();
160                 this.line_map = new Gee.HashMap<int,string>();
161                 this.node_lines = new Gee.ArrayList<int>();
162                 this.node_lines_map = new Gee.HashMap<int,Node>();
163                 this.childstore = new GLib.ListStore( typeof(Node));
164                 this.oid = uid_count++;
165                 
166         }
167         
168         public bool has_parent(Node n) 
169         {
170                 if (this.parent == null) {
171                         return false;
172                 }
173                 if (this.parent.oid == n.oid) {
174                         return true;
175                 }
176                 
177
178                 return this.parent.has_parent(n);
179         }
180         
181         
182         public  Gee.ArrayList<Node> readItems()
183         {
184                 return this.items; // note should not modify add/remove from this directly..
185                 
186         }
187         public void setNodeLine(int line, Node node) {
188                 //print("Add node @ %d\n", line);
189                 if (this.node_lines_map.has_key(line)) {
190                         return;
191                 }
192                 this.node_lines.add(line);
193                 this.node_lines_map.set(line, node);
194                 
195         }
196         
197         public void setLine(int line, string type, string prop) 
198         {
199                 //GLib.debug("set prop %s (%s) to line %d", prop, type, line);
200                 if (this.line_map.has_key(line)) {
201                         if  (this.line_map.get(line) != "e:"  ) {
202                                 return;
203                         }
204                 } else {
205                         this.lines.add(line);
206                 }
207                 this.line_map.set(line, type + ":" + prop);
208                 if (type == "e" || type == "p" ) {
209                 
210                         if (prop == "" || !this.props.has_key(prop)) {
211                                 ///GLib.debug("cant find prop '%s'", prop);
212                                 return;
213                         }
214                         
215                         var prope = this.props.get(prop);
216                         if (prope != null && type =="p") { 
217                                 prope.start_line = line;
218                         }
219                         if (prope != null && type =="e") { 
220                                 prope.end_line = line;
221                         }       
222                         
223                 }
224                 if (type == "l" || type =="x") {
225                         if (prop == "" || !this.listeners.has_key(prop)) {
226                                 //GLib.debug("cant find listener '%s'", prop);
227                                 return;
228                         }
229                         
230                         var prope = this.listeners.get(prop);
231                         if (prope != null && type =="l") { 
232                                 prope.start_line = line;
233                         }
234                         if (prope != null && type =="x") { 
235                                 prope.end_line = line;
236                         }       
237                         
238                 
239                 }
240                 
241                 
242                 
243                 
244                 //GLib.debug("setLine %d, %s", line, type + ":" + prop);
245         }
246         public void sortLines() {
247                 //print("sortLines\n");
248                 this.lines.sort((a,b) => {   
249                         return (int)a-(int)b;
250                 });
251                 this.node_lines.sort((a,b) => {   
252                         return (int)a-(int)b;
253                 });
254         }
255         public Node? lineToNode(int line)
256         {
257                 //print("Searching for line %d\n",line);
258                 var l = -1;
259                 //foreach(int el in this.node_lines) {
260                         //print("all lines %d\n", el);
261                 //}
262                 
263                 
264                 foreach(int el in this.node_lines) {
265                         //print("?match %d\n", el);
266                         if (el < line) {
267                                 
268                                 l = el;
269                                 //print("LESS\n");
270                                 continue;
271                         }
272                         if (el == line) {
273                                 //print("SAME\n");
274                                 l = el;
275                                 break;
276                         }
277                         if (l > -1) {
278                                 var ret = this.node_lines_map.get(l);
279                                 if (line > ret.line_end) {
280                                         return null;
281                                 }
282                                 //print("RETURNING NODE ON LINE %d", l);
283                                 return ret;
284                         }
285                         return null;
286                         
287                 }
288                 if (l > -1) {
289                         var ret = this.node_lines_map.get(l);
290                         if (line > ret.line_end) {
291                                 return null;
292                         }
293                         //print("RETURNING NODE ON LINE %d", l);
294                         return ret;
295
296                 }
297                 return null;
298                 
299         }
300         
301         
302         public NodeProp? lineToProp(int line)
303         {
304                 
305                 for(var i= 0; i < this.propstore.get_n_items();i++) {
306                         var p = (NodeProp) this.propstore.get_item(i);
307                         GLib.debug("prop %s lines %d -> %d", p.name, p.start_line, p.end_line);
308                         if (p.start_line > line) {
309                                 continue;
310                         }
311                         if (line > p.end_line) {
312                                 continue;
313                         }
314                         return p;
315                 }
316                 return null;
317         }
318                 
319                  
320         
321         public bool getPropertyRange(string prop, out int start, out int end)
322         {
323                 end = 0;
324                 start = -1;
325                 foreach(int el in this.lines) {
326                         if (start < 0) {
327                                 if (this.line_map.get(el) == prop) {
328                                         start = el;
329                                         end = el;
330                                 }
331                                 continue;
332                         }
333                         end = el -1;
334                         break;
335                 }
336                 return start > -1;
337         
338         
339         }
340         
341         public void dumpProps(string indent = "")
342         {
343                 print("%s:\n" , this.fqn());
344                 foreach(int el in this.lines) {
345                         print("%d: %s%s\n", el, indent, this.line_map.get(el));
346                 }
347                 foreach(Node n in this.items) {
348                         n.dumpProps(indent + "  ");
349                 }
350         }
351         
352         
353         
354         public string uid()
355         {
356                 if (this.props.get("id") == null) {
357                         return "uid-%d".printf(this.oid);
358                 }
359                 return this.props.get("id").val;
360         }
361         
362         
363         public bool hasChildren()
364         {
365                 return this.items.size > 0;
366         }
367         public bool hasXnsType()
368         {
369                 if (this.props.get("xns") != null && this.props.get("xtype") != null) {
370                         return true;
371                         
372                 }
373                 return false;
374         }
375         
376         public string FQN { // for sorting
377                 owned get { return this.fqn(); }
378                 private set  {}
379         }
380         public string NS { // for sorting
381                 owned get { return this.props.has_key("xns") ? this.props.get("xns").val  : ""; }
382                 private set  {}
383         }
384         public string fqn()
385         {
386                 if (!this.hasXnsType ()) {
387                         return "";
388                 }
389                 return this.props.get("xns").val + "." + this.props.get("xtype").val; 
390
391         }
392         public void setFqn(string name)
393         {
394                 var ar = name.split(".");
395                 var l = name.length - (ar[ar.length-1].length +1);
396                 
397
398                 
399                 if (this.props.has_key("xtype")) {
400                         this.props.get("xtype").val = ar[ar.length-1];
401                 } else {
402                         this.add_prop(new NodeProp.prop("xtype", "",  ar[ar.length-1]));                
403                 }       
404                 if (this.props.has_key("xns")) {
405                         this.props.get("xns").val = name.substring(0, l);
406                 } else {
407                         this.add_prop(new NodeProp.raw("xns", "", name.substring(0, l)));               
408                 }       
409                 
410                 
411                 //print("setFQN %s to %s\n", name , this.fqn());
412                                
413
414         }
415         // wrapper around get props that returns empty string if not found.
416         //overrides Glib.object.get (hence new)
417         public new string get(string key)
418         {
419                 
420                 var v = this.props.get(key);
421                 return v == null ? "" : v.val;
422         }       
423                  
424         public  NodeProp? get_prop(string key)
425         {
426                 
427                 return this.props.get(key);
428                 
429         }
430         
431  
432         
433
434
435         public bool has(string key)
436         {
437                 return this.props.has_key(key);
438                  
439          
440         }
441
442         public void  remove()
443         {
444                 if (this.parent == null) {
445                         GLib.debug("remove - parent is null?");
446                         return;
447                 }
448                 var nlist = new Gee.ArrayList<Node>();
449                 for (var i =0;i < this.parent.items.size; i++) {
450                         if (this.parent.items.get(i) == this) {
451                                 continue;
452                         }
453                         nlist.add(this.parent.items.get(i));
454                 }
455                 uint pos;
456                 if ( this.parent.childstore.find(this, out pos)) {
457                         this.parent.childstore.remove(pos);
458                 } 
459                 this.parent.updated_count++;
460                 this.parent.items = nlist;
461                 this.parent = null;
462
463         }
464          
465         /* creates javascript based on the rules */
466         public Node? findProp(string n) {
467                 for(var i=0;i< this.items.size;i++) {
468                         var p = this.items.get(i).get("* prop");
469                         if (p  == null) {
470                                 continue;
471                         }
472                         if (p == n) {
473                                 return this.items.get(i);
474                         }
475                 }
476                 return null;
477
478         }
479
480         
481         
482          
483         static Json.Generator gen = null;
484         
485         public string quoteString(string str)
486         {
487                 if (Node.gen == null) {
488                         Node.gen = new Json.Generator();
489                 }
490                  var n = new Json.Node(Json.NodeType.VALUE);
491                 n.set_string(str);
492  
493                 Node.gen.set_root (n);
494                 return  Node.gen.to_data (null);   
495         }
496
497         public void loadFromJsonString(string str, int ver)
498         {
499                 var pa = new Json.Parser();
500                 try {
501                         pa.load_from_data(str);
502                 } catch (GLib.Error e) {
503                         GLib.debug("Error loading string?");
504                         return;
505                 }
506                 var new_node = pa.get_root();
507                 var obj = new_node.get_object ();
508                      
509                 this.loadFromJson(obj, ver);
510         }
511         
512  
513
514         public void loadFromJson(Json.Object obj, int version) {
515                  
516                 obj.foreach_member((o , key, value) => {
517                         //print(key+"\n");
518                         if (key == "items") {
519                                 var ar = value.get_array();
520                                 ar.foreach_element( (are, ix, el) => {
521                                         var node = new Node();
522                                         node.parent = this;
523                                         node.loadFromJson(el.get_object(), version);
524                                         this.items.add(node);
525                                         this.childstore.append(node);
526                                 });
527                                 return;
528                         }
529                         if (key == "listeners") {
530                                 var li = value.get_object();
531                                 li.foreach_member((lio , li_key, li_value) => {
532                                         this.add_prop(new NodeProp.listener(li_key, this.jsonNodeAsString(li_value)));
533                                         //this.listeners.set(li_key,  new NodeProp.listener(li_key, this.jsonNodeAsString(li_value)));
534                                 });
535                                 return;
536                         }
537                         
538
539                         var rkey = key;
540                         var sval = this.jsonNodeAsString(value);
541                 
542                         if (version == 1) {
543                                 rkey = this.upgradeKey(key, sval);
544                         }
545                         var n =  new NodeProp.from_json(rkey, sval);
546                                 
547                         this.add_prop(n );
548
549
550                 });
551                 
552                 
553                 
554
555
556
557         }
558         
559         // converts the array into a string with line breaks.
560         public string jsonNodeAsString(Json.Node node)
561         {
562                 
563                 if (node.get_node_type() == Json.NodeType.ARRAY) {
564                         var  buffer = new GLib.StringBuilder();
565                         var ar = node.get_array();
566                         for (var i = 0; i < ar.get_length(); i++) {
567                                 if (i >0 ) {
568                                         buffer.append_c('\n');
569                                 }
570                                 buffer.append(ar.get_string_element(i));
571                         }
572                         return buffer.str;
573                 }
574         // hopeflyu only type value..           
575                 var sv =  Value (typeof (string));                      
576                 var v = node.get_value();
577                 v.transform(ref sv);
578                 return (string)sv;
579
580         }
581         
582         // really old files...
583
584         public string upgradeKey(string key, string val)
585         {
586                 // convert V1 to V2
587                 if (key.length < 1) {
588                         return key;
589                 }
590                 switch(key) {
591                         case "*prop":
592                         case "*args":
593                         case ".ctor":
594                         case "|init":
595                                 return "* " + key.substring(1);
596                                 
597                         case "pack":
598                                 return "* " + key;
599                 }
600                 if (key[0] == '.') { // v2 does not start with '.' ?
601                         var bits = key.substring(1).split(":");
602                         if (bits[0] == "signal") {
603                                 return "@" + string.joinv(" ", bits).substring(bits[0].length);
604                         }
605                         return "# " + string.joinv(" ", bits);                  
606                 }
607                 if (key[0] != '|' || key[1] == ' ') { // might be a v2 file..
608                         return key;
609                 }
610                 var bits = key.substring(1).split(":");
611                 // two types '$' or '|' << for methods..
612                 // javascript 
613                 if  (Regex.match_simple ("^function\\s*(", val.strip())) {
614                         return "| " + key.substring(1);
615                 }
616                 // vala function..
617                 
618                 if  (Regex.match_simple ("^\\(", val.strip())) {
619                 
620                         return "| " + string.joinv(" ", bits);
621                 }
622                 
623                 // guessing it's a property..
624                 return "$ " + string.joinv(" ", bits);
625                 
626                 
627
628         }
629
630
631
632
633
634         
635         public Node  deepClone()
636         {
637                 var n = new Node();
638                 n.loadFromJson(this.toJsonObject(), 2);
639                 return n;
640
641         }
642         public string toJsonString()
643         {
644                 if (Node.gen == null) {
645                         Node.gen = new Json.Generator();
646                         gen.pretty =  true;
647                         gen.indent = 1;
648                 }
649                 var n = new Json.Node(Json.NodeType.OBJECT);
650                 n.set_object(this.toJsonObject () );
651                 Node.gen.set_root (n);
652                 return  Node.gen.to_data (null);   
653         }
654         
655         public void jsonObjectAddStringValue(Json.Object obj, string key, string v)
656         {
657                 if (v.index_of_char('\n',0) < 0) {
658                         obj.set_string_member(key,v);
659                         return;
660                 }
661                 var aro = new Json.Array();
662                 var ar = v.split("\n");
663                 for(var i =0;i < ar.length;i++) {
664                         aro.add_string_element(ar[i]);
665                 }
666                 obj.set_array_member(key,aro);
667         }
668         
669         public Json.Object toJsonObject()
670         {
671                 var ret = new Json.Object();
672
673                 // listeners...
674                 if (this.listeners.size > 0) {
675                         var li = new Json.Object();
676                         ret.set_object_member("listeners", li);
677                         var liter = this.listeners.map_iterator();
678                         while (liter.next()) {
679                                 this.jsonObjectAddStringValue(li, liter.get_value().to_json_key(), liter.get_value().val);
680                         }
681                 }
682                 //props
683                 if (this.props.size > 0 ) {
684                         var iter = this.props.map_iterator();
685                         while (iter.next()) {
686                                 this.jsonObjectsetMember(ret, iter.get_value().to_json_key(), iter.get_value().val);
687                         }
688                 }
689                 if (this.items.size > 0) {
690                         var ar = new Json.Array();
691                         ret.set_array_member("items", ar);
692                 
693                         // children..
694                         for(var i =0;i < this.items.size;i++) {
695                                 ar.add_object_element(this.items.get(i).toJsonObject());
696                         }
697                 }
698                 return ret;
699                 
700  
701         }
702          
703         public void jsonObjectsetMember(Json.Object o, string key, string val) {
704                 if (Lang.isBoolean(val)) {
705                         o.set_boolean_member(key, val.down() == "false" ? false : true);
706                         return;
707                 }
708                 
709                 
710                 if (Lang.isNumber(val)) {
711                         if (val.contains(".")) {
712                                 //print( "ADD " + key + "=" + val + " as a double?\n");
713                                 o.set_double_member(key, double.parse (val));
714                                 return;
715
716                         }
717                         //print( "ADD " + key + "=" + val + " as a int?\n")  ;
718                         o.set_int_member(key,long.parse(val));
719                         return;
720                 }
721                 ///print( "ADD " + key + "=" + val + " as a string?\n");
722                 this.jsonObjectAddStringValue(o,key,val);
723                 //o.set_string_member(key,val);
724                 
725         }
726         
727         
728         public string nodeTipProp { 
729                 set {
730                         // NOOp ??? should 
731                 }
732                 owned get {
733                          return  this.nodeTip();
734                 } 
735         }
736         // fixme this needs to better handle 'user defined types etc..
737         public string nodeTip()
738         {
739                 var ret = this.nodeTitle(true);
740                 var spec = "";
741                 var funcs = "";
742                 var props = "";
743                 var listen = "";
744  
745                 var uprops = "";
746                 // sort?
747                 
748                 var keys = new  Gee.ArrayList<string>();
749                 foreach(var k in this.props.keys) {
750                         keys.add(k);
751                 }
752                 keys.sort((a,b) => {
753                          return Posix.strcmp(a, b);
754                 
755                 });
756                 
757                 
758                 foreach(var pk in keys) {
759                          
760                         var prop = this.props.get(pk);
761                         var i = prop.name.strip();
762                         
763                         var val = prop.val;
764                         val = val == null ? "" : val;
765                         
766                         switch(prop.ptype) {
767                                 case PROP: 
768                                 case RAW: // should they be the same?
769                                 
770                                         props += "\n\t" + GLib.Markup.escape_text(prop.rtype) +
771                                                 " <b>" + GLib.Markup.escape_text(i) +"</b> : " + 
772                                                 GLib.Markup.escape_text(val.split("\n")[0]);
773                                                 
774                                         break;
775                                         
776                         
777                                 
778                                 case METHOD :
779                                         funcs += "\n\t" + GLib.Markup.escape_text(prop.rtype) +
780                                                 " <b>" + GLib.Markup.escape_text(i) +"</b> : "  +
781                                                 GLib.Markup.escape_text(val.split("\n")[0]);
782                                         break;
783                                         
784                                  
785                                 case USER : // user defined.
786                                         uprops += "\n\t<b>" + 
787                                                 GLib.Markup.escape_text(i) +"</b> : " + 
788                                                 GLib.Markup.escape_text(val.split("\n")[0]);
789                                         break;
790                                         
791                                 case SPECIAL : // * prop| args | ctor | init
792                                         spec += "\n\t<b>" + 
793                                                 GLib.Markup.escape_text(i) +"</b> : " + 
794                                                 GLib.Markup.escape_text(val.split("\n")[0]);
795                                         break;
796                                         
797                                 case LISTENER : return  "";  // always raw...
798                                 // not used
799                                 default:
800                                         break;;
801                         
802                         }
803                          
804                         
805                 }
806                 
807                 keys = new  Gee.ArrayList<string>();
808                 foreach(var k in this.listeners.keys) {
809                         keys.add(k);
810                 }
811                 keys.sort((a,b) => {
812                          return Posix.strcmp(a, b);
813                 
814                 });
815                 
816                 foreach(var pk in keys) {
817                          
818                         var prop = this.listeners.get(pk);
819                         var i =  prop.name.strip();
820                         
821                         var val = prop.val.strip();
822                         if (val == null || val.length < 1) {
823                                 continue;
824                         }
825                          listen += "\n\t<b>" + 
826                                         GLib.Markup.escape_text(i) +"</b> : " + 
827                                         GLib.Markup.escape_text(val.split("\n")[0]);
828                         
829                 }
830                 
831                 
832                 if (props.length > 0) {
833                         ret+="\n\nProperties:" + props;
834                 }
835                 if (uprops.length > 0) {
836                         ret+="\n\nUser defined Properties:" + uprops;
837                 } 
838                 
839                 
840                 if (funcs.length > 0) {
841                         ret+="\n\nMethods:" + funcs;
842                 } 
843                 if (listen.length > 0) {
844                         ret+="\n\nListeners:" + listen;
845                 } 
846                 if (spec.length > 0) {
847                         ret+="\n\nSpecial:" + spec;
848                 } 
849                 
850                 return ret;
851
852         }
853         
854         public string nodeTitleProp { 
855                 set {
856                         // NOOp ??? should 
857                 }
858                 owned get {
859                          return  this.nodeTitle();
860                 } 
861         }
862         
863         
864         
865         
866         
867         
868         public string nodeTitle(bool for_tip = false) 
869         {
870                 string[] txt = {};
871
872                 //var sr = (typeof(c['+buildershow']) != 'undefined') &&  !c['+buildershow'] ? true : false;
873                 //if (sr) txt.push('<s>');
874
875                 if (this.has("* prop"))   { txt += (GLib.Markup.escape_text(this.get("* prop")) + ":"); }
876                 
877                 //if (renderfull && c['|xns']) {
878                 var fqn = this.fqn();
879                 var fqn_ar = fqn.split(".");
880                 txt += for_tip || fqn.length < 1 ? fqn : fqn_ar[fqn_ar.length -1];
881                 
882                 if (fqn == "Roo.bootstrap.Element" && this.has("tag")) {
883                    txt = {};
884                    txt += GLib.Markup.escape_text(this.get("tag").up());
885                 }
886                 
887                 //if (c.xtype)    { txt.push(c.xtype); }
888                         
889                 if (this.has("id"))      { txt += ("<b>[id=" + GLib.Markup.escape_text(this.get("id")) + "]</b>"); }
890                 if (this.has("fieldLabel")){ txt += ("[" + GLib.Markup.escape_text(this.get("fieldLabel")) + "]"); }
891                 if (this.has("boxLabel"))  { txt += ("[" + GLib.Markup.escape_text(this.get("boxLabel"))+ "]"); }
892                 
893                 
894                 if (this.has("layout")) { txt += ("<i>" + GLib.Markup.escape_text(this.get("layout")) + "</i>"); }
895                 if (this.has("title"))   { txt += ("<b>" + GLib.Markup.escape_text(this.get("title")) + "</b>"); }
896                 if (this.has("html") && this.get("html").length > 0)     { 
897                         var ht = this.get("html").split("\n");
898                         if (ht.length > 1) {
899                                 txt += ("<b>" + GLib.Markup.escape_text(ht[0]) + "...</b>");
900                         } else { 
901                                 txt += ("<b>" + GLib.Markup.escape_text(this.get("html")) + "</b>");
902                         }
903                 }
904                 if (this.has("label"))   { txt += ("<b>" + GLib.Markup.escape_text(this.get("label"))+ "</b>"); }
905                 if (this.has("header"))   { txt += ("<b>" + GLib.Markup.escape_text(this.get("header")) + "</b>"); }
906                 if (this.has("legend"))  { txt += ("<b>" + GLib.Markup.escape_text(this.get("legend")) + "</b>"); }
907                 if (this.has("text"))     { txt += ("<b>" + GLib.Markup.escape_text(this.get("text")) + "</b>"); }
908                 if (this.has("name"))     { txt += ("<b>" + GLib.Markup.escape_text(this.get("name"))+ "</b>"); }
909                 if (this.has("region")) { txt += ("<i>(" + GLib.Markup.escape_text(this.get("region")) + ")</i>"); }
910                 if (this.has("dataIndex")){ txt += ("[" + GLib.Markup.escape_text(this.get("dataIndex")) + "]"); }
911                 // class is quite important on bootstrap..
912                 if (this.has("cls")){ txt += ("<b>[cls=" + GLib.Markup.escape_text(this.get("cls")) + "]</b>"); }               
913                 
914                 // other 'specials?'
915                 if (fqn == "Roo.bootstrap.Link") {
916                         txt += ("<b>href=" + (this.has("name") ?  GLib.Markup.escape_text(this.get("name")) : "?" ) + "</b>");
917                         if (this.has("fa")){ txt += ("<b>[fa=" + GLib.Markup.escape_text(this.get("fa")) + "]</b>"); }                                  
918                 }
919
920
921
922                 // for flat classes...
923                 //if (typeof(c["*class"]"))!= "undefined")  { txt += ("<b>" +  c["*class"]+  "</b>"); }
924                 //if (typeof(c["*extends"]"))!= "undefined")  { txt += (": <i>" +  c["*extends"]+  "</i>"); }
925                 
926                 
927                 //if (sr) txt.push('</s>');
928                 return (txt.length == 0) ? "Element" : string.joinv(" ", txt);
929         }
930         // used by trees to display icons?
931         // needs more thought?!?
932         public string iconFilename { 
933                 set {
934                         // NOOp ??? should 
935                 }
936                 owned get {
937                         var clsname = this.fqn();
938     
939                         var clsb = clsname.split(".");
940                     var sub = clsb.length > 1 ? clsb[1].down()  : "";
941                         var fn = "/usr/share/glade/pixmaps/hicolor/16x16/actions/widget-gtk-" + sub + ".png";
942                         //if (FileUtils.test (fn, FileTest.IS_REGULAR)) {
943                                 return fn;
944                         //}
945                         //return "/dev/null"; //???
946                 } 
947         }
948         
949          
950         
951         public void insertAfter(Node child, Node after) 
952         {
953                 this.insertChild(this.items.index_of(after) + 1, child);
954         }
955         public void insertBefore(Node child, Node before)       
956         {
957                 this.insertChild(this.items.index_of(before), child);
958         }
959         
960         public void insertChild(int pos, Node child)
961         {
962                 this.items.insert(pos, child);
963                 this.childstore.insert(pos, child);
964                 child.parent = this;
965         }
966         public void appendChild(Node child)
967         {
968                 this.items.add( child);
969                 this.childstore.append(child);
970                 child.parent = this;
971         }
972         
973         
974         /**
975         
976         properties
977                 previous we had listeners / and props
978                 
979                 we really need to store this as flat array - keep it simple!?
980                 
981                 getValue(key)
982                 update(key, value)
983                 
984                 
985         
986         */
987         
988
989         
990         
991         public void loadProps(GLib.ListStore model, Project.Project project) 
992         {
993         
994                 // fixme sorting?? - no need to loop twice .. just use sorting.!
995                 var oldstore = this.propstore;
996                 this.propstore = model;
997                 for(var i =  0; i < oldstore.n_items; i++ ) {
998                         var it = (NodeProp) oldstore.get_item(i);
999                         it.update_is_valid_ptype(project);
1000                     model.append(it);
1001                         
1002                 }
1003                 this.sortProps();
1004            
1005    }
1006    // used to replace propstore, so it does not get wiped by editing a node
1007    public void dupeProps()
1008    {
1009                 GLib.debug("dupeProps START");
1010                 var oldstore = this.propstore;
1011                 this.propstore = new GLib.ListStore(typeof(NodeProp));;
1012                 for(var i =  0; i < oldstore.n_items; i++ ) {
1013                         var it = (NodeProp) oldstore.get_item(i);
1014                         this.propstore.append(it);
1015                 }
1016                 GLib.debug("dupeProps END");
1017         }
1018         
1019    
1020    public void remove_prop(NodeProp prop)
1021         {
1022                 uint pos;
1023                 if (!this.propstore.find(prop, out pos)) {
1024                         return;
1025                 }
1026                 this.propstore.remove(pos);
1027                 this.updated_count++;
1028                 
1029         }   
1030    
1031         public bool has_prop_key(NodeProp prop) 
1032         {
1033                 for(var i =  0; i < this.propstore.n_items; i++ ) {
1034                         var it = (NodeProp) this.propstore.get_item(i);
1035                         if (it.ptype == prop.ptype && it.to_index_key() == prop.to_index_key()) {
1036                                 return true;
1037                         }
1038                         
1039                 }
1040                 return false;
1041            
1042         }
1043         
1044          
1045         
1046         
1047         public void add_prop(NodeProp prop)
1048         {
1049                 if (this.has_prop_key(prop) && !prop.to_index_key().has_suffix("[]")) {
1050                         GLib.warning("duplicate key' %s'- can not add - call has_prop_key first", prop.to_index_key());
1051                         return;
1052                 }
1053                 prop.parent = this;
1054                 this.propstore.append(prop);
1055                 this.sortProps();
1056                 
1057                 this.updated_count++;
1058                 
1059                 
1060         }
1061         
1062         int props_updated_count = -1;
1063         Gee.HashMap<string,NodeProp> props_cache;
1064         
1065         public Gee.HashMap<string,NodeProp> props {
1066                 owned get {
1067                         if (this.updated_count == this.props_updated_count) {
1068                                 return this.props_cache;
1069                         }
1070                          this.props_cache = new Gee.HashMap<string,NodeProp>(); // the properties..
1071
1072                         for(var i =  0; i < this.propstore.n_items; i++ ) {
1073                                 var it = (NodeProp) this.propstore.get_item(i);
1074                                 if (it.ptype != NodePropType.LISTENER) {
1075                                 //      GLib.debug("props add key %s", it.to_index_key());
1076                                         this.props_cache.set( it.to_index_key() , it);
1077                                 }
1078                         }
1079                         this.props_updated_count = this.updated_count;
1080                         return this.props_cache;
1081                 }
1082                 private set {
1083                         GLib.error("do not set listerners direclty");
1084                 }
1085         }
1086         
1087         int listeners_updated_count = -1;
1088         Gee.HashMap<string,NodeProp> listeners_cache;
1089         
1090         //private Gee.HashMap<string,NodeProp> _listeners; // the listeners..
1091         public Gee.HashMap<string,NodeProp> listeners {
1092                 owned get {
1093                         if (this.updated_count == this.listeners_updated_count) {
1094                                 return this.listeners_cache;
1095                         }
1096                         
1097                         this.listeners_cache = new Gee.HashMap<string,NodeProp>(); // the properties..
1098
1099                         for(var i =  0; i < this.propstore.n_items; i++ ) {
1100                                 var it = (NodeProp) this.propstore.get_item(i);
1101                                 if (it.ptype == NodePropType.LISTENER) {
1102                                         this.listeners_cache.set( it.to_index_key() , it);
1103                                 }
1104                         }
1105                         this.listeners_updated_count = this.updated_count;
1106                         return this.listeners_cache;;
1107                 }
1108                 private set {
1109                         GLib.error("do not set listerners direclty");
1110                 }
1111         }
1112         private void sortProps ()
1113         {
1114         
1115                 this.propstore.sort( (a, b) => {
1116
1117                         return Posix.strcmp( ((NodeProp)a).to_sort_key(),  ((NodeProp)b).to_sort_key());
1118                         
1119                 });
1120          
1121         
1122         }
1123 }