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