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