Fix #7238 - remove clutter and change layout of interface
[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_view view;
16     public Xcls_model model;
17     public Xcls_renderer renderer;
18     public Xcls_LeftTreeMenu LeftTreeMenu;
19
20         // my vars (def)
21     public signal bool before_node_change ();
22     public signal void changed ();
23     public signal void node_selected (JsRender.Node? node, string source);
24     public Xcls_MainWindow main_window;
25
26     // ctor
27     public Xcls_WindowLeftTree()
28     {
29         _this = this;
30         this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
31
32         // my vars (dec)
33         this.main_window = null;
34
35         // set gobject values
36         var child_0 = new Xcls_Button2( _this );
37         child_0.ref();
38         this.el.add (  child_0.el  );
39         var child_1 = new Xcls_ScrolledWindow4( _this );
40         child_1.ref();
41         this.el.add (  child_1.el  );
42     }
43
44     // user defined functions
45     public           JsRender.Node? getActiveElement () { // return path to actie node.
46     
47          var path = this.getActivePath();
48          if (path.length < 1) {
49             return null;
50          }
51          return _this.model.pathToNode(path);
52          
53     }
54     public           JsRender.JsRender getActiveFile () {
55         return this.main_window.windowstate.file;
56     }
57     public           string getActivePath () {
58         
59         var view = this.view.el;
60         if (view.get_selection().count_selected_rows() < 1) {
61             return "";
62         }
63         Gtk.TreeIter iter;
64         Gtk.TreeModel mod;
65         view.get_selection().get_selected(out mod, out iter);
66         return mod.get_path(iter).to_string();
67     }
68     public class Xcls_Button2 : Object
69     {
70         public Gtk.Button el;
71         private Xcls_WindowLeftTree  _this;
72
73
74             // my vars (def)
75
76         // ctor
77         public Xcls_Button2(Xcls_WindowLeftTree _owner )
78         {
79             _this = _owner;
80             this.el = new Gtk.Button();
81
82             // my vars (dec)
83
84             // set gobject values
85             this.el.hexpand = true;
86             this.el.always_show_image = true;
87             this.el.label = "Add Child Element";
88             var child_0 = new Xcls_Image3( _this );
89             child_0.ref();
90             this.el.set_image (  child_0.el  );
91
92             //listeners
93             this.el.clicked.connect( ( ) => {
94                 
95             
96                 _this.main_window.windowstate.showAddObject(this.el);
97              
98             });
99         }
100
101         // user defined functions
102     }
103     public class Xcls_Image3 : Object
104     {
105         public Gtk.Image el;
106         private Xcls_WindowLeftTree  _this;
107
108
109             // my vars (def)
110
111         // ctor
112         public Xcls_Image3(Xcls_WindowLeftTree _owner )
113         {
114             _this = _owner;
115             this.el = new Gtk.Image();
116
117             // my vars (dec)
118
119             // set gobject values
120             this.el.icon_name = "list-add";
121         }
122
123         // user defined functions
124     }
125
126
127     public class Xcls_ScrolledWindow4 : Object
128     {
129         public Gtk.ScrolledWindow el;
130         private Xcls_WindowLeftTree  _this;
131
132
133             // my vars (def)
134
135         // ctor
136         public Xcls_ScrolledWindow4(Xcls_WindowLeftTree _owner )
137         {
138             _this = _owner;
139             this.el = new Gtk.ScrolledWindow( null, null );
140
141             // my vars (dec)
142
143             // set gobject values
144             this.el.shadow_type = Gtk.ShadowType.IN;
145             var child_0 = new Xcls_view( _this );
146             child_0.ref();
147             this.el.add (  child_0.el  );
148             var child_1 = new Xcls_LeftTreeMenu( _this );
149             child_1.ref();
150
151             // init method
152
153             this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
154         }
155
156         // user defined functions
157     }
158     public class Xcls_view : Object
159     {
160         public Gtk.TreeView el;
161         private Xcls_WindowLeftTree  _this;
162
163
164             // my vars (def)
165         public string dragData;
166         public int drag_x;
167         public string[] dropList;
168         public int drag_y;
169         public bool button_is_pressed;
170         public string lastEventSource;
171         public bool key_is_pressed;
172         public bool drag_in_motion;
173         public bool blockChanges;
174
175         // ctor
176         public Xcls_view(Xcls_WindowLeftTree _owner )
177         {
178             _this = _owner;
179             _this.view = this;
180             this.el = new Gtk.TreeView();
181
182             // my vars (dec)
183             this.button_is_pressed = false;
184             this.lastEventSource = "";
185             this.key_is_pressed = false;
186             this.blockChanges = false;
187
188             // set gobject values
189             this.el.expand = true;
190             this.el.tooltip_column = 1;
191             this.el.enable_tree_lines = true;
192             this.el.headers_visible = false;
193             var child_0 = new Xcls_model( _this );
194             child_0.ref();
195             this.el.set_model (  child_0.el  );
196             var child_1 = new Xcls_TreeViewColumn7( _this );
197             child_1.ref();
198             this.el.append_column (  child_1.el  );
199
200             // init method
201
202             {
203                 var description = new Pango.FontDescription();
204                 description.set_size(8000);
205                 this.el.override_font(description);
206             
207                 var selection = this.el.get_selection();
208                 selection.set_mode( Gtk.SelectionMode.SINGLE);
209             
210             
211                 // is this really needed??
212                 /*
213                 this.selection.signal['changed'].connect(function() {
214                     _this.get('/LeftTree.view').listeners.cursor_changed.apply(
215                         _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
216                     );
217                 });
218                 */
219                 Gtk.drag_source_set (
220                     this.el,            /* widget will be drag-able */
221                     Gdk.ModifierType.BUTTON1_MASK,       /* modifier that will start a drag */
222                     BuilderApplication.targetList,            /* lists of target to support */
223                     Gdk.DragAction.COPY   | Gdk.DragAction.MOVE    |  Gdk.DragAction.LINK           /* what to do with data after dropped */
224                 );
225             
226                 // ?? needed??
227                 //Gtk.drag_source_add_text_targets(this.el); 
228             
229                 Gtk.drag_dest_set
230                 (
231                     this.el,              /* widget that will accept a drop */
232                     Gtk.DestDefaults.MOTION  | Gtk.DestDefaults.HIGHLIGHT,
233                     BuilderApplication.targetList,            /* lists of target to support */
234                     Gdk.DragAction.COPY   | Gdk.DragAction.MOVE   | Gdk.DragAction.LINK     /* what to do with data after dropped */
235                 );
236             
237                 //Gtk.drag_dest_set_target_list(this.el, Builder.Application.targetList);
238                 //Gtk.drag_dest_add_text_targets(this.el);
239             }
240
241             //listeners
242             this.el.button_release_event.connect( (ev) => { 
243                 this.button_is_pressed = false;
244               return false;
245             });
246             this.el.button_press_event.connect( ( ev) => {
247                 //console.log("button press?");
248                 this.button_is_pressed = true;
249                 print("BUTTON DOWN\n");
250                 
251                 this.lastEventSource = "tree";
252                 if (! _this.before_node_change() ) {
253                 
254                    return true;
255                 }
256                 
257             
258                 
259                 if (ev.type != Gdk.EventType.BUTTON_PRESS  || ev.button != 3) {
260                     //print("click" + ev.type);
261                     return false;
262                 }
263                 Gtk.TreePath res;
264                 if (!_this.view.el.get_path_at_pos((int)ev.x,(int)ev.y, out res, null, null, null) ) {
265                     return true;
266                 }
267                  
268                 this.el.get_selection().select_path(res);
269                  
270                   //if (!this.get('/LeftTreeMenu').el)  { 
271                   //      this.get('/LeftTreeMenu').init(); 
272                   //  }
273                     
274                  _this.LeftTreeMenu.el.set_screen(Gdk.Screen.get_default());
275                  _this.LeftTreeMenu.el.show_all();
276                   _this.LeftTreeMenu.el.popup(null, null, null,  3, ev.time);
277                  //   print("click:" + res.path.to_string());
278                   return true;
279             });
280             this.el.cursor_changed.connect( ( ) => {
281                 print("LEFT TREE Cursor Changed\n");
282                 if (!this.button_is_pressed && !this.key_is_pressed) {
283                         // then event was started by some other action
284                         // which should manually trigger all the events..
285                         print("SKIPPING select - no button or key pressed\n");
286                         return;
287                 }
288             
289             
290                  if (this.blockChanges) { // probably not needed.. 
291                         print("SKIPPING select - blockchanges set..\n");     
292                    return  ;
293                  }
294                   if (!_this.before_node_change( ) ) {
295                      this.blockChanges = true;
296                      this.el.get_selection().unselect_all();
297                      this.blockChanges = false;
298                      
299                      return;
300                  }
301                  if (_this.main_window.windowstate.file == null) {
302                         print("SKIPPING select windowstate file is not set...\n");     
303                      return;
304                  } 
305                  
306                  //var render = this.get('/LeftTree').getRenderer();                
307                 print("LEFT TREE -> view -> selection changed called\n");
308                 
309                 
310                 // -- it appears that the selection is not updated.
311                   
312                 GLib.Timeout.add_full(GLib.Priority.DEFAULT,10 , () => {
313                      print("LEFT TREE -> view -> selection changed TIMEOUT CALLED\n");
314             
315                         if (this.el.get_selection().count_selected_rows() < 1) {
316             
317                             print("selected rows < 1\n");
318                             //??this.model.load( false);
319                             _this.node_selected(null, this.lastEventSource);
320                             
321                             return false ;
322                         }
323                             
324                             //console.log('changed');
325                         var s = this.el.get_selection();
326                          Gtk.TreeIter iter;
327                          Gtk.TreeModel mod;
328                         s.get_selected(out mod, out iter);
329                         
330                         
331                         // var val = "";
332                         GLib.Value value;
333                         _this.model.el.get_value(iter, 2, out value);
334                         _this.model.activePath = mod.get_path(iter).to_string();
335                         
336                         var node = (JsRender.Node)value.dup_object();
337                         print ("calling left_tree.node_selected\n");
338                         _this.node_selected(node, this.lastEventSource);
339                         while (Gtk.events_pending()) {
340                             Gtk.main_iteration();
341                        }
342                         var cp = mod.get_path(iter);
343                         Gtk.TreePath sp, ep;
344                         this.el.get_visible_range(out sp, out ep);
345                         // if sp is before cp then retuns 1.
346                         // if cp is before ep then retuns 1.
347                         if (cp.compare(sp) >= 0 && ep.compare(cp) >=1) {
348                             return false;
349                         }
350                         
351                          
352                         
353                         this.el.scroll_to_cell(new Gtk.TreePath.from_string(_this.model.activePath), null, true, 0.1f,0.0f);
354                         
355                         return false;
356                   });  
357                 //_this.after_node_change(node);
358             
359             //        _this.model.file.changed(node, "tree");
360                
361                 //Seed.print( value.get_string());
362                 return  ;
363                             
364             });
365             this.el.drag_begin.connect( ( ctx)  => {
366                 //print('SOURCE: drag-begin');
367                     
368                     
369                     //this.targetData = "";
370                     
371                     // find what is selected in our tree...
372                     
373                     var s = _this.view.el.get_selection();
374                     if (s.count_selected_rows() < 1) {
375                         return;
376                     }
377                     Gtk.TreeIter iter;
378                     Gtk.TreeModel mod;
379                     s.get_selected(out mod, out iter);
380             
381                     
382             
383                     // set some properties of the tree for use by the dropped element.
384                     GLib.Value value;
385                     _this.model.el.get_value(iter, 2, out value);
386                     var tp = mod.get_path(iter).to_string();
387                     var data = (JsRender.Node)(value.dup_object());
388                     var xname = data.fqn();
389                     print ("XNAME  IS " + xname+ "\n");
390                     this.dragData = tp;
391                     this.dropList = _this.main_window.windowstate.file.palete().getDropList(xname);
392                     
393                     print ("DROP LIST IS " + string.joinv(", ", this.dropList) + "\n");
394                     
395             
396                     // make the drag icon a picture of the node that was selected
397                 
398                     
399                 // by default returns the path..
400                    var path = _this.model.el.get_path(iter);
401             
402                      
403                     var pix = this.el.create_row_drag_icon ( path);
404                     
405                     Gtk.drag_set_icon_surface (ctx, pix) ;
406                     
407                     return;
408             });
409             this.el.drag_data_get.connect( ( drag_context, data, info, time) => {
410                         
411                         
412                              //print("drag-data-get");
413                              var s = this.el.get_selection();
414                              if (s.count_selected_rows() < 1) {
415                                     data.set_text("",0);     
416                                      print("return empty string - no selection..");
417                                     return;
418                                 }
419                              
420                              Gtk.TreeIter iter;
421                              Gtk.TreeModel mod;
422                              
423                              s.get_selected(out mod, out iter);
424                              
425                             
426                             
427                              GLib.Value value;
428                              _this.model.el.get_value(iter, 2, out value);
429                              var ndata = (JsRender.Node)(value.dup_object());
430                              
431                             
432                             
433                             var tp = mod.get_path(iter).to_string();
434                             // by default returns the path..
435                             
436                            if ( info != Gdk.Atom.intern("STRING",true) ) {
437                                 tp = ndata.toJsonString();
438                            }   
439                            
440                            //data.set_text(tp,tp.length);   
441                             
442                             data.set (data.get_target (), 8, (uchar[]) tp.to_utf8 ());
443                         
444                             
445                            //  print("return " + tp);
446                         });
447             this.el.drag_end.connect( (drag_context) => {
448                 //Seed.print('LEFT-TREE: drag-end');
449                     this.dragData = "";
450                     this.dropList = null;
451             //        this.targetData = "";
452                     this.highlightDropPath("",0);
453             //        return true;
454             });
455             this.el.drag_motion.connect( ( ctx, x, y, time)  => {
456                print("got drag motion\n");
457                 var src = Gtk.drag_get_source_widget(ctx);
458                this.drag_x = x;
459                this.drag_y = y;     
460             
461                if (src != this.el) {
462                
463              
464              
465                 // the point of this is to detect where an item could be dropped..
466                     print("requesting drag data\n");
467                    this.drag_in_motion = true;
468                    
469                         // request data that will be recieved by the recieve...              
470                     Gtk.drag_get_data
471                     (
472                             this.el,         // will receive 'drag-data-received' signal 
473                             ctx,        // represents the current state of the DnD 
474                             Gdk.Atom.intern("STRING",true),    // the target type we want 
475                             time            // time stamp 
476                     );
477                     return true;
478               }    
479             
480             
481               print("action: %d\n", ctx.get_actions());
482              //print("GETTING POS");
483                 var  targetData = "";
484             
485                 Gtk.TreePath path;
486                 Gtk.TreeViewDropPosition pos;
487                 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
488             
489                 // if there are not items in the tree.. the we have to set isOver to true for anything..
490                 var isEmpty = false;
491                 if (_this.model.el.iter_n_children(null) < 1) {
492                     print("got NO children?\n");
493                     isOver = true; //??? 
494                     isEmpty = true;
495                     pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
496                 }
497             
498             
499                 // ------------- a drag from self..
500             
501             
502                 //var action = Gdk.DragAction.COPY;
503                     // unless we are copying!!! ctl button..
504                 
505                 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
506                              Gdk.DragAction.COPY  : Gdk.DragAction.MOVE ;
507                             // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
508             
509             
510                 if (_this.model.el.iter_n_children(null) < 1) {
511                     // no children.. -- asume it's ok..
512                     
513                     targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
514                        
515                     this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);        
516                     Gdk.drag_status(ctx, action ,time);
517                     return true;
518                     
519                     // continue through to allow drop...
520             
521                 } 
522                     
523                     
524             
525                 
526                 
527                 //print("ISOVER? " + isOver);
528                 if (!isOver) {
529               
530                     Gdk.drag_status(ctx, 0 ,time);
531                      this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);                    
532                      return false;
533             
534                 }
535                         
536                 // drag node is parent of child..
537                 //console.log("SRC TREEPATH: " + src.treepath);
538                 //console.log("TARGET TREEPATH: " + data.path.to_string());
539                 
540                 // nned to check a  few here..
541                 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
542                 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
543                 //Gtk.TreeViewDropPosition.AFTER
544                 //Gtk.TreeViewDropPosition.BEFORE
545                 
546                 // locally dragged items to not really use the 
547                 var selection_text = this.dragData;
548                 
549                         
550                         
551                 if (selection_text == null || selection_text.length < 1) {
552                             //print("Error  - drag selection text returned NULL");
553                          Gdk.drag_status(ctx, 0 ,time);
554                         this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
555                          return false;
556                  }
557                                    
558                         
559                         // see if we are dragging into ourself?
560                 var target_path = path.to_string();            
561                 print ("Drag  %s onto %s--%d\n ", selection_text, target_path, pos);
562                 
563                 // pos : 3 = ontop - 0 = after, 1 = before
564                 //print("target_path="+target_path);
565             
566                 // 
567                 if (selection_text  == target_path) {
568                     print("self drag ?? == we should perhaps allow copy onto self..\n");
569                             
570                      Gdk.drag_status(ctx, 0 ,time);
571                       this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
572                       return false;
573             //                 -- fixme -- this is not really correct..
574             
575                 }
576                         
577                 // check that 
578                 //print("DUMPING DATA");
579                 //console.dump(data);
580                 // path, pos
581                 
582                 //print(data.path.to_string() +' => '+  data.pos);
583                 
584                 // dropList is a list of xtypes that this node could be dropped on.
585                 // it is set up when we start to drag..
586                 
587                 
588                 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
589                     
590                 print("targetDAta: " + targetData +"\n");
591                 
592                 if (targetData.length < 1) {
593                     //print("Can not find drop node path");
594                    
595                     Gdk.drag_status(ctx, 0, time);
596                     this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
597                     return false;
598                 }
599                 
600                 var td_ar = targetData.split("|");
601                   
602                 
603             
604                 Gdk.drag_status(ctx, action ,time);
605                 this.highlightDropPath(td_ar[0], (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
606                 return true;
607                    
608                    
609             });
610             this.el.key_press_event.connect( (ev) => {
611                this.key_is_pressed = true;
612                 return false;
613             });
614             this.el.key_release_event.connect( (ev) => {
615                    this.key_is_pressed = false;
616                   return false;
617             });
618             this.el.drag_data_received.connect( (ctx, x, y, sel, info, time)  => {
619               
620                     // THIS CODE ONLY RELATES TO drag  or drop of "NEW" elements or "FROM another tree.."
621               
622               
623                     //  print("Tree: drag-data-received\n");
624                     var selection_text = (string)sel.get_data();
625                     //print("selection_text= %s\n",selection_text);
626             
627                     var is_drag = this.drag_in_motion;
628                 
629                     
630             
631                         GLib.debug("Is Drag %s\n", is_drag ? "Y": "N");
632                     var  targetData = "";
633                     
634                     Gtk.TreePath path;
635                     Gtk.TreeViewDropPosition pos;
636                     var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
637                     
638                     // if there are not items in the tree.. the we have to set isOver to true for anything..
639                     var isEmpty = false;
640                     if (_this.model.el.iter_n_children(null) < 1) {
641                         GLib.debug("got NO children?\n");
642                         isOver = true; //??? 
643                         isEmpty = true;
644                         pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
645                     }
646                     
647                  
648                     //console.log("LEFT-TREE: drag-motion");
649                     var src = Gtk.drag_get_source_widget(ctx);
650                     
651                     // a drag from self - this should be handled by drop and motion.
652                     if (src == this.el) {
653                         GLib.debug("Source == this element should not happen.. ? \n");
654                         return;
655                     }
656                     //print("drag_data_recieved from another element");
657                     
658                      
659                     
660                     
661                     if (selection_text == null || selection_text.length < 1 || !isOver) {
662                         // nothing valid foudn to drop...
663                            GLib.debug("empty sel text or not over");
664                         if (is_drag) {
665                             Gdk.drag_status(ctx, 0, time);
666                             this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
667                             return;
668                         }
669                         Gtk.drag_finish (ctx, false, false, time);        // drop failed..
670                         // no drop action...
671                         return;            
672                     
673                     }
674                     var dropNode = new JsRender.Node(); 
675                     
676                     var dropNodeType  = selection_text;
677                     var show_templates = true;
678                     // for drop
679                     if (dropNodeType[0] == '{') {
680                         var pa = new Json.Parser();
681                         try {
682                             pa.load_from_data(dropNodeType);
683                         } catch (Error e) {
684                             Gtk.drag_finish (ctx, false, false, time);        // drop failed..
685                             // no drop action...
686                             return;   
687                         }
688                          
689                         dropNode.loadFromJson( pa.get_root().get_object(), 2);
690                         dropNodeType = dropNode.fqn();
691                         show_templates = false;
692                         
693                         
694                     } else {
695                         if (selection_text.contains(":")) {
696                                 var bits = selection_text.split(":");
697                             dropNode.setFqn(bits[0]);
698                             dropNode.props.set("* prop", bits[1]);
699                         } else {
700             
701                             dropNode.setFqn(selection_text);
702                         }
703                     }
704             
705                      
706                     // dropList --- need to gather this ... 
707                     GLib.debug("get dropList for : %s\n",dropNodeType);            
708                     var dropList = _this.main_window.windowstate.file.palete().getDropList(dropNodeType);
709                     
710                     GLib.debug("dropList: %s\n", string.joinv(" , ", dropList));
711                     
712                     // if drag action is link ... then we can drop it anywahere...
713                      if ((ctx.get_actions() & Gdk.DragAction.LINK) > 0) {
714                          // if path is null?? dragging into an empty tree?
715                          targetData = (path == null ? "" :  path.to_string()) + "|%d".printf((int)pos);
716                      } else {
717                     
718                     
719                         targetData = _this.model.findDropNodeByPath( isEmpty ? "" : path.to_string(), dropList, pos);
720                      }
721                     
722                     
723                         
724                     GLib.debug("targetDAta: %s", targetData );
725                     
726                     if (targetData.length < 1) {
727                      
728                         // invalid drop path..
729                         if (this.drag_in_motion) {
730                             Gdk.drag_status(ctx, 0, time);
731                             this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
732                             return;
733                         }
734                         Gtk.drag_finish (ctx, false, false, time);        // drop failed..
735                         // no drop action...
736                         return;
737                     }
738                     
739                     
740                     
741                      var td_ar = targetData.split("|");
742                       
743                     
744                     if (this.drag_in_motion) { 
745                         Gdk.drag_status(ctx, Gdk.DragAction.COPY ,time);
746             
747                         this.highlightDropPath(  td_ar[0]  , (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
748                         return;
749                     }
750                     // continue on to allow drop..
751                 
752             
753                     // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
754                     //targetData
755                         //   {parent}|{pos}|{prop}
756               
757             
758                     _this.model.dropNode(targetData, dropNode, show_templates);
759                     GLib.debug("ADD new node!!!\n");
760                         
761                     ///Xcls_DialogTemplateSelect.singleton().show( _this.model.file.palete(), node);
762                     
763                     Gtk.drag_finish (ctx, false, false,time);
764                     
765                     
766                         
767                         
768                   
769             });
770             this.el.drag_drop.connect( (  ctx, x, y, time)  => {
771                   //Seed.print("TARGET: drag-drop");
772                
773                
774                 var src = Gtk.drag_get_source_widget(ctx);
775                  
776                if (src != this.el) {
777                
778                 
779                    
780                    this.drag_in_motion = false;   
781                         // request data that will be recieved by the recieve...              
782                     Gtk.drag_get_data
783                     (
784                             this.el,         // will receive 'drag-data-received' signal 
785                             ctx,        // represents the current state of the DnD 
786                             Gdk.Atom.intern("application/json",true),    // the target type we want 
787                             time            // time stamp 
788                     );
789             
790                      
791                     // No target offered by source => error
792                
793             
794                      return  false;
795                  }
796                  
797                  // handle drop around self..
798                  
799                               
800                         
801                 //print("GETTING POS");
802                 var  targetData = "";
803                 
804                 Gtk.TreePath path;
805                 Gtk.TreeViewDropPosition pos;
806                 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
807                 
808                 // if there are not items in the tree.. the we have to set isOver to true for anything..
809                 var isEmpty = false;
810                 if (_this.model.el.iter_n_children(null) < 1) {
811                     print("got NO children?\n");
812                     isOver = true; //??? 
813                     isEmpty = true;
814                     pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
815                 }
816                 
817                  
818                  
819                 //var action = Gdk.DragAction.COPY;
820                     // unless we are copying!!! ctl button..
821                 
822                 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
823                              Gdk.DragAction.COPY  : Gdk.DragAction.MOVE ;
824                             // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
825             
826                   
827                 if (_this.model.el.iter_n_children(null) < 1) {
828                     // no children.. -- asume it's ok..
829                     
830                     targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
831                      
832                     // continue through to allow drop...
833             
834                 } else {
835                             
836                             
837                 
838                             
839                             
840                             //print("ISOVER? " + isOver);
841                     if (!isOver) {
842                         
843                         Gtk.drag_finish (ctx, false, false, time);        // drop failed..
844                         return true; // not over apoint!?! - no action on drop or motion..
845                     }
846                             
847                     // drag node is parent of child..
848                     //console.log("SRC TREEPATH: " + src.treepath);
849                     //console.log("TARGET TREEPATH: " + data.path.to_string());
850                     
851                     // nned to check a  few here..
852                     //Gtk.TreeViewDropPosition.INTO_OR_AFTER
853                     //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
854                     //Gtk.TreeViewDropPosition.AFTER
855                     //Gtk.TreeViewDropPosition.BEFORE
856                     
857                     // locally dragged items to not really use the 
858                     var selection_text = this.dragData;
859                     
860                     
861                     
862                     if (selection_text == null || selection_text.length < 1) {
863                         //print("Error  - drag selection text returned NULL");
864                       
865                          Gtk.drag_finish (ctx, false, false, time);        // drop failed..
866                          return true; /// -- fixme -- this is not really correct..
867                     }                
868                             
869                             // see if we are dragging into ourself?
870                             print ("got selection text of  " + selection_text);
871                     
872                     var target_path = path.to_string();
873                     //print("target_path="+target_path);
874             
875                     // 
876                     if (selection_text  == target_path) {
877                         print("self drag ?? == we should perhaps allow copy onto self..\n");
878                         
879                          Gtk.drag_finish (ctx, false, false, time);        // drop failed..
880             
881                          return true; /// -- fixme -- this is not really correct..
882             
883                     }
884                             
885                     // check that 
886                     //print("DUMPING DATA");
887                     //console.dump(data);
888                     // path, pos
889                     
890                     //print(data.path.to_string() +' => '+  data.pos);
891                     
892                     // dropList is a list of xtypes that this node could be dropped on.
893                     // it is set up when we start to drag..
894                     
895                     
896                     targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
897                         
898                     print("targetDAta: " + targetData +"\n");
899                     
900                     if (targetData.length < 1) {
901                         //print("Can not find drop node path");
902                          
903                         Gtk.drag_finish (ctx, false, false, time);        // drop failed..
904                         return true;
905                     }
906                                 
907                             
908                             
909                             // continue on to allow drop..
910               }
911                     // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
912             
913             
914                  var delete_selection_data = false;
915                     
916                 if (action == Gdk.DragAction.ASK)  {
917                     /* Ask the user to move or copy, then set the ctx action. */
918                 }
919             
920                 if (action == Gdk.DragAction.MOVE) {
921                     delete_selection_data = true;
922                 }
923                   
924                             // drag around.. - reorder..
925                 _this.model.moveNode(targetData, action);
926                     
927                    
928                     
929                     
930                     
931                     // we can send stuff to souce here...
932             
933             
934             // do we always say failure, so we handle the reall drop?
935                 Gtk.drag_finish (ctx, false, false,time); //delete_selection_data, time);
936             
937                 return true;
938              
939              
940              
941              
942              
943              
944             });
945         }
946
947         // user defined functions
948         public           void highlightDropPath ( string treepath, Gtk.TreeViewDropPosition pos) {
949         
950                 // highlighting for drag/drop
951                 if (treepath.length > 0) {
952                     this.el.set_drag_dest_row(  new  Gtk.TreePath.from_string( treepath ), pos);
953                   } else {
954                     this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
955                  }
956                      
957         }
958         public void setCursor (string treepath, string sourceEvent)   {
959                 this.lastEventSource = sourceEvent;
960                 //this.blockChanges = true; << block changes prevents loading of 'node data' and firing of node_selected..
961             this.el.set_cursor(new Gtk.TreePath.from_string(treepath), null, false); 
962             // fire node_selected..
963             //this.blockChanges = false;
964                 this.lastEventSource = "";
965         }
966         public           void selectNode (string treepath_str, string source) {
967                 this.lastEventSource = source;
968             //this.selection.select_path(new  Gtk.TreePath.from_string( treepath_str));
969              var tp = new Gtk.TreePath.from_string(treepath_str);
970              
971              this.el.set_cursor(tp, null, false);  
972              this.el.scroll_to_cell(tp, null, false, 0,0);
973         }
974     }
975     public class Xcls_model : Object
976     {
977         public Gtk.TreeStore el;
978         private Xcls_WindowLeftTree  _this;
979
980
981             // my vars (def)
982         public DialogTemplateSelect template_select;
983         public string activePath;
984
985         // ctor
986         public Xcls_model(Xcls_WindowLeftTree _owner )
987         {
988             _this = _owner;
989             _this.model = this;
990             this.el = new Gtk.TreeStore( 3, typeof(string),typeof(string),typeof(Object) );
991
992             // my vars (dec)
993             this.template_select = null;
994             this.activePath = "";
995
996             // set gobject values
997
998             // init method
999
1000             print("model initialized");
1001         }
1002
1003         // user defined functions
1004         public           string findDropNode (string treepath_str, string[] targets) {
1005         
1006             // this is used by the dragdrop code in the roo version AFAIR..
1007         
1008             //var path = treepath_str.replace(/^builder-/, '');
1009             // treemap is depreciated... - should really check if model has any entries..
1010         
1011             if (this.el.iter_n_children(null) < 1) {
1012                 //print("NO KEYS");
1013                 return "|%d".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
1014             }
1015             //print("FIND treepath: " + path);
1016             //console.dump(this.treemap);
1017             
1018             //if (!treepath_str.match(/^builder-/)) {
1019             //    return []; // nothing!
1020             //}
1021             if (targets.length > 0 && targets[0] == "*") {
1022                 return  treepath_str;
1023             }
1024             return this.findDropNodeByPath(treepath_str,targets, -1);
1025         }
1026         public           void loadFile (JsRender.JsRender f) {
1027             //console.dump(f);
1028             this.el.clear();
1029             _this.main_window.windowstate.leftTreeNodeSelected(null, "");
1030             // needed???
1031             _this.main_window.windowstate.file = f;
1032             
1033            
1034             if (f.tree == null) {
1035                     try {
1036                         f.loadItems( );
1037                 } catch (Error e) {
1038                         return;
1039                 }
1040             }
1041             // if it's still null?
1042             if (f.tree == null) {
1043                 return;
1044             }
1045           
1046             var o = new Gee.ArrayList<JsRender.Node>();
1047             o.add(f.tree);
1048             this.load(o,null);
1049             
1050             _this.view.el.expand_all();
1051         
1052             if (f.tree.items.size < 1) {
1053                 // single item..
1054                 
1055                 //this.get('/Window.leftvpaned').el.set_position(80);
1056                 // select first...
1057                 _this.view.el.set_cursor( 
1058                     new  Gtk.TreePath.from_string("0"), null, false);
1059                 
1060                 
1061             } else {
1062                   //this.get('/Window.leftvpaned').el.set_position(200);
1063             }
1064             
1065             return;
1066          
1067                     
1068         }
1069         public    void updateSelected () {
1070           
1071            
1072             var s = _this.view.el.get_selection();
1073             
1074              Gtk.TreeIter iter;
1075             Gtk.TreeModel mod;
1076             
1077             
1078             
1079             if (!s.get_selected(out mod, out iter)) {
1080                 return; // nothing seleted..
1081             }
1082           
1083           GLib.Value value;
1084             this.el.get_value(iter, 2, out value);
1085             var node = (JsRender.Node)(value.get_object());
1086             
1087               this.el.set(iter, 0, node.nodeTitle(),
1088                         1, node.nodeTip(), -1
1089                 );
1090         }
1091         public           string findDropNodeByPath (string treepath_str, string[] targets, int in_pref = -1) {
1092         
1093             var path = treepath_str; // dupe it..
1094             
1095             
1096             // pref : 3 = ontop - 0 = after, 1 = before
1097             int pref = in_pref < 0  ?  Gtk.TreeViewDropPosition.INTO_OR_AFTER : in_pref;
1098             
1099             var last = "";
1100             
1101             //console.dump(this.treemap);
1102             
1103             print("findDropNodeByPath : got path length %d / %s\n", path.length, path);
1104             
1105             if (path.length == 0) {
1106                 // top drop. // just return empty..
1107                 return "|%d".printf((int)pref) ;
1108                 
1109             }
1110             
1111             
1112             while (path.length > 0) {
1113             
1114                 if (path.length == treepath_str.length && pref != Gtk.TreeViewDropPosition.INTO_OR_AFTER) {
1115                     if (path.last_index_of(":") < 0 ) {
1116                         return "";
1117                     }
1118                     path = path.substring(0, path.last_index_of(":"));
1119                     last = treepath_str;
1120                     print("DROP  before or after : using %s\n",path);
1121                     continue;
1122                 }
1123             
1124                 //print("LOOKING FOR PATH: " + path);
1125                 var node_data = this.pathToNode(path);
1126                 
1127                 if (node_data == null) {
1128                     print("node not found");
1129                     return "";
1130                 }
1131                 
1132                 var xname = node_data.fqn();
1133                 var match = "";
1134                 var prop = "";
1135                 
1136                 for (var i =0; i < targets.length; i++)  {
1137                     var tg = targets[i];
1138                     if ((tg == xname)  ) {
1139                         match = tg;
1140                         break;
1141                     }
1142                     // if target is "xxxx:name"
1143                     if (tg.contains(xname +":")) {
1144                         match = tg;
1145                         var ar = tg.split(":");
1146                         prop = ar[1];
1147                         break;
1148                     }
1149                 }
1150                 
1151                 if (match.length > 0) {
1152                     if (last.length > 0) { // pref is after/before..
1153                         // then it's after last
1154                         //if (pref > 1) {
1155                         //    return "";
1156                         //}
1157                         return last + "|%d".printf((int)pref) + "|" + prop;
1158         
1159                         
1160                     }
1161                     // we need to add prop - as :store -> needs to bee added when dropping onto.
1162                     return path + "|%d".printf( (int) Gtk.TreeViewDropPosition.INTO_OR_AFTER)  + "|" + prop;
1163                 }
1164                 /*
1165                 last = "" + path;
1166                 var par = path.split(":");
1167                 string [] ppar = {};
1168                 for (var i = 0; i < par.length-1; i++) {
1169                     ppar += par[i];
1170                 }
1171                 
1172                 path = string.joinv(":", ppar);
1173                 */
1174                 break;
1175         
1176             }
1177             
1178             return "";
1179                     
1180         }
1181         public           void moveNode (string target_data, Gdk.DragAction action) 
1182         {
1183            
1184            /// target_data = "path|pos");
1185            
1186            
1187             //print("MOVE NODE");
1188             // console.dump(target_data);
1189             Gtk.TreeIter old_iter;
1190             Gtk.TreeModel mod;
1191             
1192             var s = _this.view.el.get_selection();
1193             s.get_selected(out mod , out old_iter);
1194             mod.get_path(old_iter);
1195             
1196             var node = this.pathToNode(mod.get_path(old_iter).to_string());
1197             //console.dump(node);
1198             if (node == null) {
1199                 print("moveNode: ERROR - node is null?");
1200             }
1201             
1202             
1203         
1204             // needs to drop first, otherwise the target_data 
1205             // treepath will be invalid.
1206         
1207             
1208             if ((action & Gdk.DragAction.MOVE) > 0) {
1209                     print("REMOVING OLD NODE : " + target_data + "\n");
1210                     node.remove();
1211                     this.dropNode(target_data, node, false);
1212                     this.el.remove(ref old_iter);
1213                     
1214                     
1215                                  
1216             } else {
1217                 print("DROPPING NODE // copy: " + target_data + "\n");
1218                 node = node.deepClone();
1219                 this.dropNode(target_data, node, false);
1220             }
1221             _this.changed();
1222             this.activePath= "";
1223             //this.updateNode(false,true);
1224         }
1225         public           void deleteSelected () {
1226             
1227             print("DELETE SELECTED?");
1228             //_this.view.blockChanges = true;
1229             print("GET SELECTION?");
1230         
1231             var s = _this.view.el.get_selection();
1232             
1233             print("GET  SELECTED?");
1234            Gtk.TreeIter iter;
1235             Gtk.TreeModel mod;
1236         
1237             
1238             if (!s.get_selected(out mod, out iter)) {
1239                 return; // nothing seleted..
1240             }
1241               
1242         
1243         
1244             this.activePath= "";      
1245             print("GET  vnode value?");
1246         
1247             GLib.Value value;
1248             this.el.get_value(iter, 2, out value);
1249             var data = (JsRender.Node)(value.get_object());
1250             print("removing node from Render\n");
1251             if (data.parent == null) {
1252                _this.main_window.windowstate.file.tree = null;
1253             } else {
1254                 data.remove();
1255             }
1256             print("removing node from Tree\n");    
1257             s.unselect_all();
1258             this.el.remove(ref iter);
1259         
1260             
1261             
1262             
1263             // 
1264             
1265             
1266         
1267         
1268             this.activePath= ""; // again!?!?      
1269             //this.changed(null,true);
1270             
1271             _this.changed();
1272             
1273             _this.view.blockChanges = false;
1274         }
1275         public           void load (Gee.ArrayList<JsRender.Node> tr, Gtk.TreeIter? iter) 
1276         {
1277             Gtk.TreeIter citer;
1278             //this.insert(citer,iter,0);
1279             for(var i =0 ; i < tr.size; i++) {
1280                 if (iter != null) {
1281                     this.el.insert(out citer,iter,-1); // why not append?
1282                 } else {
1283                     this.el.append(out citer,null);
1284                 }
1285                 
1286                 this.el.set(citer, 0, tr.get(i).nodeTitle(),
1287                         1, tr.get(i).nodeTip(), -1
1288                 );
1289                 var o =   GLib.Value(typeof(Object));
1290                 o.set_object((Object)tr.get(i));
1291                 
1292                 this.el.set_value(citer, 2, o);
1293                 
1294                 if (tr.get(i).items.size > 0) {
1295                     this.load(tr.get(i).items, citer);
1296                 }
1297              
1298             }
1299         
1300             
1301         }
1302         public           JsRender.Node pathToNode (string path) {
1303          
1304              
1305              Gtk.TreeIter   iter;
1306              _this.model.el.get_iter_from_string(out iter, path);
1307              
1308              GLib.Value value;
1309              _this.model.el.get_value(iter, 2, out value);
1310              
1311              return (JsRender.Node)value.dup_object();
1312         
1313         }
1314         public           void dropNode (string target_data_str, JsRender.Node node, bool show_templates) {
1315         //         print("drop Node");
1316              // console.dump(node);
1317           //    console.dump(target_data);
1318           
1319                         //target_data_str
1320                         //   {parent}|{pos}|{prop}
1321           
1322           
1323                 // 0 = before , 1=after 2/3 onto
1324           
1325                         GLib.debug("dropNode %s", target_data_str);
1326                 var target_data= target_data_str.split("|");
1327           
1328                 var parent_str = target_data[0].length > 0 ? target_data[0] : "";
1329                 var pos = target_data.length > 1 ? int.parse(target_data[1]) : 2; // ontop..
1330           
1331           
1332                 Gtk.TreePath tree_path  =   parent_str.length > 0 ? new  Gtk.TreePath.from_string( parent_str ) : null;
1333                 
1334                 
1335                 
1336                 //print("add " + tp + "@" + target_data[1]  );
1337                 
1338                 JsRender.Node parentNode = null;
1339                 
1340                 Gtk.TreeIter iter_after;
1341                 Gtk.TreeIter iter_par ;
1342                 
1343                
1344                  if (target_data.length == 3 && target_data[2].length > 0) {
1345                     node.props.set("* prop", target_data[2]);
1346                 }
1347         
1348                 Gtk.TreePath expand_parent = null;
1349                 
1350                 // we only need to show the template if it's come from else where?
1351                  if (show_templates) {
1352                  
1353                      var ts = _this.main_window.windowstate.template_select;
1354                  
1355                      var new_node = ts.show(
1356                           _this.main_window, // (Gtk.Window) _this.el.get_toplevel (),
1357                          _this.main_window.windowstate.file.palete(),
1358                             node,
1359                             _this.main_window.windowstate.project);
1360                            
1361                      if (new_node == null) {
1362                          return; // do not add?
1363                      }
1364                      node = new_node;
1365                 }        
1366                 
1367                  //print("pos is %d  \n".printf(pos));
1368                 
1369                  Gtk.TreeIter n_iter; 
1370                  
1371                  if ( parent_str.length < 1) {
1372                       this.el.append(out n_iter, null); // drop at top level..
1373                       node.parent = null;
1374                       _this.main_window.windowstate.file.tree = node;
1375                       
1376                       
1377                 } else   if (pos  < 2) {
1378                     //print(target_data[1]  > 0 ? 'insert_after' : 'insert_before');
1379                     
1380                     this.el.get_iter(out iter_after, tree_path );            
1381                     this.el.iter_parent(out iter_par, iter_after);
1382                     expand_parent = this.el.get_path(iter_par);
1383                     
1384                     GLib.Value value;
1385                     this.el.get_value( iter_par, 2, out value);
1386                     parentNode =  (JsRender.Node)value.dup_object();
1387                     
1388                     
1389                     this.el.get_value( iter_after, 2, out value);
1390                     var relNode =  (JsRender.Node)value.dup_object();
1391                     
1392                     if ( pos  > 0 ) {
1393                      
1394                         this.el.insert_after(out n_iter,    iter_par  , iter_after);
1395                         var ix = parentNode.items.index_of(relNode);
1396                         parentNode.items.insert(ix+1, node);
1397                         
1398                     } else {
1399                         this.el.insert_before(out n_iter,  iter_par  , iter_after);
1400                         var ix = parentNode.items.index_of(relNode);
1401                         parentNode.items.insert(ix, node);
1402          
1403                     }
1404                     node.parent = parentNode;
1405                     
1406                     
1407                     
1408                 } else {
1409                    //  print("appending to  " + parent_str);
1410                     this.el.get_iter(out iter_par, tree_path);
1411                     this.el.append(out n_iter,   iter_par );
1412                     expand_parent = this.el.get_path(iter_par);
1413                     
1414                     GLib.Value value;
1415                     this.el.get_value( iter_par, 2, out value);
1416                     parentNode =  (JsRender.Node)value.dup_object();
1417                     node.parent = parentNode;
1418                     parentNode.items.add(node);
1419                 }
1420                 
1421                 // reparent node in tree...
1422                
1423                 
1424                 // why only on no parent???
1425                 
1426                 //if (node.parent = null) {
1427                      
1428                    
1429                     
1430                 //}
1431                 
1432                 
1433                 // work out what kind of packing to use.. -- should be in 
1434                 if (!node.has("pack")   && parent_str.length > 1) {
1435                     
1436                     _this.main_window.windowstate.file.palete().fillPack(node,parentNode);
1437                     
1438                     
1439                 }
1440                 
1441                 // add the node...
1442                 
1443                 this.el.set(n_iter, 0, node.nodeTitle(), 1, node.nodeTip(), -1  );
1444                 var o =   GLib.Value(typeof(Object));
1445                 o.set_object((Object)node);
1446                 
1447                 this.el.set_value(n_iter, 2, o);
1448                 
1449                 
1450                 
1451                 
1452         // load children - if it has any..
1453               
1454                 if (node.items.size > 0) {
1455                     this.load(node.items, n_iter);
1456                     _this.view.el.expand_row(this.el.get_path(n_iter), true);
1457                 } else if (expand_parent != null && !_this.view.el.is_row_expanded(expand_parent)) {
1458                    _this.view.el.expand_row(expand_parent,true);
1459                 }
1460         
1461                 //if (tp != null && (node.items.length() > 0 || pos > 1)) {
1462                 //    _this.view.el.expand_row(this.el.get_path(iter_par), true);
1463                // }
1464                 // wee need to get the empty proptypes from somewhere..
1465                 
1466                 //var olditer = this.activeIter;
1467                 this.activePath = this.el.get_path(n_iter).to_string();
1468         
1469         
1470                 // pretend button was pressed, so that we can trigger select node...
1471                 _this.view.button_is_pressed = true;
1472                 _this.view.lastEventSource = "";
1473                 _this.view.el.set_cursor(this.el.get_path(n_iter), null, false);
1474                 _this.view.button_is_pressed = false;
1475                 _this.changed();
1476              
1477                 
1478                     
1479         }
1480         public string treePathFromNode (JsRender.Node node) {
1481             // iterate through the tree and find the node
1482             var ret = "";
1483             
1484             this.el.foreach((mod, pth, iter) => {
1485                 // get the node..
1486               
1487              
1488                  GLib.Value value;
1489                  _this.model.el.get_value(iter, 2, out value);
1490                  
1491         
1492                  
1493                  var n = (JsRender.Node)value;
1494         
1495                  print("compare %s to %s\n", n.fqn(), node.fqn());
1496                 if (node == n) {
1497                     ret = pth.to_string();
1498                     return true;
1499                 }
1500                 return false;
1501             });
1502             return ret;
1503         
1504         }
1505     }
1506
1507     public class Xcls_TreeViewColumn7 : Object
1508     {
1509         public Gtk.TreeViewColumn el;
1510         private Xcls_WindowLeftTree  _this;
1511
1512
1513             // my vars (def)
1514
1515         // ctor
1516         public Xcls_TreeViewColumn7(Xcls_WindowLeftTree _owner )
1517         {
1518             _this = _owner;
1519             this.el = new Gtk.TreeViewColumn();
1520
1521             // my vars (dec)
1522
1523             // set gobject values
1524             this.el.title = "test";
1525             var child_0 = new Xcls_renderer( _this );
1526             child_0.ref();
1527             this.el.pack_start (  child_0.el , true );
1528
1529             // init method
1530
1531             this.el.add_attribute(_this.renderer.el , "markup", 0 );
1532         }
1533
1534         // user defined functions
1535     }
1536     public class Xcls_renderer : Object
1537     {
1538         public Gtk.CellRendererText el;
1539         private Xcls_WindowLeftTree  _this;
1540
1541
1542             // my vars (def)
1543
1544         // ctor
1545         public Xcls_renderer(Xcls_WindowLeftTree _owner )
1546         {
1547             _this = _owner;
1548             _this.renderer = this;
1549             this.el = new Gtk.CellRendererText();
1550
1551             // my vars (dec)
1552
1553             // set gobject values
1554         }
1555
1556         // user defined functions
1557     }
1558
1559
1560
1561     public class Xcls_LeftTreeMenu : Object
1562     {
1563         public Gtk.Menu el;
1564         private Xcls_WindowLeftTree  _this;
1565
1566
1567             // my vars (def)
1568
1569         // ctor
1570         public Xcls_LeftTreeMenu(Xcls_WindowLeftTree _owner )
1571         {
1572             _this = _owner;
1573             _this.LeftTreeMenu = this;
1574             this.el = new Gtk.Menu();
1575
1576             // my vars (dec)
1577
1578             // set gobject values
1579             var child_0 = new Xcls_MenuItem10( _this );
1580             child_0.ref();
1581             this.el.add (  child_0.el  );
1582             var child_1 = new Xcls_MenuItem11( _this );
1583             child_1.ref();
1584             this.el.add (  child_1.el  );
1585             var child_2 = new Xcls_MenuItem12( _this );
1586             child_2.ref();
1587             this.el.add (  child_2.el  );
1588         }
1589
1590         // user defined functions
1591     }
1592     public class Xcls_MenuItem10 : Object
1593     {
1594         public Gtk.MenuItem el;
1595         private Xcls_WindowLeftTree  _this;
1596
1597
1598             // my vars (def)
1599
1600         // ctor
1601         public Xcls_MenuItem10(Xcls_WindowLeftTree _owner )
1602         {
1603             _this = _owner;
1604             this.el = new Gtk.MenuItem();
1605
1606             // my vars (dec)
1607
1608             // set gobject values
1609             this.el.label = "Delete Element";
1610
1611             //listeners
1612             this.el.activate.connect( ( ) => {
1613                 
1614                 print("ACTIVATE?");
1615                 
1616               
1617                  _this.model.deleteSelected();
1618             });
1619         }
1620
1621         // user defined functions
1622     }
1623
1624     public class Xcls_MenuItem11 : Object
1625     {
1626         public Gtk.MenuItem el;
1627         private Xcls_WindowLeftTree  _this;
1628
1629
1630             // my vars (def)
1631
1632         // ctor
1633         public Xcls_MenuItem11(Xcls_WindowLeftTree _owner )
1634         {
1635             _this = _owner;
1636             this.el = new Gtk.MenuItem();
1637
1638             // my vars (dec)
1639
1640             // set gobject values
1641             this.el.label = "Save as Template";
1642
1643             //listeners
1644             this.el.activate.connect( () => {
1645             
1646                  DialogSaveTemplate.singleton().show(
1647                         (Gtk.Window) _this.el.get_toplevel (), 
1648                         _this.main_window.windowstate.file.palete(), 
1649                         _this.getActiveElement()
1650                 );
1651                  
1652                 
1653             });
1654         }
1655
1656         // user defined functions
1657     }
1658
1659     public class Xcls_MenuItem12 : Object
1660     {
1661         public Gtk.MenuItem el;
1662         private Xcls_WindowLeftTree  _this;
1663
1664
1665             // my vars (def)
1666
1667         // ctor
1668         public Xcls_MenuItem12(Xcls_WindowLeftTree _owner )
1669         {
1670             _this = _owner;
1671             this.el = new Gtk.MenuItem();
1672
1673             // my vars (dec)
1674
1675             // set gobject values
1676             this.el.label = "Save as Module";
1677
1678             //listeners
1679             this.el.activate.connect( () => {
1680                 var node = _this.getActiveElement();
1681                  var name = DialogSaveModule.singleton().show(
1682                         (Gtk.Window) _this.el.get_toplevel (), 
1683                         _this.main_window.windowstate.project, 
1684                         node
1685                  );
1686                  if (name.length < 1) {
1687                         return;
1688               
1689                  }
1690                  node.props.set("* xinclude", name);
1691                  node.items.clear();
1692             
1693             
1694                 var s = _this.view.el.get_selection();
1695                 
1696                 print("GET  SELECTED?");
1697                 Gtk.TreeIter iter;
1698                 Gtk.TreeModel mod;
1699             
1700                 
1701                 if (!s.get_selected(out mod, out iter)) {
1702                     return; // nothing seleted..
1703                 }
1704                 Gtk.TreeIter citer;
1705                 var n_cn = mod.iter_n_children(iter) -1;
1706                 for (var i = n_cn; i > -1; i--) {
1707                     mod.iter_nth_child(out citer, iter, i);
1708                     
1709             
1710                     print("removing node from Tree\n");    
1711                 
1712                     _this.model.el.remove(ref citer);
1713                 }
1714                 _this.changed();
1715                 _this.node_selected(node, "tree");
1716                  
1717                 
1718             });
1719         }
1720
1721         // user defined functions
1722     }
1723
1724
1725
1726 }