f14651f83b328b0c8adc405bd6aeb7e917d6226f
[roobuilder] / src / Builder4 / WindowLeftTree.vala
1 static Xcls_WindowLeftTree  _WindowLeftTree;
2
3 public class Xcls_WindowLeftTree : Object
4 {
5         public Gtk.Box 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_viewwin viewwin;
16         public Xcls_view view;
17         public Xcls_drop drop;
18         public Xcls_selmodel selmodel;
19         public Xcls_model model;
20         public Xcls_maincol maincol;
21         public Xcls_keystate keystate;
22         public Xcls_LeftTreeMenu LeftTreeMenu;
23
24                 // my vars (def)
25         public signal bool before_node_change ();
26         public Xcls_MainWindow main_window;
27         public signal void changed ();
28         public signal void node_selected (JsRender.Node? node);
29
30         // ctor
31         public Xcls_WindowLeftTree()
32         {
33                 _this = this;
34                 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
35
36                 // my vars (dec)
37                 this.main_window = null;
38
39                 // set gobject values
40                 this.el.hexpand = true;
41                 this.el.vexpand = true;
42                 var child_1 = new Xcls_ListView2( _this );
43                 child_1.ref();
44                 this.el.append( child_1.el );
45                 new Xcls_viewwin( _this );
46                 this.el.append( _this.viewwin.el );
47         }
48
49         // user defined functions
50         public void onresize () {
51          
52                  
53                 //GLib.debug("Got allocation width of scrolled view %d", allocation.width );
54         //      _this.maincol.el.set_max_width( _this.viewwin.el.get_width()  - 32 );
55         }
56         public JsRender.Node? getActiveElement () { // return path to actie node.
57         
58              
59                 return _this.selmodel.getSelectedNode();
60             
61             
62         }
63         public JsRender.JsRender getActiveFile () {
64             return this.main_window.windowstate.file;
65         }
66         public class Xcls_ListView2 : Object
67         {
68                 public Gtk.ListView el;
69                 private Xcls_WindowLeftTree  _this;
70
71
72                         // my vars (def)
73
74                 // ctor
75                 public Xcls_ListView2(Xcls_WindowLeftTree _owner )
76                 {
77                         _this = _owner;
78                         var child_1 = new Xcls_SignalListItemFactory3( _this );
79                         child_1.ref();
80                         this.el = new Gtk.ListView( null, child_1.el );
81
82                         // my vars (dec)
83
84                         // set gobject values
85                 }
86
87                 // user defined functions
88         }
89         public class Xcls_SignalListItemFactory3 : Object
90         {
91                 public Gtk.SignalListItemFactory el;
92                 private Xcls_WindowLeftTree  _this;
93
94
95                         // my vars (def)
96
97                 // ctor
98                 public Xcls_SignalListItemFactory3(Xcls_WindowLeftTree _owner )
99                 {
100                         _this = _owner;
101                         this.el = new Gtk.SignalListItemFactory();
102
103                         // my vars (dec)
104
105                         // set gobject values
106                 }
107
108                 // user defined functions
109         }
110
111
112         public class Xcls_viewwin : Object
113         {
114                 public Gtk.ScrolledWindow el;
115                 private Xcls_WindowLeftTree  _this;
116
117
118                         // my vars (def)
119
120                 // ctor
121                 public Xcls_viewwin(Xcls_WindowLeftTree _owner )
122                 {
123                         _this = _owner;
124                         _this.viewwin = this;
125                         this.el = new Gtk.ScrolledWindow();
126
127                         // my vars (dec)
128
129                         // set gobject values
130                         this.el.vscrollbar_policy = Gtk.PolicyType.AUTOMATIC;
131                         this.el.has_frame = true;
132                         this.el.hexpand = true;
133                         this.el.vexpand = true;
134                         this.el.hscrollbar_policy = Gtk.PolicyType.AUTOMATIC;
135                         new Xcls_view( _this );
136                         this.el.child = _this.view.el;
137                         new Xcls_LeftTreeMenu( _this );
138                 }
139
140                 // user defined functions
141         }
142         public class Xcls_view : Object
143         {
144                 public Gtk.ColumnView el;
145                 private Xcls_WindowLeftTree  _this;
146
147
148                         // my vars (def)
149                 public bool blockChanges;
150                 public bool headers_visible;
151                 public string lastEventSource;
152                 public bool button_is_pressed;
153                 public Gtk.CssProvider css;
154                 public JsRender.Node? dragNode;
155
156                 // ctor
157                 public Xcls_view(Xcls_WindowLeftTree _owner )
158                 {
159                         _this = _owner;
160                         _this.view = this;
161                         new Xcls_selmodel( _this );
162                         this.el = new Gtk.ColumnView( _this.selmodel.el );
163
164                         // my vars (dec)
165                         this.blockChanges = false;
166                         this.headers_visible = false;
167                         this.lastEventSource = "";
168                         this.button_is_pressed = false;
169                         this.dragNode = null;
170
171                         // set gobject values
172                         this.el.name = "left-tree-view";
173                         this.el.hexpand = false;
174                         this.el.vexpand = true;
175                         var child_2 = new Xcls_GestureClick6( _this );
176                         child_2.ref();
177                         this.el.add_controller(  child_2.el );
178                         var child_3 = new Xcls_GestureClick7( _this );
179                         child_3.ref();
180                         this.el.add_controller(  child_3.el );
181                         var child_4 = new Xcls_DragSource8( _this );
182                         child_4.ref();
183                         this.el.add_controller(  child_4.el );
184                         var child_5 = new Xcls_EventControllerKey9( _this );
185                         child_5.ref();
186                         this.el.add_controller(  child_5.el );
187                         new Xcls_drop( _this );
188                         this.el.add_controller(  _this.drop.el );
189                         new Xcls_maincol( _this );
190                         this.el.append_column ( _this.maincol.el  );
191                         var child_8 = new Xcls_ColumnViewColumn15( _this );
192                         child_8.ref();
193                         this.el.append_column ( child_8.el  );
194                         new Xcls_keystate( _this );
195                         this.el.add_controller(  _this.keystate.el );
196
197                         // init method
198
199                         {
200                          
201                           this.css = new Gtk.CssProvider();
202                         //      try {
203                                         this.css.load_from_string("
204                         #left-tree-view { font-size: 12px;}     
205                         .drag-over  { background-color:#88a3bc; }
206                         .drag-below  {   
207                          border-bottom-width: 5px; 
208                          border-bottom-style: solid;
209                          border-bottom-color: #88a3bc;
210                         }
211                         .drag-above  {
212                          border-top-width: 5px;
213                          border-top-style: solid;
214                          border-top-color: #88a3bc;
215                         }
216                         #left-tree-view indent {
217                         -gtk-icon-size : 2px;
218                         }
219                         #left-tree-view indent:nth-last-child(2)  {
220                         min-width: 24px;
221                         }
222                         ");
223                         
224                                 Gtk.StyleContext.add_provider_for_display(
225                                         this.el.get_display(),
226                                         this.css,
227                                         Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
228                                 );
229                                 
230                                   
231                         }
232                 }
233
234                 // user defined functions
235                 public Gtk.Widget? getWidgetAtRow (uint row) {
236                 /*
237                         
238                 from            https://discourse.gnome.org/t/gtk4-finding-a-row-data-on-gtkcolumnview/8465
239                         var colview = gesture.widget;
240                         var line_no = check_list_widget(colview, x,y);
241                          if (line_no > -1) {
242                                 var item = colview.model.get_item(line_no);
243                                  
244                         }
245                         */
246                                 //GLib.debug("Get Widget At Row %d", (int)row);
247                         var  child = this.el.get_first_child(); 
248                         var line_no = -1; 
249                         var reading_header = true;
250                          
251                         while (child != null) {
252                                         GLib.debug("Got %s", child.get_type().name());
253                            
254                            if (reading_header) {
255                                                 
256                 
257                                                 if (child.get_type().name() != "GtkColumnListView") {
258                                                    
259                                                         child = child.get_next_sibling();
260                                                         continue;
261                                                 }
262                                                 // should be columnlistview
263                                                 child = child.get_first_child(); 
264                                          
265                                          
266                                                 
267                                                 reading_header = false;
268                                                  
269                                     }
270                                     
271                                   
272                             
273                                     line_no++;
274                                         if (line_no == row) {
275                                                 //GLib.debug("Returning widget %s", child.get_type().name());
276                                             return (Gtk.Widget)child;
277                                     }
278                                 child = child.get_next_sibling(); 
279                         }
280                                 //GLib.debug("Rturning null");
281                         return null;
282                 
283                  }
284                 public int getColAt (double x,  double y) {
285                 /*
286                         
287                 from            https://discourse.gnome.org/t/gtk4-finding-a-row-data-on-gtkcolumnview/8465
288                           
289                         */
290                                 //Gtk.Allocation alloc = { 0, 0, 0, 0 };
291                                 //GLib.debug("Cehck %d, %d", x,y);
292                         var  child = this.el.get_first_child(); 
293                          
294                         var col = 0;
295                         var offx = 0;
296                         while (child != null) {
297                                         
298                                         if (child.get_type().name() == "GtkColumnViewRowWidget") {
299                                                 child = child.get_first_child();
300                                                 continue;
301                                         }
302                                         
303                                         //child.get_allocation(out alloc);
304                                         if (x <  (child.get_width() + offx)) {
305                                                 return col;
306                                         }
307                                         return 1;
308                                         //offx += child.get_width();
309                                         //col++;
310                                         //child = child.get_next_sibling();
311                                 }
312                              
313                                           
314                         return -1;
315                 
316                  }
317                 public int getRowAt (double x,  double in_y, out string pos) {
318                 
319                 
320                          
321                 
322                 /*
323                         
324                 from            https://discourse.gnome.org/t/gtk4-finding-a-row-data-on-gtkcolumnview/8465
325                         var colview = gesture.widget;
326                         var line_no = check_list_widget(colview, x,y);
327                          if (line_no > -1) {
328                                 var item = colview.model.get_item(line_no);
329                                  
330                         }
331                         */
332                                  
333                                 
334                                 //GLib.debug("offset = %d  y = %d", (int) voff, (int) in_y);
335                         var y = in_y + _this.viewwin.el.vadjustment.value; 
336                         var  child = this.el.get_first_child(); 
337                         //Gtk.Allocation alloc = { 0, 0, 0, 0 };
338                         var line_no = -1; 
339                         var reading_header = true;
340                         var real_y = 0;
341                         var header_height  = 0;
342                         pos = "none";
343                         var h = 0;
344                         while (child != null) {
345                                         //GLib.debug("Got %s", child.get_type().name());
346                             if (reading_header) {
347                                                 
348                 
349                                                 if (child.get_type().name() != "GtkColumnListView") {
350                                                 h += child.get_height();
351                                                         child = child.get_next_sibling();
352                                                         continue;
353                                                 }
354                                                 // should be columnlistview
355                                                 child = child.get_first_child(); 
356                                             GLib.debug("header height=%d", h);
357                                                 header_height =  h;
358                                                 
359                                                 reading_header = false;
360                                                 
361                                 }
362                                 
363                                     if (child.get_type().name() != "GtkColumnViewRowWidget") {
364                                     child = child.get_next_sibling();
365                                     continue;
366                                     }
367                                     
368                                         if (y < header_height) {
369                                         return -1;
370                                 }
371                                     
372                                     line_no++;
373                                         var hh = child.get_height();
374                                         //child.get_allocation(out alloc);
375                                         //GLib.debug("got cell xy = %d,%d  w,h= %d,%d", alloc.x, alloc.y, alloc.width, alloc.height);
376                                         //GLib.debug("row %d y= %d %s", line_no, (int) (header_height + alloc.y),
377                                         
378                                         //      child.visible ? "VIS" : "hidden");
379                 
380                                     if (y >  (header_height + real_y) && y <= (header_height +  real_y + hh) ) {
381                                         if (y > ( header_height + real_y + (hh * 0.8))) {
382                                                 pos = "below";
383                                         } else if (y > ( header_height + real_y + (hh * 0.2))) {
384                                                 pos = "over";
385                                         } else {
386                                                 pos = "above";
387                                                 }
388                                          GLib.debug("getRowAt return : %d, %s", line_no, pos);
389                                             return line_no;
390                                     }
391                  
392                 
393                                     if (real_y + hh > y) {
394                                         return -1;
395                                 }
396                                 real_y += hh;
397                                 child = child.get_next_sibling(); 
398                         }
399                         return -1;
400                 
401                  }
402                 public Gtk.Widget? getWidgetAt (double x,  double in_y) {
403                 /*
404                         
405                 from            https://discourse.gnome.org/t/gtk4-finding-a-row-data-on-gtkcolumnview/8465
406                         var colview = gesture.widget;
407                         var line_no = check_list_widget(colview, x,y);
408                          if (line_no > -1) {
409                                 var item = colview.model.get_item(line_no);
410                                  
411                         }
412                         */
413                         var y = in_y + _this.viewwin.el.vadjustment.value; 
414                         var  child = this.el.get_first_child(); 
415                         //Gtk.Allocation alloc = { 0, 0, 0, 0 };
416                         var line_no = -1; 
417                         var reading_header = true;
418                         var curr_y = 0;
419                         var header_height  = 0;
420                         var h = 0;
421                         while (child != null) {
422                                         //GLib.debug("Got %s", child.get_type().name());
423                                 if (reading_header) {
424                                                 
425                 
426                                                 if (child.get_type().name() != "GtkColumnListView") {
427                                                 h += child.get_height();
428                                                         child = child.get_next_sibling();
429                                                         continue;
430                                                 }
431                                                 // should be columnlistview
432                                                 child = child.get_first_child(); 
433                                             GLib.debug("header height=%d", h);
434                                                 header_height =  h;
435                                                 
436                                                 reading_header = false;
437                                                 
438                                 }
439                                     line_no++;
440                 
441                                         if (y < header_height) {
442                                         return null;
443                                 }
444                 
445                                         var hh = child.get_height();
446                                         //GLib.debug("got cell xy = %d,%d  w,h= %d,%d", alloc.x, alloc.y, alloc.width, alloc.height);
447                 
448                                     if (y > curr_y && y <= header_height + hh + curr_y ) {
449                                             return (Gtk.Widget)child;
450                                     }
451                                     curr_y +=  hh ;
452                 
453                                     if (curr_y > y) {
454                                         return null;
455                                 }
456                                 child = child.get_next_sibling(); 
457                         }
458                         return null;
459                 
460                  }
461         }
462         public class Xcls_GestureClick6 : Object
463         {
464                 public Gtk.GestureClick el;
465                 private Xcls_WindowLeftTree  _this;
466
467
468                         // my vars (def)
469
470                 // ctor
471                 public Xcls_GestureClick6(Xcls_WindowLeftTree _owner )
472                 {
473                         _this = _owner;
474                         this.el = new Gtk.GestureClick();
475
476                         // my vars (dec)
477
478                         // set gobject values
479
480                         //listeners
481                         this.el.released.connect( (n_press, x, y) => {
482                          
483                             _this.view.button_is_pressed = false;
484                         
485                         
486                         });
487                         this.el.pressed.connect( (n_press, x, y) => {
488                          
489                             //console.log("button press?");
490                             
491                             //this.el.set_state(Gtk.EventSequenceState.CLAIMED);
492                         
493                         
494                             
495                             _this.view.button_is_pressed = true;
496                               
497                             _this.view.lastEventSource = "tree";
498                             if (! _this.before_node_change() ) {
499                                 GLib.debug("before_node_change return false");
500                                return ;
501                             }
502                             
503                                  // nothing there -show dialog
504                             if (_this.model.el.get_n_items() < 1) {
505                                     _this.main_window.windowstate.showAddObject(_this.view.el, null);
506                                 GLib.debug("no items");
507                                     return ;
508                             }
509                             string pos;
510                             var row = _this.view.getRowAt(x,y, out pos );
511                             if (row < 0) {
512                                     GLib.debug("no row selected items");
513                                     return;
514                             }
515                             
516                             var node =   _this.selmodel.getNodeAt(row);
517                             if (node == null) {
518                                 GLib.warning("No node found at row %d", row);
519                                 return;
520                                 }
521                         
522                              
523                              
524                             if (_this.view.getColAt(x,y) > 0 ) {
525                                     GLib.debug("add colum clicked.");
526                                 var fqn = node.fqn();
527                                 var cn = _this.main_window.windowstate.project.palete.getChildList(fqn, false);
528                                         if (cn.size < 1) {
529                                                 return ;
530                                         }
531                         
532                                         _this.main_window.windowstate.leftTreeBeforeChange();
533                                         //_this.view.el.get_selection().select_path(res);
534                                         GLib.debug("Button Pressed - start show window");
535                                         _this.main_window.windowstate.showAddObject(_this.view.el, node);
536                                         GLib.debug("Button Pressed - finsihed show window");
537                                 return ;
538                                 }
539                             
540                                  
541                              
542                         });
543                 }
544
545                 // user defined functions
546         }
547
548         public class Xcls_GestureClick7 : Object
549         {
550                 public Gtk.GestureClick el;
551                 private Xcls_WindowLeftTree  _this;
552
553
554                         // my vars (def)
555
556                 // ctor
557                 public Xcls_GestureClick7(Xcls_WindowLeftTree _owner )
558                 {
559                         _this = _owner;
560                         this.el = new Gtk.GestureClick();
561
562                         // my vars (dec)
563
564                         // set gobject values
565                         this.el.button = 3;
566
567                         //listeners
568                         this.el.pressed.connect( (n_press, x, y) => {
569                         
570                                 
571                                   
572                                  
573                             if (_this.model.el.get_n_items() < 1) {
574                          
575                                 GLib.debug("no items");
576                                     return ;
577                             }
578                             string pos;
579                             var row = _this.view.getRowAt(x,y, out pos );
580                             if (row < 0) {
581                                     GLib.debug("no row selected items");
582                                     return;
583                             }
584                             
585                             var node =   _this.selmodel.getNodeAt(row);
586                             if (node == null) {
587                                 GLib.warning("No node found at row %d", row);
588                                 return;
589                                 }
590                                 _this.model.selectNode(node);
591                              
592                              
593                              
594                                 GLib.debug("Prssed %d", (int)  this.el.get_current_button());
595                                 //_this.deletemenu.el.set_parent(_this.view.el);
596                                 _this.LeftTreeMenu.el.set_parent(_this.view.el);
597                                 
598                                 
599                                 //Gtk.Allocation rect;
600                                 //_this.view.el.get_allocation(out rect);
601                                 //_this.deletemenu.el.set_has_arrow(false);
602                                 _this.LeftTreeMenu.el.set_position(Gtk.PositionType.BOTTOM); 
603                                 
604                                         
605                                 _this.LeftTreeMenu.el.set_offset( 
606                                                 (int)x  ,
607                                                 (int)y - (int)_this.view.el.get_height());
608                         
609                             _this.LeftTreeMenu.el.popup();
610                               
611                         });
612                 }
613
614                 // user defined functions
615         }
616
617         public class Xcls_DragSource8 : Object
618         {
619                 public Gtk.DragSource el;
620                 private Xcls_WindowLeftTree  _this;
621
622
623                         // my vars (def)
624
625                 // ctor
626                 public Xcls_DragSource8(Xcls_WindowLeftTree _owner )
627                 {
628                         _this = _owner;
629                         this.el = new Gtk.DragSource();
630
631                         // my vars (dec)
632
633                         // set gobject values
634                         this.el.actions = Gdk.DragAction.COPY   | Gdk.DragAction.MOVE   ;
635
636                         //listeners
637                         this.el.drag_cancel.connect( (drag, reason) => {
638                         
639                                 _this.view.dragNode = null;
640                                 return true;
641                         });
642                         this.el.prepare.connect( (x, y) => {
643                         
644                                 
645                                 
646                         ///     ( drag_context, data, info, time) => {
647                                     
648                         
649                                 //print("drag-data-get");
650                                 var ndata = _this.selmodel.getSelectedNode();
651                                 if (ndata == null) {
652                                         GLib.debug("return empty string - no selection..");
653                                         return null;
654                                  
655                                 }
656                         
657                           
658                                 //data.set_text(tp,tp.length);   
659                         
660                                 var     str = ndata.toJsonString();
661                                 GLib.debug("prepare  store: %s", str);
662                                 GLib.Value ov = GLib.Value(typeof(string));
663                                 ov.set_string(str);
664                                 var cont = new Gdk.ContentProvider.for_value(ov);
665                             /*
666                                 GLib.Value v = GLib.Value(typeof(string));
667                                 //var str = drop.read_text( [ "text/plain" ] 0);
668                                  
669                                         cont.get_value(ref v);
670                                  
671                                 }
672                                 GLib.debug("set %s", v.get_string());
673                               */  
674                                 return cont;
675                                  
676                                  
677                         });
678                         this.el.drag_begin.connect( ( drag )  => {
679                                 GLib.debug("SOURCE: drag-begin");
680                                  
681                             // find what is selected in our tree...
682                             var data = _this.selmodel.getSelectedNode();
683                                 if (data == null) {
684                                         return  ;
685                                 }
686                                 _this.view.dragNode = data;
687                             var xname = data.fqn();
688                             GLib.debug ("XNAME  IS %s", xname);
689                         
690                                 var widget = _this.view.getWidgetAtRow(_this.selmodel.el.selected);
691                                 
692                                 
693                             var paintable = new Gtk.WidgetPaintable(widget);
694                             this.el.set_icon(paintable, 0,0);
695                                     
696                          
697                         });
698                         this.el.drag_end.connect( (drag, delete_data) => {
699                         
700                         _this.view.dragNode = null;
701                         });
702                 }
703
704                 // user defined functions
705         }
706
707         public class Xcls_EventControllerKey9 : Object
708         {
709                 public Gtk.EventControllerKey el;
710                 private Xcls_WindowLeftTree  _this;
711
712
713                         // my vars (def)
714
715                 // ctor
716                 public Xcls_EventControllerKey9(Xcls_WindowLeftTree _owner )
717                 {
718                         _this = _owner;
719                         this.el = new Gtk.EventControllerKey();
720
721                         // my vars (dec)
722
723                         // set gobject values
724
725                         //listeners
726                         this.el.key_pressed.connect( (keyval, keycode, state) => {
727                         
728                          
729                         
730                                 if (keyval != Gdk.Key.Delete && keyval != Gdk.Key.BackSpace)  {
731                                         return true;
732                                 }
733                         
734                                 _this.model.deleteSelected();
735                                 return true;
736                         
737                         });
738                 }
739
740                 // user defined functions
741         }
742
743         public class Xcls_drop : Object
744         {
745                 public Gtk.DropTarget el;
746                 private Xcls_WindowLeftTree  _this;
747
748
749                         // my vars (def)
750                 public Gtk.Widget? highlightWidget;
751                 public JsRender.Node? lastDragNode;
752                 public string lastDragString;
753
754                 // ctor
755                 public Xcls_drop(Xcls_WindowLeftTree _owner )
756                 {
757                         _this = _owner;
758                         _this.drop = this;
759                         this.el = new Gtk.DropTarget ( typeof(string) ,
760                 Gdk.DragAction.COPY   | Gdk.DragAction.MOVE   );
761
762                         // my vars (dec)
763                         this.highlightWidget = null;
764                         this.lastDragNode = null;
765                         this.lastDragString = "";
766
767                         // set gobject values
768
769                         //listeners
770                         this.el.accept.connect( (drop) => {
771                         
772                                 GLib.debug("got DropTarget:accept");
773                          
774                         // NOT REALLY NEEDED? = put stuff in drop?
775                         
776                         
777                         /* (  ctx, x, y, time)  => {
778                               //Seed.print("TARGET: drag-drop");
779                            
780                            
781                             var src = Gtk.drag_get_source_widget(ctx);
782                              
783                            if (src != this.el) {
784                            
785                             
786                                
787                                this.drag_in_motion = false;   
788                                     // request data that will be recieved by the recieve...              
789                                 Gtk.drag_get_data
790                                 (
791                                         this.el,         // will receive 'drag-data-received' signal 
792                                         ctx,        // represents the current state of the DnD 
793                                         Gdk.Atom.intern("application/json",true),    // the target type we want 
794                                         time            // time stamp 
795                                 );
796                         
797                                  
798                                 // No target offered by source => error
799                            
800                         
801                                  return  false;
802                              }
803                              
804                              // handle drop around self..
805                              
806                                           
807                                     
808                             //print("GETTING POS");
809                             var  targetData = "";
810                             
811                             Gtk.TreePath path;
812                             Gtk.TreeViewDropPosition pos;
813                             var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
814                             
815                             // if there are not items in the tree.. the we have to set isOver to true for anything..
816                             var isEmpty = false;
817                             if (_this.model.el.iter_n_children(null) < 1) {
818                                 print("got NO children?\n");
819                                 isOver = true; //??? 
820                                 isEmpty = true;
821                                 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
822                             }
823                             
824                              
825                              
826                             //var action = Gdk.DragAction.COPY;
827                                 // unless we are copying!!! ctl button..
828                             
829                             var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
830                                          Gdk.DragAction.COPY  : Gdk.DragAction.MOVE ;
831                                         // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
832                         
833                               
834                             if (_this.model.el.iter_n_children(null) < 1) {
835                                 // no children.. -- asume it's ok..
836                                 
837                                 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
838                                  
839                                 // continue through to allow drop...
840                         
841                             } else {
842                                         
843                                         
844                             
845                                         
846                                         
847                                         //print("ISOVER? " + isOver);
848                                 if (!isOver) {
849                                     
850                                     Gtk.drag_finish (ctx, false, false, time);        // drop failed..
851                                     return true; // not over apoint!?! - no action on drop or motion..
852                                 }
853                                         
854                                 // drag node is parent of child..
855                                 //console.log("SRC TREEPATH: " + src.treepath);
856                                 //console.log("TARGET TREEPATH: " + data.path.to_string());
857                                 
858                                 // nned to check a  few here..
859                                 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
860                                 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
861                                 //Gtk.TreeViewDropPosition.AFTER
862                                 //Gtk.TreeViewDropPosition.BEFORE
863                                 
864                                 // locally dragged items to not really use the 
865                                 var selection_text = this.dragData;
866                                 
867                                 
868                                 
869                                 if (selection_text == null || selection_text.length < 1) {
870                                     //print("Error  - drag selection text returned NULL");
871                                   
872                                      Gtk.drag_finish (ctx, false, false, time);        // drop failed..
873                                      return true; /// -- fixme -- this is not really correct..
874                                 }                
875                                         
876                                         // see if we are dragging into ourself?
877                                         print ("got selection text of  " + selection_text);
878                                 
879                                 var target_path = path.to_string();
880                                 //print("target_path="+target_path);
881                         
882                                 // 
883                                 if (selection_text  == target_path) {
884                                     print("self drag ?? == we should perhaps allow copy onto self..\n");
885                                     
886                                      Gtk.drag_finish (ctx, false, false, time);        // drop failed..
887                         
888                                      return true; /// -- fixme -- this is not really correct..
889                         
890                                 }
891                                         
892                                 // check that 
893                                 //print("DUMPING DATA");
894                                 //console.dump(data);
895                                 // path, pos
896                                 
897                                 //print(data.path.to_string() +' => '+  data.pos);
898                                 
899                                 // dropList is a list of xtypes that this node could be dropped on.
900                                 // it is set up when we start to drag..
901                                 
902                                 
903                                 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
904                                     
905                                 print("targetDAta: " + targetData +"\n");
906                                 
907                                 if (targetData.length < 1) {
908                                     //print("Can not find drop node path");
909                                      
910                                     Gtk.drag_finish (ctx, false, false, time);        // drop failed..
911                                     return true;
912                                 }
913                                             
914                                         
915                                         
916                                         // continue on to allow drop..
917                           }
918                                 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
919                         
920                         
921                              var delete_selection_data = false;
922                                 
923                             if (action == Gdk.DragAction.ASK)  {
924                                 // Ask the user to move or copy, then set the ctx action. 
925                             }
926                         
927                             if (action == Gdk.DragAction.MOVE) {
928                                 delete_selection_data = true;
929                             }
930                               
931                                         // drag around.. - reorder..
932                             _this.model.moveNode(targetData, action);
933                                 
934                                
935                                 
936                                 
937                                 
938                                 // we can send stuff to souce here...
939                         
940                         
941                         // do we always say failure, so we handle the reall drop?
942                             Gtk.drag_finish (ctx, false, false,time); //delete_selection_data, time);
943                         
944                             return true;
945                          
946                          
947                          
948                          
949                          
950                          
951                         }
952                         */
953                                 return true;
954                         });
955                         this.el.motion.connect( (  x, y) => {
956                          
957                                 var is_shift = _this.keystate.is_shift > 0;
958                                 
959                                 GLib.debug("shift is    %s", _this.keystate.is_shift > 0 ? "SHIFT" : "-");
960                                 string pos; // over / before / after..
961                         
962                             //GLib.debug("got drag motion");
963                         
964                             GLib.Value v = GLib.Value(typeof(string));
965                                 //var str = drop.read_text( [ "text/plain" ] 0);
966                                 var cont = this.el.current_drop.get_drag().content ;
967                                 try {
968                                         cont.get_value(ref v);
969                                 } catch (GLib.Error e) {
970                                     GLib.debug("failed to get drag value");
971                                         return Gdk.DragAction.COPY;      
972                                 
973                                 }
974                          
975                                 //GLib.debug("got %s", v.get_string());
976                                   
977                                 if (this.lastDragString != v.get_string() || this.lastDragNode == null) {
978                                         // still dragging same node
979                          
980                                         this.lastDragNode = new JsRender.Node(); 
981                                         this.lastDragNode.loadFromJsonString(v.get_string(), 1);
982                                 }
983                             
984                         
985                                 var drop_on_to = _this.main_window.windowstate.file.palete().getDropList(
986                                                         this.lastDragNode.fqn());
987                              
988                              string[] str = {};
989                              foreach(var dp in drop_on_to) {
990                                 str += dp;
991                                 }
992                                 GLib.debug("droplist: %s", string.joinv(", ", str));
993                              
994                              
995                             // if there are not items in the tree.. the we have to set isOver to true for anything..
996                          
997                             if (_this.model.el.n_items < 1) {
998                                 // FIXME check valid drop types?
999                                 if (drop_on_to.contains("*top")) {
1000                                                 this.addHighlight(_this.view.el, "over");
1001                                         } else {
1002                                                 this.addHighlight(null, "");            
1003                                         }
1004                         
1005                                         return Gdk.DragAction.COPY; // no need to highlight?
1006                              
1007                             }
1008                             
1009                             
1010                                 GLib.debug("check is over");
1011                                  
1012                             // if path of source and dest are inside each other..
1013                             // need to add source info to drag?
1014                             // the fail();
1015                                 var row = _this.view.getRowAt(x,y, out pos);
1016                                 
1017                                 if (row < 0) {
1018                                         this.addHighlight(null, "");    
1019                                         return Gdk.DragAction.COPY;
1020                                 }
1021                                 var tr = (Gtk.TreeListRow)_this.view.el.model.get_object(row);
1022                                 
1023                                 var node =  (JsRender.Node)tr.get_item();
1024                                 
1025                                 GLib.debug("Drop over node: %s", node.fqn());
1026                                 
1027                         
1028                                 if (pos == "above" || pos == "below") {
1029                                         if (node.parent == null) {
1030                                                 GLib.debug("no parent try center");
1031                                                 pos = "over";
1032                                         } else {
1033                                                  
1034                                                 if (!drop_on_to.contains(node.parent.fqn())) {
1035                                                         GLib.debug("drop on does not contain %s - try center" , node.parent.fqn());
1036                                                         pos = "over";
1037                                                 } else {
1038                                                         GLib.debug("drop  contains %s - using %s" , node.parent.fqn(), pos);
1039                                                         if (_this.view.dragNode  != null && is_shift) {
1040                                                                 if (node.parent.oid == _this.view.dragNode.oid || node.parent.has_parent(_this.view.dragNode)) {
1041                                                                         GLib.debug("shift drop not self not allowed");
1042                                                                         this.addHighlight(null, "");
1043                                                                         return Gdk.DragAction.COPY;     
1044                                                                 }
1045                                                                 
1046                                                         }
1047                                                         
1048                                                 }
1049                                                 
1050                                                 
1051                                                 
1052                                         }
1053                                         
1054                                         
1055                                 }
1056                                 if (pos == "over") {
1057                                         if (!drop_on_to.contains(node.fqn())) {
1058                                                 GLib.debug("drop on does not contain %s - try center" , node.fqn());
1059                                                 this.addHighlight(null, ""); 
1060                                                 return is_shift ?  Gdk.DragAction.MOVE :  Gdk.DragAction.COPY;          
1061                                         }
1062                                         if (_this.view.dragNode  != null && is_shift) {
1063                                                 if (node.oid == _this.view.dragNode.oid || node.has_parent(_this.view.dragNode)) {
1064                                                         GLib.debug("shift drop not self not allowed");
1065                                                         this.addHighlight(null, "");
1066                                                         return Gdk.DragAction.COPY;     
1067                                                 }
1068                                         }
1069                                                 
1070                                 }
1071                                 
1072                                 
1073                                     // _this.view.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
1074                                 var w = _this.view.getWidgetAt(x,y);
1075                                 this.addHighlight(w, pos); 
1076                                 return is_shift ?  Gdk.DragAction.MOVE :  Gdk.DragAction.COPY;          
1077                         });
1078                         this.el.leave.connect( ( ) => {
1079                                 this.addHighlight(null,"");
1080                         
1081                         });
1082                         this.el.drop.connect( (v, x, y) => {
1083                                 
1084                                 this.addHighlight(null,"");
1085                          
1086                                 var is_shift = _this.keystate.is_shift > 0;
1087                          
1088                                 var pos = "";
1089                                 // -- get position..
1090                                 if (this.lastDragString != v.get_string() || this.lastDragNode == null) {
1091                                         // still dragging same node
1092                          
1093                                         this.lastDragNode = new JsRender.Node(); 
1094                                         this.lastDragNode.loadFromJsonString(v.get_string(), 1);
1095                                 }
1096                             
1097                                      
1098                                
1099                             var dropNode = new JsRender.Node(); 
1100                                 dropNode.loadFromJsonString(v.get_string(), 1);
1101                                 var drop_on_to = _this.main_window.windowstate.file.palete().getDropList(dropNode.fqn());
1102                            
1103                             // if there are not items in the tree.. the we have to set isOver to true for anything..
1104                          
1105                             if (_this.model.el.n_items < 1) {
1106                                 // FIXME check valid drop types?
1107                                 if (!drop_on_to.contains("*top")) {
1108                                                 GLib.debug("drop on to list does not contain top?");
1109                                                 return false;   
1110                                         }
1111                                         // add new node to top..
1112                                         
1113                                         
1114                                          var m = (GLib.ListStore) _this.model.el.model;
1115                                 _this.main_window.windowstate.file.tree = dropNode;  
1116                             
1117                            
1118                                         m.append(dropNode);
1119                                         _this.model.selectNode(dropNode);       
1120                                         _this.changed();
1121                                         return true; // no need to highlight?
1122                              
1123                             }
1124                         
1125                         
1126                         
1127                                 var row = _this.view.getRowAt(x,y, out pos);
1128                                 if (row < 0) {
1129                                         return   false; //Gdk.DragAction.COPY;
1130                                 }
1131                                 var tr = (Gtk.TreeListRow)_this.view.el.model.get_object(row);
1132                                 
1133                                 var node =  (JsRender.Node)tr.get_item();
1134                         
1135                                 if (pos == "above" || pos == "below") {
1136                                         if (node.parent == null) {
1137                                                 pos = "over";
1138                                         } else {
1139                                                 if (!drop_on_to.contains(node.parent.fqn())) {
1140                                                         pos = "over";
1141                                                 } else {
1142                                                         GLib.debug("drop  contains %s - using %s" , node.parent.fqn(), pos);
1143                                                         if (_this.view.dragNode  != null && is_shift) {
1144                                                                 if (node.parent.oid == _this.view.dragNode.oid || node.parent.has_parent(_this.view.dragNode)) {
1145                                                                         GLib.debug("shift drop not self not allowed");
1146                                                                         return false;   
1147                                                                 }
1148                                                                 
1149                                                         }
1150                                                         
1151                                                         
1152                                                 }
1153                                         }
1154                                         
1155                                 }
1156                                 if (pos == "over") {
1157                                         if (!drop_on_to.contains(node.fqn())) {
1158                                                 GLib.debug("drop on does not contain %s - try center" , node.fqn());
1159                                                 return false;
1160                         
1161                                         }
1162                                         if (node.oid == _this.view.dragNode.oid || node.has_parent(_this.view.dragNode)) {
1163                                                 GLib.debug("shift drop not self not allowed");
1164                                                 return false;   
1165                                         }
1166                                 }
1167                                 
1168                                 switch(pos) {
1169                                         case "over":
1170                                                 node.appendChild(dropNode);
1171                                                 if (is_shift && _this.view.dragNode != null) {
1172                                                         _this.model.selectNode(null); 
1173                                                         _this.view.dragNode.remove();
1174                                                 }
1175                                                         
1176                                                 
1177                                                 _this.model.selectNode(dropNode); 
1178                                                 
1179                                                 _this.changed();                                                
1180                                                 return true;
1181                                                 
1182                                         case "above":
1183                                                 GLib.debug("Above - insertBefore");
1184                                         
1185                                                 node.parent.insertBefore(dropNode, node);
1186                                                 if (is_shift && _this.view.dragNode != null) {
1187                                                         _this.model.selectNode(null);                   
1188                                                         _this.view.dragNode.remove();
1189                                                 }
1190                                 
1191                                                 _this.model.selectNode(dropNode);                       
1192                                                 _this.changed();
1193                                                 return true;
1194                                                 
1195                                         case "below":
1196                                                 GLib.debug("Below - insertAfter");              
1197                                                 if (is_shift && _this.view.dragNode != null) {
1198                                                         _this.model.selectNode(null);                   
1199                                                         _this.view.dragNode.remove();
1200                                                 }
1201                                 
1202                                                 
1203                                                 node.parent.insertAfter(dropNode, node);
1204                                                 _this.model.selectNode(dropNode);       
1205                                                 _this.changed();
1206                                                 // select it
1207                                                 return true;
1208                                                 
1209                                         default:
1210                                                 // should not happen
1211                                                 return false;
1212                                 }
1213                                 
1214                                 
1215                              
1216                                         
1217                                         
1218                         
1219                         });
1220                 }
1221
1222                 // user defined functions
1223                 public void addHighlight (Gtk.Widget? w, string hl) {
1224                         if (this.highlightWidget != null) {
1225                                 var ww  = this.highlightWidget;
1226                                 GLib.debug("clear drag from previous highlight");
1227                                 if (ww.has_css_class("drag-below")) {
1228                                          ww.remove_css_class("drag-below");
1229                                 }
1230                                 if (ww.has_css_class("drag-above")) {
1231                                          ww.remove_css_class("drag-above");
1232                                 }
1233                                 if (ww.has_css_class("drag-over")) {
1234                                          ww.remove_css_class("drag-over");
1235                                 }
1236                         }
1237                         if (w != null) {
1238                                 GLib.debug("add drag=%s to widget", hl);        
1239                                 if (!w.has_css_class("drag-" + hl)) {
1240                                         w.add_css_class("drag-" + hl);
1241                                 }
1242                         }
1243                         this.highlightWidget = w;
1244                 }
1245         }
1246
1247         public class Xcls_selmodel : Object
1248         {
1249                 public Gtk.SingleSelection el;
1250                 private Xcls_WindowLeftTree  _this;
1251
1252
1253                         // my vars (def)
1254
1255                 // ctor
1256                 public Xcls_selmodel(Xcls_WindowLeftTree _owner )
1257                 {
1258                         _this = _owner;
1259                         _this.selmodel = this;
1260                         new Xcls_model( _this );
1261                         this.el = new Gtk.SingleSelection( _this.model.el );
1262
1263                         // my vars (dec)
1264
1265                         // set gobject values
1266
1267                         //listeners
1268                         this.el.selection_changed.connect( (position, n_items) => {
1269                         
1270                                 
1271                                         
1272                                         //if (!this.button_is_pressed && !this.key_is_pressed) {
1273                                                 // then event was started by some other action
1274                                                 // which should manually trigger all the events..
1275                                         //      print("SKIPPING select - no button or key pressed\n");
1276                                         //      return;
1277                                         //}
1278                         
1279                         
1280                                          if (_this.view.blockChanges) { // probably not needed.. 
1281                                                 GLib.debug("SKIPPING select - blockchanges set..");     
1282                                            return  ;
1283                                          }
1284                         
1285                                           if (!_this.before_node_change( ) ) {
1286                                                  _this.view.blockChanges = true;
1287                                                  _this.selmodel.el.unselect_all();
1288                                                  _this.view.blockChanges = false;
1289                                                  
1290                                                  return;
1291                                          }
1292                                          if (_this.main_window.windowstate.file == null) {
1293                                                 GLib.debug("SKIPPING select windowstate file is not set...");     
1294                                                 return;
1295                                          } 
1296                                          
1297                                          //var render = this.get('/LeftTree').getRenderer();                
1298                                         GLib.debug("LEFT TREE -> view -> selection changed called");
1299                                         
1300                                         
1301                                         // -- it appears that the selection is not updated.
1302                                          // select the node...
1303                                          //_this.selmodel.el.set_selected(row);
1304                          
1305                                          GLib.debug("LEFT TREE -> view -> selection changed TIMEOUT CALLED");
1306                         
1307                                     var snode = _this.selmodel.getSelectedNode();
1308                                     if (snode == null) {
1309                         
1310                                          GLib.debug("selected rows < 1");
1311                                         //??this.model.load( false);
1312                                         _this.node_selected(null);
1313                                         
1314                                         return   ;
1315                                     }
1316                                  
1317                                     // why dup_?
1318                                     
1319                         
1320                                     GLib.debug ("calling left_tree.node_selected");
1321                                     _this.node_selected(snode);
1322                                    
1323                                      
1324                                     
1325                                      
1326                                     // no need to scroll. it's in the view as we clicked on it.
1327                                    // _this.view.el.scroll_to_cell(new Gtk.TreePath.from_string(_this.model.activePath), null, true, 0.1f,0.0f);
1328                                     
1329                                     return  ;
1330                         });
1331                 }
1332
1333                 // user defined functions
1334                 public JsRender.Node? getSelectedNode () {
1335                   if (this.el.selected_item == null) {
1336                                 return null;
1337                   }                             
1338                    var tr = (Gtk.TreeListRow)this.el.selected_item;
1339                    return (JsRender.Node)tr.get_item();
1340                          
1341                 }
1342                 public JsRender.Node getNodeAt (uint row) {
1343                 
1344                    var tr = (Gtk.TreeListRow)this.el.get_item(row);
1345                    
1346                    var a = tr.get_item();;   
1347                    GLib.debug("get_item (2) = %s", a.get_type().name());
1348                         
1349                    
1350                    return (JsRender.Node)tr.get_item();
1351                          
1352                 }
1353         }
1354         public class Xcls_model : Object
1355         {
1356                 public Gtk.TreeListModel el;
1357                 private Xcls_WindowLeftTree  _this;
1358
1359
1360                         // my vars (def)
1361
1362                 // ctor
1363                 public Xcls_model(Xcls_WindowLeftTree _owner )
1364                 {
1365                         _this = _owner;
1366                         _this.model = this;
1367                         this.el = this.updateModel(null);
1368
1369                         // my vars (dec)
1370
1371                         // set gobject values
1372                 }
1373
1374                 // user defined functions
1375                 public void loadFile (JsRender.JsRender f) {
1376                     //console.dump(f);
1377                     
1378                     _this.drop.highlightWidget = null;
1379                     
1380                     var m = (GLib.ListStore) this.el.model;
1381                         m.remove_all();
1382                     _this.main_window.windowstate.leftTreeNodeSelected(null);
1383                     // needed???
1384                     _this.main_window.windowstate.file = f;
1385                     
1386                    
1387                     if (f.tree == null) {
1388                             try {
1389                                 f.loadItems( );
1390                         } catch (Error e) {
1391                                 return;
1392                         }
1393                     }
1394                     // if it's still null?
1395                     if (f.tree == null) {
1396                                 _this.main_window.windowstate.showAddObject(_this.view.el, null);
1397                     
1398                         return;
1399                     }
1400                         m.append(f.tree);
1401                         
1402                         // expand???
1403                 
1404                 /*
1405                     if (f.tree.readItems().size < 1) {
1406                         // single item..
1407                         
1408                         //this.get('/Window.leftvpaned').el.set_position(80);
1409                         // select first...
1410                         _this.view.el.set_cursor( 
1411                             new  Gtk.TreePath.from_string("0"), null, false);
1412                         
1413                         
1414                     } else {
1415                           //this.get('/Window.leftvpaned').el.set_position(200);
1416                     }
1417                   */  
1418                     
1419                     
1420                 
1421                     //_this.maincol.el.set_max_width(_this.viewwin.el.get_allocated_width() - 32);
1422                  
1423                     _this.selmodel.el.set_selected(Gtk.INVALID_LIST_POSITION);
1424                    _this.updateErrors();
1425                     return;
1426                  
1427                             
1428                 }
1429                 public void deleteSelected () {
1430                 
1431                 
1432                         
1433                         var node = _this.selmodel.getSelectedNode();
1434                         
1435                 
1436                      if (node == null) {
1437                         GLib.debug("delete Selected - no node slected?");
1438                              return;
1439                      }
1440                     _this.selmodel.el.unselect_all();
1441                     
1442                     node.remove();
1443                         GLib.debug("delete Selected - done");
1444                     _this.changed();
1445                 /*    
1446                     print("DELETE SELECTED?");
1447                     //_this.view.blockChanges = true;
1448                     print("GET SELECTION?");
1449                 
1450                     var s = _this.view.el.get_selection();
1451                     
1452                     print("GET  SELECTED?");
1453                    Gtk.TreeIter iter;
1454                     Gtk.TreeModel mod;
1455                 
1456                     
1457                     if (!s.get_selected(out mod, out iter)) {
1458                         return; // nothing seleted..
1459                     }
1460                       
1461                 
1462                 
1463                     this.activePath= "";      
1464                     print("GET  vnode value?");
1465                 
1466                     GLib.Value value;
1467                     this.el.get_value(iter, 2, out value);
1468                     var data = (JsRender.Node)(value.get_object());
1469                     print("removing node from Render\n");
1470                     if (data.parent == null) {
1471                        _this.main_window.windowstate.file.tree = null;
1472                     } else {
1473                         data.remove();
1474                     }
1475                     print("removing node from Tree\n");    
1476                     s.unselect_all();
1477                     this.el.remove(ref iter);
1478                 
1479                     
1480                     
1481                     
1482                     // 
1483                     
1484                     
1485                 
1486                 
1487                     this.activePath= ""; // again!?!?      
1488                     //this.changed(null,true);
1489                     
1490                     _this.changed();
1491                     
1492                     _this.view.blockChanges = false;
1493                     */
1494                 }
1495                 public Gtk.TreeListModel updateModel (GLib.ListStore? m) {
1496                         this.el = new Gtk.TreeListModel(
1497                                 m != null ? m : new GLib.ListStore(typeof(JsRender.Node)), //..... << that's our store..
1498                                 false, // passthru
1499                                 true, // autexpand
1500                                 (item) => {
1501                                         return ((JsRender.Node)item).childstore;
1502                                 
1503                                 }
1504                         );
1505                         if (_this.selmodel.el == null) {
1506                                 return this.el;
1507                         }
1508                         _this.selmodel.el.set_model(this.el);
1509                         return this.el;
1510                 }
1511                 public void selectNode (JsRender.Node node) 
1512                 {
1513                         var row = -1;
1514                         var s = (Gtk.SingleSelection)_this.view.el.model;
1515                         for (var i = 0; i < s.n_items; i++) {
1516                                 //GLib.debug("check node %s", s.get_item(i).get_type().name());
1517                                 var lr = (Gtk.TreeListRow)s.get_item(i);
1518                                 GLib.debug("check node %s", lr.get_item().get_type().name());
1519                                 if (((JsRender.Node)lr.get_item()).oid == node.oid) {
1520                                         row  = i;
1521                                         break;
1522                                 }
1523                         }
1524                         if (row < 0) {
1525                                 // select none?
1526                                 GLib.debug("Could not find node");
1527                                 return;
1528                         }
1529                         GLib.debug("Select %d", row);
1530                         s.set_selected(row);
1531                         _this.view.el.scroll_to(row, null, Gtk.ListScrollFlags.SELECT, null);
1532                         //_this.node_selected(node);                    
1533                         
1534                 
1535                 }
1536         }
1537
1538
1539         public class Xcls_maincol : Object
1540         {
1541                 public Gtk.ColumnViewColumn el;
1542                 private Xcls_WindowLeftTree  _this;
1543
1544
1545                         // my vars (def)
1546
1547                 // ctor
1548                 public Xcls_maincol(Xcls_WindowLeftTree _owner )
1549                 {
1550                         _this = _owner;
1551                         _this.maincol = this;
1552                         var child_1 = new Xcls_SignalListItemFactory14( _this );
1553                         child_1.ref();
1554                         this.el = new Gtk.ColumnViewColumn( "Property", child_1.el );
1555
1556                         // my vars (dec)
1557
1558                         // set gobject values
1559                         this.el.id = "maincol";
1560                         this.el.expand = true;
1561                         this.el.resizable = true;
1562                 }
1563
1564                 // user defined functions
1565         }
1566         public class Xcls_SignalListItemFactory14 : Object
1567         {
1568                 public Gtk.SignalListItemFactory el;
1569                 private Xcls_WindowLeftTree  _this;
1570
1571
1572                         // my vars (def)
1573
1574                 // ctor
1575                 public Xcls_SignalListItemFactory14(Xcls_WindowLeftTree _owner )
1576                 {
1577                         _this = _owner;
1578                         this.el = new Gtk.SignalListItemFactory();
1579
1580                         // my vars (dec)
1581
1582                         // set gobject values
1583
1584                         //listeners
1585                         this.el.setup.connect( (listitem) => {
1586                                 
1587                                 var expand = new Gtk.TreeExpander();
1588                                  
1589                                 expand.set_indent_for_depth(true);
1590                                 expand.set_indent_for_icon(true);
1591                                 var hbox = new Gtk.Box(Gtk.Orientation.HORIZONTAL,0);
1592                                 var icon = new Gtk.Image();
1593                                 var lbl = new Gtk.Label("");
1594                                 lbl.use_markup = true;
1595                                 lbl.ellipsize = Pango.EllipsizeMode.END;
1596                                 
1597                                 icon.margin_end = 4;
1598                                 lbl.justify = Gtk.Justification.LEFT;
1599                                 lbl.xalign = 0;
1600                         
1601                         //      listitem.activatable = true; ??
1602                                 
1603                                 hbox.append(icon);
1604                                 hbox.append(lbl);
1605                                 expand.set_child(hbox);
1606                                 ((Gtk.ListItem)listitem).set_child(expand);
1607                                 
1608                         });
1609                         this.el.bind.connect( (listitem) => {
1610                                  GLib.debug("listitme is is %s", ((Gtk.ListItem)listitem).get_type().name());
1611                                 
1612                                 //var expand = (Gtk.TreeExpander) ((Gtk.ListItem)listitem).get_child();
1613                                 var expand = (Gtk.TreeExpander)  ((Gtk.ListItem)listitem).get_child();
1614                                  
1615                                  
1616                                 var hbox = (Gtk.Box) expand.child;
1617                          
1618                                 
1619                                 var img = (Gtk.Image) hbox.get_first_child();
1620                                 var lbl = (Gtk.Label) img.get_next_sibling();
1621                                 
1622                                 var lr = (Gtk.TreeListRow)((Gtk.ListItem)listitem).get_item();
1623                                 var node = (JsRender.Node) lr.get_item();
1624                                 
1625                            GLib.debug("node is %s", node.get_type().name());
1626                         // was item (1) in old layout
1627                         
1628                                 
1629                          
1630                                  /* 
1631                                 var ic = Gtk.IconTheme.get_for_display(_this.el.get_display());
1632                             var clsname = node.fqn();
1633                             
1634                             var clsb = clsname.split(".");
1635                             var sub = clsb.length > 1 ? clsb[1].down()  : "";
1636                              
1637                             var fn = "/usr/share/glade/pixmaps/hicolor/16x16/actions/widget-gtk-" + sub + ".png";
1638                             try { 
1639                                  
1640                                          
1641                                         if (FileUtils.test (fn, FileTest.IS_REGULAR)) {
1642                                             img.set_from_file(fn);
1643                                                  
1644                                         } else {
1645                                                 img.set_from_paintable(
1646                                                         ic.lookup_icon (
1647                                                                 "media-playback-stop", null,  16,1, 
1648                                                          Gtk.TextDirection.NONE, 0
1649                                                 )
1650                                                  );
1651                                         }
1652                                 } catch (GLib.Error e) {}
1653                             */
1654                             expand.set_hide_expander( !node.hasChildren() );
1655                                 expand.set_list_row(lr);
1656                                 
1657                                 node.bind_property("iconFilename",
1658                                             img, "file",
1659                                            GLib.BindingFlags.SYNC_CREATE);
1660                                 
1661                                 node.bind_property("nodeTitleProp",
1662                                             lbl, "label",
1663                                            GLib.BindingFlags.SYNC_CREATE);
1664                                 node.bind_property("nodeTipProp",
1665                                             lbl, "tooltip_markup",
1666                                            GLib.BindingFlags.SYNC_CREATE);
1667                                 // bind image...
1668                                 
1669                         });
1670                 }
1671
1672                 // user defined functions
1673         }
1674
1675
1676         public class Xcls_ColumnViewColumn15 : Object
1677         {
1678                 public Gtk.ColumnViewColumn el;
1679                 private Xcls_WindowLeftTree  _this;
1680
1681
1682                         // my vars (def)
1683
1684                 // ctor
1685                 public Xcls_ColumnViewColumn15(Xcls_WindowLeftTree _owner )
1686                 {
1687                         _this = _owner;
1688                         var child_1 = new Xcls_SignalListItemFactory16( _this );
1689                         child_1.ref();
1690                         this.el = new Gtk.ColumnViewColumn( "Add", child_1.el );
1691
1692                         // my vars (dec)
1693
1694                         // set gobject values
1695                         this.el.fixed_width = 25;
1696                 }
1697
1698                 // user defined functions
1699         }
1700         public class Xcls_SignalListItemFactory16 : Object
1701         {
1702                 public Gtk.SignalListItemFactory el;
1703                 private Xcls_WindowLeftTree  _this;
1704
1705
1706                         // my vars (def)
1707
1708                 // ctor
1709                 public Xcls_SignalListItemFactory16(Xcls_WindowLeftTree _owner )
1710                 {
1711                         _this = _owner;
1712                         this.el = new Gtk.SignalListItemFactory();
1713
1714                         // my vars (dec)
1715
1716                         // set gobject values
1717
1718                         //listeners
1719                         this.el.setup.connect( (listitem) => {
1720                         
1721                                  
1722                                 var icon = new Gtk.Image();
1723                                  
1724                                 ((Gtk.ListItem)listitem).set_child(icon);
1725                         });
1726                         this.el.bind.connect( (listitem) => {
1727                         
1728                                 var img = (Gtk.Image) ((Gtk.ListItem)listitem).get_child(); 
1729                                 var lr = (Gtk.TreeListRow)((Gtk.ListItem)listitem).get_item();
1730                                 var node = (JsRender.Node) lr.get_item();
1731                                 
1732                           
1733                             var ic = Gtk.IconTheme.get_for_display(_this.el.get_display());
1734                                 img.set_from_paintable(
1735                                         ic.lookup_icon (
1736                                                 "list-add", null,  16,1, 
1737                                                  Gtk.TextDirection.NONE, 0
1738                                         )
1739                                  );
1740                                  
1741                                 var fqn = node.fqn();
1742                             var cn = _this.main_window.windowstate.project.palete.getChildList(fqn, false);
1743                         
1744                                 img.set_visible(cn.size > 0 ? true : false);
1745                                  
1746                         });
1747                 }
1748
1749                 // user defined functions
1750         }
1751
1752
1753         public class Xcls_keystate : Object
1754         {
1755                 public Gtk.EventControllerKey el;
1756                 private Xcls_WindowLeftTree  _this;
1757
1758
1759                         // my vars (def)
1760                 public int is_shift;
1761
1762                 // ctor
1763                 public Xcls_keystate(Xcls_WindowLeftTree _owner )
1764                 {
1765                         _this = _owner;
1766                         _this.keystate = this;
1767                         this.el = new Gtk.EventControllerKey();
1768
1769                         // my vars (dec)
1770                         this.is_shift = 0;
1771
1772                         // set gobject values
1773
1774                         //listeners
1775                         this.el.key_released.connect( (keyval, keycode, state) => {
1776                                 GLib.debug("key release %d, %d, %d" , (int) keyval, (int)  keycode, state);
1777                                 if (keyval == Gdk.Key.Shift_L || keyval == Gdk.Key.Shift_R) {
1778                                         this.is_shift = 0;
1779                                 }
1780                                 //GLib.debug("set state %d , shift = %d", (int)this.el.get_current_event_state(), Gdk.ModifierType.SHIFT_MASK);
1781                         
1782                         
1783                          
1784                         });
1785                         this.el.key_pressed.connect( (keyval, keycode, state) => {
1786                         
1787                                 if (keyval == Gdk.Key.Shift_L || keyval == Gdk.Key.Shift_R) {
1788                                         this.is_shift = 1;
1789                                 }
1790                                 return true;
1791                         });
1792                 }
1793
1794                 // user defined functions
1795         }
1796
1797
1798         public class Xcls_LeftTreeMenu : Object
1799         {
1800                 public Gtk.Popover el;
1801                 private Xcls_WindowLeftTree  _this;
1802
1803
1804                         // my vars (def)
1805
1806                 // ctor
1807                 public Xcls_LeftTreeMenu(Xcls_WindowLeftTree _owner )
1808                 {
1809                         _this = _owner;
1810                         _this.LeftTreeMenu = this;
1811                         this.el = new Gtk.Popover();
1812
1813                         // my vars (dec)
1814
1815                         // set gobject values
1816                         var child_1 = new Xcls_Box19( _this );
1817                         this.el.child = child_1.el;
1818                 }
1819
1820                 // user defined functions
1821         }
1822         public class Xcls_Box19 : Object
1823         {
1824                 public Gtk.Box el;
1825                 private Xcls_WindowLeftTree  _this;
1826
1827
1828                         // my vars (def)
1829
1830                 // ctor
1831                 public Xcls_Box19(Xcls_WindowLeftTree _owner )
1832                 {
1833                         _this = _owner;
1834                         this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
1835
1836                         // my vars (dec)
1837
1838                         // set gobject values
1839                         var child_1 = new Xcls_Button20( _this );
1840                         child_1.ref();
1841                         this.el.append( child_1.el );
1842                         var child_2 = new Xcls_Button21( _this );
1843                         child_2.ref();
1844                         this.el.append( child_2.el );
1845                         var child_3 = new Xcls_Button22( _this );
1846                         child_3.ref();
1847                         this.el.append( child_3.el );
1848                 }
1849
1850                 // user defined functions
1851         }
1852         public class Xcls_Button20 : Object
1853         {
1854                 public Gtk.Button el;
1855                 private Xcls_WindowLeftTree  _this;
1856
1857
1858                         // my vars (def)
1859
1860                 // ctor
1861                 public Xcls_Button20(Xcls_WindowLeftTree _owner )
1862                 {
1863                         _this = _owner;
1864                         this.el = new Gtk.Button();
1865
1866                         // my vars (dec)
1867
1868                         // set gobject values
1869                         this.el.label = "Delete Element";
1870
1871                         //listeners
1872                         this.el.clicked.connect( ( ) => {
1873                         _this.LeftTreeMenu.el.hide();
1874                          _this.model.deleteSelected();
1875                         _this.changed();
1876                         });
1877                 }
1878
1879                 // user defined functions
1880         }
1881
1882         public class Xcls_Button21 : Object
1883         {
1884                 public Gtk.Button el;
1885                 private Xcls_WindowLeftTree  _this;
1886
1887
1888                         // my vars (def)
1889
1890                 // ctor
1891                 public Xcls_Button21(Xcls_WindowLeftTree _owner )
1892                 {
1893                         _this = _owner;
1894                         this.el = new Gtk.Button();
1895
1896                         // my vars (dec)
1897
1898                         // set gobject values
1899                         this.el.label = "Save as Template";
1900
1901                         //listeners
1902                         this.el.clicked.connect( () => {
1903                         _this.LeftTreeMenu.el.hide();
1904                              DialogSaveTemplate.singleton().showIt(
1905                                     (Gtk.Window) _this.el.get_root (), 
1906                                     _this.main_window.windowstate.file.palete(), 
1907                                     _this.getActiveElement()
1908                             );
1909                              
1910                             
1911                         });
1912                 }
1913
1914                 // user defined functions
1915         }
1916
1917         public class Xcls_Button22 : Object
1918         {
1919                 public Gtk.Button el;
1920                 private Xcls_WindowLeftTree  _this;
1921
1922
1923                         // my vars (def)
1924
1925                 // ctor
1926                 public Xcls_Button22(Xcls_WindowLeftTree _owner )
1927                 {
1928                         _this = _owner;
1929                         this.el = new Gtk.Button();
1930
1931                         // my vars (dec)
1932
1933                         // set gobject values
1934                         this.el.label = "Save as Module";
1935
1936                         //listeners
1937                         this.el.clicked.connect( () => {
1938                             
1939                             _this.LeftTreeMenu.el.hide();
1940                             var node = _this.getActiveElement();
1941                               
1942                              
1943                              var sm = DialogSaveModule.singleton();
1944                              
1945                              
1946                             sm.showIt(
1947                                     (Gtk.Window) _this.el.get_root (), 
1948                                     _this.main_window.windowstate.project, 
1949                                     node
1950                              );
1951                              /*
1952                              gtk4 migration - disabled this part.. probably not used muchanyway
1953                              
1954                              
1955                              if (name.length < 1) {
1956                                     return;
1957                           
1958                              }
1959                              node.set_prop( new JsRender.NodeProp.special("xinclude", name));
1960                              node.items.clear();
1961                         
1962                         
1963                             var s = _this.view.el.get_selection();
1964                             
1965                             print("GET  SELECTED?");
1966                             Gtk.TreeIter iter;
1967                             Gtk.TreeModel mod;
1968                         
1969                             
1970                             if (!s.get_selected(out mod, out iter)) {
1971                                 return; // nothing seleted..
1972                             }
1973                             Gtk.TreeIter citer;
1974                             var n_cn = mod.iter_n_children(iter) -1;
1975                             for (var i = n_cn; i > -1; i--) {
1976                                 mod.iter_nth_child(out citer, iter, i);
1977                                 
1978                         
1979                                 print("removing node from Tree\n");    
1980                             
1981                                 _this.model.el.remove(ref citer);
1982                             }
1983                             _this.changed();
1984                             _this.node_selected(node, "tree");
1985                              */
1986                             
1987                         });
1988                 }
1989
1990                 // user defined functions
1991         }
1992
1993
1994
1995
1996 }