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);
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.model.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 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.tooltip_column = 1;
98 this.el.enable_tree_lines = true;
99 this.el.headers_visible = false;
100 var child_0 = new Xcls_model( _this );
102 this.el.set_model ( child_0.el );
103 var child_1 = new Xcls_TreeViewColumn4( _this );
105 this.el.append_column ( child_1.el );
110 var description = new Pango.FontDescription();
111 description.set_size(8000);
112 this.el.override_font(description);
114 var selection = this.el.get_selection();
115 selection.set_mode( Gtk.SelectionMode.SINGLE);
118 // is this really needed??
120 this.selection.signal['changed'].connect(function() {
121 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
122 _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
126 Gtk.drag_source_set (
127 this.el, /* widget will be drag-able */
128 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
129 BuilderApplication.targetList, /* lists of target to support */
130 Gdk.DragAction.COPY | Gdk.DragAction.MOVE | Gdk.DragAction.LINK /* what to do with data after dropped */
134 //Gtk.drag_source_add_text_targets(this.el);
138 this.el, /* widget that will accept a drop */
139 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
140 BuilderApplication.targetList, /* lists of target to support */
141 Gdk.DragAction.COPY | Gdk.DragAction.MOVE | Gdk.DragAction.LINK /* what to do with data after dropped */
144 //Gtk.drag_dest_set_target_list(this.el, Builder.Application.targetList);
145 //Gtk.drag_dest_add_text_targets(this.el);
149 this.el.button_press_event.connect( ( ev) => {
150 //console.log("button press?");
151 if (! _this.before_node_change(null) ) {
156 if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button != 3) {
157 //print("click" + ev.type);
161 if (!_this.view.el.get_path_at_pos((int)ev.x,(int)ev.y, out res, null, null, null) ) {
165 this.el.get_selection().select_path(res);
167 //if (!this.get('/LeftTreeMenu').el) {
168 // this.get('/LeftTreeMenu').init();
171 _this.LeftTreeMenu.el.set_screen(Gdk.Screen.get_default());
172 _this.LeftTreeMenu.el.show_all();
173 _this.LeftTreeMenu.el.popup(null, null, null, 3, ev.time);
174 // print("click:" + res.path.to_string());
177 this.el.drag_begin.connect( ( ctx) => {
178 //print('SOURCE: drag-begin');
181 //this.targetData = "";
183 // find what is selected in our tree...
185 var s = _this.view.el.get_selection();
186 if (s.count_selected_rows() < 1) {
191 s.get_selected(out mod, out iter);
195 // set some properties of the tree for use by the dropped element.
197 _this.model.el.get_value(iter, 2, out value);
198 var tp = mod.get_path(iter).to_string();
199 var data = (JsRender.Node)(value.dup_object());
200 var xname = data.fqn();
201 print ("XNAME IS " + xname+ "\n");
203 this.dropList = _this.model.file.palete().getDropList(xname);
205 print ("DROP LIST IS " + string.joinv(", ", this.dropList) + "\n");
208 // make the drag icon a picture of the node that was selected
211 // by default returns the path..
212 var path = _this.model.el.get_path(iter);
215 var pix = this.el.create_row_drag_icon ( path);
217 Gtk.drag_set_icon_surface (ctx, pix) ;
221 this.el.cursor_changed.connect( ( ) => {
224 if (this.blockChanges) { // probably not needed..
227 if (!_this.before_node_change(null) ) {
228 this.blockChanges = true;
229 this.el.get_selection().unselect_all();
230 this.blockChanges = false;
233 if (_this.model.file == null) {
237 //var render = this.get('/LeftTree').getRenderer();
238 print("LEFT TREE -> view -> selection changed called\n");
241 // -- it appears that the selection is not updated.
243 GLib.Timeout.add_full(GLib.Priority.DEFAULT,10 , () => {
246 if (this.el.get_selection().count_selected_rows() < 1) {
248 print("selected rows < 1\n");
249 //??this.model.load( false);
250 _this.node_selected(null);
255 //console.log('changed');
256 var s = this.el.get_selection();
259 s.get_selected(out mod, out iter);
264 _this.model.el.get_value(iter, 2, out value);
265 _this.model.activePath = mod.get_path(iter).to_string();
267 var node = (JsRender.Node)value.dup_object();
268 _this.node_selected(node);
269 while (Gtk.events_pending()) {
270 Gtk.main_iteration();
272 var cp = mod.get_path(iter);
274 this.el.get_visible_range(out sp, out ep);
275 // if sp is before cp then retuns 1.
276 // if cp is before ep then retuns 1.
277 if (cp.compare(sp) >= 0 && ep.compare(cp) >=1) {
283 this.el.scroll_to_cell(new Gtk.TreePath.from_string(_this.model.activePath), null, true, 0.1f,0.0f);
287 //_this.after_node_change(node);
289 // _this.model.file.changed(node, "tree");
291 //Seed.print( value.get_string());
295 this.el.drag_end.connect( (drag_context) => {
296 //Seed.print('LEFT-TREE: drag-end');
298 this.dropList = null;
299 // this.targetData = "";
300 this.highlightDropPath("",0);
303 this.el.drag_motion.connect( ( ctx, x, y, time) => {
304 print("got drag motion\n");
305 var src = Gtk.drag_get_source_widget(ctx);
309 if (src != this.el) {
313 // the point of this is to detect where an item could be dropped..
314 print("requesting drag data\n");
315 this.drag_in_motion = true;
317 // request data that will be recieved by the recieve...
320 this.el, // will receive 'drag-data-received' signal
321 ctx, // represents the current state of the DnD
322 Gdk.Atom.intern("STRING",true), // the target type we want
329 print("action: %d\n", ctx.get_actions());
330 //print("GETTING POS");
334 Gtk.TreeViewDropPosition pos;
335 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
337 // if there are not items in the tree.. the we have to set isOver to true for anything..
339 if (_this.model.el.iter_n_children(null) < 1) {
340 print("got NO children?\n");
343 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
347 // ------------- a drag from self..
350 //var action = Gdk.DragAction.COPY;
351 // unless we are copying!!! ctl button..
353 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
354 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
355 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
358 if (_this.model.el.iter_n_children(null) < 1) {
359 // no children.. -- asume it's ok..
361 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
363 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
364 Gdk.drag_status(ctx, action ,time);
367 // continue through to allow drop...
375 //print("ISOVER? " + isOver);
378 Gdk.drag_status(ctx, 0 ,time);
379 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
384 // drag node is parent of child..
385 //console.log("SRC TREEPATH: " + src.treepath);
386 //console.log("TARGET TREEPATH: " + data.path.to_string());
388 // nned to check a few here..
389 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
390 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
391 //Gtk.TreeViewDropPosition.AFTER
392 //Gtk.TreeViewDropPosition.BEFORE
394 // locally dragged items to not really use the
395 var selection_text = this.dragData;
399 if (selection_text == null || selection_text.length < 1) {
400 //print("Error - drag selection text returned NULL");
401 Gdk.drag_status(ctx, 0 ,time);
402 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
407 // see if we are dragging into ourself?
408 var target_path = path.to_string();
409 print ("Drag %s onto %s--%d\n ", selection_text, target_path, pos);
411 // pos : 3 = ontop - 0 = after, 1 = before
412 //print("target_path="+target_path);
415 if (selection_text == target_path) {
416 print("self drag ?? == we should perhaps allow copy onto self..\n");
418 Gdk.drag_status(ctx, 0 ,time);
419 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
421 // -- fixme -- this is not really correct..
426 //print("DUMPING DATA");
427 //console.dump(data);
430 //print(data.path.to_string() +' => '+ data.pos);
432 // dropList is a list of xtypes that this node could be dropped on.
433 // it is set up when we start to drag..
436 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
438 print("targetDAta: " + targetData +"\n");
440 if (targetData.length < 1) {
441 //print("Can not find drop node path");
443 Gdk.drag_status(ctx, 0, time);
444 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
448 var td_ar = targetData.split("|");
452 Gdk.drag_status(ctx, action ,time);
453 this.highlightDropPath(td_ar[0], (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
458 this.el.drag_data_get.connect( ( drag_context, data, info, time) => {
461 //print("drag-data-get");
462 var s = this.el.get_selection();
463 if (s.count_selected_rows() < 1) {
465 print("return empty string - no selection..");
472 s.get_selected(out mod, out iter);
477 _this.model.el.get_value(iter, 2, out value);
478 var ndata = (JsRender.Node)(value.dup_object());
482 var tp = mod.get_path(iter).to_string();
483 // by default returns the path..
485 if ( info != Gdk.Atom.intern("STRING",true) ) {
486 tp = ndata.toJsonString();
489 //data.set_text(tp,tp.length);
491 data.set (data.get_target (), 8, (uchar[]) tp.to_utf8 ());
494 // print("return " + tp);
496 this.el.drag_data_received.connect( (ctx, x, y, sel, info, time) => {
498 // THIS CODE ONLY RELATES TO drag or drop of "NEW" elements or "FROM another tree.."
501 // print("Tree: drag-data-received\n");
502 var selection_text = (string)sel.get_data();
503 //print("selection_text= %s\n",selection_text);
505 var is_drag = this.drag_in_motion;
509 print("Is Drag %s\n", is_drag ? "Y": "N");
513 Gtk.TreeViewDropPosition pos;
514 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
516 // if there are not items in the tree.. the we have to set isOver to true for anything..
518 if (_this.model.el.iter_n_children(null) < 1) {
519 print("got NO children?\n");
522 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
526 //console.log("LEFT-TREE: drag-motion");
527 var src = Gtk.drag_get_source_widget(ctx);
529 // a drag from self - this should be handled by drop and motion.
530 if (src == this.el) {
531 print("Source == this element should not happen.. ? \n");
534 //print("drag_data_recieved from another element");
539 if (selection_text == null || selection_text.length < 1 || !isOver) {
540 // nothing valid foudn to drop...
541 print("empty sel text or not over");
543 Gdk.drag_status(ctx, 0, time);
544 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
547 Gtk.drag_finish (ctx, false, false, time); // drop failed..
552 var dropNode = new JsRender.Node();
554 var dropNodeType = selection_text;
555 var show_templates = true;
557 if (dropNodeType[0] == '{') {
558 var pa = new Json.Parser();
560 pa.load_from_data(dropNodeType);
562 Gtk.drag_finish (ctx, false, false, time); // drop failed..
567 dropNode.loadFromJson( pa.get_root().get_object(), 2);
568 dropNodeType = dropNode.fqn();
569 show_templates = false;
574 dropNode.setFqn(selection_text);
578 // dropList --- need to gather this ...
579 print("get dropList for : %s\n",dropNodeType);
580 var dropList = _this.model.file.palete().getDropList(dropNodeType);
582 print("dropList: %s\n", string.joinv(" , ", dropList));
584 // if drag action is link ... then we can drop it anywahere...
585 if ((ctx.get_actions() & Gdk.DragAction.LINK) > 0) {
586 // if path is null?? dragging into an empty tree?
587 targetData = (path == null ? "" : path.to_string()) + "|%d".printf((int)pos);
591 targetData = _this.model.findDropNodeByPath( isEmpty ? "" : path.to_string(), dropList, pos);
596 print("targetDAta: " + targetData +"\n");
598 if (targetData.length < 1) {
600 // invalid drop path..
601 if (this.drag_in_motion) {
602 Gdk.drag_status(ctx, 0, time);
603 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
606 Gtk.drag_finish (ctx, false, false, time); // drop failed..
612 var td_ar = targetData.split("|");
615 if (this.drag_in_motion) {
616 Gdk.drag_status(ctx, Gdk.DragAction.COPY ,time);
618 this.highlightDropPath( td_ar[0] , (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
621 // continue on to allow drop..
624 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
627 _this.model.dropNode(targetData, dropNode, show_templates);
628 print("ADD new node!!!\n");
630 ///Xcls_DialogTemplateSelect.singleton().show( _this.model.file.palete(), node);
632 Gtk.drag_finish (ctx, false, false,time);
639 this.el.drag_drop.connect( ( ctx, x, y, time) => {
640 //Seed.print("TARGET: drag-drop");
643 var src = Gtk.drag_get_source_widget(ctx);
645 if (src != this.el) {
649 this.drag_in_motion = false;
650 // request data that will be recieved by the recieve...
653 this.el, // will receive 'drag-data-received' signal
654 ctx, // represents the current state of the DnD
655 Gdk.Atom.intern("application/json",true), // the target type we want
660 // No target offered by source => error
666 // handle drop around self..
670 //print("GETTING POS");
674 Gtk.TreeViewDropPosition pos;
675 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
677 // if there are not items in the tree.. the we have to set isOver to true for anything..
679 if (_this.model.el.iter_n_children(null) < 1) {
680 print("got NO children?\n");
683 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
688 //var action = Gdk.DragAction.COPY;
689 // unless we are copying!!! ctl button..
691 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
692 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
693 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
696 if (_this.model.el.iter_n_children(null) < 1) {
697 // no children.. -- asume it's ok..
699 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
701 // continue through to allow drop...
709 //print("ISOVER? " + isOver);
712 Gtk.drag_finish (ctx, false, false, time); // drop failed..
713 return true; // not over apoint!?! - no action on drop or motion..
716 // drag node is parent of child..
717 //console.log("SRC TREEPATH: " + src.treepath);
718 //console.log("TARGET TREEPATH: " + data.path.to_string());
720 // nned to check a few here..
721 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
722 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
723 //Gtk.TreeViewDropPosition.AFTER
724 //Gtk.TreeViewDropPosition.BEFORE
726 // locally dragged items to not really use the
727 var selection_text = this.dragData;
731 if (selection_text == null || selection_text.length < 1) {
732 //print("Error - drag selection text returned NULL");
734 Gtk.drag_finish (ctx, false, false, time); // drop failed..
735 return true; /// -- fixme -- this is not really correct..
738 // see if we are dragging into ourself?
739 print ("got selection text of " + selection_text);
741 var target_path = path.to_string();
742 //print("target_path="+target_path);
745 if (selection_text == target_path) {
746 print("self drag ?? == we should perhaps allow copy onto self..\n");
748 Gtk.drag_finish (ctx, false, false, time); // drop failed..
750 return true; /// -- fixme -- this is not really correct..
755 //print("DUMPING DATA");
756 //console.dump(data);
759 //print(data.path.to_string() +' => '+ data.pos);
761 // dropList is a list of xtypes that this node could be dropped on.
762 // it is set up when we start to drag..
765 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
767 print("targetDAta: " + targetData +"\n");
769 if (targetData.length < 1) {
770 //print("Can not find drop node path");
772 Gtk.drag_finish (ctx, false, false, time); // drop failed..
778 // continue on to allow drop..
780 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
783 var delete_selection_data = false;
785 if (action == Gdk.DragAction.ASK) {
786 /* Ask the user to move or copy, then set the ctx action. */
789 if (action == Gdk.DragAction.MOVE) {
790 delete_selection_data = true;
793 // drag around.. - reorder..
794 _this.model.moveNode(targetData, action);
800 // we can send stuff to souce here...
803 // do we always say failure, so we handle the reall drop?
804 Gtk.drag_finish (ctx, false, false,time); //delete_selection_data, time);
816 // user defined functions
817 public void highlightDropPath ( string treepath, Gtk.TreeViewDropPosition pos) {
819 // highlighting for drag/drop
820 if (treepath.length > 0) {
821 this.el.set_drag_dest_row( new Gtk.TreePath.from_string( treepath ), pos);
823 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
827 public void selectNode (string treepath_str) {
828 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
829 var tp = new Gtk.TreePath.from_string(treepath_str);
831 this.el.set_cursor(tp, null, false);
832 this.el.scroll_to_cell(tp, null, false, 0,0);
835 public class Xcls_model : Object
837 public Gtk.TreeStore el;
838 private Xcls_WindowLeftTree _this;
842 public DialogTemplateSelect template_select;
843 public string activePath;
846 public Xcls_model(Xcls_WindowLeftTree _owner )
850 this.el = new Gtk.TreeStore( 3, typeof(string),typeof(string),typeof(Object) );
853 this.template_select = null;
854 this.activePath = "";
856 // set gobject values
860 print("model initialized");
863 // user defined functions
864 public string findDropNode (string treepath_str, string[] targets) {
866 // this is used by the dragdrop code in the roo version AFAIR..
868 //var path = treepath_str.replace(/^builder-/, '');
869 // treemap is depreciated... - should really check if model has any entries..
871 if (this.el.iter_n_children(null) < 1) {
873 return "|%d".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
875 //print("FIND treepath: " + path);
876 //console.dump(this.treemap);
878 //if (!treepath_str.match(/^builder-/)) {
879 // return []; // nothing!
881 if (targets.length > 0 && targets[0] == "*") {
884 return this.findDropNodeByPath(treepath_str,targets, -1);
886 public void loadFile (JsRender.JsRender f) {
889 this.main_window.windowstate.file = f;
892 if (f.tree == null) {
895 // if it's still null?
896 if (f.tree == null) {
900 var o = new Gee.ArrayList<JsRender.Node>();
904 _this.view.el.expand_all();
906 if (f.tree.items.size < 1) {
909 //this.get('/Window.leftvpaned').el.set_position(80);
911 _this.view.el.set_cursor(
912 new Gtk.TreePath.from_string("0"), null, false);
916 //this.get('/Window.leftvpaned').el.set_position(200);
923 public void updateSelected () {
926 var s = _this.view.el.get_selection();
933 if (!s.get_selected(out mod, out iter)) {
934 return; // nothing seleted..
938 this.el.get_value(iter, 2, out value);
939 var node = (JsRender.Node)(value.get_object());
941 this.el.set(iter, 0, node.nodeTitle(),
942 1, node.nodeTip(), -1
945 public string findDropNodeByPath (string treepath_str, string[] targets, int in_pref = -1) {
947 var path = treepath_str; // dupe it..
950 // pref : 3 = ontop - 0 = after, 1 = before
951 int pref = in_pref < 0 ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : in_pref;
955 //console.dump(this.treemap);
957 print("findDropNodeByPath : got path length %d / %s\n", path.length, path);
959 if (path.length == 0) {
960 // top drop. // just return empty..
961 return "|%d".printf((int)pref) ;
966 while (path.length > 0) {
968 if (path.length == treepath_str.length && pref != Gtk.TreeViewDropPosition.INTO_OR_AFTER) {
969 if (path.last_index_of(":") < 0 ) {
972 path = path.substring(0, path.last_index_of(":"));
974 print("DROP before or after : using %s\n",path);
978 //print("LOOKING FOR PATH: " + path);
979 var node_data = this.pathToNode(path);
981 if (node_data == null) {
982 print("node not found");
986 var xname = node_data.fqn();
990 for (var i =0; i < targets.length; i++) {
992 if ((tg == xname) ) {
996 // if target is "xxxx:name"
997 if (tg.contains(xname +":")) {
999 var ar = tg.split(":");
1005 if (match.length > 0) {
1006 if (last.length > 0) { // pref is after/before..
1007 // then it's after last
1011 return last + "|%d".printf((int)pref) + "|" + prop;
1015 // we need to add prop - as :store -> needs to bee added when dropping onto.
1016 return path + "|%d".printf( (int) Gtk.TreeViewDropPosition.INTO_OR_AFTER) + "|" + prop;
1020 var par = path.split(":");
1021 string [] ppar = {};
1022 for (var i = 0; i < par.length-1; i++) {
1026 path = string.joinv(":", ppar);
1035 public void moveNode (string target_data, Gdk.DragAction action)
1038 /// target_data = "path|pos");
1041 //print("MOVE NODE");
1042 // console.dump(target_data);
1043 Gtk.TreeIter old_iter;
1046 var s = _this.view.el.get_selection();
1047 s.get_selected(out mod , out old_iter);
1048 mod.get_path(old_iter);
1050 var node = this.pathToNode(mod.get_path(old_iter).to_string());
1051 //console.dump(node);
1053 print("moveNode: ERROR - node is null?");
1058 // needs to drop first, otherwise the target_data
1059 // treepath will be invalid.
1062 if ((action & Gdk.DragAction.MOVE) > 0) {
1063 print("REMOVING OLD NODE : " + target_data + "\n");
1065 this.dropNode(target_data, node, false);
1066 this.el.remove(ref old_iter);
1071 print("DROPPING NODE // copy: " + target_data + "\n");
1072 node = node.deepClone();
1073 this.dropNode(target_data, node, false);
1076 this.activePath= "";
1077 //this.updateNode(false,true);
1079 public void load (Gee.ArrayList<JsRender.Node> tr, Gtk.TreeIter? iter)
1082 //this.insert(citer,iter,0);
1083 for(var i =0 ; i < tr.size; i++) {
1085 this.el.insert(out citer,iter,-1); // why not append?
1087 this.el.append(out citer,null);
1090 this.el.set(citer, 0, tr.get(i).nodeTitle(),
1091 1, tr.get(i).nodeTip(), -1
1093 var o = GLib.Value(typeof(Object));
1094 o.set_object((Object)tr.get(i));
1096 this.el.set_value(citer, 2, o);
1098 if (tr.get(i).items.size > 0) {
1099 this.load(tr.get(i).items, citer);
1106 public void deleteSelected () {
1108 print("DELETE SELECTED?");
1109 //_this.view.blockChanges = true;
1110 print("GET SELECTION?");
1112 var s = _this.view.el.get_selection();
1114 print("GET SELECTED?");
1119 if (!s.get_selected(out mod, out iter)) {
1120 return; // nothing seleted..
1125 this.activePath= "";
1126 print("GET vnode value?");
1129 this.el.get_value(iter, 2, out value);
1130 var data = (JsRender.Node)(value.get_object());
1131 print("removing node from Render\n");
1132 if (data.parent == null) {
1133 this.file.tree = null;
1137 print("removing node from Tree\n");
1139 this.el.remove(ref iter);
1149 this.activePath= ""; // again!?!?
1150 //this.changed(null,true);
1154 _this.view.blockChanges = false;
1156 public JsRender.Node pathToNode (string path) {
1160 _this.model.el.get_iter_from_string(out iter, path);
1163 _this.model.el.get_value(iter, 2, out value);
1165 return (JsRender.Node)value.dup_object();
1168 public void dropNode (string target_data_str, JsRender.Node node, bool show_templates) {
1169 // print("drop Node");
1170 // console.dump(node);
1171 // console.dump(target_data);
1174 // 0 = before , 1=after 2/3 onto
1177 var target_data= target_data_str.split("|");
1179 var parent_str = target_data[0].length > 0 ? target_data[0] : "";
1180 var pos = target_data.length > 1 ? int.parse(target_data[1]) : 2; // ontop..
1183 Gtk.TreePath tree_path = parent_str.length > 0 ? new Gtk.TreePath.from_string( parent_str ) : null;
1187 //print("add " + tp + "@" + target_data[1] );
1189 JsRender.Node parentNode = null;
1191 Gtk.TreeIter iter_after;
1192 Gtk.TreeIter iter_par ;
1195 if (target_data.length == 3 && target_data[2].length > 0) {
1196 node.props.set("* prop", target_data[2]);
1199 Gtk.TreePath expand_parent = null;
1201 // we only need to show the template if it's come from else where?
1202 if (show_templates) {
1204 var ts = _this.main_window.windowstate.template_select;
1206 var new_node = ts.show(
1207 _this.main_window, // (Gtk.Window) _this.el.get_toplevel (),
1212 if (new_node == null) {
1213 return; // do not add?
1218 //print("pos is %d \n".printf(pos));
1220 Gtk.TreeIter n_iter;
1222 if ( parent_str.length < 1) {
1223 this.el.append(out n_iter, null); // drop at top level..
1225 this.file.tree = node;
1228 } else if (pos < 2) {
1229 //print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
1231 this.el.get_iter(out iter_after, tree_path );
1232 this.el.iter_parent(out iter_par, iter_after);
1233 expand_parent = this.el.get_path(iter_par);
1236 this.el.get_value( iter_par, 2, out value);
1237 parentNode = (JsRender.Node)value.dup_object();
1240 this.el.get_value( iter_after, 2, out value);
1241 var relNode = (JsRender.Node)value.dup_object();
1245 this.el.insert_after(out n_iter, iter_par , iter_after);
1246 var ix = parentNode.items.index_of(relNode);
1247 parentNode.items.insert(ix+1, node);
1250 this.el.insert_before(out n_iter, iter_par , iter_after);
1251 var ix = parentNode.items.index_of(relNode);
1252 parentNode.items.insert(ix, node);
1255 node.parent = parentNode;
1260 // print("appending to " + parent_str);
1261 this.el.get_iter(out iter_par, tree_path);
1262 this.el.append(out n_iter, iter_par );
1263 expand_parent = this.el.get_path(iter_par);
1266 this.el.get_value( iter_par, 2, out value);
1267 parentNode = (JsRender.Node)value.dup_object();
1268 node.parent = parentNode;
1269 parentNode.items.add(node);
1272 // reparent node in tree...
1275 // why only on no parent???
1277 //if (node.parent = null) {
1284 // work out what kind of packing to use.. -- should be in
1285 if (!node.has("pack") && parent_str.length > 1) {
1287 this.file.palete().fillPack(node,parentNode);
1294 this.el.set(n_iter, 0, node.nodeTitle(), 1, node.nodeTip(), -1 );
1295 var o = GLib.Value(typeof(Object));
1296 o.set_object((Object)node);
1298 this.el.set_value(n_iter, 2, o);
1303 // load children - if it has any..
1305 if (node.items.size > 0) {
1306 this.load(node.items, n_iter);
1307 _this.view.el.expand_row(this.el.get_path(n_iter), true);
1308 } else if (expand_parent != null && !_this.view.el.is_row_expanded(expand_parent)) {
1309 _this.view.el.expand_row(expand_parent,true);
1312 //if (tp != null && (node.items.length() > 0 || pos > 1)) {
1313 // _this.view.el.expand_row(this.el.get_path(iter_par), true);
1315 // wee need to get the empty proptypes from somewhere..
1317 //var olditer = this.activeIter;
1318 this.activePath = this.el.get_path(n_iter).to_string();
1323 _this.view.el.set_cursor(this.el.get_path(n_iter), null, false);
1329 public string treePathFromNode (JsRender.Node node) {
1330 // iterate through the tree and find the node
1333 this.el.foreach((mod, pth, iter) => {
1338 _this.model.el.get_value(iter, 2, out value);
1342 var n = (JsRender.Node)value;
1344 print("compare %s to %s\n", n.fqn(), node.fqn());
1346 ret = pth.to_string();
1356 public class Xcls_TreeViewColumn4 : Object
1358 public Gtk.TreeViewColumn el;
1359 private Xcls_WindowLeftTree _this;
1365 public Xcls_TreeViewColumn4(Xcls_WindowLeftTree _owner )
1368 this.el = new Gtk.TreeViewColumn();
1372 // set gobject values
1373 this.el.title = "test";
1374 var child_0 = new Xcls_renderer( _this );
1376 this.el.pack_start ( child_0.el , true );
1380 this.el.add_attribute(_this.renderer.el , "markup", 0 );
1383 // user defined functions
1385 public class Xcls_renderer : Object
1387 public Gtk.CellRendererText el;
1388 private Xcls_WindowLeftTree _this;
1394 public Xcls_renderer(Xcls_WindowLeftTree _owner )
1397 _this.renderer = this;
1398 this.el = new Gtk.CellRendererText();
1402 // set gobject values
1405 // user defined functions
1410 public class Xcls_LeftTreeMenu : Object
1413 private Xcls_WindowLeftTree _this;
1419 public Xcls_LeftTreeMenu(Xcls_WindowLeftTree _owner )
1422 _this.LeftTreeMenu = this;
1423 this.el = new Gtk.Menu();
1427 // set gobject values
1428 var child_0 = new Xcls_MenuItem7( _this );
1430 this.el.add ( child_0.el );
1431 var child_1 = new Xcls_MenuItem8( _this );
1433 this.el.add ( child_1.el );
1434 var child_2 = new Xcls_MenuItem9( _this );
1436 this.el.add ( child_2.el );
1439 // user defined functions
1441 public class Xcls_MenuItem7 : Object
1443 public Gtk.MenuItem el;
1444 private Xcls_WindowLeftTree _this;
1450 public Xcls_MenuItem7(Xcls_WindowLeftTree _owner )
1453 this.el = new Gtk.MenuItem();
1457 // set gobject values
1458 this.el.label = "Delete Element";
1461 this.el.activate.connect( ( ) => {
1466 _this.model.deleteSelected();
1470 // user defined functions
1473 public class Xcls_MenuItem8 : Object
1475 public Gtk.MenuItem el;
1476 private Xcls_WindowLeftTree _this;
1482 public Xcls_MenuItem8(Xcls_WindowLeftTree _owner )
1485 this.el = new Gtk.MenuItem();
1489 // set gobject values
1490 this.el.label = "Save as Template";
1493 this.el.activate.connect( () => {
1495 DialogSaveTemplate.singleton().show(
1496 (Gtk.Window) _this.el.get_toplevel (),
1497 _this.model.file.palete(),
1498 _this.getActiveElement()
1505 // user defined functions
1508 public class Xcls_MenuItem9 : Object
1510 public Gtk.MenuItem el;
1511 private Xcls_WindowLeftTree _this;
1517 public Xcls_MenuItem9(Xcls_WindowLeftTree _owner )
1520 this.el = new Gtk.MenuItem();
1524 // set gobject values
1525 this.el.label = "Save as Module";
1528 this.el.activate.connect( () => {
1529 var node = _this.getActiveElement();
1530 var name = DialogSaveModule.singleton().show(
1531 (Gtk.Window) _this.el.get_toplevel (),
1532 _this.model.file.project,
1535 if (name.length < 1) {
1539 node.props.set("* xinclude", name);
1543 var s = _this.view.el.get_selection();
1545 print("GET SELECTED?");
1550 if (!s.get_selected(out mod, out iter)) {
1551 return; // nothing seleted..
1554 var n_cn = mod.iter_n_children(iter) -1;
1555 for (var i = n_cn; i > -1; i--) {
1556 mod.iter_nth_child(out citer, iter, i);
1559 print("removing node from Tree\n");
1561 _this.model.el.remove(ref citer);
1564 _this.node_selected(node);
1570 // user defined functions