5c8954c2dde7101693fc13951e6de8686819c8a5
[app.Builder.js] / Builder / LeftTree.js
1 //<Script type="text/javascript">
2 //<Script type="text/javascript">
3 Gio = imports.gi.Gio;
4 Gtk = imports.gi.Gtk;
5 Gdk = imports.gi.Gdk;
6 GObject = imports.gi.GObject;
7 Pango = imports.gi.Pango ;
8
9 XObject = imports.XObject.XObject;
10 console = imports.console;
11
12 // recursive imports here break!!?
13 Roo             = imports.Builder.Provider.Palete.Roo.Roo;
14 LeftTreeMenu    = imports.Builder.LeftTreeMenu.LeftTreeMenu;
15 LeftPanel       = imports.Builder.LeftPanel.LeftPanel;
16 MidPropTree     = imports.Builder.MidPropTree.MidPropTree;
17
18 RightEditor     = imports.Builder.RightEditor.RightEditor;
19 // http://www.google.com/codesearch/p?hl=en#EKZaOgYQHwo/unstable/sources/sylpheed-2.2.9.tar.bz2%7C1erxr_ilM1o/sylpheed-2.2.9/src/folderview.c&q=gtk_tree_view_get_drag_dest_row
20
21 var idSeed = 0;
22 function id(el, prefix){
23     prefix = prefix || "left-tree";
24     //el = Roo.getDom(el);
25     var ret = prefix + (++idSeed);
26     return ret;
27     //return el ? (el.id ? el.id : (el.id = id)) : id;
28 }
29
30 LeftTree = new XObject(
31 {
32         xtype: Gtk.ScrolledWindow,
33         smooth_scroll : true,
34         
35         shadow_type :  Gtk.ShadowType.IN,
36         init : function() {
37             this.targetList.add( this.atoms["STRING"], 0 , 1);
38             // will not work without changes to gir..
39            // var ta_ar = Gtk.target_table_new_from_list(this.targetList,r);
40             
41             XObject.prototype.init.call(this); 
42             this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
43             
44              
45         },
46         
47         getPaleteProvider: function ()
48         {
49             var model = this.get('model');
50             var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
51             return pm.getPalete(model.file.getType());
52             
53         },
54         
55         renderView: function() // renders into the preview pane..
56         {
57             var model = this.get('model');
58             print("RENDER VIEW?" + model.file.getType());
59             switch( model.file.getType()) {
60                 case 'Roo':
61                     var RightBrowser    = imports.Builder.RightBrowser.RightBrowser;
62                     RightBrowser.get('view').renderJS(model.toJS(false,true)[0]);
63                 case 'Gtk':
64                     var RightGtkView = imports.Builder.RightGtkView.RightGtkView ;
65                     RightGtkView.renderJS(model.toJS(false,true)[0]);
66             }
67             
68         },
69         
70         atoms : {
71            "STRING" : Gdk.atom_intern("STRING")
72         },
73                         
74         targetList :  new Gtk.TargetList(),
75         
76         items : [        
77             {
78                 id : 'view',
79                 xtype: Gtk.TreeView,
80                 headers_visible :  false,
81                 enable_tree_lines :  true,
82                 tooltip_column : 0,
83                 // selection  -- set by init..
84                 init : function() {
85                     XObject.prototype.init.call(this); 
86                     
87                     var description = new Pango.FontDescription.c_new();
88                     description.set_size(8000);
89                     this.el.modify_font(description);
90                     
91                     this.selection = this.el.get_selection();
92                     this.selection.set_mode( Gtk.SelectionMode.SINGLE);
93                     this.selection.signal['changed'].connect(function() {
94                         LeftTree.get('view').listeners['cursor-changed'].apply(
95                             LeftTree.get('view'), [ LeftTree.get('view'), '']
96                         );
97                     });
98                     
99                     Gtk.drag_source_set (
100                         this.el,            /* widget will be drag-able */
101                         Gdk.ModifierType.BUTTON1_MASK,       /* modifier that will start a drag */
102                         null,            /* lists of target to support */
103                         0,              /* size of list */
104                         Gdk.DragAction.COPY   | Gdk.DragAction.MOVE           /* what to do with data after dropped */
105                     );
106                     var targets = new Gtk.TargetList();
107                     targets.add( LeftTree.atoms["STRING"], 0, 0);
108                     Gtk.drag_source_set_target_list(this.el, targets);
109
110                     Gtk.drag_source_add_text_targets(this.el); 
111                     Gtk.drag_dest_set
112                     (
113                             this.el,              /* widget that will accept a drop */
114                             Gtk.DestDefaults.MOTION  | Gtk.DestDefaults.HIGHLIGHT,
115                             null,            /* lists of target to support */
116                             0,              /* size of list */
117                             Gdk.DragAction.COPY   | Gdk.DragAction.MOVE       /* what to do with data after dropped */
118                     );
119                      
120                     Gtk.drag_dest_set_target_list(this.el, targets);
121                     Gtk.drag_dest_add_text_targets(this.el);
122                     
123                     
124                 },
125                 
126                 highlight : function(treepath_ar) {
127                     if (treepath_ar.length && treepath_ar[0].length ) {
128                         this.el.set_drag_dest_row( 
129                             new  Gtk.TreePath.from_string( treepath_ar[0] ),  treepath_ar[1]);
130                     } else {
131                         this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
132                     }
133                      
134                 },
135                 
136                 selectNode : function(treepath_str) 
137                 {
138                     
139                    this.selection.select_path(new  Gtk.TreePath.from_string( treepath_str));
140                 },
141                 
142                 listeners : {
143                     
144                     
145                     
146                     'button-press-event' : function(tv, ev) {
147                         console.log("button press?");
148                         if (ev.type != Gdk.EventType.BUTTON_PRESS  || ev.button.button != 3) {
149                             Seed.print("click" + ev.type);
150                             return false;
151                         }
152                       
153                     
154                         var res = {}; 
155                         LeftTree.get('view').el.get_path_at_pos(ev.button.x,ev.button.y, res);
156                         
157                         if (!LeftTreeMenu.el)  LeftTreeMenu.init();
158                         
159                         LeftTreeMenu.el.set_screen(Gdk.Screen.get_default());
160                         LeftTreeMenu.el.show_all();
161                         LeftTreeMenu.el.popup(null, null, null, null, 3, ev.button.time);
162                         Seed.print("click:" + res.path.to_string());
163                         return false;
164                         
165                     },
166                     
167                      'drag-begin' : function (w, ctx, ud) 
168                     {
169                            // we could fill this in now...
170                         Seed.print('SOURCE: drag-begin');
171                          this.targetData = false;
172                         // find what is selected in our tree...
173                         var iter = new Gtk.TreeIter();
174                         var s = this.selection;
175                         s.get_selected(LeftTree.get('model').el, iter);
176
177                         // set some properties of the tree for use by the dropped element.
178                         var value = new GObject.Value('');
179                         LeftTree.get('model').el.get_value(iter, 2, value);
180                         var data = JSON.parse(value.value);
181                         var xname = LeftTree.get('model').file.guessName(data);
182                         
183                         this.el.dragData = xname;
184                         this.el.dropList = LeftTree.getPaleteProvider().getDropList(xname);
185                         
186
187                         // make the drag icon a picture of the node that was selected
188                         var path = LeftTree.get('model').el.get_path(iter);
189                         this.el.treepath = path.to_string();
190                         
191                         var pix = this.el.create_row_drag_icon ( path);
192                         
193                         Gtk.drag_set_icon_pixmap (ctx,
194                             pix.get_colormap(),
195                             pix,
196                             null,
197                             -10,
198                             -10);
199                         
200                         return true;
201                       
202                         
203                     },
204                     
205                     'drag-end' : function ( w,  drag_context, x, y, time, user_data)   
206                     {
207                         // i'm not sure if this would work, without implementing the whole kaboodle.
208                         Seed.print('LEFT-TREE: drag-end');
209                         this.el.dragData = false;
210                         this.el.dropList = false;
211                         this.targetData = false;
212                         LeftTree.get('view').highlight(false);
213                         return true;
214                       
215                       
216                     },
217                     'drag-motion' : function (w, ctx,  x,   y,   time, ud) 
218                     {
219                         
220                         console.log("LEFT-TREE: drag-motion");
221                         var src = Gtk.drag_get_source_widget(ctx);
222
223                         // a drag from  elsewhere...- prevent drop..
224                         if (!src.dragData) {
225                             print("no drag data!");
226                             Gdk.drag_status(ctx, 0, time);
227                             this.targetData = false;
228                             return true;
229                         }
230                         var action = Gdk.DragAction.COPY;
231                         if (src == this.el) {
232                             // unless we are copying!!! ctl button..
233                             action = Gdk.DragAction.MOVE;
234                         }
235                         var data = {};
236                         print("GETTING POS");
237                         var isOver = LeftTree.get('view').el.get_dest_row_at_pos(x,y, data);
238                         print("ISOVER? " + isOver);
239                         if (!isOver) {
240                             Gdk.drag_status(ctx, 0 ,time);
241                             return false; // not over apoint!?!
242                         }
243                         // drag node is parent of child..
244                         console.log("SRC TREEPATH: " + src.treepath);
245                         console.log("TARGET TREEPATH: " + data.path.to_string());
246                         
247                         // nned to check a  few here..
248                         //Gtk.TreeViewDropPosition.INTO_OR_AFTER
249                         //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
250                         //Gtk.TreeViewDropPosition.AFTER
251                         //Gtk.TreeViewDropPosition.BEFORE
252                         
253                         if (typeof(src.treepath) != 'undefined'  && 
254                             src.treepath == data.path.to_string().substring(0,src.treepath.length)) {
255                             print("subpath drag");
256                              Gdk.drag_status(ctx, 0 ,time);
257                             return false;
258                         }
259                         
260                         // check that 
261                         //print("DUMPING DATA");
262                         //console.dump(data);
263                         // path, pos
264                         
265                         Seed.print(data.path.to_string() +' => '+  data.pos);
266                         var tg = LeftTree.get('model').findDropNodeByPath(
267                             data.path.to_string(), src.dropList, data.pos);
268                             
269                         LeftTree.get('view').highlight(tg);
270                         if (!tg.length) {
271                             print("Can not find drop node path");
272                             this.targetData = false;
273                             Gdk.drag_status(ctx, 0, time);
274                             return true;
275                         }
276                         //console.dump(tg);
277                         this.targetData = tg;    
278                         
279                         
280                         Gdk.drag_status(ctx, action ,time);
281                          
282                         return true;
283                     },
284                     
285                     'drag-drop'  : function (w, ctx, x, y,time, ud) 
286                     {
287                                 
288                         Seed.print("TARGET: drag-drop");
289                        
290                         Gtk.drag_get_data
291                         (
292                                 w,         /* will receive 'drag-data-received' signal */
293                                 ctx,        /* represents the current state of the DnD */
294                                 LeftTree.atoms["STRING"],    /* the target type we want */
295                                 time            /* time stamp */
296                         );
297                         
298                          
299                         /* No target offered by source => error */
300                        
301
302                         return  true;
303                         
304
305                     },
306                    'drag-data-received' : function (w, ctx,  x,  y, sel_data,  target_type,  time, ud) 
307                     {
308                         Seed.print("Tree: drag-data-received");
309                         delete_selection_data = false;
310                         dnd_success = false;
311                         /* Deal with what we are given from source */
312                         if( sel_data && sel_data.length ) {
313                             
314                             if (ctx.action == Gdk.DragAction.ASK)  {
315                                 /* Ask the user to move or copy, then set the ctx action. */
316                             }
317
318                             if (ctx.action == Gdk.DragAction.MOVE) {
319                                 //delete_selection_data = true;
320                             }
321                             
322                             var source = Gtk.drag_get_source_widget(ctx);
323  
324                             if (this.targetData) {
325                                 if (source != this.el) {
326                                     LeftTree.get('model').dropNode(this.targetData,  source.dragData);
327                                 } else {
328                                     // drag around.. - reorder..
329                                     LeftTree.get('model').moveNode(this.targetData);
330                                     
331                                     
332                                 }
333                                 //Seed.print(this.targetData);
334                               
335                             }
336                             
337                             
338                             
339                             // we can send stuff to souce here...
340
341                             dnd_success = true;
342
343                         }
344
345                         if (dnd_success == false)
346                         {
347                                 Seed.print ("DnD data transfer failed!\n");
348                         }
349
350                         Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
351                         return true;
352                     },
353                     
354                     'cursor-changed'  : function(tv, a) {
355                         var iter = new Gtk.TreeIter();
356                         
357                         if (this.selection.count_selected_rows() < 1) {
358                             LeftPanel.get('model').load( false);
359                             MidPropTree.activeElement =  false;
360                             MidPropTree.hideWin();
361                             var RightPalete     = imports.Builder.RightPalete.RightPalete;
362                             var pm = RightPalete.get('model');
363                             if (!LeftTree.getPaleteProvider()) {
364                                 // it may not be loaded yet..
365                                 return  true;
366                             }
367                             pm.load( LeftTree.getPaleteProvider().gatherList(
368                                 LeftTree.get('model').listAllTypes()));
369                            
370                             return true;
371                         }
372                         
373                         //console.log('changed');
374                         var s = this.selection;
375                         s.get_selected(LeftTree.get('model').el, iter);
376                         
377                         
378                         // var val = "";
379                         value = new GObject.Value('');
380                         LeftTree.get('model').el.get_value(iter, 2, value);
381                         LeftTree.get('model').activeIter = iter;
382                         
383                         var data = JSON.parse(value.value);
384                         MidPropTree.activeElement =  data;
385                         MidPropTree.hideWin();
386                         LeftPanel.get('model').load( data);
387                         
388                         console.log(value.value);
389                        // _g.button.set_label(''+value.get_string());
390                         var RightPalete     = imports.Builder.RightPalete.RightPalete;
391                         var pm = RightPalete.get('model');
392                         pm.load( RightPalete.provider.gatherList(
393                             LeftTree.get('model').listAllTypes()));
394                        
395                         
396                        
397                        
398                         //Seed.print( value.get_string());
399                         return true;
400                         
401                         
402                     
403                     }
404                 },
405                 
406                 items  : [
407                     {
408                         id : 'model',
409                         pack : ['set_model'],
410                         
411                         
412                         xtype: Gtk.TreeStore,
413                          
414                         init : function() {
415                             XObject.prototype.init.call(this); 
416                  
417                             
418                             this.el.set_column_types ( 3, [
419                                                     GObject.TYPE_STRING, // title 
420                                                     GObject.TYPE_STRING, // tip
421                                                     GObject.TYPE_STRING // source..
422                                                     ] );
423                             
424                             //if (LeftProjectTree.project).getProvider()
425                             
426                            
427                         },
428                         activeIter : false,
429                         
430                         
431                         changed : function( n, refresh) 
432                         {
433                             print("MODEL CHANGED CALLED" + this.activeIter);
434                             if (this.activeIter) {
435                                     
436                                 this.el.set_value(this.activeIter, 0, [GObject.TYPE_STRING, this.nodeTitle(n)]);
437                                 this.el.set_value(this.activeIter, 1, [GObject.TYPE_STRING, this.nodeTitle(n)]);
438                                 
439                                 this.el.set_value(this.activeIter, 2, [GObject.TYPE_STRING, this.nodeToJSON(n)]);
440                             }
441                                 //this.currentTree = this.toJS(false, true)[0];
442                             this.file.items = this.toJS(false, false);
443                             print("AFTER CHANGED")
444                             //console.dump(this.file.items);
445                             this.file.save();
446                             this.currentTree = this.file.items[0];
447                             //console.log(this.file.toSource());
448                             
449                             if (refresh) {
450                                 print("REDNER BROWSER?!");
451                                 LeftTree.renderView();
452                                 
453                                 var RightPalete     = imports.Builder.RightPalete.RightPalete;
454                                 var pm = RightPalete.get('model');
455                                 if (!RightPalete.provider) {
456                                     pm.load([]);
457                                     return;
458                                 }
459                                 
460                                 
461                                 pm.load( RightPalete.provider.gatherList(this.listAllTypes()));
462                                 //imports['Builder/RightBrowser.js'].renderJS(this.toJS());
463                             }
464                              
465                         },
466                         
467                         
468                         loadFile : function(f)
469                         {
470                             //console.dump(f);
471                             this.el.clear();
472                             this.file = f;
473                             
474                             if (!f) {
475                                 console.log('missing file');
476                                 return;
477                             }
478                             
479                             // load the file if not loaded..
480                             if (f.items === false) {
481                                 var _this = this;
482                                 f.loadItems(function() {
483                                     _this.loadFile(f);
484                                 });
485                                 return;
486                                 
487                             }
488                             if (f.items.length && typeof(f.items[0]) == 'string') {
489                             
490                                 RightEditor.el.show();
491                                 RightEditor.get('view').load( f.items[0]);
492                                 return;
493                             }
494                             print("LOAD");
495                             //console.dump(f.items);
496                             this.load(f.items);
497                             LeftTree.get('view').el.expand_all();
498                             var Window = imports.Builder.Window.Window;
499                             if (!f.items.length) {
500                                 // single item..
501                                 
502                                 Window.get('leftvpaned').el.set_position(80);
503                                 // select first...
504                                 LeftTree.get('view').el.set_cursor( 
505                                     new  Gtk.TreePath.from_string('0'), null, false);
506                                 
507                                 
508                             } else {
509                                   Window.get('leftvpaned').el.set_position(200);
510                             }
511                             
512                             
513                             print("hide right editior");
514                             RightEditor.el.hide();
515                             print("set current tree");
516                             this.currentTree = this.toJS(false, false)[0];
517                             //console.dump(this.currentTree);
518                             this.currentTree = this.currentTree || { items: [] };
519                             LeftTree.renderView();
520                             //console.dump(this.map);
521                             var RightPalete     = imports.Builder.RightPalete.RightPalete;
522                             var pm = RightPalete.get('model');
523                             // set up provider..
524                             
525                             RightPalete.provider = LeftTree.getPaleteProvider();
526                             
527                             if (!RightPalete.provider) {
528                                 print ("********* PALETE PROVIDER MISSING?!!");
529                             }
530                             LeftTree.renderView();
531                             
532                             pm.load( LeftTree.getPaleteProvider().gatherList(this.listAllTypes()));
533                             
534                             
535                                     
536                             Window.get('view-notebook').el.set_current_page(
537                                 LeftTree.get('model').file.getType()== 'Roo' ? 0 : -1);
538                                     
539                             
540                             
541                         },
542                         
543                         findDropNode : function (treepath_str, targets)
544                         {
545                             
546                             
547                             var path = treepath_str.replace(/^builder-/, '');
548                             
549                             if (!XObject.keys(this.treemap).length) {
550                                 print("NO KEYS");
551                                 return [ '',  Gtk.TreeViewDropPosition.INTO_OR_AFTER];
552                             }
553                             print("FIND treepath: " + path);
554                             //console.dump(this.treemap);
555                             
556                             if (!treepath_str.match(/^builder-/)) {
557                                 return []; // nothing!
558                             }
559                             if (targets === true) {
560                                 return [ path ];
561                             }
562                             return this.findDropNodeByPath(path,targets) 
563                         },
564                         findDropNodeByPath : function (treepath_str, targets, pref)
565                         {
566                             
567                             var path = treepath_str + ''; // dupe it..
568                             pref = typeof(pref) == 'undefined' ?  Gtk.TreeViewDropPosition.INTO_OR_AFTER : pref;
569                             var last = false;
570                             //console.dump(this.treemap);
571                             while (path.length) {
572                                 print("LOOKING FOR PATH: " + path);
573                                 var node_data = this.singleNodeToJS(path);
574                                 if (node_data === false) {
575                                     print("node not found");
576                                     return [];
577                                 }
578                                 
579                                 var xname = LeftTree.get('model').file.guessName(node_data);
580                                 var match = false;
581                                 var prop = '';
582                                 targets.forEach(function(tg) {
583                                     if (match) {
584                                         return;;
585                                     }
586                                     if ((tg == xname)  ) {
587                                         match = tg;
588                                     }
589                                     if (tg.indexOf(xname +':') === 0) {
590                                         match = tg;
591                                         prop = tg.split(':').pop();
592                                     }
593                                 });
594                                 
595                                 if (match) {
596                                     if (last) { // pref is after/before..
597                                         // then it's after last
598                                         if (pref > 1) {
599                                             return []; // do not allow..
600                                         }
601                                         return [ last, pref , prop];
602                                         
603                                     }
604                                     return [ path , Gtk.TreeViewDropPosition.INTO_OR_AFTER , prop];
605                                 }
606                                 var par = path.split(':');
607                                 last = path;
608                                 par.pop();
609                                 path = par.join(':');
610                             }
611                             
612                             return [];
613                             
614                             
615                         },
616                         
617                         dropNode: function(target_data, node) {
618                             
619                             console.dump(target_data);
620                             var tp = target_data[0].length ? new  Gtk.TreePath.from_string( target_data[0] ) : false;
621                             
622                             print("add where: " + target_data[1]  );
623                             var parent = tp;
624                             var after = false;
625                             if (target_data[1]  < 2) { // before or after..
626                                 var ar = target_data[0].split(':');
627                                 ar.pop();
628                                 parent  = new  Gtk.TreePath.from_string( ar.join(':') );
629                                 after = tp;
630                             }
631                             var n_iter = new Gtk.TreeIter();
632                             var iter_par = new Gtk.TreeIter();
633                             var iter_after = after ? new Gtk.TreeIter() : false;
634                             if (parent !== false) {
635                                 this.el.get_iter(iter_par, parent);
636                             } else {
637                                 iter_par = null;
638                             }
639                             
640                             
641                             if (after) {
642                                 Seed.print(target_data[1]  > 0 ? 'insert_after' : 'insert_before');
643                                 this.el.get_iter(iter_after, after);
644                                 this.el[ target_data[1]  > 0 ? 'insert_after' : 'insert_before'](
645                                         n_iter, iter_par, iter_after);
646                                 
647                             } else {
648                                 this.el.append(n_iter, iter_par);
649                                 
650                             }
651                             
652                             if (typeof(node) == 'string') {
653                                 var ar = node.split('.');
654                                 var xtype = ar.pop();
655                                 
656                                 node = {
657                                     '|xns' : ar.join('.'),
658                                     'xtype' : xtype
659                                 };
660                                 if (target_data.length == 3 && target_data[2].length) {
661                                     node['*prop'] = target_data[2];
662                                 }
663                                 
664                             }
665                             var xitems = [];
666                             if (node.items) {
667                                 xitems = node.items;
668                                 delete node.items;
669                             }
670                             if (xitems) {
671                                 this.load(xitems, n_iter);
672                             }
673                             if (xitems || after) {
674                                 LeftTree.get('view').el.expand_row(this.el.get_path(iter_par), true);
675                             }
676                             // wee need to get the empty proptypes from somewhere..
677                             
678                             //var olditer = this.activeIter;
679                             this.activeIter = n_iter;
680                             this.changed(node, true);
681                             
682                             
683                             
684                             LeftTree.get('view').el.set_cursor(this.el.get_path(n_iter), null, false);
685                             
686                             //Builder.MidPropTree._model.load(node);
687                             //Builder.MidPropTree._win.hideWin();
688                             //Builder.LeftPanel._model.load( node);
689                             
690                             
691                             
692                             
693                         },
694                         moveNode: function(target_data) {
695                             
696                             //print("MOVE NODE");
697                            // console.dump(target_data);
698                             var old_iter = new Gtk.TreeIter();
699                             var s = LeftTree.get('view').selection;
700                             s.get_selected(this.el, old_iter);
701                             var node = this.nodeToJS(old_iter,false);
702                             //console.dump(node);
703                             
704                             
705                             // needs to drop first, otherwise the target_data 
706                             // treepath will be invalid.
707                             
708                             this.dropNode(target_data, node);
709                             this.el.remove(old_iter);
710                             
711                             
712                         },
713                         
714                         deleteSelected: function() {
715                             
716                             
717                             
718                             var old_iter = new Gtk.TreeIter();
719                             var s = LeftTree.get('view').selection;
720                             s.get_selected(this.el, old_iter);
721                             s.unselect_all();
722                             
723                             this.el.remove(old_iter);
724                             
725                             // rebuild treemap.
726                             this.map = {};
727                             this.treemap = { };
728                             //this.toJS(null, true) // does not do anything?
729                             this.activeIter = false;
730                             this.changed(false,true);
731                             
732                             
733                             
734                         },    
735                         
736                         
737                         currentTree  : false,
738                          
739                         treemap: false, // map of treepath to nodes.
740                         
741                         listAllTypes : function()
742                         {
743                             
744                             
745                             var s = LeftTree.get('view').selection;
746                             print ("LIST ALL TYPES: " + s.count_selected_rows() );
747                             
748                             if (s.count_selected_rows() > 0) {
749                                 var iter = new Gtk.TreeIter();    
750                                 s.get_selected(LeftTree.get('model').el, iter);
751
752                                 // set some properties of the tree for use by the dropped element.
753                                 var value = new GObject.Value('');
754                                 LeftTree.get('model').el.get_value(iter, 2, value);
755                                 var data = JSON.parse(value.value);
756                                 
757                                 
758                                 var xname = LeftTree.get('model').file.guessName(data);
759                                 console.log('selected:' + xname);
760                                 if (xname.length) {
761                                     return [ xname ];
762                                 }
763                                 return []; // could not find it..
764                             }
765                             
766                             var ret = [ ];
767                             
768                             function addall(li)
769                             {
770                                 li.forEach(function(el) {
771                                     // this is specific to roo!!!?
772                                     
773                                     var fullpath =  LeftTree.get('model').file.guessName(el);
774                                     if (fullpath.length && ret.indexOf(fullpath) < 0) {
775                                         ret.push(fullpath);
776                                     }
777                                     
778                                     
779                                     if (el.items && el.items.length) {
780                                         addall(el.items);
781                                     }
782                                     
783                                 })
784                                 
785                                 
786                             }
787                             
788                             addall([this.currentTree]);
789                             
790                             // only if we have nothing, should we add '*top'
791                             if (!ret.length) {
792                                 ret = [ '*top' ];
793                             }
794                             console.log('all types in tree');
795                             console.dump(ret);
796                             
797                             return ret;
798                             
799                             
800                         },
801                         singleNodeToJS: function (treepath) 
802                         {
803                             var iter = new Gtk.TreeIter(); 
804                             if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
805                                 return false;
806                             }
807                             
808                             var iv = this.getValue(iter, 2);
809                            
810                             return JSON.parse(iv);
811                             
812                         },
813                         
814                         /**
815                          * convert tree into a javascript array
816                          * 
817                          */
818                         nodeToJS: function (iter, with_id) 
819                         {
820                             var par = new Gtk.TreeIter(); 
821                             var iv = this.getValue(iter, 2);
822                            // print("IV" + iv);
823                             var k = JSON.parse(iv);
824                             if (k.json && !this.el.iter_parent( par, iter  )) {
825                                 delete k.json;
826                             }
827                             
828                             if (with_id) {
829                                 var treepath_str = this.el.get_path(iter).to_string();
830                                 k.id =  'builder-'+ treepath_str ;
831                                
832                                 this.treemap[  treepath_str ] = k;
833                                 k.xtreepath = treepath_str ;
834                                 
835                             }
836                             if (this.el.iter_has_child(iter)) {
837                                 citer = new Gtk.TreeIter();
838                                 this.el.iter_children(citer, iter);
839                                 k.items = this.toJS(citer,with_id);
840                             }
841                             return k;
842                         },
843                          /**
844                           * iterates through child nodes (or top..)
845                           * 
846                           */
847                         toJS: function(iter, with_id)
848                         {
849                             Seed.print("WITHID: "+ with_id);
850                             
851                             var first = false;
852                             if (!iter) {
853                                 
854                                 this.treemap = { }; 
855                                 
856                                 iter = new Gtk.TreeIter();
857                                 if (!this.el.get_iter_first(iter)) {
858                                     return [];
859                                 }
860                                 first = true;
861                             } 
862                             
863                             var ar = [];
864                                
865                             while (true) {
866                                 
867                                 var k = this.nodeToJS(iter, with_id); 
868                                 ar.push(k);
869                                 
870                                 
871                                 if (!this.el.iter_next(iter)) {
872                                     break;
873                                 }
874                             }
875                             
876                             return ar;
877                             // convert the list into a json string..
878                         
879                             
880                         },
881                         getValue: function (iter, col) {
882                             var gval = new GObject.Value('');
883                             this.el.get_value(iter, col ,gval);
884                             return  gval.value;
885                             
886                             
887                         },
888                         
889                         nodeTitle: function(c)
890                         {
891                               
892                             var txt = [];
893                             c = c || {};
894                             var sr = (typeof(c['+buildershow']) != 'undefined') &&  !c['+buildershow'] ? true : false;
895                             if (sr) txt.push('<s>');
896                             if (typeof(c['*prop']) != 'undefined')   { txt.push(c['*prop']+ ':'); }
897                             if (c.xtype)      { txt.push(c.xtype); }
898                             if (c.id)      { txt.push('<b>[id=' + c.id + ']</b>'); }
899                             if (c.fieldLabel) { txt.push('[' + c.fieldLabel + ']'); }
900                             if (c.boxLabel)   { txt.push('[' + c.boxLabel + ']'); }
901                             
902                             
903                             if (c.layout)     { txt.push('<i>' + c.layout + '</i>'); }
904                             if (c.title)      { txt.push('<b>' + c.title + '</b>'); }
905                             if (c.label)      { txt.push('<b>' + c.label+ '</b>'); }
906                             if (c.header)    { txt.push('<b>' + c.header + '</b>'); }
907                             if (c.legend)      { txt.push('<b>' + c.legend + '</b>'); }
908                             if (c.text)       { txt.push('<b>' + c.text + '</b>'); }
909                             if (c.name)       { txt.push('<b>' + c.name+ '</b>'); }
910                             if (c.region)     { txt.push('<i>(' + c.region + ')</i>'); }
911                             if (c.dataIndex) { txt.push('[' + c.dataIndex+ ']'); }
912                             
913                             // for flat classes...
914                             if (typeof(c['*class']) != 'undefined')  { txt.push('<b>' +  c['*class']+  '</b>'); }
915                             if (typeof(c['*extends']) != 'undefined')  { txt.push(': <i>' +  c['*extends']+  '</i>'); }
916                             
917                             
918                             if (sr) txt.push('</s>');
919                             return (txt.length == 0 ? "Element" : txt.join(" "));
920                         
921                       //console.log(n.xtype);
922                            // return n.xtype;
923                         },
924                         
925                         nodeToJSON : function(c) {
926                             var o  = {}
927                             for (var i in c) {
928                                 if (i == 'items') {
929                                      continue;
930                                 }
931                                 o[i] = c[i];
932                             }
933                             return JSON.stringify(o);
934                         },
935                         /**
936                          * load javascript array onto an iter..
937                          * @param tr = array of elements
938                          * @param iter = iter of parent (or null if not..)
939                          */
940                         
941                         
942                          
943                         
944                         load : function(tr,iter)
945                         {
946                             var citer = new Gtk.TreeIter();
947                             //this.insert(citer,iter,0);
948                             for(var i =0 ; i < tr.length; i++) {
949                                 if (iter) {
950                                     this.el.insert(citer,iter,-1);
951                                 } else {
952                                     this.el.append(citer);
953                                 }
954                                 
955                                 this.el.set_value(citer, 0, [GObject.TYPE_STRING, this.nodeTitle(tr[i]) ]);
956                                 this.el.set_value(citer, 1, [GObject.TYPE_STRING, this.nodeTitle(tr[i]) ]);
957                                 this.el.set_value(citer, 2, [GObject.TYPE_STRING, this.nodeToJSON(tr[i])]);
958                                 if (tr[i].items && tr[i].items.length) {
959                                     this.load(tr[i].items, citer);
960                                 }
961                             }
962                             
963                             
964                             
965                             
966                         },
967                         
968                         
969                         
970                       //  this.expand_all();
971                     },
972                     
973                       
974                     {
975                         xtype: Gtk.TreeViewColumn,
976                         pack : ['append_column'],
977                         init : function(){
978                             XObject.prototype.init.call(this); 
979                             this.el.add_attribute(this.items[0].el , 'markup', 0 );
980                            
981                         },
982                         items : [
983                             {
984                                 
985                                 xtype: Gtk.CellRendererText,
986                                 pack: [ 'pack_start']
987                                   
988                             } 
989                         ],
990                      
991                       
992                     }
993                     
994                ]
995             }
996         ]
997                 
998          
999     }
1000 );
1001