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