1 static Xcls_WindowLeftTree _WindowLeftTree;
3 public class Xcls_WindowLeftTree : Object
5 public Gtk.ScrolledWindow el;
6 private Xcls_WindowLeftTree _this;
8 public static Xcls_WindowLeftTree singleton()
10 if (_WindowLeftTree == null) {
11 _WindowLeftTree= new Xcls_WindowLeftTree();
13 return _WindowLeftTree;
15 public Xcls_view view;
16 public Xcls_model model;
17 public Xcls_renderer renderer;
18 public Xcls_LeftTreeMenu LeftTreeMenu;
21 public signal bool before_node_change (JsRender.Node? node);
22 public signal void changed ();
23 public signal void node_selected (JsRender.Node? node, string source);
24 public Xcls_MainWindow main_window;
27 public Xcls_WindowLeftTree()
30 this.el = new Gtk.ScrolledWindow( null, null );
33 this.main_window = null;
36 this.el.shadow_type = Gtk.ShadowType.IN;
37 var child_0 = new Xcls_view( _this );
39 this.el.add ( child_0.el );
40 var child_1 = new Xcls_LeftTreeMenu( _this );
45 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
48 // user defined functions
49 public JsRender.Node? getActiveElement () { // return path to actie node.
51 var path = this.getActivePath();
52 if (path.length < 1) {
55 return _this.model.pathToNode(path);
58 public JsRender.JsRender getActiveFile () {
59 return this.main_window.windowstate.file;
61 public string getActivePath () {
63 var view = this.view.el;
64 if (view.get_selection().count_selected_rows() < 1) {
69 view.get_selection().get_selected(out mod, out iter);
70 return mod.get_path(iter).to_string();
72 public class Xcls_view : Object
74 public Gtk.TreeView el;
75 private Xcls_WindowLeftTree _this;
79 public string dragData;
80 public string[] dropList;
83 public bool drag_in_motion;
84 public bool blockChanges;
87 public Xcls_view(Xcls_WindowLeftTree _owner )
91 this.el = new Gtk.TreeView();
94 this.blockChanges = false;
97 this.el.expand = true;
98 this.el.tooltip_column = 1;
99 this.el.enable_tree_lines = true;
100 this.el.headers_visible = false;
101 var child_0 = new Xcls_model( _this );
103 this.el.set_model ( child_0.el );
104 var child_1 = new Xcls_TreeViewColumn4( _this );
106 this.el.append_column ( child_1.el );
111 var description = new Pango.FontDescription();
112 description.set_size(8000);
113 this.el.override_font(description);
115 var selection = this.el.get_selection();
116 selection.set_mode( Gtk.SelectionMode.SINGLE);
119 // is this really needed??
121 this.selection.signal['changed'].connect(function() {
122 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
123 _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
127 Gtk.drag_source_set (
128 this.el, /* widget will be drag-able */
129 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
130 BuilderApplication.targetList, /* lists of target to support */
131 Gdk.DragAction.COPY | Gdk.DragAction.MOVE | Gdk.DragAction.LINK /* what to do with data after dropped */
135 //Gtk.drag_source_add_text_targets(this.el);
139 this.el, /* widget that will accept a drop */
140 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
141 BuilderApplication.targetList, /* lists of target to support */
142 Gdk.DragAction.COPY | Gdk.DragAction.MOVE | Gdk.DragAction.LINK /* what to do with data after dropped */
145 //Gtk.drag_dest_set_target_list(this.el, Builder.Application.targetList);
146 //Gtk.drag_dest_add_text_targets(this.el);
150 this.el.button_press_event.connect( ( ev) => {
151 //console.log("button press?");
152 if (! _this.before_node_change(null) ) {
158 if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button != 3) {
159 //print("click" + ev.type);
163 if (!_this.view.el.get_path_at_pos((int)ev.x,(int)ev.y, out res, null, null, null) ) {
167 this.el.get_selection().select_path(res);
169 //if (!this.get('/LeftTreeMenu').el) {
170 // this.get('/LeftTreeMenu').init();
173 _this.LeftTreeMenu.el.set_screen(Gdk.Screen.get_default());
174 _this.LeftTreeMenu.el.show_all();
175 _this.LeftTreeMenu.el.popup(null, null, null, 3, ev.time);
176 // print("click:" + res.path.to_string());
179 this.el.cursor_changed.connect( ( ) => {
182 if (this.blockChanges) { // probably not needed..
185 if (!_this.before_node_change(null) ) {
186 this.blockChanges = true;
187 this.el.get_selection().unselect_all();
188 this.blockChanges = false;
191 if (_this.main_window.windowstate.file == null) {
195 //var render = this.get('/LeftTree').getRenderer();
196 print("LEFT TREE -> view -> selection changed called\n");
199 // -- it appears that the selection is not updated.
201 GLib.Timeout.add_full(GLib.Priority.DEFAULT,10 , () => {
204 if (this.el.get_selection().count_selected_rows() < 1) {
206 print("selected rows < 1\n");
207 //??this.model.load( false);
208 _this.node_selected(null, this.lastEventSource);
213 //console.log('changed');
214 var s = this.el.get_selection();
217 s.get_selected(out mod, out iter);
222 _this.model.el.get_value(iter, 2, out value);
223 _this.model.activePath = mod.get_path(iter).to_string();
225 var node = (JsRender.Node)value.dup_object();
226 _this.node_selected(node);
227 while (Gtk.events_pending()) {
228 Gtk.main_iteration();
230 var cp = mod.get_path(iter);
232 this.el.get_visible_range(out sp, out ep);
233 // if sp is before cp then retuns 1.
234 // if cp is before ep then retuns 1.
235 if (cp.compare(sp) >= 0 && ep.compare(cp) >=1) {
241 this.el.scroll_to_cell(new Gtk.TreePath.from_string(_this.model.activePath), null, true, 0.1f,0.0f);
245 //_this.after_node_change(node);
247 // _this.model.file.changed(node, "tree");
249 //Seed.print( value.get_string());
253 this.el.drag_begin.connect( ( ctx) => {
254 //print('SOURCE: drag-begin');
257 //this.targetData = "";
259 // find what is selected in our tree...
261 var s = _this.view.el.get_selection();
262 if (s.count_selected_rows() < 1) {
267 s.get_selected(out mod, out iter);
271 // set some properties of the tree for use by the dropped element.
273 _this.model.el.get_value(iter, 2, out value);
274 var tp = mod.get_path(iter).to_string();
275 var data = (JsRender.Node)(value.dup_object());
276 var xname = data.fqn();
277 print ("XNAME IS " + xname+ "\n");
279 this.dropList = _this.main_window.windowstate.file.palete().getDropList(xname);
281 print ("DROP LIST IS " + string.joinv(", ", this.dropList) + "\n");
284 // make the drag icon a picture of the node that was selected
287 // by default returns the path..
288 var path = _this.model.el.get_path(iter);
291 var pix = this.el.create_row_drag_icon ( path);
293 Gtk.drag_set_icon_surface (ctx, pix) ;
297 this.el.drag_end.connect( (drag_context) => {
298 //Seed.print('LEFT-TREE: drag-end');
300 this.dropList = null;
301 // this.targetData = "";
302 this.highlightDropPath("",0);
305 this.el.drag_motion.connect( ( ctx, x, y, time) => {
306 print("got drag motion\n");
307 var src = Gtk.drag_get_source_widget(ctx);
311 if (src != this.el) {
315 // the point of this is to detect where an item could be dropped..
316 print("requesting drag data\n");
317 this.drag_in_motion = true;
319 // request data that will be recieved by the recieve...
322 this.el, // will receive 'drag-data-received' signal
323 ctx, // represents the current state of the DnD
324 Gdk.Atom.intern("STRING",true), // the target type we want
331 print("action: %d\n", ctx.get_actions());
332 //print("GETTING POS");
336 Gtk.TreeViewDropPosition pos;
337 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
339 // if there are not items in the tree.. the we have to set isOver to true for anything..
341 if (_this.model.el.iter_n_children(null) < 1) {
342 print("got NO children?\n");
345 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
349 // ------------- a drag from self..
352 //var action = Gdk.DragAction.COPY;
353 // unless we are copying!!! ctl button..
355 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
356 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
357 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
360 if (_this.model.el.iter_n_children(null) < 1) {
361 // no children.. -- asume it's ok..
363 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
365 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
366 Gdk.drag_status(ctx, action ,time);
369 // continue through to allow drop...
377 //print("ISOVER? " + isOver);
380 Gdk.drag_status(ctx, 0 ,time);
381 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
386 // drag node is parent of child..
387 //console.log("SRC TREEPATH: " + src.treepath);
388 //console.log("TARGET TREEPATH: " + data.path.to_string());
390 // nned to check a few here..
391 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
392 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
393 //Gtk.TreeViewDropPosition.AFTER
394 //Gtk.TreeViewDropPosition.BEFORE
396 // locally dragged items to not really use the
397 var selection_text = this.dragData;
401 if (selection_text == null || selection_text.length < 1) {
402 //print("Error - drag selection text returned NULL");
403 Gdk.drag_status(ctx, 0 ,time);
404 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
409 // see if we are dragging into ourself?
410 var target_path = path.to_string();
411 print ("Drag %s onto %s--%d\n ", selection_text, target_path, pos);
413 // pos : 3 = ontop - 0 = after, 1 = before
414 //print("target_path="+target_path);
417 if (selection_text == target_path) {
418 print("self drag ?? == we should perhaps allow copy onto self..\n");
420 Gdk.drag_status(ctx, 0 ,time);
421 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
423 // -- fixme -- this is not really correct..
428 //print("DUMPING DATA");
429 //console.dump(data);
432 //print(data.path.to_string() +' => '+ data.pos);
434 // dropList is a list of xtypes that this node could be dropped on.
435 // it is set up when we start to drag..
438 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
440 print("targetDAta: " + targetData +"\n");
442 if (targetData.length < 1) {
443 //print("Can not find drop node path");
445 Gdk.drag_status(ctx, 0, time);
446 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
450 var td_ar = targetData.split("|");
454 Gdk.drag_status(ctx, action ,time);
455 this.highlightDropPath(td_ar[0], (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
460 this.el.drag_data_get.connect( ( drag_context, data, info, time) => {
463 //print("drag-data-get");
464 var s = this.el.get_selection();
465 if (s.count_selected_rows() < 1) {
467 print("return empty string - no selection..");
474 s.get_selected(out mod, out iter);
479 _this.model.el.get_value(iter, 2, out value);
480 var ndata = (JsRender.Node)(value.dup_object());
484 var tp = mod.get_path(iter).to_string();
485 // by default returns the path..
487 if ( info != Gdk.Atom.intern("STRING",true) ) {
488 tp = ndata.toJsonString();
491 //data.set_text(tp,tp.length);
493 data.set (data.get_target (), 8, (uchar[]) tp.to_utf8 ());
496 // print("return " + tp);
498 this.el.drag_data_received.connect( (ctx, x, y, sel, info, time) => {
500 // THIS CODE ONLY RELATES TO drag or drop of "NEW" elements or "FROM another tree.."
503 // print("Tree: drag-data-received\n");
504 var selection_text = (string)sel.get_data();
505 //print("selection_text= %s\n",selection_text);
507 var is_drag = this.drag_in_motion;
511 print("Is Drag %s\n", is_drag ? "Y": "N");
515 Gtk.TreeViewDropPosition pos;
516 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
518 // if there are not items in the tree.. the we have to set isOver to true for anything..
520 if (_this.model.el.iter_n_children(null) < 1) {
521 print("got NO children?\n");
524 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
528 //console.log("LEFT-TREE: drag-motion");
529 var src = Gtk.drag_get_source_widget(ctx);
531 // a drag from self - this should be handled by drop and motion.
532 if (src == this.el) {
533 print("Source == this element should not happen.. ? \n");
536 //print("drag_data_recieved from another element");
541 if (selection_text == null || selection_text.length < 1 || !isOver) {
542 // nothing valid foudn to drop...
543 print("empty sel text or not over");
545 Gdk.drag_status(ctx, 0, time);
546 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
549 Gtk.drag_finish (ctx, false, false, time); // drop failed..
554 var dropNode = new JsRender.Node();
556 var dropNodeType = selection_text;
557 var show_templates = true;
559 if (dropNodeType[0] == '{') {
560 var pa = new Json.Parser();
562 pa.load_from_data(dropNodeType);
564 Gtk.drag_finish (ctx, false, false, time); // drop failed..
569 dropNode.loadFromJson( pa.get_root().get_object(), 2);
570 dropNodeType = dropNode.fqn();
571 show_templates = false;
576 dropNode.setFqn(selection_text);
580 // dropList --- need to gather this ...
581 print("get dropList for : %s\n",dropNodeType);
582 var dropList = _this.main_window.windowstate.file.palete().getDropList(dropNodeType);
584 print("dropList: %s\n", string.joinv(" , ", dropList));
586 // if drag action is link ... then we can drop it anywahere...
587 if ((ctx.get_actions() & Gdk.DragAction.LINK) > 0) {
588 // if path is null?? dragging into an empty tree?
589 targetData = (path == null ? "" : path.to_string()) + "|%d".printf((int)pos);
593 targetData = _this.model.findDropNodeByPath( isEmpty ? "" : path.to_string(), dropList, pos);
598 print("targetDAta: " + targetData +"\n");
600 if (targetData.length < 1) {
602 // invalid drop path..
603 if (this.drag_in_motion) {
604 Gdk.drag_status(ctx, 0, time);
605 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
608 Gtk.drag_finish (ctx, false, false, time); // drop failed..
614 var td_ar = targetData.split("|");
617 if (this.drag_in_motion) {
618 Gdk.drag_status(ctx, Gdk.DragAction.COPY ,time);
620 this.highlightDropPath( td_ar[0] , (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
623 // continue on to allow drop..
626 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
629 _this.model.dropNode(targetData, dropNode, show_templates);
630 print("ADD new node!!!\n");
632 ///Xcls_DialogTemplateSelect.singleton().show( _this.model.file.palete(), node);
634 Gtk.drag_finish (ctx, false, false,time);
641 this.el.drag_drop.connect( ( ctx, x, y, time) => {
642 //Seed.print("TARGET: drag-drop");
645 var src = Gtk.drag_get_source_widget(ctx);
647 if (src != this.el) {
651 this.drag_in_motion = false;
652 // request data that will be recieved by the recieve...
655 this.el, // will receive 'drag-data-received' signal
656 ctx, // represents the current state of the DnD
657 Gdk.Atom.intern("application/json",true), // the target type we want
662 // No target offered by source => error
668 // handle drop around self..
672 //print("GETTING POS");
676 Gtk.TreeViewDropPosition pos;
677 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
679 // if there are not items in the tree.. the we have to set isOver to true for anything..
681 if (_this.model.el.iter_n_children(null) < 1) {
682 print("got NO children?\n");
685 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
690 //var action = Gdk.DragAction.COPY;
691 // unless we are copying!!! ctl button..
693 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
694 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
695 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
698 if (_this.model.el.iter_n_children(null) < 1) {
699 // no children.. -- asume it's ok..
701 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
703 // continue through to allow drop...
711 //print("ISOVER? " + isOver);
714 Gtk.drag_finish (ctx, false, false, time); // drop failed..
715 return true; // not over apoint!?! - no action on drop or motion..
718 // drag node is parent of child..
719 //console.log("SRC TREEPATH: " + src.treepath);
720 //console.log("TARGET TREEPATH: " + data.path.to_string());
722 // nned to check a few here..
723 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
724 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
725 //Gtk.TreeViewDropPosition.AFTER
726 //Gtk.TreeViewDropPosition.BEFORE
728 // locally dragged items to not really use the
729 var selection_text = this.dragData;
733 if (selection_text == null || selection_text.length < 1) {
734 //print("Error - drag selection text returned NULL");
736 Gtk.drag_finish (ctx, false, false, time); // drop failed..
737 return true; /// -- fixme -- this is not really correct..
740 // see if we are dragging into ourself?
741 print ("got selection text of " + selection_text);
743 var target_path = path.to_string();
744 //print("target_path="+target_path);
747 if (selection_text == target_path) {
748 print("self drag ?? == we should perhaps allow copy onto self..\n");
750 Gtk.drag_finish (ctx, false, false, time); // drop failed..
752 return true; /// -- fixme -- this is not really correct..
757 //print("DUMPING DATA");
758 //console.dump(data);
761 //print(data.path.to_string() +' => '+ data.pos);
763 // dropList is a list of xtypes that this node could be dropped on.
764 // it is set up when we start to drag..
767 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
769 print("targetDAta: " + targetData +"\n");
771 if (targetData.length < 1) {
772 //print("Can not find drop node path");
774 Gtk.drag_finish (ctx, false, false, time); // drop failed..
780 // continue on to allow drop..
782 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
785 var delete_selection_data = false;
787 if (action == Gdk.DragAction.ASK) {
788 /* Ask the user to move or copy, then set the ctx action. */
791 if (action == Gdk.DragAction.MOVE) {
792 delete_selection_data = true;
795 // drag around.. - reorder..
796 _this.model.moveNode(targetData, action);
802 // we can send stuff to souce here...
805 // do we always say failure, so we handle the reall drop?
806 Gtk.drag_finish (ctx, false, false,time); //delete_selection_data, time);
818 // user defined functions
819 public void highlightDropPath ( string treepath, Gtk.TreeViewDropPosition pos) {
821 // highlighting for drag/drop
822 if (treepath.length > 0) {
823 this.el.set_drag_dest_row( new Gtk.TreePath.from_string( treepath ), pos);
825 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
829 public void selectNode (string treepath_str) {
830 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
831 var tp = new Gtk.TreePath.from_string(treepath_str);
833 this.el.set_cursor(tp, null, false);
834 this.el.scroll_to_cell(tp, null, false, 0,0);
837 public class Xcls_model : Object
839 public Gtk.TreeStore el;
840 private Xcls_WindowLeftTree _this;
844 public DialogTemplateSelect template_select;
845 public string activePath;
848 public Xcls_model(Xcls_WindowLeftTree _owner )
852 this.el = new Gtk.TreeStore( 3, typeof(string),typeof(string),typeof(Object) );
855 this.template_select = null;
856 this.activePath = "";
858 // set gobject values
862 print("model initialized");
865 // user defined functions
866 public string findDropNode (string treepath_str, string[] targets) {
868 // this is used by the dragdrop code in the roo version AFAIR..
870 //var path = treepath_str.replace(/^builder-/, '');
871 // treemap is depreciated... - should really check if model has any entries..
873 if (this.el.iter_n_children(null) < 1) {
875 return "|%d".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
877 //print("FIND treepath: " + path);
878 //console.dump(this.treemap);
880 //if (!treepath_str.match(/^builder-/)) {
881 // return []; // nothing!
883 if (targets.length > 0 && targets[0] == "*") {
886 return this.findDropNodeByPath(treepath_str,targets, -1);
888 public void loadFile (JsRender.JsRender f) {
893 _this.main_window.windowstate.file = f;
896 if (f.tree == null) {
903 // if it's still null?
904 if (f.tree == null) {
908 var o = new Gee.ArrayList<JsRender.Node>();
912 _this.view.el.expand_all();
914 if (f.tree.items.size < 1) {
917 //this.get('/Window.leftvpaned').el.set_position(80);
919 _this.view.el.set_cursor(
920 new Gtk.TreePath.from_string("0"), null, false);
924 //this.get('/Window.leftvpaned').el.set_position(200);
931 public void updateSelected () {
934 var s = _this.view.el.get_selection();
941 if (!s.get_selected(out mod, out iter)) {
942 return; // nothing seleted..
946 this.el.get_value(iter, 2, out value);
947 var node = (JsRender.Node)(value.get_object());
949 this.el.set(iter, 0, node.nodeTitle(),
950 1, node.nodeTip(), -1
953 public string findDropNodeByPath (string treepath_str, string[] targets, int in_pref = -1) {
955 var path = treepath_str; // dupe it..
958 // pref : 3 = ontop - 0 = after, 1 = before
959 int pref = in_pref < 0 ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : in_pref;
963 //console.dump(this.treemap);
965 print("findDropNodeByPath : got path length %d / %s\n", path.length, path);
967 if (path.length == 0) {
968 // top drop. // just return empty..
969 return "|%d".printf((int)pref) ;
974 while (path.length > 0) {
976 if (path.length == treepath_str.length && pref != Gtk.TreeViewDropPosition.INTO_OR_AFTER) {
977 if (path.last_index_of(":") < 0 ) {
980 path = path.substring(0, path.last_index_of(":"));
982 print("DROP before or after : using %s\n",path);
986 //print("LOOKING FOR PATH: " + path);
987 var node_data = this.pathToNode(path);
989 if (node_data == null) {
990 print("node not found");
994 var xname = node_data.fqn();
998 for (var i =0; i < targets.length; i++) {
1000 if ((tg == xname) ) {
1004 // if target is "xxxx:name"
1005 if (tg.contains(xname +":")) {
1007 var ar = tg.split(":");
1013 if (match.length > 0) {
1014 if (last.length > 0) { // pref is after/before..
1015 // then it's after last
1019 return last + "|%d".printf((int)pref) + "|" + prop;
1023 // we need to add prop - as :store -> needs to bee added when dropping onto.
1024 return path + "|%d".printf( (int) Gtk.TreeViewDropPosition.INTO_OR_AFTER) + "|" + prop;
1028 var par = path.split(":");
1029 string [] ppar = {};
1030 for (var i = 0; i < par.length-1; i++) {
1034 path = string.joinv(":", ppar);
1043 public void moveNode (string target_data, Gdk.DragAction action)
1046 /// target_data = "path|pos");
1049 //print("MOVE NODE");
1050 // console.dump(target_data);
1051 Gtk.TreeIter old_iter;
1054 var s = _this.view.el.get_selection();
1055 s.get_selected(out mod , out old_iter);
1056 mod.get_path(old_iter);
1058 var node = this.pathToNode(mod.get_path(old_iter).to_string());
1059 //console.dump(node);
1061 print("moveNode: ERROR - node is null?");
1066 // needs to drop first, otherwise the target_data
1067 // treepath will be invalid.
1070 if ((action & Gdk.DragAction.MOVE) > 0) {
1071 print("REMOVING OLD NODE : " + target_data + "\n");
1073 this.dropNode(target_data, node, false);
1074 this.el.remove(ref old_iter);
1079 print("DROPPING NODE // copy: " + target_data + "\n");
1080 node = node.deepClone();
1081 this.dropNode(target_data, node, false);
1084 this.activePath= "";
1085 //this.updateNode(false,true);
1087 public void load (Gee.ArrayList<JsRender.Node> tr, Gtk.TreeIter? iter)
1090 //this.insert(citer,iter,0);
1091 for(var i =0 ; i < tr.size; i++) {
1093 this.el.insert(out citer,iter,-1); // why not append?
1095 this.el.append(out citer,null);
1098 this.el.set(citer, 0, tr.get(i).nodeTitle(),
1099 1, tr.get(i).nodeTip(), -1
1101 var o = GLib.Value(typeof(Object));
1102 o.set_object((Object)tr.get(i));
1104 this.el.set_value(citer, 2, o);
1106 if (tr.get(i).items.size > 0) {
1107 this.load(tr.get(i).items, citer);
1114 public void deleteSelected () {
1116 print("DELETE SELECTED?");
1117 //_this.view.blockChanges = true;
1118 print("GET SELECTION?");
1120 var s = _this.view.el.get_selection();
1122 print("GET SELECTED?");
1127 if (!s.get_selected(out mod, out iter)) {
1128 return; // nothing seleted..
1133 this.activePath= "";
1134 print("GET vnode value?");
1137 this.el.get_value(iter, 2, out value);
1138 var data = (JsRender.Node)(value.get_object());
1139 print("removing node from Render\n");
1140 if (data.parent == null) {
1141 _this.main_window.windowstate.file.tree = null;
1145 print("removing node from Tree\n");
1147 this.el.remove(ref iter);
1157 this.activePath= ""; // again!?!?
1158 //this.changed(null,true);
1162 _this.view.blockChanges = false;
1164 public JsRender.Node pathToNode (string path) {
1168 _this.model.el.get_iter_from_string(out iter, path);
1171 _this.model.el.get_value(iter, 2, out value);
1173 return (JsRender.Node)value.dup_object();
1176 public void dropNode (string target_data_str, JsRender.Node node, bool show_templates) {
1177 // print("drop Node");
1178 // console.dump(node);
1179 // console.dump(target_data);
1182 // 0 = before , 1=after 2/3 onto
1185 var target_data= target_data_str.split("|");
1187 var parent_str = target_data[0].length > 0 ? target_data[0] : "";
1188 var pos = target_data.length > 1 ? int.parse(target_data[1]) : 2; // ontop..
1191 Gtk.TreePath tree_path = parent_str.length > 0 ? new Gtk.TreePath.from_string( parent_str ) : null;
1195 //print("add " + tp + "@" + target_data[1] );
1197 JsRender.Node parentNode = null;
1199 Gtk.TreeIter iter_after;
1200 Gtk.TreeIter iter_par ;
1203 if (target_data.length == 3 && target_data[2].length > 0) {
1204 node.props.set("* prop", target_data[2]);
1207 Gtk.TreePath expand_parent = null;
1209 // we only need to show the template if it's come from else where?
1210 if (show_templates) {
1212 var ts = _this.main_window.windowstate.template_select;
1214 var new_node = ts.show(
1215 _this.main_window, // (Gtk.Window) _this.el.get_toplevel (),
1216 _this.main_window.windowstate.file.palete(),
1218 _this.main_window.windowstate.project);
1220 if (new_node == null) {
1221 return; // do not add?
1226 //print("pos is %d \n".printf(pos));
1228 Gtk.TreeIter n_iter;
1230 if ( parent_str.length < 1) {
1231 this.el.append(out n_iter, null); // drop at top level..
1233 _this.main_window.windowstate.file.tree = node;
1236 } else if (pos < 2) {
1237 //print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
1239 this.el.get_iter(out iter_after, tree_path );
1240 this.el.iter_parent(out iter_par, iter_after);
1241 expand_parent = this.el.get_path(iter_par);
1244 this.el.get_value( iter_par, 2, out value);
1245 parentNode = (JsRender.Node)value.dup_object();
1248 this.el.get_value( iter_after, 2, out value);
1249 var relNode = (JsRender.Node)value.dup_object();
1253 this.el.insert_after(out n_iter, iter_par , iter_after);
1254 var ix = parentNode.items.index_of(relNode);
1255 parentNode.items.insert(ix+1, node);
1258 this.el.insert_before(out n_iter, iter_par , iter_after);
1259 var ix = parentNode.items.index_of(relNode);
1260 parentNode.items.insert(ix, node);
1263 node.parent = parentNode;
1268 // print("appending to " + parent_str);
1269 this.el.get_iter(out iter_par, tree_path);
1270 this.el.append(out n_iter, iter_par );
1271 expand_parent = this.el.get_path(iter_par);
1274 this.el.get_value( iter_par, 2, out value);
1275 parentNode = (JsRender.Node)value.dup_object();
1276 node.parent = parentNode;
1277 parentNode.items.add(node);
1280 // reparent node in tree...
1283 // why only on no parent???
1285 //if (node.parent = null) {
1292 // work out what kind of packing to use.. -- should be in
1293 if (!node.has("pack") && parent_str.length > 1) {
1295 _this.main_window.windowstate.file.palete().fillPack(node,parentNode);
1302 this.el.set(n_iter, 0, node.nodeTitle(), 1, node.nodeTip(), -1 );
1303 var o = GLib.Value(typeof(Object));
1304 o.set_object((Object)node);
1306 this.el.set_value(n_iter, 2, o);
1311 // load children - if it has any..
1313 if (node.items.size > 0) {
1314 this.load(node.items, n_iter);
1315 _this.view.el.expand_row(this.el.get_path(n_iter), true);
1316 } else if (expand_parent != null && !_this.view.el.is_row_expanded(expand_parent)) {
1317 _this.view.el.expand_row(expand_parent,true);
1320 //if (tp != null && (node.items.length() > 0 || pos > 1)) {
1321 // _this.view.el.expand_row(this.el.get_path(iter_par), true);
1323 // wee need to get the empty proptypes from somewhere..
1325 //var olditer = this.activeIter;
1326 this.activePath = this.el.get_path(n_iter).to_string();
1331 _this.view.el.set_cursor(this.el.get_path(n_iter), null, false);
1337 public string treePathFromNode (JsRender.Node node) {
1338 // iterate through the tree and find the node
1341 this.el.foreach((mod, pth, iter) => {
1346 _this.model.el.get_value(iter, 2, out value);
1350 var n = (JsRender.Node)value;
1352 print("compare %s to %s\n", n.fqn(), node.fqn());
1354 ret = pth.to_string();
1364 public class Xcls_TreeViewColumn4 : Object
1366 public Gtk.TreeViewColumn el;
1367 private Xcls_WindowLeftTree _this;
1373 public Xcls_TreeViewColumn4(Xcls_WindowLeftTree _owner )
1376 this.el = new Gtk.TreeViewColumn();
1380 // set gobject values
1381 this.el.title = "test";
1382 var child_0 = new Xcls_renderer( _this );
1384 this.el.pack_start ( child_0.el , true );
1388 this.el.add_attribute(_this.renderer.el , "markup", 0 );
1391 // user defined functions
1393 public class Xcls_renderer : Object
1395 public Gtk.CellRendererText el;
1396 private Xcls_WindowLeftTree _this;
1402 public Xcls_renderer(Xcls_WindowLeftTree _owner )
1405 _this.renderer = this;
1406 this.el = new Gtk.CellRendererText();
1410 // set gobject values
1413 // user defined functions
1418 public class Xcls_LeftTreeMenu : Object
1421 private Xcls_WindowLeftTree _this;
1427 public Xcls_LeftTreeMenu(Xcls_WindowLeftTree _owner )
1430 _this.LeftTreeMenu = this;
1431 this.el = new Gtk.Menu();
1435 // set gobject values
1436 var child_0 = new Xcls_MenuItem7( _this );
1438 this.el.add ( child_0.el );
1439 var child_1 = new Xcls_MenuItem8( _this );
1441 this.el.add ( child_1.el );
1442 var child_2 = new Xcls_MenuItem9( _this );
1444 this.el.add ( child_2.el );
1447 // user defined functions
1449 public class Xcls_MenuItem7 : Object
1451 public Gtk.MenuItem el;
1452 private Xcls_WindowLeftTree _this;
1458 public Xcls_MenuItem7(Xcls_WindowLeftTree _owner )
1461 this.el = new Gtk.MenuItem();
1465 // set gobject values
1466 this.el.label = "Delete Element";
1469 this.el.activate.connect( ( ) => {
1474 _this.model.deleteSelected();
1478 // user defined functions
1481 public class Xcls_MenuItem8 : Object
1483 public Gtk.MenuItem el;
1484 private Xcls_WindowLeftTree _this;
1490 public Xcls_MenuItem8(Xcls_WindowLeftTree _owner )
1493 this.el = new Gtk.MenuItem();
1497 // set gobject values
1498 this.el.label = "Save as Template";
1501 this.el.activate.connect( () => {
1503 DialogSaveTemplate.singleton().show(
1504 (Gtk.Window) _this.el.get_toplevel (),
1505 _this.main_window.windowstate.file.palete(),
1506 _this.getActiveElement()
1513 // user defined functions
1516 public class Xcls_MenuItem9 : Object
1518 public Gtk.MenuItem el;
1519 private Xcls_WindowLeftTree _this;
1525 public Xcls_MenuItem9(Xcls_WindowLeftTree _owner )
1528 this.el = new Gtk.MenuItem();
1532 // set gobject values
1533 this.el.label = "Save as Module";
1536 this.el.activate.connect( () => {
1537 var node = _this.getActiveElement();
1538 var name = DialogSaveModule.singleton().show(
1539 (Gtk.Window) _this.el.get_toplevel (),
1540 _this.main_window.windowstate.project,
1543 if (name.length < 1) {
1547 node.props.set("* xinclude", name);
1551 var s = _this.view.el.get_selection();
1553 print("GET SELECTED?");
1558 if (!s.get_selected(out mod, out iter)) {
1559 return; // nothing seleted..
1562 var n_cn = mod.iter_n_children(iter) -1;
1563 for (var i = n_cn; i > -1; i--) {
1564 mod.iter_nth_child(out citer, iter, i);
1567 print("removing node from Tree\n");
1569 _this.model.el.remove(ref citer);
1572 _this.node_selected(node, "tree");
1578 // user defined functions