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