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