src/Builder4/WindowLeftTree.bjs
[app.Builder.js] / src / Builder4 / WindowLeftTree.vala
1 static Xcls_WindowLeftTree  _WindowLeftTree;
2
3 public class Xcls_WindowLeftTree : Object 
4 {
5     public Gtk.ScrolledWindow el;
6     private Xcls_WindowLeftTree  _this;
7
8     public static Xcls_WindowLeftTree singleton()
9     {
10         if (_WindowLeftTree == null) {
11             _WindowLeftTree= new Xcls_WindowLeftTree();
12         }
13         return _WindowLeftTree;
14     }
15     public Xcls_view view;
16     public Xcls_model model;
17     public Xcls_renderer renderer;
18     public Xcls_LeftTreeMenu LeftTreeMenu;
19
20         // my vars (def)
21     public signal bool before_node_change (JsRender.Node? node);
22     public signal void changed ();
23     public signal void node_selected (JsRender.Node? node);
24     public Xcls_MainWindow main_window;
25
26     // ctor 
27     public Xcls_WindowLeftTree()
28     {
29         _this = this;
30         this.el = new Gtk.ScrolledWindow( null, null );
31
32         // my vars (dec)
33         this.main_window = null;
34
35         // set gobject values
36         this.el.shadow_type = Gtk.ShadowType.IN;
37         var child_0 = new Xcls_view( _this );
38         child_0.ref();
39         this.el.add (  child_0.el  );
40         var child_1 = new Xcls_LeftTreeMenu( _this );
41         child_1.ref();
42
43         // init method 
44
45         this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
46     }
47
48     // user defined functions 
49     public           JsRender.Node? getActiveElement () { // return path to actie node.
50     
51          var path = this.getActivePath();
52          if (path.length < 1) {
53             return null;
54          }
55          return _this.model.pathToNode(path);
56          
57     }
58     public           JsRender.JsRender getActiveFile () {
59         return this.model.file;
60     }
61     public           string getActivePath () {
62         var model = this.model;
63         var view = this.view.el;
64         if (view.get_selection().count_selected_rows() < 1) {
65             return "";
66         }
67         Gtk.TreeIter iter;
68         Gtk.TreeModel mod;
69         view.get_selection().get_selected(out mod, out iter);
70         return mod.get_path(iter).to_string();
71     }
72     public class Xcls_view : Object 
73     {
74         public Gtk.TreeView el;
75         private Xcls_WindowLeftTree  _this;
76
77
78             // my vars (def)
79         public string dragData;
80         public int drag_x;
81         public string[] dropList;
82         public int drag_y;
83         public bool drag_in_motion;
84         public bool blockChanges;
85
86         // ctor 
87         public Xcls_view(Xcls_WindowLeftTree _owner )
88         {
89             _this = _owner;
90             _this.view = this;
91             this.el = new Gtk.TreeView();
92
93             // my vars (dec)
94             this.blockChanges = false;
95
96             // set gobject values
97             this.el.tooltip_column = 1;
98             this.el.enable_tree_lines = true;
99             this.el.headers_visible = false;
100             var child_0 = new Xcls_model( _this );
101             child_0.ref();
102             this.el.set_model (  child_0.el  );
103             var child_1 = new Xcls_TreeViewColumn4( _this );
104             child_1.ref();
105             this.el.append_column (  child_1.el  );
106
107             // init method 
108
109             {
110                 var description = new Pango.FontDescription();
111                 description.set_size(8000);
112                 this.el.modify_font(description);
113             
114                 var selection = this.el.get_selection();
115                 selection.set_mode( Gtk.SelectionMode.SINGLE);
116             
117             
118                 // is this really needed??
119                 /*
120                 this.selection.signal['changed'].connect(function() {
121                     _this.get('/LeftTree.view').listeners.cursor_changed.apply(
122                         _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
123                     );
124                 });
125                 */
126                 Gtk.drag_source_set (
127                     this.el,            /* widget will be drag-able */
128                     Gdk.ModifierType.BUTTON1_MASK,       /* modifier that will start a drag */
129                     BuilderApplication.targetList,            /* lists of target to support */
130                     Gdk.DragAction.COPY   | Gdk.DragAction.MOVE    |  Gdk.DragAction.LINK           /* what to do with data after dropped */
131                 );
132             
133                 // ?? needed??
134                 //Gtk.drag_source_add_text_targets(this.el); 
135             
136                 Gtk.drag_dest_set
137                 (
138                     this.el,              /* widget that will accept a drop */
139                     Gtk.DestDefaults.MOTION  | Gtk.DestDefaults.HIGHLIGHT,
140                     BuilderApplication.targetList,            /* lists of target to support */
141                     Gdk.DragAction.COPY   | Gdk.DragAction.MOVE   | Gdk.DragAction.LINK     /* what to do with data after dropped */
142                 );
143             
144                 //Gtk.drag_dest_set_target_list(this.el, Builder.Application.targetList);
145                 //Gtk.drag_dest_add_text_targets(this.el);
146             }
147
148             // listeners 
149             this.el.button_press_event.connect( ( ev) => {
150                 //console.log("button press?");
151                 if (! _this.before_node_change(null) ) {
152                    return true;
153                 }
154             
155                 
156                 if (ev.type != Gdk.EventType.BUTTON_PRESS  || ev.button != 3) {
157                     //print("click" + ev.type);
158                     return false;
159                 }
160                 Gtk.TreePath res;
161                 if (!_this.view.el.get_path_at_pos((int)ev.x,(int)ev.y, out res, null, null, null) ) {
162                     return true;
163                 }
164                  
165                 this.el.get_selection().select_path(res);
166                  
167                   //if (!this.get('/LeftTreeMenu').el)  { 
168                   //      this.get('/LeftTreeMenu').init(); 
169                   //  }
170                     
171                  _this.LeftTreeMenu.el.set_screen(Gdk.Screen.get_default());
172                  _this.LeftTreeMenu.el.show_all();
173                   _this.LeftTreeMenu.el.popup(null, null, null,  3, ev.time);
174                  //   print("click:" + res.path.to_string());
175                   return true;
176             });
177             this.el.drag_begin.connect( ( ctx)  => {
178                 //print('SOURCE: drag-begin');
179                     
180                     
181                     //this.targetData = "";
182                     
183                     // find what is selected in our tree...
184                     
185                     var s = _this.view.el.get_selection();
186                     if (s.count_selected_rows() < 1) {
187                         return;
188                     }
189                     Gtk.TreeIter iter;
190                     Gtk.TreeModel mod;
191                     s.get_selected(out mod, out iter);
192             
193                     
194             
195                     // set some properties of the tree for use by the dropped element.
196                     GLib.Value value;
197                     _this.model.el.get_value(iter, 2, out value);
198                     var tp = mod.get_path(iter).to_string();
199                     var data = (JsRender.Node)(value.dup_object());
200                     var xname = data.fqn();
201                     print ("XNAME  IS " + xname+ "\n");
202                     this.dragData = tp;
203                     this.dropList = _this.model.file.palete().getDropList(xname);
204                     
205                     print ("DROP LIST IS " + string.joinv(", ", this.dropList) + "\n");
206                     
207             
208                     // make the drag icon a picture of the node that was selected
209                 
210                     
211                 // by default returns the path..
212                    var path = _this.model.el.get_path(iter);
213             
214                      
215                     var pix = this.el.create_row_drag_icon ( path);
216                     
217                     Gtk.drag_set_icon_surface (ctx, pix) ;
218                     
219                     return;
220             });
221             this.el.cursor_changed.connect( ( ) => {
222             
223             
224                  if (this.blockChanges) { // probably not needed.. 
225                    return  ;
226                  }
227                   if (!_this.before_node_change(null) ) {
228                      this.blockChanges = true;
229                      this.el.get_selection().unselect_all();
230                      this.blockChanges = false;
231                      return;
232                  }
233                  if (_this.model.file == null) {
234                      return;
235                  } 
236                  
237                  //var render = this.get('/LeftTree').getRenderer();                
238                 print("LEFT TREE -> view -> selection changed called\n");
239                 
240                 
241                 // -- it appears that the selection is not updated.
242                 
243                 GLib.Timeout.add_full(GLib.Priority.DEFAULT,10 , () => {
244                      
245             
246                         if (this.el.get_selection().count_selected_rows() < 1) {
247             
248                             print("selected rows < 1\n");
249                             //??this.model.load( false);
250                             _this.node_selected(null);
251                             
252                             return false ;
253                         }
254                             
255                             //console.log('changed');
256                         var s = this.el.get_selection();
257                          Gtk.TreeIter iter;
258                          Gtk.TreeModel mod;
259                         s.get_selected(out mod, out iter);
260                         
261                         
262                         // var val = "";
263                         GLib.Value value;
264                         _this.model.el.get_value(iter, 2, out value);
265                         _this.model.activePath = mod.get_path(iter).to_string();
266                         
267                         var node = (JsRender.Node)value.dup_object();
268                         _this.node_selected(node);
269                         
270                         this.el.scroll_to_cell(new Gtk.TreePath.from_string(_this.model.activePath), null, true, 0.1f,0.0f);
271                         
272                         return false;
273                   });  
274                 //_this.after_node_change(node);
275             
276             //        _this.model.file.changed(node, "tree");
277                
278                 //Seed.print( value.get_string());
279                 return  ;
280                             
281             });
282             this.el.drag_end.connect( (drag_context) => {
283                 //Seed.print('LEFT-TREE: drag-end');
284                     this.dragData = "";
285                     this.dropList = null;
286             //        this.targetData = "";
287                     this.highlightDropPath("",0);
288             //        return true;
289             });
290             this.el.drag_motion.connect( ( ctx, x, y, time)  => {
291                print("got drag motion\n");
292                 var src = Gtk.drag_get_source_widget(ctx);
293                this.drag_x = x;
294                this.drag_y = y;     
295             
296                if (src != this.el) {
297                
298              
299              
300                 // the point of this is to detect where an item could be dropped..
301                     print("requesting drag data\n");
302                    this.drag_in_motion = true;
303                    
304                         // request data that will be recieved by the recieve...              
305                     Gtk.drag_get_data
306                     (
307                             this.el,         // will receive 'drag-data-received' signal 
308                             ctx,        // represents the current state of the DnD 
309                             Gdk.Atom.intern("STRING",true),    // the target type we want 
310                             time            // time stamp 
311                     );
312                     return true;
313               }    
314             
315             
316               print("action: %d\n", ctx.get_actions());
317              //print("GETTING POS");
318                 var  targetData = "";
319             
320                 Gtk.TreePath path;
321                 Gtk.TreeViewDropPosition pos;
322                 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
323             
324                 // if there are not items in the tree.. the we have to set isOver to true for anything..
325                 var isEmpty = false;
326                 if (_this.model.el.iter_n_children(null) < 1) {
327                     print("got NO children?\n");
328                     isOver = true; //??? 
329                     isEmpty = true;
330                     pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
331                 }
332             
333             
334                 // ------------- a drag from self..
335             
336             
337                 //var action = Gdk.DragAction.COPY;
338                     // unless we are copying!!! ctl button..
339                 
340                 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
341                              Gdk.DragAction.COPY  : Gdk.DragAction.MOVE ;
342                             // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
343             
344             
345                 if (_this.model.el.iter_n_children(null) < 1) {
346                     // no children.. -- asume it's ok..
347                     
348                     targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
349                        
350                     this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);        
351                     Gdk.drag_status(ctx, action ,time);
352                     return true;
353                     
354                     // continue through to allow drop...
355             
356                 } 
357                     
358                     
359             
360                 
361                 
362                 //print("ISOVER? " + isOver);
363                 if (!isOver) {
364               
365                     Gdk.drag_status(ctx, 0 ,time);
366                      this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);                    
367                      return false;
368             
369                 }
370                         
371                 // drag node is parent of child..
372                 //console.log("SRC TREEPATH: " + src.treepath);
373                 //console.log("TARGET TREEPATH: " + data.path.to_string());
374                 
375                 // nned to check a  few here..
376                 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
377                 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
378                 //Gtk.TreeViewDropPosition.AFTER
379                 //Gtk.TreeViewDropPosition.BEFORE
380                 
381                 // locally dragged items to not really use the 
382                 var selection_text = this.dragData;
383                 
384                         
385                         
386                 if (selection_text == null || selection_text.length < 1) {
387                             //print("Error  - drag selection text returned NULL");
388                          Gdk.drag_status(ctx, 0 ,time);
389                         this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
390                          return false;
391                  }
392                                    
393                         
394                         // see if we are dragging into ourself?
395                 var target_path = path.to_string();            
396                 print ("Drag  %s onto %s--%d\n ", selection_text, target_path, pos);
397                 
398                 // pos : 3 = ontop - 0 = after, 1 = before
399                 //print("target_path="+target_path);
400             
401                 // 
402                 if (selection_text  == target_path) {
403                     print("self drag ?? == we should perhaps allow copy onto self..\n");
404                             
405                      Gdk.drag_status(ctx, 0 ,time);
406                       this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
407                       return false;
408             //                 -- fixme -- this is not really correct..
409             
410                 }
411                         
412                 // check that 
413                 //print("DUMPING DATA");
414                 //console.dump(data);
415                 // path, pos
416                 
417                 //print(data.path.to_string() +' => '+  data.pos);
418                 
419                 // dropList is a list of xtypes that this node could be dropped on.
420                 // it is set up when we start to drag..
421                 
422                 
423                 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
424                     
425                 print("targetDAta: " + targetData +"\n");
426                 
427                 if (targetData.length < 1) {
428                     //print("Can not find drop node path");
429                    
430                     Gdk.drag_status(ctx, 0, time);
431                     this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
432                     return false;
433                 }
434                 
435                 var td_ar = targetData.split("|");
436                   
437                 
438             
439                 Gdk.drag_status(ctx, action ,time);
440                 this.highlightDropPath(td_ar[0], (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
441                 return true;
442                    
443                    
444             });
445             this.el.drag_data_get.connect( ( drag_context, data, info, time) => {
446                         
447                         
448                              //print("drag-data-get");
449                              var s = this.el.get_selection();
450                              if (s.count_selected_rows() < 1) {
451                                     data.set_text("",0);     
452                                      print("return empty string - no selection..");
453                                     return;
454                                 }
455                              
456                              Gtk.TreeIter iter;
457                              Gtk.TreeModel mod;
458                              
459                              s.get_selected(out mod, out iter);
460                              
461                             
462                             
463                              GLib.Value value;
464                              _this.model.el.get_value(iter, 2, out value);
465                              var ndata = (JsRender.Node)(value.dup_object());
466                              var xname = ndata.fqn();
467                             
468                             
469                             var tp = mod.get_path(iter).to_string();
470                             // by default returns the path..
471                             
472                            if ( info != Gdk.Atom.intern("STRING",true) ) {
473                                 tp = ndata.toJsonString();
474                            }   
475                            
476                            //data.set_text(tp,tp.length);   
477                             
478                             data.set (data.get_target (), 8, (uchar[]) tp.to_utf8 ());
479                         
480                             
481                            //  print("return " + tp);
482                         });
483             this.el.drag_data_received.connect( (ctx, x, y, sel, info, time)  => {
484               
485                     // THIS CODE ONLY RELATES TO drag  or drop of "NEW" elements or "FROM another tree.."
486               
487               
488                     //  print("Tree: drag-data-received\n");
489                     var selection_text = (string)sel.get_data();
490                     //print("selection_text= %s\n",selection_text);
491             
492                     var is_drag = this.drag_in_motion;
493                 
494                     
495             
496                     print("Is Drag %s\n", is_drag ? "Y": "N");
497                     var  targetData = "";
498                     
499                     Gtk.TreePath path;
500                     Gtk.TreeViewDropPosition pos;
501                     var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
502                     
503                     // if there are not items in the tree.. the we have to set isOver to true for anything..
504                     var isEmpty = false;
505                     if (_this.model.el.iter_n_children(null) < 1) {
506                         print("got NO children?\n");
507                         isOver = true; //??? 
508                         isEmpty = true;
509                         pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
510                     }
511                     
512                  
513                     //console.log("LEFT-TREE: drag-motion");
514                     var src = Gtk.drag_get_source_widget(ctx);
515                     
516                     // a drag from self - this should be handled by drop and motion.
517                     if (src == this.el) {
518                         print("Source == this element should not happen.. ? \n");
519                         return;
520                     }
521                     //print("drag_data_recieved from another element");
522                     
523                      
524                     
525                     
526                     if (selection_text == null || selection_text.length < 1 || !isOver) {
527                         // nothing valid foudn to drop...
528                            print("empty sel text or not over");
529                         if (is_drag) {
530                             Gdk.drag_status(ctx, 0, time);
531                             this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
532                             return;
533                         }
534                         Gtk.drag_finish (ctx, false, false, time);        // drop failed..
535                         // no drop action...
536                         return;            
537                     
538                     }
539                     var dropNode = new JsRender.Node(); 
540                     
541                     var dropNodeType  = selection_text;
542                     var show_templates = true;
543                     // for drop
544                     if (dropNodeType[0] == '{') {
545                         var pa = new Json.Parser();
546                         pa.load_from_data(dropNodeType);
547                          
548                         dropNode.loadFromJson( pa.get_root().get_object(), 2);
549                         dropNodeType = dropNode.fqn();
550                         show_templates = false;
551                         
552                         
553                     } else {
554             
555                         dropNode.setFqn(selection_text);
556                     }
557             
558                      
559                     // dropList --- need to gather this ... 
560                     print("get dropList for : %s\n",dropNodeType);            
561                     var dropList = _this.model.file.palete().getDropList(dropNodeType);
562                     
563                     print("dropList: %s\n", string.joinv(" , ", dropList));
564                     
565                     // if drag action is link ... then we can drop it anywahere...
566                      if ((ctx.get_actions() & Gdk.DragAction.LINK) > 0) {
567                          // if path is null?? dragging into an empty tree?
568                          targetData = (path == null ? "" :  path.to_string()) + "|%d".printf((int)pos);
569                      } else {
570                     
571                     
572                         targetData = _this.model.findDropNodeByPath( isEmpty ? "" : path.to_string(), dropList, pos);
573                      }
574                     
575                     
576                         
577                     print("targetDAta: " + targetData +"\n");
578                     
579                     if (targetData.length < 1) {
580                      
581                         // invalid drop path..
582                         if (this.drag_in_motion) {
583                             Gdk.drag_status(ctx, 0, time);
584                             this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
585                             return;
586                         }
587                         Gtk.drag_finish (ctx, false, false, time);        // drop failed..
588                         // no drop action...
589                         return;
590                     }
591                     // valid drop path..
592                     
593                       var td_ar = targetData.split("|");
594                       
595                     
596                     if (this.drag_in_motion) { 
597                         Gdk.drag_status(ctx, Gdk.DragAction.COPY ,time);
598             
599                         this.highlightDropPath(  td_ar[0]  , (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
600                         return;
601                     }
602                     // continue on to allow drop..
603                 
604             
605                     // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
606                     
607             
608                     _this.model.dropNode(targetData, dropNode, show_templates);
609                     print("ADD new node!!!\n");
610                         
611                     ///Xcls_DialogTemplateSelect.singleton().show( _this.model.file.palete(), node);
612                     
613                     Gtk.drag_finish (ctx, false, false,time);
614                     
615                     
616                         
617                         
618                   
619             });
620             this.el.drag_drop.connect( (  ctx, x, y, time)  => {
621                   //Seed.print("TARGET: drag-drop");
622                
623                
624                 var src = Gtk.drag_get_source_widget(ctx);
625                  
626                if (src != this.el) {
627                
628                 
629                    
630                    this.drag_in_motion = false;   
631                         // request data that will be recieved by the recieve...              
632                     Gtk.drag_get_data
633                     (
634                             this.el,         // will receive 'drag-data-received' signal 
635                             ctx,        // represents the current state of the DnD 
636                             Gdk.Atom.intern("application/json",true),    // the target type we want 
637                             time            // time stamp 
638                     );
639             
640                      
641                     // No target offered by source => error
642                
643             
644                      return  false;
645                  }
646                  
647                  // handle drop around self..
648                  
649                               
650                         
651                 //print("GETTING POS");
652                 var  targetData = "";
653                 
654                 Gtk.TreePath path;
655                 Gtk.TreeViewDropPosition pos;
656                 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
657                 
658                 // if there are not items in the tree.. the we have to set isOver to true for anything..
659                 var isEmpty = false;
660                 if (_this.model.el.iter_n_children(null) < 1) {
661                     print("got NO children?\n");
662                     isOver = true; //??? 
663                     isEmpty = true;
664                     pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
665                 }
666                 
667                  
668                  
669                 //var action = Gdk.DragAction.COPY;
670                     // unless we are copying!!! ctl button..
671                 
672                 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
673                              Gdk.DragAction.COPY  : Gdk.DragAction.MOVE ;
674                             // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
675             
676                   
677                 if (_this.model.el.iter_n_children(null) < 1) {
678                     // no children.. -- asume it's ok..
679                     
680                     targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
681                      
682                     // continue through to allow drop...
683             
684                 } else {
685                             
686                             
687                 
688                             
689                             
690                             //print("ISOVER? " + isOver);
691                     if (!isOver) {
692                         
693                         Gtk.drag_finish (ctx, false, false, time);        // drop failed..
694                         return true; // not over apoint!?! - no action on drop or motion..
695                     }
696                             
697                     // drag node is parent of child..
698                     //console.log("SRC TREEPATH: " + src.treepath);
699                     //console.log("TARGET TREEPATH: " + data.path.to_string());
700                     
701                     // nned to check a  few here..
702                     //Gtk.TreeViewDropPosition.INTO_OR_AFTER
703                     //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
704                     //Gtk.TreeViewDropPosition.AFTER
705                     //Gtk.TreeViewDropPosition.BEFORE
706                     
707                     // locally dragged items to not really use the 
708                     var selection_text = this.dragData;
709                     
710                     
711                     
712                     if (selection_text == null || selection_text.length < 1) {
713                         //print("Error  - drag selection text returned NULL");
714                       
715                          Gtk.drag_finish (ctx, false, false, time);        // drop failed..
716                          return true; /// -- fixme -- this is not really correct..
717                     }                
718                             
719                             // see if we are dragging into ourself?
720                             print ("got selection text of  " + selection_text);
721                     
722                     var target_path = path.to_string();
723                     //print("target_path="+target_path);
724             
725                     // 
726                     if (selection_text  == target_path) {
727                         print("self drag ?? == we should perhaps allow copy onto self..\n");
728                         
729                          Gtk.drag_finish (ctx, false, false, time);        // drop failed..
730             
731                          return true; /// -- fixme -- this is not really correct..
732             
733                     }
734                             
735                     // check that 
736                     //print("DUMPING DATA");
737                     //console.dump(data);
738                     // path, pos
739                     
740                     //print(data.path.to_string() +' => '+  data.pos);
741                     
742                     // dropList is a list of xtypes that this node could be dropped on.
743                     // it is set up when we start to drag..
744                     
745                     
746                     targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
747                         
748                     print("targetDAta: " + targetData +"\n");
749                     
750                     if (targetData.length < 1) {
751                         //print("Can not find drop node path");
752                          
753                         Gtk.drag_finish (ctx, false, false, time);        // drop failed..
754                         return true;
755                     }
756                     
757                     var td_ar = targetData.split("|");
758                               
759                             
760                             
761                             // continue on to allow drop..
762               }
763                     // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
764             
765             
766                  var delete_selection_data = false;
767                     
768                 if (action == Gdk.DragAction.ASK)  {
769                     /* Ask the user to move or copy, then set the ctx action. */
770                 }
771             
772                 if (action == Gdk.DragAction.MOVE) {
773                     delete_selection_data = true;
774                 }
775                   
776                             // drag around.. - reorder..
777                 _this.model.moveNode(targetData, action);
778                     
779                    
780                     
781                     
782                     
783                     // we can send stuff to souce here...
784             
785             
786             // do we always say failure, so we handle the reall drop?
787                 Gtk.drag_finish (ctx, false, false,time); //delete_selection_data, time);
788             
789                 return true;
790              
791              
792              
793              
794              
795              
796             });
797         }
798
799         // user defined functions 
800         public           void highlightDropPath ( string treepath, Gtk.TreeViewDropPosition pos) {
801         
802                 // highlighting for drag/drop
803                 if (treepath.length > 0) {
804                     this.el.set_drag_dest_row(  new  Gtk.TreePath.from_string( treepath ), pos);
805                   } else {
806                     this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
807                  }
808                      
809         }
810         public           void selectNode (string treepath_str) {
811             //this.selection.select_path(new  Gtk.TreePath.from_string( treepath_str));
812              var tp = new Gtk.TreePath.from_string(treepath_str);
813              
814              this.el.set_cursor(tp, null, false);  
815              this.el.scroll_to_cell(tp, null, false, 0,0);
816         }
817     }
818     public class Xcls_model : Object 
819     {
820         public Gtk.TreeStore el;
821         private Xcls_WindowLeftTree  _this;
822
823
824             // my vars (def)
825         public DialogTemplateSelect template_select;
826         public JsRender.JsRender? file;
827         public string activePath;
828         public Project.Project? project;
829
830         // ctor 
831         public Xcls_model(Xcls_WindowLeftTree _owner )
832         {
833             _this = _owner;
834             _this.model = this;
835             this.el = new Gtk.TreeStore( 3, typeof(string),typeof(string),typeof(Object) );
836
837             // my vars (dec)
838             this.template_select = null;
839             this.file = null;
840             this.activePath = "";
841             this.project = null;
842
843             // set gobject values
844
845             // init method 
846
847             print("model initialized");
848         }
849
850         // user defined functions 
851         public           string findDropNode (string treepath_str, string[] targets) {
852         
853             // this is used by the dragdrop code in the roo version AFAIR..
854         
855             //var path = treepath_str.replace(/^builder-/, '');
856             // treemap is depreciated... - should really check if model has any entries..
857         
858             if (this.el.iter_n_children(null) < 1) {
859                 //print("NO KEYS");
860                 return "|%d".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
861             }
862             //print("FIND treepath: " + path);
863             //console.dump(this.treemap);
864             
865             //if (!treepath_str.match(/^builder-/)) {
866             //    return []; // nothing!
867             //}
868             if (targets.length > 0 && targets[0] == "*") {
869                 return  treepath_str;
870             }
871             return this.findDropNodeByPath(treepath_str,targets, -1);
872         }
873         public           void loadFile (JsRender.JsRender f) {
874             //console.dump(f);
875             this.el.clear();
876             this.file = f;
877             
878             
879         //    if (!f) {
880         //        console.log('missing file');
881         //        return;
882         //    }
883             
884             // load the file if not loaded..
885             if (f.tree == null) {
886                 f.loadItems( );
887             }
888             // if it's still null?
889             if (f.tree == null) {
890                 return;
891             }
892             
893             /// this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name);
894             
895             //if (f.items.length && typeof(f.items[0]) == 'string') {
896             
897                 //this.get('/RightEditor').el.show();
898                 //this.get('/RightEditor.view').load( f.items[0]);
899             //    return;
900             //}
901             //print("LOAD");
902             //print(JSON.stringify(f.items, null,4));
903             //console.dump(f.items);
904             var o = new Gee.ArrayList<JsRender.Node>();
905             o.add(f.tree);
906             this.load(o,null);
907             
908             _this.view.el.expand_all();
909         
910             if (f.tree.items.size < 1) {
911                 // single item..
912                 
913                 //this.get('/Window.leftvpaned').el.set_position(80);
914                 // select first...
915                 _this.view.el.set_cursor( 
916                     new  Gtk.TreePath.from_string("0"), null, false);
917                 
918                 
919             } else {
920                   //this.get('/Window.leftvpaned').el.set_position(200);
921             }
922             
923             return;
924             /*    
925             
926             //print("hide right editior");
927             //this.get('/RightEditor').el.hide();
928             //this.get('/Editor').el.hide();
929             //print("set current tree");
930             //this.currentTree = this.toJS(false, false)[0];
931             //console.dump(this.currentTree);
932             //this.currentTree = this.currentTree || { items: [] };
933             //_this.renderView();
934             //console.dump(this.map);
935             //var RightPalete     = imports.Builder.RightPalete.RightPalete;
936             
937             
938             var pm = this.get('/RightPalete.model');
939             // set up provider..
940             
941             this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
942             
943             if (!this.get('/RightPalete').provider) {
944                 print ("********* PALETE PROVIDER MISSING?!!");
945             }
946             this.get('/LeftTree').renderView();
947             
948             pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
949             
950             
951                     
952             this.get('/Window.view-notebook').el.set_current_page(
953                 this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
954                 */
955                     
956         }
957         public    void updateSelected () {
958           
959            
960             var s = _this.view.el.get_selection();
961             
962              Gtk.TreeIter iter;
963             Gtk.TreeModel mod;
964             
965             
966             
967             if (!s.get_selected(out mod, out iter)) {
968                 return; // nothing seleted..
969             }
970           
971           GLib.Value value;
972             this.el.get_value(iter, 2, out value);
973             var node = (JsRender.Node)(value.get_object());
974             
975               this.el.set(iter, 0, node.nodeTitle(),
976                         1, node.nodeTip(), -1
977                 );
978         }
979         public           string findDropNodeByPath (string treepath_str, string[] targets, int in_pref = -1) {
980         
981             var path = treepath_str; // dupe it..
982             
983             
984             // pref : 3 = ontop - 0 = after, 1 = before
985             int pref = in_pref < 0  ?  Gtk.TreeViewDropPosition.INTO_OR_AFTER : in_pref;
986             
987             var last = "";
988             
989             //console.dump(this.treemap);
990             
991             print("findDropNodeByPath : got path length %d / %s\n", path.length, path);
992             
993             if (path.length == 0) {
994                 // top drop. // just return empty..
995                 return "|%d".printf((int)pref) ;
996                 
997             }
998             
999             
1000             while (path.length > 0) {
1001             
1002                 if (path.length == treepath_str.length && pref != Gtk.TreeViewDropPosition.INTO_OR_AFTER) {
1003                     if (path.last_index_of(":") < 0 ) {
1004                         return "";
1005                     }
1006                     path = path.substring(0, path.last_index_of(":"));
1007                     last = treepath_str;
1008                     print("DROP  before or after : using %s\n",path);
1009                     continue;
1010                 }
1011             
1012                 //print("LOOKING FOR PATH: " + path);
1013                 var node_data = this.pathToNode(path);
1014                 
1015                 if (node_data == null) {
1016                     print("node not found");
1017                     return "";
1018                 }
1019                 
1020                 var xname = node_data.fqn();
1021                 var match = "";
1022                 var prop = "";
1023                 
1024                 for (var i =0; i < targets.length; i++)  {
1025                     var tg = targets[i];
1026                     if ((tg == xname)  ) {
1027                         match = tg;
1028                         break;
1029                     }
1030                     // if target is "xxxx:name"
1031                     if (tg.contains(xname +":")) {
1032                         match = tg;
1033                         var ar = tg.split(":");
1034                         prop = ar[1];
1035                         break;
1036                     }
1037                 }
1038                 
1039                 if (match.length > 0) {
1040                     if (last.length > 0) { // pref is after/before..
1041                         // then it's after last
1042                         //if (pref > 1) {
1043                         //    return "";
1044                         //}
1045                         return last + "|%d".printf((int)pref) + "|" + prop;
1046         
1047                         
1048                     }
1049                     // we need to add prop - as :store -> needs to bee added when dropping onto.
1050                     return path + "|%d".printf( (int) Gtk.TreeViewDropPosition.INTO_OR_AFTER)  + "|" + prop;
1051                 }
1052                 /*
1053                 last = "" + path;
1054                 var par = path.split(":");
1055                 string [] ppar = {};
1056                 for (var i = 0; i < par.length-1; i++) {
1057                     ppar += par[i];
1058                 }
1059                 
1060                 path = string.joinv(":", ppar);
1061                 */
1062                 break;
1063         
1064             }
1065             
1066             return "";
1067                     
1068         }
1069         public           void moveNode (string target_data, Gdk.DragAction action) 
1070         {
1071            
1072            /// target_data = "path|pos");
1073            
1074            
1075             //print("MOVE NODE");
1076             // console.dump(target_data);
1077             Gtk.TreeIter old_iter;
1078             Gtk.TreeModel mod;
1079             
1080             var s = _this.view.el.get_selection();
1081             s.get_selected(out mod , out old_iter);
1082             mod.get_path(old_iter);
1083             
1084             var node = this.pathToNode(mod.get_path(old_iter).to_string());
1085             //console.dump(node);
1086             if (node == null) {
1087                 print("moveNode: ERROR - node is null?");
1088             }
1089             
1090             
1091         
1092             // needs to drop first, otherwise the target_data 
1093             // treepath will be invalid.
1094         
1095             
1096             if ((action & Gdk.DragAction.MOVE) > 0) {
1097                     print("REMOVING OLD NODE : " + target_data + "\n");
1098                     node.remove();
1099                     this.dropNode(target_data, node, false);
1100                     this.el.remove(ref old_iter);
1101                     
1102                     
1103                                  
1104             } else {
1105                 print("DROPPING NODE // copy: " + target_data + "\n");
1106                 node = node.deepClone();
1107                 this.dropNode(target_data, node, false);
1108             }
1109             _this.changed();
1110             this.activePath= "";
1111             //this.updateNode(false,true);
1112         }
1113         public           void load (Gee.ArrayList<JsRender.Node> tr, Gtk.TreeIter? iter) 
1114         {
1115             Gtk.TreeIter citer;
1116             //this.insert(citer,iter,0);
1117             for(var i =0 ; i < tr.size; i++) {
1118                 if (iter != null) {
1119                     this.el.insert(out citer,iter,-1); // why not append?
1120                 } else {
1121                     this.el.append(out citer,null);
1122                 }
1123                 
1124                 this.el.set(citer, 0, tr.get(i).nodeTitle(),
1125                         1, tr.get(i).nodeTip(), -1
1126                 );
1127                 var o = new GLib.Value(typeof(Object));
1128                 o.set_object((Object)tr.get(i));
1129                 
1130                 this.el.set_value(citer, 2, o);
1131                 
1132                 if (tr.get(i).items.size > 0) {
1133                     this.load(tr.get(i).items, citer);
1134                 }
1135              
1136             }
1137         
1138             
1139         }
1140         public           void deleteSelected () {
1141             
1142             print("DELETE SELECTED?");
1143             //_this.view.blockChanges = true;
1144             print("GET SELECTION?");
1145         
1146             var s = _this.view.el.get_selection();
1147             
1148             print("GET  SELECTED?");
1149            Gtk.TreeIter iter;
1150             Gtk.TreeModel mod;
1151         
1152             
1153             if (!s.get_selected(out mod, out iter)) {
1154                 return; // nothing seleted..
1155             }
1156               
1157         
1158         
1159             this.activePath= "";      
1160             print("GET  vnode value?");
1161         
1162             GLib.Value value;
1163             this.el.get_value(iter, 2, out value);
1164             var data = (JsRender.Node)(value.get_object());
1165             print("removing node from Render\n");
1166             if (data.parent == null) {
1167                 this.file.tree = null;
1168             } else {
1169                 data.remove();
1170             }
1171             print("removing node from Tree\n");    
1172             s.unselect_all();
1173             this.el.remove(ref iter);
1174         
1175             
1176             
1177             
1178             // 
1179             
1180             
1181         
1182         
1183             this.activePath= ""; // again!?!?      
1184             //this.changed(null,true);
1185             
1186             _this.changed();
1187             
1188             _this.view.blockChanges = false;
1189         }
1190         public           JsRender.Node pathToNode (string path) {
1191          
1192              
1193              Gtk.TreeIter   iter;
1194              _this.model.el.get_iter_from_string(out iter, path);
1195              
1196              GLib.Value value;
1197              _this.model.el.get_value(iter, 2, out value);
1198              
1199              return (JsRender.Node)value.dup_object();
1200         
1201         }
1202         public           void dropNode (string target_data_str, JsRender.Node node, bool show_templates) {
1203         //         print("drop Node");
1204              // console.dump(node);
1205           //    console.dump(target_data);
1206           
1207           
1208                 // 0 = before , 1=after 2/3 onto
1209           
1210           
1211                 var target_data= target_data_str.split("|");
1212           
1213                 var parent_str = target_data[0].length > 0 ? target_data[0] : "";
1214                 var pos = target_data.length > 1 ? int.parse(target_data[1]) : 2; // ontop..
1215           
1216           
1217                 Gtk.TreePath tree_path  =   parent_str.length > 0 ? new  Gtk.TreePath.from_string( parent_str ) : null;
1218                 
1219                 
1220                 
1221                 //print("add " + tp + "@" + target_data[1]  );
1222                 
1223                 JsRender.Node parentNode = null;
1224                 
1225                 Gtk.TreeIter iter_after;
1226                 Gtk.TreeIter iter_par ;
1227                 
1228                
1229                  if (target_data.length == 3 && target_data[2].length > 0) {
1230                     node.props.set("* prop", target_data[2]);
1231                 }
1232         
1233                 Gtk.TreePath expand_parent = null;
1234                 
1235                 // we only need to show the template if it's come from else where?
1236                  if (show_templates) {
1237                  
1238                     if (this.template_select == null) {
1239                         this.template_select = new DialogTemplateSelect();
1240                      }
1241                  
1242                      var new_node = this.template_select.show(
1243                           (Gtk.Window) _this.el.get_toplevel (),
1244                               this.file.palete(),
1245                            node);
1246                            
1247                      if (new_node == null) {
1248                          return; // do not add?
1249                      }
1250                      node = new_node;
1251                 }        
1252                 
1253                  //print("pos is %d  \n".printf(pos));
1254                 
1255                  Gtk.TreeIter n_iter; 
1256                  
1257                  if ( parent_str.length < 1) {
1258                       this.el.append(out n_iter, null); // drop at top level..
1259                       node.parent = null;
1260                       this.file.tree = node;
1261                       
1262                       
1263                 } else   if (pos  < 2) {
1264                     //print(target_data[1]  > 0 ? 'insert_after' : 'insert_before');
1265                     
1266                     this.el.get_iter(out iter_after, tree_path );            
1267                     this.el.iter_parent(out iter_par, iter_after);
1268                     expand_parent = this.el.get_path(iter_par);
1269                     
1270                     GLib.Value value;
1271                     this.el.get_value( iter_par, 2, out value);
1272                     parentNode =  (JsRender.Node)value.dup_object();
1273                     
1274                     
1275                     this.el.get_value( iter_after, 2, out value);
1276                     var relNode =  (JsRender.Node)value.dup_object();
1277                     
1278                     if ( pos  > 0 ) {
1279                      
1280                         this.el.insert_after(out n_iter,    iter_par  , iter_after);
1281                         var ix = parentNode.items.index_of(relNode);
1282                         parentNode.items.insert(ix+1, node);
1283                         
1284                     } else {
1285                         this.el.insert_before(out n_iter,  iter_par  , iter_after);
1286                         var ix = parentNode.items.index_of(relNode);
1287                         parentNode.items.insert(ix, node);
1288          
1289                     }
1290                     node.parent = parentNode;
1291                     
1292                     
1293                     
1294                 } else {
1295                    //  print("appending to  " + parent_str);
1296                     this.el.get_iter(out iter_par, tree_path);
1297                     this.el.append(out n_iter,   iter_par );
1298                     expand_parent = this.el.get_path(iter_par);
1299                     
1300                     GLib.Value value;
1301                     this.el.get_value( iter_par, 2, out value);
1302                     parentNode =  (JsRender.Node)value.dup_object();
1303                     node.parent = parentNode;
1304                     parentNode.items.add(node);
1305                 }
1306                 
1307                 // reparent node in tree...
1308                
1309                 
1310                 // why only on no parent???
1311                 
1312                 //if (node.parent = null) {
1313                      
1314                    
1315                     
1316                 //}
1317                 
1318                 
1319                 // work out what kind of packing to use.. -- should be in 
1320                 if (!node.has("pack")   && parent_str.length > 1) {
1321                     
1322                     this.file.palete().fillPack(node,parentNode);
1323                     
1324                     
1325                 }
1326                 
1327                 // add the node...
1328                 
1329                 this.el.set(n_iter, 0, node.nodeTitle(), 1, node.nodeTip(), -1  );
1330                 var o = new GLib.Value(typeof(Object));
1331                 o.set_object((Object)node);
1332                 
1333                 this.el.set_value(n_iter, 2, o);
1334                 
1335                 
1336                 
1337                 
1338         // load children - if it has any..
1339               
1340                 if (node.items.size > 0) {
1341                     this.load(node.items, n_iter);
1342                     _this.view.el.expand_row(this.el.get_path(n_iter), true);
1343                 } else if (expand_parent != null && !_this.view.el.is_row_expanded(expand_parent)) {
1344                    _this.view.el.expand_row(expand_parent,true);
1345                 }
1346         
1347                 //if (tp != null && (node.items.length() > 0 || pos > 1)) {
1348                 //    _this.view.el.expand_row(this.el.get_path(iter_par), true);
1349                // }
1350                 // wee need to get the empty proptypes from somewhere..
1351                 
1352                 //var olditer = this.activeIter;
1353                 this.activePath = this.el.get_path(n_iter).to_string();
1354         
1355         
1356                 
1357                 
1358                 _this.view.el.set_cursor(this.el.get_path(n_iter), null, false);
1359                 _this.changed();
1360              
1361                 
1362                     
1363         }
1364     }
1365     public class Xcls_TreeViewColumn4 : Object 
1366     {
1367         public Gtk.TreeViewColumn el;
1368         private Xcls_WindowLeftTree  _this;
1369
1370
1371             // my vars (def)
1372
1373         // ctor 
1374         public Xcls_TreeViewColumn4(Xcls_WindowLeftTree _owner )
1375         {
1376             _this = _owner;
1377             this.el = new Gtk.TreeViewColumn();
1378
1379             // my vars (dec)
1380
1381             // set gobject values
1382             this.el.title = "test";
1383             var child_0 = new Xcls_renderer( _this );
1384             child_0.ref();
1385             this.el.pack_start (  child_0.el , true );
1386
1387             // init method 
1388
1389             this.el.add_attribute(_this.renderer.el , "markup", 0 );
1390         }
1391
1392         // user defined functions 
1393     }
1394     public class Xcls_renderer : Object 
1395     {
1396         public Gtk.CellRendererText el;
1397         private Xcls_WindowLeftTree  _this;
1398
1399
1400             // my vars (def)
1401
1402         // ctor 
1403         public Xcls_renderer(Xcls_WindowLeftTree _owner )
1404         {
1405             _this = _owner;
1406             _this.renderer = this;
1407             this.el = new Gtk.CellRendererText();
1408
1409             // my vars (dec)
1410
1411             // set gobject values
1412         }
1413
1414         // user defined functions 
1415     }
1416     public class Xcls_LeftTreeMenu : Object 
1417     {
1418         public Gtk.Menu el;
1419         private Xcls_WindowLeftTree  _this;
1420
1421
1422             // my vars (def)
1423
1424         // ctor 
1425         public Xcls_LeftTreeMenu(Xcls_WindowLeftTree _owner )
1426         {
1427             _this = _owner;
1428             _this.LeftTreeMenu = this;
1429             this.el = new Gtk.Menu();
1430
1431             // my vars (dec)
1432
1433             // set gobject values
1434             var child_0 = new Xcls_MenuItem7( _this );
1435             child_0.ref();
1436             this.el.add (  child_0.el  );
1437             var child_1 = new Xcls_MenuItem8( _this );
1438             child_1.ref();
1439             this.el.add (  child_1.el  );
1440             var child_2 = new Xcls_MenuItem9( _this );
1441             child_2.ref();
1442             this.el.add (  child_2.el  );
1443         }
1444
1445         // user defined functions 
1446     }
1447     public class Xcls_MenuItem7 : Object 
1448     {
1449         public Gtk.MenuItem el;
1450         private Xcls_WindowLeftTree  _this;
1451
1452
1453             // my vars (def)
1454
1455         // ctor 
1456         public Xcls_MenuItem7(Xcls_WindowLeftTree _owner )
1457         {
1458             _this = _owner;
1459             this.el = new Gtk.MenuItem();
1460
1461             // my vars (dec)
1462
1463             // set gobject values
1464             this.el.label = "Delete Element";
1465
1466             // listeners 
1467             this.el.activate.connect( ( ) => {
1468                 
1469                 print("ACTIVATE?");
1470                 
1471               
1472                  _this.model.deleteSelected();
1473             });
1474         }
1475
1476         // user defined functions 
1477     }
1478     public class Xcls_MenuItem8 : Object 
1479     {
1480         public Gtk.MenuItem el;
1481         private Xcls_WindowLeftTree  _this;
1482
1483
1484             // my vars (def)
1485
1486         // ctor 
1487         public Xcls_MenuItem8(Xcls_WindowLeftTree _owner )
1488         {
1489             _this = _owner;
1490             this.el = new Gtk.MenuItem();
1491
1492             // my vars (dec)
1493
1494             // set gobject values
1495             this.el.label = "Save as Template";
1496
1497             // listeners 
1498             this.el.activate.connect( () => {
1499             
1500                  DialogSaveTemplate.singleton().show(
1501                         (Gtk.Window) _this.el.get_toplevel (), 
1502                         _this.model.file.palete(), 
1503                         _this.getActiveElement()
1504                 );
1505                  
1506                 
1507             });
1508         }
1509
1510         // user defined functions 
1511     }
1512     public class Xcls_MenuItem9 : Object 
1513     {
1514         public Gtk.MenuItem el;
1515         private Xcls_WindowLeftTree  _this;
1516
1517
1518             // my vars (def)
1519
1520         // ctor 
1521         public Xcls_MenuItem9(Xcls_WindowLeftTree _owner )
1522         {
1523             _this = _owner;
1524             this.el = new Gtk.MenuItem();
1525
1526             // my vars (dec)
1527
1528             // set gobject values
1529             this.el.label = "Save as Module";
1530
1531             // listeners 
1532             this.el.activate.connect( () => {
1533                 var node = _this.getActiveElement();
1534                  var name = DialogSaveModule.singleton().show(
1535                         (Gtk.Window) _this.el.get_toplevel (), 
1536                         _this.model.file.project, 
1537                         node
1538                  );
1539                  if (name.length < 1) {
1540                         return;
1541               
1542                  }
1543                  node.props.set("* xinclude", name);
1544                  node.items.clear();
1545             
1546             
1547                 var s = _this.view.el.get_selection();
1548                 
1549                 print("GET  SELECTED?");
1550                 Gtk.TreeIter iter;
1551                 Gtk.TreeModel mod;
1552             
1553                 
1554                 if (!s.get_selected(out mod, out iter)) {
1555                     return; // nothing seleted..
1556                 }
1557                 Gtk.TreeIter citer;
1558                 var n_cn = mod.iter_n_children(iter) -1;
1559                 for (var i = n_cn; i > -1; i--) {
1560                     mod.iter_nth_child(out citer, iter, i);
1561                     
1562             
1563                     print("removing node from Tree\n");    
1564                 
1565                     _this.model.el.remove(ref citer);
1566                 }
1567                 _this.changed();
1568                 _this.node_selected(node);
1569                  
1570                 
1571             });
1572         }
1573
1574         // user defined functions 
1575     }
1576 }