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                     return path + "|%d".printf( (int) Gtk.TreeViewDropPosition.INTO_OR_AFTER)  + "|" + prop;
1047                 }
1048                 /*
1049                 last = "" + path;
1050                 var par = path.split(":");
1051                 string [] ppar = {};
1052                 for (var i = 0; i < par.length-1; i++) {
1053                     ppar += par[i];
1054                 }
1055                 
1056                 path = string.joinv(":", ppar);
1057                 */
1058                 break;
1059         
1060             }
1061             
1062             return "";
1063                     
1064         }
1065         public           void moveNode (string target_data, Gdk.DragAction action) 
1066         {
1067            
1068            /// target_data = "path|pos");
1069            
1070            
1071             //print("MOVE NODE");
1072             // console.dump(target_data);
1073             Gtk.TreeIter old_iter;
1074             Gtk.TreeModel mod;
1075             
1076             var s = _this.view.el.get_selection();
1077             s.get_selected(out mod , out old_iter);
1078             mod.get_path(old_iter);
1079             
1080             var node = this.pathToNode(mod.get_path(old_iter).to_string());
1081             //console.dump(node);
1082             if (node == null) {
1083                 print("moveNode: ERROR - node is null?");
1084             }
1085             
1086             
1087         
1088             // needs to drop first, otherwise the target_data 
1089             // treepath will be invalid.
1090         
1091             
1092             if ((action & Gdk.DragAction.MOVE) > 0) {
1093                     print("REMOVING OLD NODE : " + target_data + "\n");
1094                     node.remove();
1095                     this.dropNode(target_data, node, false);
1096                     this.el.remove(ref old_iter);
1097                     
1098                     
1099                                  
1100             } else {
1101                 print("DROPPING NODE // copy: " + target_data + "\n");
1102                 node = node.deepClone();
1103                 this.dropNode(target_data, node, false);
1104             }
1105             _this.changed();
1106             this.activePath= "";
1107             //this.updateNode(false,true);
1108         }
1109         public           void load (Gee.ArrayList<JsRender.Node> tr, Gtk.TreeIter? iter) 
1110         {
1111             Gtk.TreeIter citer;
1112             //this.insert(citer,iter,0);
1113             for(var i =0 ; i < tr.size; i++) {
1114                 if (iter != null) {
1115                     this.el.insert(out citer,iter,-1); // why not append?
1116                 } else {
1117                     this.el.append(out citer,null);
1118                 }
1119                 
1120                 this.el.set(citer, 0, tr.get(i).nodeTitle(),
1121                         1, tr.get(i).nodeTip(), -1
1122                 );
1123                 var o = new GLib.Value(typeof(Object));
1124                 o.set_object((Object)tr.get(i));
1125                 
1126                 this.el.set_value(citer, 2, o);
1127                 
1128                 if (tr.get(i).items.size > 0) {
1129                     this.load(tr.get(i).items, citer);
1130                 }
1131              
1132             }
1133         
1134             
1135         }
1136         public           void deleteSelected () {
1137             
1138             print("DELETE SELECTED?");
1139             //_this.view.blockChanges = true;
1140             print("GET SELECTION?");
1141         
1142             var s = _this.view.el.get_selection();
1143             
1144             print("GET  SELECTED?");
1145            Gtk.TreeIter iter;
1146             Gtk.TreeModel mod;
1147         
1148             
1149             if (!s.get_selected(out mod, out iter)) {
1150                 return; // nothing seleted..
1151             }
1152               
1153         
1154         
1155             this.activePath= "";      
1156             print("GET  vnode value?");
1157         
1158             GLib.Value value;
1159             this.el.get_value(iter, 2, out value);
1160             var data = (JsRender.Node)(value.get_object());
1161             print("removing node from Render\n");
1162             if (data.parent == null) {
1163                 this.file.tree = null;
1164             } else {
1165                 data.remove();
1166             }
1167             print("removing node from Tree\n");    
1168             s.unselect_all();
1169             this.el.remove(ref iter);
1170         
1171             
1172             
1173             
1174             // 
1175             
1176             
1177         
1178         
1179             this.activePath= ""; // again!?!?      
1180             //this.changed(null,true);
1181             
1182             _this.changed();
1183             
1184             _this.view.blockChanges = false;
1185         }
1186         public           JsRender.Node pathToNode (string path) {
1187          
1188              
1189              Gtk.TreeIter   iter;
1190              _this.model.el.get_iter_from_string(out iter, path);
1191              
1192              GLib.Value value;
1193              _this.model.el.get_value(iter, 2, out value);
1194              
1195              return (JsRender.Node)value.dup_object();
1196         
1197         }
1198         public           void dropNode (string target_data_str, JsRender.Node node, bool show_templates) {
1199         //         print("drop Node");
1200              // console.dump(node);
1201           //    console.dump(target_data);
1202           
1203           
1204                 // 0 = before , 1=after 2/3 onto
1205           
1206           
1207                 var target_data= target_data_str.split("|");
1208           
1209                 var parent_str = target_data[0].length > 0 ? target_data[0] : "";
1210                 var pos = target_data.length > 1 ? int.parse(target_data[1]) : 2; // ontop..
1211           
1212           
1213                 Gtk.TreePath tree_path  =   parent_str.length > 0 ? new  Gtk.TreePath.from_string( parent_str ) : null;
1214                 
1215                 
1216                 
1217                 //print("add " + tp + "@" + target_data[1]  );
1218                 
1219                 JsRender.Node parentNode = null;
1220                 
1221                 Gtk.TreeIter iter_after;
1222                 Gtk.TreeIter iter_par ;
1223                 
1224                
1225                  if (target_data.length == 3 && target_data[2].length > 0) {
1226                     node.props.set("* prop", target_data[2]);
1227                 }
1228         
1229                 Gtk.TreePath expand_parent = null;
1230                 
1231                 // we only need to show the template if it's come from else where?
1232                  if (show_templates) {
1233                  
1234                     if (this.template_select == null) {
1235                         this.template_select = new DialogTemplateSelect();
1236                      }
1237                  
1238                      var new_node = this.template_select.show(
1239                           (Gtk.Window) _this.el.get_toplevel (),
1240                               this.file.palete(),
1241                            node);
1242                            
1243                      if (new_node != null) {
1244                          node = new_node;
1245                      }
1246                 }        
1247                 
1248                  //print("pos is %d  \n".printf(pos));
1249                 
1250                  Gtk.TreeIter n_iter; 
1251                  
1252                  if ( parent_str.length < 1) {
1253                       this.el.append(out n_iter, null); // drop at top level..
1254                       node.parent = null;
1255                       this.file.tree = node;
1256                       
1257                       
1258                 } else   if (pos  < 2) {
1259                     //print(target_data[1]  > 0 ? 'insert_after' : 'insert_before');
1260                     
1261                     this.el.get_iter(out iter_after, tree_path );            
1262                     this.el.iter_parent(out iter_par, iter_after);
1263                     expand_parent = this.el.get_path(iter_par);
1264                     
1265                     GLib.Value value;
1266                     this.el.get_value( iter_par, 2, out value);
1267                     parentNode =  (JsRender.Node)value.dup_object();
1268                     
1269                     
1270                     this.el.get_value( iter_after, 2, out value);
1271                     var relNode =  (JsRender.Node)value.dup_object();
1272                     
1273                     if ( pos  > 0 ) {
1274                      
1275                         this.el.insert_after(out n_iter,    iter_par  , iter_after);
1276                         var ix = parentNode.items.index_of(relNode);
1277                         parentNode.items.insert(ix+1, node);
1278                         
1279                     } else {
1280                         this.el.insert_before(out n_iter,  iter_par  , iter_after);
1281                         var ix = parentNode.items.index_of(relNode);
1282                         parentNode.items.insert(ix, node);
1283          
1284                     }
1285                     node.parent = parentNode;
1286                     
1287                     
1288                     
1289                 } else {
1290                    //  print("appending to  " + parent_str);
1291                     this.el.get_iter(out iter_par, tree_path);
1292                     this.el.append(out n_iter,   iter_par );
1293                     expand_parent = this.el.get_path(iter_par);
1294                     
1295                     GLib.Value value;
1296                     this.el.get_value( iter_par, 2, out value);
1297                     parentNode =  (JsRender.Node)value.dup_object();
1298                     node.parent = parentNode;
1299                     parentNode.items.add(node);
1300                 }
1301                 
1302                 // reparent node in tree...
1303                
1304                 
1305                 // why only on no parent???
1306                 
1307                 //if (node.parent = null) {
1308                      
1309                    
1310                     
1311                 //}
1312                 
1313                 
1314                 // work out what kind of packing to use.. -- should be in 
1315                 if (!node.has("pack")   && parent_str.length > 1) {
1316                     
1317                     this.file.palete().fillPack(node,parentNode);
1318                     
1319                     
1320                 }
1321                 
1322                 // add the node...
1323                 
1324                 this.el.set(n_iter, 0, node.nodeTitle(), 1, node.nodeTip(), -1  );
1325                 var o = new GLib.Value(typeof(Object));
1326                 o.set_object((Object)node);
1327                 
1328                 this.el.set_value(n_iter, 2, o);
1329                 
1330                 
1331                 
1332                 
1333         // load children - if it has any..
1334               
1335                 if (node.items.size > 0) {
1336                     this.load(node.items, n_iter);
1337                     _this.view.el.expand_row(this.el.get_path(n_iter), true);
1338                 } else if (expand_parent != null && !_this.view.el.is_row_expanded(expand_parent)) {
1339                    _this.view.el.expand_row(expand_parent,true);
1340                 }
1341         
1342                 //if (tp != null && (node.items.length() > 0 || pos > 1)) {
1343                 //    _this.view.el.expand_row(this.el.get_path(iter_par), true);
1344                // }
1345                 // wee need to get the empty proptypes from somewhere..
1346                 
1347                 //var olditer = this.activeIter;
1348                 this.activePath = this.el.get_path(n_iter).to_string();
1349         
1350         
1351                 
1352                 
1353                 _this.view.el.set_cursor(this.el.get_path(n_iter), null, false);
1354                 _this.changed();
1355              
1356                 
1357                     
1358         }
1359     }
1360     public class Xcls_TreeViewColumn4 : Object 
1361     {
1362         public Gtk.TreeViewColumn el;
1363         private Xcls_WindowLeftTree  _this;
1364
1365
1366             // my vars (def)
1367
1368         // ctor 
1369         public Xcls_TreeViewColumn4(Xcls_WindowLeftTree _owner )
1370         {
1371             _this = _owner;
1372             this.el = new Gtk.TreeViewColumn();
1373
1374             // my vars (dec)
1375
1376             // set gobject values
1377             this.el.title = "test";
1378             var child_0 = new Xcls_renderer( _this );
1379             child_0.ref();
1380             this.el.pack_start (  child_0.el , true );
1381
1382             // init method 
1383
1384             this.el.add_attribute(_this.renderer.el , "markup", 0 );
1385         }
1386
1387         // user defined functions 
1388     }
1389     public class Xcls_renderer : Object 
1390     {
1391         public Gtk.CellRendererText el;
1392         private Xcls_WindowLeftTree  _this;
1393
1394
1395             // my vars (def)
1396
1397         // ctor 
1398         public Xcls_renderer(Xcls_WindowLeftTree _owner )
1399         {
1400             _this = _owner;
1401             _this.renderer = this;
1402             this.el = new Gtk.CellRendererText();
1403
1404             // my vars (dec)
1405
1406             // set gobject values
1407         }
1408
1409         // user defined functions 
1410     }
1411     public class Xcls_LeftTreeMenu : Object 
1412     {
1413         public Gtk.Menu el;
1414         private Xcls_WindowLeftTree  _this;
1415
1416
1417             // my vars (def)
1418
1419         // ctor 
1420         public Xcls_LeftTreeMenu(Xcls_WindowLeftTree _owner )
1421         {
1422             _this = _owner;
1423             _this.LeftTreeMenu = this;
1424             this.el = new Gtk.Menu();
1425
1426             // my vars (dec)
1427
1428             // set gobject values
1429             var child_0 = new Xcls_MenuItem7( _this );
1430             child_0.ref();
1431             this.el.add (  child_0.el  );
1432             var child_1 = new Xcls_MenuItem8( _this );
1433             child_1.ref();
1434             this.el.add (  child_1.el  );
1435             var child_2 = new Xcls_MenuItem9( _this );
1436             child_2.ref();
1437             this.el.add (  child_2.el  );
1438         }
1439
1440         // user defined functions 
1441     }
1442     public class Xcls_MenuItem7 : Object 
1443     {
1444         public Gtk.MenuItem el;
1445         private Xcls_WindowLeftTree  _this;
1446
1447
1448             // my vars (def)
1449
1450         // ctor 
1451         public Xcls_MenuItem7(Xcls_WindowLeftTree _owner )
1452         {
1453             _this = _owner;
1454             this.el = new Gtk.MenuItem();
1455
1456             // my vars (dec)
1457
1458             // set gobject values
1459             this.el.label = "Delete Element";
1460
1461             // listeners 
1462             this.el.activate.connect( ( ) => {
1463                 
1464                 print("ACTIVATE?");
1465                 
1466               
1467                  _this.model.deleteSelected();
1468             });
1469         }
1470
1471         // user defined functions 
1472     }
1473     public class Xcls_MenuItem8 : Object 
1474     {
1475         public Gtk.MenuItem el;
1476         private Xcls_WindowLeftTree  _this;
1477
1478
1479             // my vars (def)
1480
1481         // ctor 
1482         public Xcls_MenuItem8(Xcls_WindowLeftTree _owner )
1483         {
1484             _this = _owner;
1485             this.el = new Gtk.MenuItem();
1486
1487             // my vars (dec)
1488
1489             // set gobject values
1490             this.el.label = "Save as Template";
1491
1492             // listeners 
1493             this.el.activate.connect( () => {
1494             
1495                  DialogSaveTemplate.singleton().show(
1496                         (Gtk.Window) _this.el.get_toplevel (), 
1497                         _this.model.file.palete(), 
1498                         _this.getActiveElement()
1499                 );
1500                  
1501                 
1502             });
1503         }
1504
1505         // user defined functions 
1506     }
1507     public class Xcls_MenuItem9 : Object 
1508     {
1509         public Gtk.MenuItem el;
1510         private Xcls_WindowLeftTree  _this;
1511
1512
1513             // my vars (def)
1514
1515         // ctor 
1516         public Xcls_MenuItem9(Xcls_WindowLeftTree _owner )
1517         {
1518             _this = _owner;
1519             this.el = new Gtk.MenuItem();
1520
1521             // my vars (dec)
1522
1523             // set gobject values
1524             this.el.label = "Save as Module";
1525
1526             // listeners 
1527             this.el.activate.connect( () => {
1528                 var node = _this.getActiveElement();
1529                  var name = DialogSaveModule.singleton().show(
1530                         (Gtk.Window) _this.el.get_toplevel (), 
1531                         _this.model.file.project, 
1532                         node
1533                  );
1534                  if (name.length < 1) {
1535                         return;
1536               
1537                  }
1538                  node.props.set("* xinclude", name);
1539                  node.items.clear();
1540             
1541             
1542                 var s = _this.view.el.get_selection();
1543                 
1544                 print("GET  SELECTED?");
1545                 Gtk.TreeIter iter;
1546                 Gtk.TreeModel mod;
1547             
1548                 
1549                 if (!s.get_selected(out mod, out iter)) {
1550                     return; // nothing seleted..
1551                 }
1552                 Gtk.TreeIter citer;
1553                 var n_cn = mod.iter_n_children(iter) -1;
1554                 for (var i = n_cn; i > -1; i--) {
1555                     mod.iter_nth_child(out citer, iter, i);
1556                     
1557             
1558                     print("removing node from Tree\n");    
1559                 
1560                     _this.model.el.remove(ref citer);
1561                 }
1562                 _this.changed();
1563                 _this.node_selected(node);
1564                  
1565                 
1566             });
1567         }
1568
1569         // user defined functions 
1570     }
1571 }