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