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