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