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