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