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