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