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