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