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