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