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