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