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