bbe1c8dfe13f0acc2f83ab55bfccbc67084fb4f4
[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(data.path.to_string(), src.dropList, data.pos);
267                         LeftTree.get('view').highlight(tg);
268                         if (!tg.length) {
269                             this.targetData = false;
270                             Gdk.drag_status(ctx, 0, time);
271                             return true;
272                         }
273                         //console.dump(tg);
274                         this.targetData = tg;    
275                         
276                         
277                         Gdk.drag_status(ctx, action ,time);
278                          
279                         return true;
280                     },
281                     
282                     'drag-drop'  : function (w, ctx, x, y,time, ud) 
283                     {
284                                 
285                         Seed.print("TARGET: drag-drop");
286                        
287                         Gtk.drag_get_data
288                         (
289                                 w,         /* will receive 'drag-data-received' signal */
290                                 ctx,        /* represents the current state of the DnD */
291                                 LeftTree.atoms["STRING"],    /* the target type we want */
292                                 time            /* time stamp */
293                         );
294                         
295                          
296                         /* No target offered by source => error */
297                        
298
299                         return  true;
300                         
301
302                     },
303                    'drag-data-received' : function (w, ctx,  x,  y, sel_data,  target_type,  time, ud) 
304                     {
305                         Seed.print("Tree: drag-data-received");
306                         delete_selection_data = false;
307                         dnd_success = false;
308                         /* Deal with what we are given from source */
309                         if( sel_data && sel_data.length ) {
310                             
311                             if (ctx.action == Gdk.DragAction.ASK)  {
312                                 /* Ask the user to move or copy, then set the ctx action. */
313                             }
314
315                             if (ctx.action == Gdk.DragAction.MOVE) {
316                                 //delete_selection_data = true;
317                             }
318                             
319                             var source = Gtk.drag_get_source_widget(ctx);
320  
321                             if (this.targetData) {
322                                 if (source != this.el) {
323                                     LeftTree.get('model').dropNode(this.targetData,  source.dragData);
324                                 } else {
325                                     // drag around.. - reorder..
326                                     LeftTree.get('model').moveNode(this.targetData);
327                                     
328                                     
329                                 }
330                                 //Seed.print(this.targetData);
331                               
332                             }
333                             
334                             
335                             
336                             // we can send stuff to souce here...
337
338                             dnd_success = true;
339
340                         }
341
342                         if (dnd_success == false)
343                         {
344                                 Seed.print ("DnD data transfer failed!\n");
345                         }
346
347                         Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
348                         return true;
349                     },
350                     
351                     'cursor-changed'  : function(tv, a) {
352                         var iter = new Gtk.TreeIter();
353                         
354                         if (this.selection.count_selected_rows() < 1) {
355                             LeftPanel.get('model').load( false);
356                             MidPropTree.activeElement =  false;
357                             MidPropTree.hideWin();
358                             var RightPalete     = imports.Builder.RightPalete.RightPalete;
359                             var pm = RightPalete.get('model');
360                             if (!LeftTree.getPaleteProvider()) {
361                                 // it may not be loaded yet..
362                                 return  true;
363                             }
364                             pm.load( LeftTree.getPaleteProvider().gatherList(
365                                 LeftTree.get('model').listAllTypes()));
366                            
367                             return true;
368                         }
369                         
370                         //console.log('changed');
371                         var s = this.selection;
372                         s.get_selected(LeftTree.get('model').el, iter);
373                         
374                         
375                         // var val = "";
376                         value = new GObject.Value('');
377                         LeftTree.get('model').el.get_value(iter, 2, value);
378                         LeftTree.get('model').activeIter = iter;
379                         
380                         var data = JSON.parse(value.value);
381                         MidPropTree.activeElement =  data;
382                         MidPropTree.hideWin();
383                         LeftPanel.get('model').load( data);
384                         
385                         console.log(value.value);
386                        // _g.button.set_label(''+value.get_string());
387                         var RightPalete     = imports.Builder.RightPalete.RightPalete;
388                         var pm = RightPalete.get('model');
389                         pm.load( RightPalete.provider.gatherList(
390                             LeftTree.get('model').listAllTypes()));
391                        
392                         
393                        
394                        
395                         //Seed.print( value.get_string());
396                         return true;
397                         
398                         
399                     
400                     }
401                 },
402                 
403                 items  : [
404                     {
405                         id : 'model',
406                         pack : ['set_model'],
407                         
408                         
409                         xtype: Gtk.TreeStore,
410                          
411                         init : function() {
412                             XObject.prototype.init.call(this); 
413                  
414                             
415                             this.el.set_column_types ( 3, [
416                                                     GObject.TYPE_STRING, // title 
417                                                     GObject.TYPE_STRING, // tip
418                                                     GObject.TYPE_STRING // source..
419                                                     ] );
420                             
421                             //if (LeftProjectTree.project).getProvider()
422                             
423                            
424                         },
425                         activeIter : false,
426                         
427                         
428                         changed : function( n, refresh) 
429                         {
430                             print("MODEL CHANGED CALLED" + this.activeIter);
431                             if (this.activeIter) {
432                                     
433                                 this.el.set_value(this.activeIter, 0, [GObject.TYPE_STRING, this.nodeTitle(n)]);
434                                 this.el.set_value(this.activeIter, 1, [GObject.TYPE_STRING, this.nodeTitle(n)]);
435                                 
436                                 this.el.set_value(this.activeIter, 2, [GObject.TYPE_STRING, this.nodeToJSON(n)]);
437                             }
438                                 //this.currentTree = this.toJS(false, true)[0];
439                             this.file.items = this.toJS(false, false);
440                             print("AFTER CHANGED")
441                             //console.dump(this.file.items);
442                             this.file.save();
443                             this.currentTree = this.file.items[0];
444                             //console.log(this.file.toSource());
445                             
446                             if (refresh) {
447                                 print("REDNER BROWSER?!");
448                                 LeftTree.renderView();
449                                 
450                                 var RightPalete     = imports.Builder.RightPalete.RightPalete;
451                                 var pm = RightPalete.get('model');
452                                 if (!RightPalete.provider) {
453                                     pm.load([]);
454                                     return;
455                                 }
456                                 
457                                 
458                                 pm.load( RightPalete.provider.gatherList(this.listAllTypes()));
459                                 //imports['Builder/RightBrowser.js'].renderJS(this.toJS());
460                             }
461                              
462                         },
463                         
464                         
465                         loadFile : function(f)
466                         {
467                             //console.dump(f);
468                             this.el.clear();
469                             this.file = f;
470                             
471                             if (!f) {
472                                 console.log('missing file');
473                                 return;
474                             }
475                             
476                             // load the file if not loaded..
477                             if (f.items === false) {
478                                 var _this = this;
479                                 f.loadItems(function() {
480                                     _this.loadFile(f);
481                                 });
482                                 return;
483                                 
484                             }
485                             if (f.items.length && typeof(f.items[0]) == 'string') {
486                             
487                                 RightEditor.el.show();
488                                 RightEditor.get('view').load( f.items[0]);
489                                 return;
490                             }
491                             print("LOAD");
492                             //console.dump(f.items);
493                             this.load(f.items);
494                             LeftTree.get('view').el.expand_all();
495                             var Window = imports.Builder.Window.Window;
496                             if (!f.items.length) {
497                                 // single item..
498                                 
499                                 Window.get('leftvpaned').el.set_position(80);
500                                 // select first...
501                                 LeftTree.get('view').el.set_cursor( 
502                                     new  Gtk.TreePath.from_string('0'), null, false);
503                                 
504                                 
505                             } else {
506                                   Window.get('leftvpaned').el.set_position(200);
507                             }
508                             
509                             
510                             print("hide right editior");
511                             RightEditor.el.hide();
512                             print("set current tree");
513                             this.currentTree = this.toJS(false, false)[0];
514                             //console.dump(this.currentTree);
515                             this.currentTree = this.currentTree || { items: [] };
516                             LeftTree.renderView();
517                             //console.dump(this.map);
518                             var RightPalete     = imports.Builder.RightPalete.RightPalete;
519                             var pm = RightPalete.get('model');
520                             // set up provider..
521                             
522                             RightPalete.provider = LeftTree.getPaleteProvider();
523                             
524                             if (!RightPalete.provider) {
525                                 print ("********* PALETE PROVIDER MISSING?!!");
526                             }
527                             LeftTree.renderView();
528                             
529                             pm.load( LeftTree.getPaleteProvider().gatherList(this.listAllTypes()));
530                             
531                             
532                                     
533                             Window.get('view-notebook').el.set_current_page(
534                                 LeftTree.get('model').file.getType()== 'Roo' ? 0 : -1);
535                                     
536                             
537                             
538                         },
539                         
540                         findDropNode : function (treepath_str, targets)
541                         {
542                             
543                             
544                             var path = treepath_str.replace(/^builder-/, '');
545                             
546                             if (!XObject.keys(this.treemap).length) {
547                                 print("NO KEYS");
548                                 return [ '',  Gtk.TreeViewDropPosition.INTO_OR_AFTER];
549                             }
550                             print("FIND treepath: " + path);
551                             //console.dump(this.treemap);
552                             
553                             if (!treepath_str.match(/^builder-/)) {
554                                 return []; // nothing!
555                             }
556                             if (targets === true) {
557                                 return [ path ];
558                             }
559                             return this.findDropNodeByPath(path,targets) 
560                         },
561                         findDropNodeByPath : function (treepath_str, targets, pref)
562                         {
563                             
564                             var path = treepath_str + ''; // dupe it..
565                             pref = typeof(pref) == 'undefined' ?  Gtk.TreeViewDropPosition.INTO_OR_AFTER : pref;
566                             var last = false;
567                             //console.dump(this.treemap);
568                             while (path.length) {
569                                 if (typeof(this.treemap[path]) == 'undefined') {
570                                     return [];
571                                 }
572                                 
573                                 var xname = LeftTree.get('model').file.guessName(this.treemap[path]);
574                                 var match = false;
575                                 var prop = '';
576                                 targets.forEach(function(tg) {
577                                     if (match) {
578                                         return;;
579                                     }
580                                     if ((tg == xname)  ) {
581                                         match = tg;
582                                     }
583                                     if (tg.indexOf(xname +':') === 0) {
584                                         match = tg;
585                                         prop = tg.split(':').pop();
586                                     }
587                                 });
588                                 
589                                 if (match) {
590                                     if (last) { // pref is after/before..
591                                         // then it's after last
592                                         if (pref > 1) {
593                                             return []; // do not allow..
594                                         }
595                                         return [ last, pref , prop];
596                                         
597                                     }
598                                     return [ path , Gtk.TreeViewDropPosition.INTO_OR_AFTER , prop];
599                                 }
600                                 var par = path.split(':');
601                                 last = path;
602                                 par.pop();
603                                 path = par.join(':');
604                             }
605                             return [];
606                             
607                             
608                         },
609                         
610                         dropNode: function(target_data, node) {
611                             
612                             console.dump(target_data);
613                             var tp = target_data[0].length ? new  Gtk.TreePath.from_string( target_data[0] ) : false;
614                             
615                             print("add where: " + target_data[1]  );
616                             var parent = tp;
617                             var after = false;
618                             if (target_data[1]  < 2) { // before or after..
619                                 var ar = target_data[0].split(':');
620                                 ar.pop();
621                                 parent  = new  Gtk.TreePath.from_string( ar.join(':') );
622                                 after = tp;
623                             }
624                             var n_iter = new Gtk.TreeIter();
625                             var iter_par = new Gtk.TreeIter();
626                             var iter_after = after ? new Gtk.TreeIter() : false;
627                             if (parent !== false) {
628                                 this.el.get_iter(iter_par, parent);
629                             } else {
630                                 iter_par = null;
631                             }
632                             
633                             
634                             if (after) {
635                                 Seed.print(target_data[1]  > 0 ? 'insert_after' : 'insert_before');
636                                 this.el.get_iter(iter_after, after);
637                                 this.el[ target_data[1]  > 0 ? 'insert_after' : 'insert_before'](
638                                         n_iter, iter_par, iter_after);
639                                 
640                             } else {
641                                 this.el.append(n_iter, iter_par);
642                                 
643                             }
644                             
645                             if (typeof(node) == 'string') {
646                                 var ar = node.split('.');
647                                 var xtype = ar.pop();
648                                 
649                                 node = {
650                                     '|xns' : ar.join('.'),
651                                     'xtype' : xtype
652                                 };
653                                 if (target_data.length == 3 && target_data[2].length) {
654                                     node['*prop'] = target_data[2];
655                                 }
656                                 
657                             }
658                             var xitems = [];
659                             if (node.items) {
660                                 xitems = node.items;
661                                 delete node.items;
662                             }
663                             if (xitems) {
664                                 this.load(xitems, n_iter);
665                             }
666                             if (xitems || after) {
667                                 LeftTree.get('view').el.expand_row(this.el.get_path(iter_par), true);
668                             }
669                             // wee need to get the empty proptypes from somewhere..
670                             
671                             //var olditer = this.activeIter;
672                             this.activeIter = n_iter;
673                             this.changed(node, true);
674                             
675                             
676                             
677                             LeftTree.get('view').el.set_cursor(this.el.get_path(n_iter), null, false);
678                             
679                             //Builder.MidPropTree._model.load(node);
680                             //Builder.MidPropTree._win.hideWin();
681                             //Builder.LeftPanel._model.load( node);
682                             
683                             
684                             
685                             
686                         },
687                         moveNode: function(target_data) {
688                             
689                             //print("MOVE NODE");
690                            // console.dump(target_data);
691                             var old_iter = new Gtk.TreeIter();
692                             var s = LeftTree.get('view').selection;
693                             s.get_selected(this.el, old_iter);
694                             var node = this.nodeToJS(old_iter,false);
695                             //console.dump(node);
696                             
697                             
698                             // needs to drop first, otherwise the target_data 
699                             // treepath will be invalid.
700                             
701                             this.dropNode(target_data, node);
702                             this.el.remove(old_iter);
703                             
704                             
705                         },
706                         
707                         deleteSelected: function() {
708                             
709                             
710                             
711                             var old_iter = new Gtk.TreeIter();
712                             var s = LeftTree.get('view').selection;
713                             s.get_selected(this.el, old_iter);
714                             s.unselect_all();
715                             
716                             this.el.remove(old_iter);
717                             
718                             // rebuild treemap.
719                             this.map = {};
720                             this.treemap = { };
721                             //this.toJS(null, true) // does not do anything?
722                             this.activeIter = false;
723                             this.changed(false,true);
724                             
725                             
726                             
727                         },    
728                         
729                         
730                         currentTree  : false,
731                          
732                         treemap: false, // map of treepath to nodes.
733                         
734                         listAllTypes : function()
735                         {
736                             
737                             
738                             var s = LeftTree.get('view').selection;
739                             print ("LIST ALL TYPES: " + s.count_selected_rows() );
740                             
741                             if (s.count_selected_rows() > 0) {
742                                 var iter = new Gtk.TreeIter();    
743                                 s.get_selected(LeftTree.get('model').el, iter);
744
745                                 // set some properties of the tree for use by the dropped element.
746                                 var value = new GObject.Value('');
747                                 LeftTree.get('model').el.get_value(iter, 2, value);
748                                 var data = JSON.parse(value.value);
749                                 
750                                 
751                                 var xname = LeftTree.get('model').file.guessName(data);
752                                 console.log('selected:' + xname);
753                                 if (xname.length) {
754                                     return [ xname ];
755                                 }
756                                 return []; // could not find it..
757                             }
758                             
759                             var ret = [ ];
760                             
761                             function addall(li)
762                             {
763                                 li.forEach(function(el) {
764                                     // this is specific to roo!!!?
765                                     
766                                     var fullpath =  LeftTree.get('model').file.guessName(el);
767                                     if (fullpath.length && ret.indexOf(fullpath) < 0) {
768                                         ret.push(fullpath);
769                                     }
770                                     
771                                     
772                                     if (el.items && el.items.length) {
773                                         addall(el.items);
774                                     }
775                                     
776                                 })
777                                 
778                                 
779                             }
780                             
781                             addall([this.currentTree]);
782                             
783                             // only if we have nothing, should we add '*top'
784                             if (!ret.length) {
785                                 ret = [ '*top' ];
786                             }
787                             console.log('all types in tree');
788                             console.dump(ret);
789                             
790                             return ret;
791                             
792                             
793                         },
794                         
795                         
796                         /**
797                          * convert tree into a javascript array
798                          * 
799                          */
800                         nodeToJS: function (iter, with_id) 
801                         {
802                             var par = new Gtk.TreeIter(); 
803                             var iv = this.getValue(iter, 2);
804                            // print("IV" + iv);
805                             var k = JSON.parse(iv);
806                             if (k.json && !this.el.iter_parent( par, iter  )) {
807                                 delete k.json;
808                             }
809                             
810                             if (with_id) {
811                                 var treepath_str = this.el.get_path(iter).to_string();
812                                 k.id =  'builder-'+ treepath_str ;
813                                
814                                 this.treemap[  treepath_str ] = k;
815                                 k.xtreepath = treepath_str ;
816                                 
817                             }
818                             if (this.el.iter_has_child(iter)) {
819                                 citer = new Gtk.TreeIter();
820                                 this.el.iter_children(citer, iter);
821                                 k.items = this.toJS(citer,with_id);
822                             }
823                             return k;
824                         },
825                          /**
826                           * iterates through child nodes (or top..)
827                           * 
828                           */
829                         toJS: function(iter, with_id)
830                         {
831                             Seed.print("WITHID: "+ with_id);
832                             
833                             var first = false;
834                             if (!iter) {
835                                 
836                                 this.treemap = { }; 
837                                 
838                                 iter = new Gtk.TreeIter();
839                                 if (!this.el.get_iter_first(iter)) {
840                                     return [];
841                                 }
842                                 first = true;
843                             } 
844                             
845                             var ar = [];
846                                
847                             while (true) {
848                                 
849                                 var k = this.nodeToJS(iter, with_id); 
850                                 ar.push(k);
851                                 
852                                 
853                                 if (!this.el.iter_next(iter)) {
854                                     break;
855                                 }
856                             }
857                             
858                             return ar;
859                             // convert the list into a json string..
860                         
861                             
862                         },
863                         getValue: function (iter, col) {
864                             var gval = new GObject.Value('');
865                             this.el.get_value(iter, col ,gval);
866                             return  gval.value;
867                             
868                             
869                         },
870                         
871                         nodeTitle: function(c)
872                         {
873                               
874                             var txt = [];
875                             c = c || {};
876                             var sr = (typeof(c['+buildershow']) != 'undefined') &&  !c['+buildershow'] ? true : false;
877                             if (sr) txt.push('<s>');
878                             if (typeof(c['*prop']) != 'undefined')   { txt.push(c['*prop']+ ':'); }
879                             if (c.xtype)      { txt.push(c.xtype); }
880                             if (c.id)      { txt.push('<b>[id=' + c.id + ']</b>'); }
881                             if (c.fieldLabel) { txt.push('[' + c.fieldLabel + ']'); }
882                             if (c.boxLabel)   { txt.push('[' + c.boxLabel + ']'); }
883                             
884                             
885                             if (c.layout)     { txt.push('<i>' + c.layout + '</i>'); }
886                             if (c.title)      { txt.push('<b>' + c.title + '</b>'); }
887                             if (c.label)      { txt.push('<b>' + c.label+ '</b>'); }
888                             if (c.header)    { txt.push('<b>' + c.header + '</b>'); }
889                             if (c.legend)      { txt.push('<b>' + c.legend + '</b>'); }
890                             if (c.text)       { txt.push('<b>' + c.text + '</b>'); }
891                             if (c.name)       { txt.push('<b>' + c.name+ '</b>'); }
892                             if (c.region)     { txt.push('<i>(' + c.region + ')</i>'); }
893                             if (c.dataIndex) { txt.push('[' + c.dataIndex+ ']'); }
894                             
895                             // for flat classes...
896                             if (typeof(c['*class']) != 'undefined')  { txt.push('<b>' +  c['*class']+  '</b>'); }
897                             if (typeof(c['*extends']) != 'undefined')  { txt.push(': <i>' +  c['*extends']+  '</i>'); }
898                             
899                             
900                             if (sr) txt.push('</s>');
901                             return (txt.length == 0 ? "Element" : txt.join(" "));
902                         
903                       //console.log(n.xtype);
904                            // return n.xtype;
905                         },
906                         
907                         nodeToJSON : function(c) {
908                             var o  = {}
909                             for (var i in c) {
910                                 if (i == 'items') {
911                                      continue;
912                                 }
913                                 o[i] = c[i];
914                             }
915                             return JSON.stringify(o);
916                         },
917                         /**
918                          * load javascript array onto an iter..
919                          * @param tr = array of elements
920                          * @param iter = iter of parent (or null if not..)
921                          */
922                         
923                         
924                          
925                         
926                         load : function(tr,iter)
927                         {
928                             var citer = new Gtk.TreeIter();
929                             //this.insert(citer,iter,0);
930                             for(var i =0 ; i < tr.length; i++) {
931                                 if (iter) {
932                                     this.el.insert(citer,iter,-1);
933                                 } else {
934                                     this.el.append(citer);
935                                 }
936                                 
937                                 this.el.set_value(citer, 0, [GObject.TYPE_STRING, this.nodeTitle(tr[i]) ]);
938                                 this.el.set_value(citer, 1, [GObject.TYPE_STRING, this.nodeTitle(tr[i]) ]);
939                                 this.el.set_value(citer, 2, [GObject.TYPE_STRING, this.nodeToJSON(tr[i])]);
940                                 if (tr[i].items && tr[i].items.length) {
941                                     this.load(tr[i].items, citer);
942                                 }
943                             }
944                             
945                             
946                             
947                             
948                         },
949                         
950                         
951                         
952                       //  this.expand_all();
953                     },
954                     
955                       
956                     {
957                         xtype: Gtk.TreeViewColumn,
958                         pack : ['append_column'],
959                         init : function(){
960                             XObject.prototype.init.call(this); 
961                             this.el.add_attribute(this.items[0].el , 'markup', 0 );
962                            
963                         },
964                         items : [
965                             {
966                                 
967                                 xtype: Gtk.CellRendererText,
968                                 pack: [ 'pack_start']
969                                   
970                             } 
971                         ],
972                      
973                       
974                     }
975                     
976                ]
977             }
978         ]
979                 
980          
981     }
982 );
983