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;
81 public string[] dropList;
83 public string lastEventSource;
84 public bool drag_in_motion;
85 public bool blockChanges;
88 public Xcls_view(Xcls_WindowLeftTree _owner )
92 this.el = new Gtk.TreeView();
95 this.lastEventSource = "";
96 this.blockChanges = false;
99 this.el.expand = true;
100 this.el.tooltip_column = 1;
101 this.el.enable_tree_lines = true;
102 this.el.headers_visible = false;
103 var child_0 = new Xcls_model( _this );
105 this.el.set_model ( child_0.el );
106 var child_1 = new Xcls_TreeViewColumn4( _this );
108 this.el.append_column ( child_1.el );
113 var description = new Pango.FontDescription();
114 description.set_size(8000);
115 this.el.override_font(description);
117 var selection = this.el.get_selection();
118 selection.set_mode( Gtk.SelectionMode.SINGLE);
121 // is this really needed??
123 this.selection.signal['changed'].connect(function() {
124 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
125 _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
129 Gtk.drag_source_set (
130 this.el, /* widget will be drag-able */
131 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
132 BuilderApplication.targetList, /* lists of target to support */
133 Gdk.DragAction.COPY | Gdk.DragAction.MOVE | Gdk.DragAction.LINK /* what to do with data after dropped */
137 //Gtk.drag_source_add_text_targets(this.el);
141 this.el, /* widget that will accept a drop */
142 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
143 BuilderApplication.targetList, /* lists of target to support */
144 Gdk.DragAction.COPY | Gdk.DragAction.MOVE | Gdk.DragAction.LINK /* what to do with data after dropped */
147 //Gtk.drag_dest_set_target_list(this.el, Builder.Application.targetList);
148 //Gtk.drag_dest_add_text_targets(this.el);
152 this.el.button_press_event.connect( ( ev) => {
153 //console.log("button press?");
154 this.lastEventSource = "tree";
155 if (! _this.before_node_change(null) ) {
161 if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button != 3) {
162 //print("click" + ev.type);
166 if (!_this.view.el.get_path_at_pos((int)ev.x,(int)ev.y, out res, null, null, null) ) {
170 this.el.get_selection().select_path(res);
172 //if (!this.get('/LeftTreeMenu').el) {
173 // this.get('/LeftTreeMenu').init();
176 _this.LeftTreeMenu.el.set_screen(Gdk.Screen.get_default());
177 _this.LeftTreeMenu.el.show_all();
178 _this.LeftTreeMenu.el.popup(null, null, null, 3, ev.time);
179 // print("click:" + res.path.to_string());
182 this.el.drag_begin.connect( ( ctx) => {
183 //print('SOURCE: drag-begin');
186 //this.targetData = "";
188 // find what is selected in our tree...
190 var s = _this.view.el.get_selection();
191 if (s.count_selected_rows() < 1) {
196 s.get_selected(out mod, out iter);
200 // set some properties of the tree for use by the dropped element.
202 _this.model.el.get_value(iter, 2, out value);
203 var tp = mod.get_path(iter).to_string();
204 var data = (JsRender.Node)(value.dup_object());
205 var xname = data.fqn();
206 print ("XNAME IS " + xname+ "\n");
208 this.dropList = _this.main_window.windowstate.file.palete().getDropList(xname);
210 print ("DROP LIST IS " + string.joinv(", ", this.dropList) + "\n");
213 // make the drag icon a picture of the node that was selected
216 // by default returns the path..
217 var path = _this.model.el.get_path(iter);
220 var pix = this.el.create_row_drag_icon ( path);
222 Gtk.drag_set_icon_surface (ctx, pix) ;
226 this.el.cursor_changed.connect( ( ) => {
229 if (this.blockChanges) { // probably not needed..
232 if (!_this.before_node_change(null) ) {
233 this.blockChanges = true;
234 this.el.get_selection().unselect_all();
235 this.blockChanges = false;
238 if (_this.main_window.windowstate.file == null) {
242 //var render = this.get('/LeftTree').getRenderer();
243 print("LEFT TREE -> view -> selection changed called\n");
246 // -- it appears that the selection is not updated.
248 GLib.Timeout.add_full(GLib.Priority.DEFAULT,10 , () => {
251 if (this.el.get_selection().count_selected_rows() < 1) {
253 print("selected rows < 1\n");
254 //??this.model.load( false);
255 _this.node_selected(null, this.lastEventSource);
260 //console.log('changed');
261 var s = this.el.get_selection();
264 s.get_selected(out mod, out iter);
269 _this.model.el.get_value(iter, 2, out value);
270 _this.model.activePath = mod.get_path(iter).to_string();
272 var node = (JsRender.Node)value.dup_object();
273 _this.node_selected(node, this.lastEventSource);
274 while (Gtk.events_pending()) {
275 Gtk.main_iteration();
277 var cp = mod.get_path(iter);
279 this.el.get_visible_range(out sp, out ep);
280 // if sp is before cp then retuns 1.
281 // if cp is before ep then retuns 1.
282 if (cp.compare(sp) >= 0 && ep.compare(cp) >=1) {
288 this.el.scroll_to_cell(new Gtk.TreePath.from_string(_this.model.activePath), null, true, 0.1f,0.0f);
292 //_this.after_node_change(node);
294 // _this.model.file.changed(node, "tree");
296 //Seed.print( value.get_string());
300 this.el.drag_end.connect( (drag_context) => {
301 //Seed.print('LEFT-TREE: drag-end');
303 this.dropList = null;
304 // this.targetData = "";
305 this.highlightDropPath("",0);
308 this.el.drag_motion.connect( ( ctx, x, y, time) => {
309 print("got drag motion\n");
310 var src = Gtk.drag_get_source_widget(ctx);
314 if (src != this.el) {
318 // the point of this is to detect where an item could be dropped..
319 print("requesting drag data\n");
320 this.drag_in_motion = true;
322 // request data that will be recieved by the recieve...
325 this.el, // will receive 'drag-data-received' signal
326 ctx, // represents the current state of the DnD
327 Gdk.Atom.intern("STRING",true), // the target type we want
334 print("action: %d\n", ctx.get_actions());
335 //print("GETTING POS");
339 Gtk.TreeViewDropPosition pos;
340 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
342 // if there are not items in the tree.. the we have to set isOver to true for anything..
344 if (_this.model.el.iter_n_children(null) < 1) {
345 print("got NO children?\n");
348 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
352 // ------------- a drag from self..
355 //var action = Gdk.DragAction.COPY;
356 // unless we are copying!!! ctl button..
358 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
359 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
360 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
363 if (_this.model.el.iter_n_children(null) < 1) {
364 // no children.. -- asume it's ok..
366 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
368 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
369 Gdk.drag_status(ctx, action ,time);
372 // continue through to allow drop...
380 //print("ISOVER? " + isOver);
383 Gdk.drag_status(ctx, 0 ,time);
384 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
389 // drag node is parent of child..
390 //console.log("SRC TREEPATH: " + src.treepath);
391 //console.log("TARGET TREEPATH: " + data.path.to_string());
393 // nned to check a few here..
394 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
395 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
396 //Gtk.TreeViewDropPosition.AFTER
397 //Gtk.TreeViewDropPosition.BEFORE
399 // locally dragged items to not really use the
400 var selection_text = this.dragData;
404 if (selection_text == null || selection_text.length < 1) {
405 //print("Error - drag selection text returned NULL");
406 Gdk.drag_status(ctx, 0 ,time);
407 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
412 // see if we are dragging into ourself?
413 var target_path = path.to_string();
414 print ("Drag %s onto %s--%d\n ", selection_text, target_path, pos);
416 // pos : 3 = ontop - 0 = after, 1 = before
417 //print("target_path="+target_path);
420 if (selection_text == target_path) {
421 print("self drag ?? == we should perhaps allow copy onto self..\n");
423 Gdk.drag_status(ctx, 0 ,time);
424 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
426 // -- fixme -- this is not really correct..
431 //print("DUMPING DATA");
432 //console.dump(data);
435 //print(data.path.to_string() +' => '+ data.pos);
437 // dropList is a list of xtypes that this node could be dropped on.
438 // it is set up when we start to drag..
441 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
443 print("targetDAta: " + targetData +"\n");
445 if (targetData.length < 1) {
446 //print("Can not find drop node path");
448 Gdk.drag_status(ctx, 0, time);
449 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
453 var td_ar = targetData.split("|");
457 Gdk.drag_status(ctx, action ,time);
458 this.highlightDropPath(td_ar[0], (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
463 this.el.drag_data_get.connect( ( drag_context, data, info, time) => {
466 //print("drag-data-get");
467 var s = this.el.get_selection();
468 if (s.count_selected_rows() < 1) {
470 print("return empty string - no selection..");
477 s.get_selected(out mod, out iter);
482 _this.model.el.get_value(iter, 2, out value);
483 var ndata = (JsRender.Node)(value.dup_object());
487 var tp = mod.get_path(iter).to_string();
488 // by default returns the path..
490 if ( info != Gdk.Atom.intern("STRING",true) ) {
491 tp = ndata.toJsonString();
494 //data.set_text(tp,tp.length);
496 data.set (data.get_target (), 8, (uchar[]) tp.to_utf8 ());
499 // print("return " + tp);
501 this.el.drag_data_received.connect( (ctx, x, y, sel, info, time) => {
503 // THIS CODE ONLY RELATES TO drag or drop of "NEW" elements or "FROM another tree.."
506 // print("Tree: drag-data-received\n");
507 var selection_text = (string)sel.get_data();
508 //print("selection_text= %s\n",selection_text);
510 var is_drag = this.drag_in_motion;
514 print("Is Drag %s\n", is_drag ? "Y": "N");
518 Gtk.TreeViewDropPosition pos;
519 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
521 // if there are not items in the tree.. the we have to set isOver to true for anything..
523 if (_this.model.el.iter_n_children(null) < 1) {
524 print("got NO children?\n");
527 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
531 //console.log("LEFT-TREE: drag-motion");
532 var src = Gtk.drag_get_source_widget(ctx);
534 // a drag from self - this should be handled by drop and motion.
535 if (src == this.el) {
536 print("Source == this element should not happen.. ? \n");
539 //print("drag_data_recieved from another element");
544 if (selection_text == null || selection_text.length < 1 || !isOver) {
545 // nothing valid foudn to drop...
546 print("empty sel text or not over");
548 Gdk.drag_status(ctx, 0, time);
549 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
552 Gtk.drag_finish (ctx, false, false, time); // drop failed..
557 var dropNode = new JsRender.Node();
559 var dropNodeType = selection_text;
560 var show_templates = true;
562 if (dropNodeType[0] == '{') {
563 var pa = new Json.Parser();
565 pa.load_from_data(dropNodeType);
567 Gtk.drag_finish (ctx, false, false, time); // drop failed..
572 dropNode.loadFromJson( pa.get_root().get_object(), 2);
573 dropNodeType = dropNode.fqn();
574 show_templates = false;
579 dropNode.setFqn(selection_text);
583 // dropList --- need to gather this ...
584 print("get dropList for : %s\n",dropNodeType);
585 var dropList = _this.main_window.windowstate.file.palete().getDropList(dropNodeType);
587 print("dropList: %s\n", string.joinv(" , ", dropList));
589 // if drag action is link ... then we can drop it anywahere...
590 if ((ctx.get_actions() & Gdk.DragAction.LINK) > 0) {
591 // if path is null?? dragging into an empty tree?
592 targetData = (path == null ? "" : path.to_string()) + "|%d".printf((int)pos);
596 targetData = _this.model.findDropNodeByPath( isEmpty ? "" : path.to_string(), dropList, pos);
601 print("targetDAta: " + targetData +"\n");
603 if (targetData.length < 1) {
605 // invalid drop path..
606 if (this.drag_in_motion) {
607 Gdk.drag_status(ctx, 0, time);
608 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
611 Gtk.drag_finish (ctx, false, false, time); // drop failed..
617 var td_ar = targetData.split("|");
620 if (this.drag_in_motion) {
621 Gdk.drag_status(ctx, Gdk.DragAction.COPY ,time);
623 this.highlightDropPath( td_ar[0] , (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
626 // continue on to allow drop..
629 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
632 _this.model.dropNode(targetData, dropNode, show_templates);
633 print("ADD new node!!!\n");
635 ///Xcls_DialogTemplateSelect.singleton().show( _this.model.file.palete(), node);
637 Gtk.drag_finish (ctx, false, false,time);
644 this.el.drag_drop.connect( ( ctx, x, y, time) => {
645 //Seed.print("TARGET: drag-drop");
648 var src = Gtk.drag_get_source_widget(ctx);
650 if (src != this.el) {
654 this.drag_in_motion = false;
655 // request data that will be recieved by the recieve...
658 this.el, // will receive 'drag-data-received' signal
659 ctx, // represents the current state of the DnD
660 Gdk.Atom.intern("application/json",true), // the target type we want
665 // No target offered by source => error
671 // handle drop around self..
675 //print("GETTING POS");
679 Gtk.TreeViewDropPosition pos;
680 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
682 // if there are not items in the tree.. the we have to set isOver to true for anything..
684 if (_this.model.el.iter_n_children(null) < 1) {
685 print("got NO children?\n");
688 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
693 //var action = Gdk.DragAction.COPY;
694 // unless we are copying!!! ctl button..
696 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
697 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
698 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
701 if (_this.model.el.iter_n_children(null) < 1) {
702 // no children.. -- asume it's ok..
704 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
706 // continue through to allow drop...
714 //print("ISOVER? " + isOver);
717 Gtk.drag_finish (ctx, false, false, time); // drop failed..
718 return true; // not over apoint!?! - no action on drop or motion..
721 // drag node is parent of child..
722 //console.log("SRC TREEPATH: " + src.treepath);
723 //console.log("TARGET TREEPATH: " + data.path.to_string());
725 // nned to check a few here..
726 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
727 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
728 //Gtk.TreeViewDropPosition.AFTER
729 //Gtk.TreeViewDropPosition.BEFORE
731 // locally dragged items to not really use the
732 var selection_text = this.dragData;
736 if (selection_text == null || selection_text.length < 1) {
737 //print("Error - drag selection text returned NULL");
739 Gtk.drag_finish (ctx, false, false, time); // drop failed..
740 return true; /// -- fixme -- this is not really correct..
743 // see if we are dragging into ourself?
744 print ("got selection text of " + selection_text);
746 var target_path = path.to_string();
747 //print("target_path="+target_path);
750 if (selection_text == target_path) {
751 print("self drag ?? == we should perhaps allow copy onto self..\n");
753 Gtk.drag_finish (ctx, false, false, time); // drop failed..
755 return true; /// -- fixme -- this is not really correct..
760 //print("DUMPING DATA");
761 //console.dump(data);
764 //print(data.path.to_string() +' => '+ data.pos);
766 // dropList is a list of xtypes that this node could be dropped on.
767 // it is set up when we start to drag..
770 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
772 print("targetDAta: " + targetData +"\n");
774 if (targetData.length < 1) {
775 //print("Can not find drop node path");
777 Gtk.drag_finish (ctx, false, false, time); // drop failed..
783 // continue on to allow drop..
785 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
788 var delete_selection_data = false;
790 if (action == Gdk.DragAction.ASK) {
791 /* Ask the user to move or copy, then set the ctx action. */
794 if (action == Gdk.DragAction.MOVE) {
795 delete_selection_data = true;
798 // drag around.. - reorder..
799 _this.model.moveNode(targetData, action);
805 // we can send stuff to souce here...
808 // do we always say failure, so we handle the reall drop?
809 Gtk.drag_finish (ctx, false, false,time); //delete_selection_data, time);
821 // user defined functions
822 public void highlightDropPath ( string treepath, Gtk.TreeViewDropPosition pos) {
824 // highlighting for drag/drop
825 if (treepath.length > 0) {
826 this.el.set_drag_dest_row( new Gtk.TreePath.from_string( treepath ), pos);
828 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
832 public void setCursor (string treepath, string sourceEvent) {
833 this.lastEventSource = sourceEvent;
834 this.blockChanges = true;
835 this.el.set_cursor(new Gtk.TreePath.from_string(treepath), null, false);
836 this.blockChanges = true;
837 this.lastEventSource = "";
839 public void selectNode (string treepath_str, string source) {
840 this.lastEventSource = source;
841 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
842 var tp = new Gtk.TreePath.from_string(treepath_str);
844 this.el.set_cursor(tp, null, false);
845 this.el.scroll_to_cell(tp, null, false, 0,0);
848 public class Xcls_model : Object
850 public Gtk.TreeStore el;
851 private Xcls_WindowLeftTree _this;
855 public DialogTemplateSelect template_select;
856 public string activePath;
859 public Xcls_model(Xcls_WindowLeftTree _owner )
863 this.el = new Gtk.TreeStore( 3, typeof(string),typeof(string),typeof(Object) );
866 this.template_select = null;
867 this.activePath = "";
869 // set gobject values
873 print("model initialized");
876 // user defined functions
877 public string findDropNode (string treepath_str, string[] targets) {
879 // this is used by the dragdrop code in the roo version AFAIR..
881 //var path = treepath_str.replace(/^builder-/, '');
882 // treemap is depreciated... - should really check if model has any entries..
884 if (this.el.iter_n_children(null) < 1) {
886 return "|%d".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
888 //print("FIND treepath: " + path);
889 //console.dump(this.treemap);
891 //if (!treepath_str.match(/^builder-/)) {
892 // return []; // nothing!
894 if (targets.length > 0 && targets[0] == "*") {
897 return this.findDropNodeByPath(treepath_str,targets, -1);
899 public void loadFile (JsRender.JsRender f) {
904 _this.main_window.windowstate.file = f;
907 if (f.tree == null) {
914 // if it's still null?
915 if (f.tree == null) {
919 var o = new Gee.ArrayList<JsRender.Node>();
923 _this.view.el.expand_all();
925 if (f.tree.items.size < 1) {
928 //this.get('/Window.leftvpaned').el.set_position(80);
930 _this.view.el.set_cursor(
931 new Gtk.TreePath.from_string("0"), null, false);
935 //this.get('/Window.leftvpaned').el.set_position(200);
942 public void updateSelected () {
945 var s = _this.view.el.get_selection();
952 if (!s.get_selected(out mod, out iter)) {
953 return; // nothing seleted..
957 this.el.get_value(iter, 2, out value);
958 var node = (JsRender.Node)(value.get_object());
960 this.el.set(iter, 0, node.nodeTitle(),
961 1, node.nodeTip(), -1
964 public string findDropNodeByPath (string treepath_str, string[] targets, int in_pref = -1) {
966 var path = treepath_str; // dupe it..
969 // pref : 3 = ontop - 0 = after, 1 = before
970 int pref = in_pref < 0 ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : in_pref;
974 //console.dump(this.treemap);
976 print("findDropNodeByPath : got path length %d / %s\n", path.length, path);
978 if (path.length == 0) {
979 // top drop. // just return empty..
980 return "|%d".printf((int)pref) ;
985 while (path.length > 0) {
987 if (path.length == treepath_str.length && pref != Gtk.TreeViewDropPosition.INTO_OR_AFTER) {
988 if (path.last_index_of(":") < 0 ) {
991 path = path.substring(0, path.last_index_of(":"));
993 print("DROP before or after : using %s\n",path);
997 //print("LOOKING FOR PATH: " + path);
998 var node_data = this.pathToNode(path);
1000 if (node_data == null) {
1001 print("node not found");
1005 var xname = node_data.fqn();
1009 for (var i =0; i < targets.length; i++) {
1010 var tg = targets[i];
1011 if ((tg == xname) ) {
1015 // if target is "xxxx:name"
1016 if (tg.contains(xname +":")) {
1018 var ar = tg.split(":");
1024 if (match.length > 0) {
1025 if (last.length > 0) { // pref is after/before..
1026 // then it's after last
1030 return last + "|%d".printf((int)pref) + "|" + prop;
1034 // we need to add prop - as :store -> needs to bee added when dropping onto.
1035 return path + "|%d".printf( (int) Gtk.TreeViewDropPosition.INTO_OR_AFTER) + "|" + prop;
1039 var par = path.split(":");
1040 string [] ppar = {};
1041 for (var i = 0; i < par.length-1; i++) {
1045 path = string.joinv(":", ppar);
1054 public void moveNode (string target_data, Gdk.DragAction action)
1057 /// target_data = "path|pos");
1060 //print("MOVE NODE");
1061 // console.dump(target_data);
1062 Gtk.TreeIter old_iter;
1065 var s = _this.view.el.get_selection();
1066 s.get_selected(out mod , out old_iter);
1067 mod.get_path(old_iter);
1069 var node = this.pathToNode(mod.get_path(old_iter).to_string());
1070 //console.dump(node);
1072 print("moveNode: ERROR - node is null?");
1077 // needs to drop first, otherwise the target_data
1078 // treepath will be invalid.
1081 if ((action & Gdk.DragAction.MOVE) > 0) {
1082 print("REMOVING OLD NODE : " + target_data + "\n");
1084 this.dropNode(target_data, node, false);
1085 this.el.remove(ref old_iter);
1090 print("DROPPING NODE // copy: " + target_data + "\n");
1091 node = node.deepClone();
1092 this.dropNode(target_data, node, false);
1095 this.activePath= "";
1096 //this.updateNode(false,true);
1098 public void load (Gee.ArrayList<JsRender.Node> tr, Gtk.TreeIter? iter)
1101 //this.insert(citer,iter,0);
1102 for(var i =0 ; i < tr.size; i++) {
1104 this.el.insert(out citer,iter,-1); // why not append?
1106 this.el.append(out citer,null);
1109 this.el.set(citer, 0, tr.get(i).nodeTitle(),
1110 1, tr.get(i).nodeTip(), -1
1112 var o = GLib.Value(typeof(Object));
1113 o.set_object((Object)tr.get(i));
1115 this.el.set_value(citer, 2, o);
1117 if (tr.get(i).items.size > 0) {
1118 this.load(tr.get(i).items, citer);
1125 public void deleteSelected () {
1127 print("DELETE SELECTED?");
1128 //_this.view.blockChanges = true;
1129 print("GET SELECTION?");
1131 var s = _this.view.el.get_selection();
1133 print("GET SELECTED?");
1138 if (!s.get_selected(out mod, out iter)) {
1139 return; // nothing seleted..
1144 this.activePath= "";
1145 print("GET vnode value?");
1148 this.el.get_value(iter, 2, out value);
1149 var data = (JsRender.Node)(value.get_object());
1150 print("removing node from Render\n");
1151 if (data.parent == null) {
1152 _this.main_window.windowstate.file.tree = null;
1156 print("removing node from Tree\n");
1158 this.el.remove(ref iter);
1168 this.activePath= ""; // again!?!?
1169 //this.changed(null,true);
1173 _this.view.blockChanges = false;
1175 public JsRender.Node pathToNode (string path) {
1179 _this.model.el.get_iter_from_string(out iter, path);
1182 _this.model.el.get_value(iter, 2, out value);
1184 return (JsRender.Node)value.dup_object();
1187 public void dropNode (string target_data_str, JsRender.Node node, bool show_templates) {
1188 // print("drop Node");
1189 // console.dump(node);
1190 // console.dump(target_data);
1193 // 0 = before , 1=after 2/3 onto
1196 var target_data= target_data_str.split("|");
1198 var parent_str = target_data[0].length > 0 ? target_data[0] : "";
1199 var pos = target_data.length > 1 ? int.parse(target_data[1]) : 2; // ontop..
1202 Gtk.TreePath tree_path = parent_str.length > 0 ? new Gtk.TreePath.from_string( parent_str ) : null;
1206 //print("add " + tp + "@" + target_data[1] );
1208 JsRender.Node parentNode = null;
1210 Gtk.TreeIter iter_after;
1211 Gtk.TreeIter iter_par ;
1214 if (target_data.length == 3 && target_data[2].length > 0) {
1215 node.props.set("* prop", target_data[2]);
1218 Gtk.TreePath expand_parent = null;
1220 // we only need to show the template if it's come from else where?
1221 if (show_templates) {
1223 var ts = _this.main_window.windowstate.template_select;
1225 var new_node = ts.show(
1226 _this.main_window, // (Gtk.Window) _this.el.get_toplevel (),
1227 _this.main_window.windowstate.file.palete(),
1229 _this.main_window.windowstate.project);
1231 if (new_node == null) {
1232 return; // do not add?
1237 //print("pos is %d \n".printf(pos));
1239 Gtk.TreeIter n_iter;
1241 if ( parent_str.length < 1) {
1242 this.el.append(out n_iter, null); // drop at top level..
1244 _this.main_window.windowstate.file.tree = node;
1247 } else if (pos < 2) {
1248 //print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
1250 this.el.get_iter(out iter_after, tree_path );
1251 this.el.iter_parent(out iter_par, iter_after);
1252 expand_parent = this.el.get_path(iter_par);
1255 this.el.get_value( iter_par, 2, out value);
1256 parentNode = (JsRender.Node)value.dup_object();
1259 this.el.get_value( iter_after, 2, out value);
1260 var relNode = (JsRender.Node)value.dup_object();
1264 this.el.insert_after(out n_iter, iter_par , iter_after);
1265 var ix = parentNode.items.index_of(relNode);
1266 parentNode.items.insert(ix+1, node);
1269 this.el.insert_before(out n_iter, iter_par , iter_after);
1270 var ix = parentNode.items.index_of(relNode);
1271 parentNode.items.insert(ix, node);
1274 node.parent = parentNode;
1279 // print("appending to " + parent_str);
1280 this.el.get_iter(out iter_par, tree_path);
1281 this.el.append(out n_iter, iter_par );
1282 expand_parent = this.el.get_path(iter_par);
1285 this.el.get_value( iter_par, 2, out value);
1286 parentNode = (JsRender.Node)value.dup_object();
1287 node.parent = parentNode;
1288 parentNode.items.add(node);
1291 // reparent node in tree...
1294 // why only on no parent???
1296 //if (node.parent = null) {
1303 // work out what kind of packing to use.. -- should be in
1304 if (!node.has("pack") && parent_str.length > 1) {
1306 _this.main_window.windowstate.file.palete().fillPack(node,parentNode);
1313 this.el.set(n_iter, 0, node.nodeTitle(), 1, node.nodeTip(), -1 );
1314 var o = GLib.Value(typeof(Object));
1315 o.set_object((Object)node);
1317 this.el.set_value(n_iter, 2, o);
1322 // load children - if it has any..
1324 if (node.items.size > 0) {
1325 this.load(node.items, n_iter);
1326 _this.view.el.expand_row(this.el.get_path(n_iter), true);
1327 } else if (expand_parent != null && !_this.view.el.is_row_expanded(expand_parent)) {
1328 _this.view.el.expand_row(expand_parent,true);
1331 //if (tp != null && (node.items.length() > 0 || pos > 1)) {
1332 // _this.view.el.expand_row(this.el.get_path(iter_par), true);
1334 // wee need to get the empty proptypes from somewhere..
1336 //var olditer = this.activeIter;
1337 this.activePath = this.el.get_path(n_iter).to_string();
1342 _this.view.el.set_cursor(this.el.get_path(n_iter), null, false);
1348 public string treePathFromNode (JsRender.Node node) {
1349 // iterate through the tree and find the node
1352 this.el.foreach((mod, pth, iter) => {
1357 _this.model.el.get_value(iter, 2, out value);
1361 var n = (JsRender.Node)value;
1363 print("compare %s to %s\n", n.fqn(), node.fqn());
1365 ret = pth.to_string();
1375 public class Xcls_TreeViewColumn4 : Object
1377 public Gtk.TreeViewColumn el;
1378 private Xcls_WindowLeftTree _this;
1384 public Xcls_TreeViewColumn4(Xcls_WindowLeftTree _owner )
1387 this.el = new Gtk.TreeViewColumn();
1391 // set gobject values
1392 this.el.title = "test";
1393 var child_0 = new Xcls_renderer( _this );
1395 this.el.pack_start ( child_0.el , true );
1399 this.el.add_attribute(_this.renderer.el , "markup", 0 );
1402 // user defined functions
1404 public class Xcls_renderer : Object
1406 public Gtk.CellRendererText el;
1407 private Xcls_WindowLeftTree _this;
1413 public Xcls_renderer(Xcls_WindowLeftTree _owner )
1416 _this.renderer = this;
1417 this.el = new Gtk.CellRendererText();
1421 // set gobject values
1424 // user defined functions
1429 public class Xcls_LeftTreeMenu : Object
1432 private Xcls_WindowLeftTree _this;
1438 public Xcls_LeftTreeMenu(Xcls_WindowLeftTree _owner )
1441 _this.LeftTreeMenu = this;
1442 this.el = new Gtk.Menu();
1446 // set gobject values
1447 var child_0 = new Xcls_MenuItem7( _this );
1449 this.el.add ( child_0.el );
1450 var child_1 = new Xcls_MenuItem8( _this );
1452 this.el.add ( child_1.el );
1453 var child_2 = new Xcls_MenuItem9( _this );
1455 this.el.add ( child_2.el );
1458 // user defined functions
1460 public class Xcls_MenuItem7 : Object
1462 public Gtk.MenuItem el;
1463 private Xcls_WindowLeftTree _this;
1469 public Xcls_MenuItem7(Xcls_WindowLeftTree _owner )
1472 this.el = new Gtk.MenuItem();
1476 // set gobject values
1477 this.el.label = "Delete Element";
1480 this.el.activate.connect( ( ) => {
1485 _this.model.deleteSelected();
1489 // user defined functions
1492 public class Xcls_MenuItem8 : Object
1494 public Gtk.MenuItem el;
1495 private Xcls_WindowLeftTree _this;
1501 public Xcls_MenuItem8(Xcls_WindowLeftTree _owner )
1504 this.el = new Gtk.MenuItem();
1508 // set gobject values
1509 this.el.label = "Save as Template";
1512 this.el.activate.connect( () => {
1514 DialogSaveTemplate.singleton().show(
1515 (Gtk.Window) _this.el.get_toplevel (),
1516 _this.main_window.windowstate.file.palete(),
1517 _this.getActiveElement()
1524 // user defined functions
1527 public class Xcls_MenuItem9 : Object
1529 public Gtk.MenuItem el;
1530 private Xcls_WindowLeftTree _this;
1536 public Xcls_MenuItem9(Xcls_WindowLeftTree _owner )
1539 this.el = new Gtk.MenuItem();
1543 // set gobject values
1544 this.el.label = "Save as Module";
1547 this.el.activate.connect( () => {
1548 var node = _this.getActiveElement();
1549 var name = DialogSaveModule.singleton().show(
1550 (Gtk.Window) _this.el.get_toplevel (),
1551 _this.main_window.windowstate.project,
1554 if (name.length < 1) {
1558 node.props.set("* xinclude", name);
1562 var s = _this.view.el.get_selection();
1564 print("GET SELECTED?");
1569 if (!s.get_selected(out mod, out iter)) {
1570 return; // nothing seleted..
1573 var n_cn = mod.iter_n_children(iter) -1;
1574 for (var i = n_cn; i > -1; i--) {
1575 mod.iter_nth_child(out citer, iter, i);
1578 print("removing node from Tree\n");
1580 _this.model.el.remove(ref citer);
1583 _this.node_selected(node, "tree");
1589 // user defined functions