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 ();
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;
836             this.el.set_cursor(new Gtk.TreePath.from_string(treepath), null, false); 
837             this.blockChanges = false;
838                 this.lastEventSource = "";
839         }
840         public           void selectNode (string treepath_str, string source) {
841                 this.lastEventSource = source;
842             //this.selection.select_path(new  Gtk.TreePath.from_string( treepath_str));
843              var tp = new Gtk.TreePath.from_string(treepath_str);
844              
845              this.el.set_cursor(tp, null, false);  
846              this.el.scroll_to_cell(tp, null, false, 0,0);
847         }
848     }
849     public class Xcls_model : Object
850     {
851         public Gtk.TreeStore el;
852         private Xcls_WindowLeftTree  _this;
853
854
855             // my vars (def)
856         public DialogTemplateSelect template_select;
857         public string activePath;
858
859         // ctor
860         public Xcls_model(Xcls_WindowLeftTree _owner )
861         {
862             _this = _owner;
863             _this.model = this;
864             this.el = new Gtk.TreeStore( 3, typeof(string),typeof(string),typeof(Object) );
865
866             // my vars (dec)
867             this.template_select = null;
868             this.activePath = "";
869
870             // set gobject values
871
872             // init method
873
874             print("model initialized");
875         }
876
877         // user defined functions
878         public           string findDropNode (string treepath_str, string[] targets) {
879         
880             // this is used by the dragdrop code in the roo version AFAIR..
881         
882             //var path = treepath_str.replace(/^builder-/, '');
883             // treemap is depreciated... - should really check if model has any entries..
884         
885             if (this.el.iter_n_children(null) < 1) {
886                 //print("NO KEYS");
887                 return "|%d".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
888             }
889             //print("FIND treepath: " + path);
890             //console.dump(this.treemap);
891             
892             //if (!treepath_str.match(/^builder-/)) {
893             //    return []; // nothing!
894             //}
895             if (targets.length > 0 && targets[0] == "*") {
896                 return  treepath_str;
897             }
898             return this.findDropNodeByPath(treepath_str,targets, -1);
899         }
900         public           void loadFile (JsRender.JsRender f) {
901             //console.dump(f);
902             this.el.clear();
903             
904             // needed???
905             _this.main_window.windowstate.file = f;
906             
907            
908             if (f.tree == null) {
909                     try {
910                         f.loadItems( );
911                 } catch (Error e) {
912                         return;
913                 }
914             }
915             // if it's still null?
916             if (f.tree == null) {
917                 return;
918             }
919           
920             var o = new Gee.ArrayList<JsRender.Node>();
921             o.add(f.tree);
922             this.load(o,null);
923             
924             _this.view.el.expand_all();
925         
926             if (f.tree.items.size < 1) {
927                 // single item..
928                 
929                 //this.get('/Window.leftvpaned').el.set_position(80);
930                 // select first...
931                 _this.view.el.set_cursor( 
932                     new  Gtk.TreePath.from_string("0"), null, false);
933                 
934                 
935             } else {
936                   //this.get('/Window.leftvpaned').el.set_position(200);
937             }
938             
939             return;
940          
941                     
942         }
943         public    void updateSelected () {
944           
945            
946             var s = _this.view.el.get_selection();
947             
948              Gtk.TreeIter iter;
949             Gtk.TreeModel mod;
950             
951             
952             
953             if (!s.get_selected(out mod, out iter)) {
954                 return; // nothing seleted..
955             }
956           
957           GLib.Value value;
958             this.el.get_value(iter, 2, out value);
959             var node = (JsRender.Node)(value.get_object());
960             
961               this.el.set(iter, 0, node.nodeTitle(),
962                         1, node.nodeTip(), -1
963                 );
964         }
965         public           string findDropNodeByPath (string treepath_str, string[] targets, int in_pref = -1) {
966         
967             var path = treepath_str; // dupe it..
968             
969             
970             // pref : 3 = ontop - 0 = after, 1 = before
971             int pref = in_pref < 0  ?  Gtk.TreeViewDropPosition.INTO_OR_AFTER : in_pref;
972             
973             var last = "";
974             
975             //console.dump(this.treemap);
976             
977             print("findDropNodeByPath : got path length %d / %s\n", path.length, path);
978             
979             if (path.length == 0) {
980                 // top drop. // just return empty..
981                 return "|%d".printf((int)pref) ;
982                 
983             }
984             
985             
986             while (path.length > 0) {
987             
988                 if (path.length == treepath_str.length && pref != Gtk.TreeViewDropPosition.INTO_OR_AFTER) {
989                     if (path.last_index_of(":") < 0 ) {
990                         return "";
991                     }
992                     path = path.substring(0, path.last_index_of(":"));
993                     last = treepath_str;
994                     print("DROP  before or after : using %s\n",path);
995                     continue;
996                 }
997             
998                 //print("LOOKING FOR PATH: " + path);
999                 var node_data = this.pathToNode(path);
1000                 
1001                 if (node_data == null) {
1002                     print("node not found");
1003                     return "";
1004                 }
1005                 
1006                 var xname = node_data.fqn();
1007                 var match = "";
1008                 var prop = "";
1009                 
1010                 for (var i =0; i < targets.length; i++)  {
1011                     var tg = targets[i];
1012                     if ((tg == xname)  ) {
1013                         match = tg;
1014                         break;
1015                     }
1016                     // if target is "xxxx:name"
1017                     if (tg.contains(xname +":")) {
1018                         match = tg;
1019                         var ar = tg.split(":");
1020                         prop = ar[1];
1021                         break;
1022                     }
1023                 }
1024                 
1025                 if (match.length > 0) {
1026                     if (last.length > 0) { // pref is after/before..
1027                         // then it's after last
1028                         //if (pref > 1) {
1029                         //    return "";
1030                         //}
1031                         return last + "|%d".printf((int)pref) + "|" + prop;
1032         
1033                         
1034                     }
1035                     // we need to add prop - as :store -> needs to bee added when dropping onto.
1036                     return path + "|%d".printf( (int) Gtk.TreeViewDropPosition.INTO_OR_AFTER)  + "|" + prop;
1037                 }
1038                 /*
1039                 last = "" + path;
1040                 var par = path.split(":");
1041                 string [] ppar = {};
1042                 for (var i = 0; i < par.length-1; i++) {
1043                     ppar += par[i];
1044                 }
1045                 
1046                 path = string.joinv(":", ppar);
1047                 */
1048                 break;
1049         
1050             }
1051             
1052             return "";
1053                     
1054         }
1055         public           void moveNode (string target_data, Gdk.DragAction action) 
1056         {
1057            
1058            /// target_data = "path|pos");
1059            
1060            
1061             //print("MOVE NODE");
1062             // console.dump(target_data);
1063             Gtk.TreeIter old_iter;
1064             Gtk.TreeModel mod;
1065             
1066             var s = _this.view.el.get_selection();
1067             s.get_selected(out mod , out old_iter);
1068             mod.get_path(old_iter);
1069             
1070             var node = this.pathToNode(mod.get_path(old_iter).to_string());
1071             //console.dump(node);
1072             if (node == null) {
1073                 print("moveNode: ERROR - node is null?");
1074             }
1075             
1076             
1077         
1078             // needs to drop first, otherwise the target_data 
1079             // treepath will be invalid.
1080         
1081             
1082             if ((action & Gdk.DragAction.MOVE) > 0) {
1083                     print("REMOVING OLD NODE : " + target_data + "\n");
1084                     node.remove();
1085                     this.dropNode(target_data, node, false);
1086                     this.el.remove(ref old_iter);
1087                     
1088                     
1089                                  
1090             } else {
1091                 print("DROPPING NODE // copy: " + target_data + "\n");
1092                 node = node.deepClone();
1093                 this.dropNode(target_data, node, false);
1094             }
1095             _this.changed();
1096             this.activePath= "";
1097             //this.updateNode(false,true);
1098         }
1099         public           void load (Gee.ArrayList<JsRender.Node> tr, Gtk.TreeIter? iter) 
1100         {
1101             Gtk.TreeIter citer;
1102             //this.insert(citer,iter,0);
1103             for(var i =0 ; i < tr.size; i++) {
1104                 if (iter != null) {
1105                     this.el.insert(out citer,iter,-1); // why not append?
1106                 } else {
1107                     this.el.append(out citer,null);
1108                 }
1109                 
1110                 this.el.set(citer, 0, tr.get(i).nodeTitle(),
1111                         1, tr.get(i).nodeTip(), -1
1112                 );
1113                 var o =   GLib.Value(typeof(Object));
1114                 o.set_object((Object)tr.get(i));
1115                 
1116                 this.el.set_value(citer, 2, o);
1117                 
1118                 if (tr.get(i).items.size > 0) {
1119                     this.load(tr.get(i).items, citer);
1120                 }
1121              
1122             }
1123         
1124             
1125         }
1126         public           void deleteSelected () {
1127             
1128             print("DELETE SELECTED?");
1129             //_this.view.blockChanges = true;
1130             print("GET SELECTION?");
1131         
1132             var s = _this.view.el.get_selection();
1133             
1134             print("GET  SELECTED?");
1135            Gtk.TreeIter iter;
1136             Gtk.TreeModel mod;
1137         
1138             
1139             if (!s.get_selected(out mod, out iter)) {
1140                 return; // nothing seleted..
1141             }
1142               
1143         
1144         
1145             this.activePath= "";      
1146             print("GET  vnode value?");
1147         
1148             GLib.Value value;
1149             this.el.get_value(iter, 2, out value);
1150             var data = (JsRender.Node)(value.get_object());
1151             print("removing node from Render\n");
1152             if (data.parent == null) {
1153                _this.main_window.windowstate.file.tree = null;
1154             } else {
1155                 data.remove();
1156             }
1157             print("removing node from Tree\n");    
1158             s.unselect_all();
1159             this.el.remove(ref iter);
1160         
1161             
1162             
1163             
1164             // 
1165             
1166             
1167         
1168         
1169             this.activePath= ""; // again!?!?      
1170             //this.changed(null,true);
1171             
1172             _this.changed();
1173             
1174             _this.view.blockChanges = false;
1175         }
1176         public           JsRender.Node pathToNode (string path) {
1177          
1178              
1179              Gtk.TreeIter   iter;
1180              _this.model.el.get_iter_from_string(out iter, path);
1181              
1182              GLib.Value value;
1183              _this.model.el.get_value(iter, 2, out value);
1184              
1185              return (JsRender.Node)value.dup_object();
1186         
1187         }
1188         public           void dropNode (string target_data_str, JsRender.Node node, bool show_templates) {
1189         //         print("drop Node");
1190              // console.dump(node);
1191           //    console.dump(target_data);
1192           
1193           
1194                 // 0 = before , 1=after 2/3 onto
1195           
1196           
1197                 var target_data= target_data_str.split("|");
1198           
1199                 var parent_str = target_data[0].length > 0 ? target_data[0] : "";
1200                 var pos = target_data.length > 1 ? int.parse(target_data[1]) : 2; // ontop..
1201           
1202           
1203                 Gtk.TreePath tree_path  =   parent_str.length > 0 ? new  Gtk.TreePath.from_string( parent_str ) : null;
1204                 
1205                 
1206                 
1207                 //print("add " + tp + "@" + target_data[1]  );
1208                 
1209                 JsRender.Node parentNode = null;
1210                 
1211                 Gtk.TreeIter iter_after;
1212                 Gtk.TreeIter iter_par ;
1213                 
1214                
1215                  if (target_data.length == 3 && target_data[2].length > 0) {
1216                     node.props.set("* prop", target_data[2]);
1217                 }
1218         
1219                 Gtk.TreePath expand_parent = null;
1220                 
1221                 // we only need to show the template if it's come from else where?
1222                  if (show_templates) {
1223                  
1224                      var ts = _this.main_window.windowstate.template_select;
1225                  
1226                      var new_node = ts.show(
1227                           _this.main_window, // (Gtk.Window) _this.el.get_toplevel (),
1228                          _this.main_window.windowstate.file.palete(),
1229                             node,
1230                             _this.main_window.windowstate.project);
1231                            
1232                      if (new_node == null) {
1233                          return; // do not add?
1234                      }
1235                      node = new_node;
1236                 }        
1237                 
1238                  //print("pos is %d  \n".printf(pos));
1239                 
1240                  Gtk.TreeIter n_iter; 
1241                  
1242                  if ( parent_str.length < 1) {
1243                       this.el.append(out n_iter, null); // drop at top level..
1244                       node.parent = null;
1245                       _this.main_window.windowstate.file.tree = node;
1246                       
1247                       
1248                 } else   if (pos  < 2) {
1249                     //print(target_data[1]  > 0 ? 'insert_after' : 'insert_before');
1250                     
1251                     this.el.get_iter(out iter_after, tree_path );            
1252                     this.el.iter_parent(out iter_par, iter_after);
1253                     expand_parent = this.el.get_path(iter_par);
1254                     
1255                     GLib.Value value;
1256                     this.el.get_value( iter_par, 2, out value);
1257                     parentNode =  (JsRender.Node)value.dup_object();
1258                     
1259                     
1260                     this.el.get_value( iter_after, 2, out value);
1261                     var relNode =  (JsRender.Node)value.dup_object();
1262                     
1263                     if ( pos  > 0 ) {
1264                      
1265                         this.el.insert_after(out n_iter,    iter_par  , iter_after);
1266                         var ix = parentNode.items.index_of(relNode);
1267                         parentNode.items.insert(ix+1, node);
1268                         
1269                     } else {
1270                         this.el.insert_before(out n_iter,  iter_par  , iter_after);
1271                         var ix = parentNode.items.index_of(relNode);
1272                         parentNode.items.insert(ix, node);
1273          
1274                     }
1275                     node.parent = parentNode;
1276                     
1277                     
1278                     
1279                 } else {
1280                    //  print("appending to  " + parent_str);
1281                     this.el.get_iter(out iter_par, tree_path);
1282                     this.el.append(out n_iter,   iter_par );
1283                     expand_parent = this.el.get_path(iter_par);
1284                     
1285                     GLib.Value value;
1286                     this.el.get_value( iter_par, 2, out value);
1287                     parentNode =  (JsRender.Node)value.dup_object();
1288                     node.parent = parentNode;
1289                     parentNode.items.add(node);
1290                 }
1291                 
1292                 // reparent node in tree...
1293                
1294                 
1295                 // why only on no parent???
1296                 
1297                 //if (node.parent = null) {
1298                      
1299                    
1300                     
1301                 //}
1302                 
1303                 
1304                 // work out what kind of packing to use.. -- should be in 
1305                 if (!node.has("pack")   && parent_str.length > 1) {
1306                     
1307                     _this.main_window.windowstate.file.palete().fillPack(node,parentNode);
1308                     
1309                     
1310                 }
1311                 
1312                 // add the node...
1313                 
1314                 this.el.set(n_iter, 0, node.nodeTitle(), 1, node.nodeTip(), -1  );
1315                 var o =   GLib.Value(typeof(Object));
1316                 o.set_object((Object)node);
1317                 
1318                 this.el.set_value(n_iter, 2, o);
1319                 
1320                 
1321                 
1322                 
1323         // load children - if it has any..
1324               
1325                 if (node.items.size > 0) {
1326                     this.load(node.items, n_iter);
1327                     _this.view.el.expand_row(this.el.get_path(n_iter), true);
1328                 } else if (expand_parent != null && !_this.view.el.is_row_expanded(expand_parent)) {
1329                    _this.view.el.expand_row(expand_parent,true);
1330                 }
1331         
1332                 //if (tp != null && (node.items.length() > 0 || pos > 1)) {
1333                 //    _this.view.el.expand_row(this.el.get_path(iter_par), true);
1334                // }
1335                 // wee need to get the empty proptypes from somewhere..
1336                 
1337                 //var olditer = this.activeIter;
1338                 this.activePath = this.el.get_path(n_iter).to_string();
1339         
1340         
1341                 
1342                 
1343                 _this.view.el.set_cursor(this.el.get_path(n_iter), null, false);
1344                 _this.changed();
1345              
1346                 
1347                     
1348         }
1349         public string treePathFromNode (JsRender.Node node) {
1350             // iterate through the tree and find the node
1351             var ret = "";
1352             
1353             this.el.foreach((mod, pth, iter) => {
1354                 // get the node..
1355               
1356              
1357                  GLib.Value value;
1358                  _this.model.el.get_value(iter, 2, out value);
1359                  
1360         
1361                  
1362                  var n = (JsRender.Node)value;
1363         
1364                  print("compare %s to %s\n", n.fqn(), node.fqn());
1365                 if (node == n) {
1366                     ret = pth.to_string();
1367                     return true;
1368                 }
1369                 return false;
1370             });
1371             return ret;
1372         
1373         }
1374     }
1375
1376     public class Xcls_TreeViewColumn4 : Object
1377     {
1378         public Gtk.TreeViewColumn el;
1379         private Xcls_WindowLeftTree  _this;
1380
1381
1382             // my vars (def)
1383
1384         // ctor
1385         public Xcls_TreeViewColumn4(Xcls_WindowLeftTree _owner )
1386         {
1387             _this = _owner;
1388             this.el = new Gtk.TreeViewColumn();
1389
1390             // my vars (dec)
1391
1392             // set gobject values
1393             this.el.title = "test";
1394             var child_0 = new Xcls_renderer( _this );
1395             child_0.ref();
1396             this.el.pack_start (  child_0.el , true );
1397
1398             // init method
1399
1400             this.el.add_attribute(_this.renderer.el , "markup", 0 );
1401         }
1402
1403         // user defined functions
1404     }
1405     public class Xcls_renderer : Object
1406     {
1407         public Gtk.CellRendererText el;
1408         private Xcls_WindowLeftTree  _this;
1409
1410
1411             // my vars (def)
1412
1413         // ctor
1414         public Xcls_renderer(Xcls_WindowLeftTree _owner )
1415         {
1416             _this = _owner;
1417             _this.renderer = this;
1418             this.el = new Gtk.CellRendererText();
1419
1420             // my vars (dec)
1421
1422             // set gobject values
1423         }
1424
1425         // user defined functions
1426     }
1427
1428
1429
1430     public class Xcls_LeftTreeMenu : Object
1431     {
1432         public Gtk.Menu el;
1433         private Xcls_WindowLeftTree  _this;
1434
1435
1436             // my vars (def)
1437
1438         // ctor
1439         public Xcls_LeftTreeMenu(Xcls_WindowLeftTree _owner )
1440         {
1441             _this = _owner;
1442             _this.LeftTreeMenu = this;
1443             this.el = new Gtk.Menu();
1444
1445             // my vars (dec)
1446
1447             // set gobject values
1448             var child_0 = new Xcls_MenuItem7( _this );
1449             child_0.ref();
1450             this.el.add (  child_0.el  );
1451             var child_1 = new Xcls_MenuItem8( _this );
1452             child_1.ref();
1453             this.el.add (  child_1.el  );
1454             var child_2 = new Xcls_MenuItem9( _this );
1455             child_2.ref();
1456             this.el.add (  child_2.el  );
1457         }
1458
1459         // user defined functions
1460     }
1461     public class Xcls_MenuItem7 : Object
1462     {
1463         public Gtk.MenuItem el;
1464         private Xcls_WindowLeftTree  _this;
1465
1466
1467             // my vars (def)
1468
1469         // ctor
1470         public Xcls_MenuItem7(Xcls_WindowLeftTree _owner )
1471         {
1472             _this = _owner;
1473             this.el = new Gtk.MenuItem();
1474
1475             // my vars (dec)
1476
1477             // set gobject values
1478             this.el.label = "Delete Element";
1479
1480             //listeners
1481             this.el.activate.connect( ( ) => {
1482                 
1483                 print("ACTIVATE?");
1484                 
1485               
1486                  _this.model.deleteSelected();
1487             });
1488         }
1489
1490         // user defined functions
1491     }
1492
1493     public class Xcls_MenuItem8 : Object
1494     {
1495         public Gtk.MenuItem el;
1496         private Xcls_WindowLeftTree  _this;
1497
1498
1499             // my vars (def)
1500
1501         // ctor
1502         public Xcls_MenuItem8(Xcls_WindowLeftTree _owner )
1503         {
1504             _this = _owner;
1505             this.el = new Gtk.MenuItem();
1506
1507             // my vars (dec)
1508
1509             // set gobject values
1510             this.el.label = "Save as Template";
1511
1512             //listeners
1513             this.el.activate.connect( () => {
1514             
1515                  DialogSaveTemplate.singleton().show(
1516                         (Gtk.Window) _this.el.get_toplevel (), 
1517                         _this.main_window.windowstate.file.palete(), 
1518                         _this.getActiveElement()
1519                 );
1520                  
1521                 
1522             });
1523         }
1524
1525         // user defined functions
1526     }
1527
1528     public class Xcls_MenuItem9 : Object
1529     {
1530         public Gtk.MenuItem el;
1531         private Xcls_WindowLeftTree  _this;
1532
1533
1534             // my vars (def)
1535
1536         // ctor
1537         public Xcls_MenuItem9(Xcls_WindowLeftTree _owner )
1538         {
1539             _this = _owner;
1540             this.el = new Gtk.MenuItem();
1541
1542             // my vars (dec)
1543
1544             // set gobject values
1545             this.el.label = "Save as Module";
1546
1547             //listeners
1548             this.el.activate.connect( () => {
1549                 var node = _this.getActiveElement();
1550                  var name = DialogSaveModule.singleton().show(
1551                         (Gtk.Window) _this.el.get_toplevel (), 
1552                         _this.main_window.windowstate.project, 
1553                         node
1554                  );
1555                  if (name.length < 1) {
1556                         return;
1557               
1558                  }
1559                  node.props.set("* xinclude", name);
1560                  node.items.clear();
1561             
1562             
1563                 var s = _this.view.el.get_selection();
1564                 
1565                 print("GET  SELECTED?");
1566                 Gtk.TreeIter iter;
1567                 Gtk.TreeModel mod;
1568             
1569                 
1570                 if (!s.get_selected(out mod, out iter)) {
1571                     return; // nothing seleted..
1572                 }
1573                 Gtk.TreeIter citer;
1574                 var n_cn = mod.iter_n_children(iter) -1;
1575                 for (var i = n_cn; i > -1; i--) {
1576                     mod.iter_nth_child(out citer, iter, i);
1577                     
1578             
1579                     print("removing node from Tree\n");    
1580                 
1581                     _this.model.el.remove(ref citer);
1582                 }
1583                 _this.changed();
1584                 _this.node_selected(node, "tree");
1585                  
1586                 
1587             });
1588         }
1589
1590         // user defined functions
1591     }
1592
1593
1594 }