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;
88 public Xcls_view(Xcls_WindowLeftTree _owner )
92 this.el = new Gtk.TreeView();
95 this.blockChanges = false;
98 this.el.expand = true;
99 this.el.tooltip_column = 1;
100 this.el.enable_tree_lines = true;
101 this.el.headers_visible = false;
102 var child_0 = new Xcls_model( _this );
104 this.el.set_model ( child_0.el );
105 var child_1 = new Xcls_TreeViewColumn4( _this );
107 this.el.append_column ( child_1.el );
112 var description = new Pango.FontDescription();
113 description.set_size(8000);
114 this.el.override_font(description);
116 var selection = this.el.get_selection();
117 selection.set_mode( Gtk.SelectionMode.SINGLE);
120 // is this really needed??
122 this.selection.signal['changed'].connect(function() {
123 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
124 _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
128 Gtk.drag_source_set (
129 this.el, /* widget will be drag-able */
130 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
131 BuilderApplication.targetList, /* lists of target to support */
132 Gdk.DragAction.COPY | Gdk.DragAction.MOVE | Gdk.DragAction.LINK /* what to do with data after dropped */
136 //Gtk.drag_source_add_text_targets(this.el);
140 this.el, /* widget that will accept a drop */
141 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
142 BuilderApplication.targetList, /* lists of target to support */
143 Gdk.DragAction.COPY | Gdk.DragAction.MOVE | Gdk.DragAction.LINK /* what to do with data after dropped */
146 //Gtk.drag_dest_set_target_list(this.el, Builder.Application.targetList);
147 //Gtk.drag_dest_add_text_targets(this.el);
151 this.el.button_press_event.connect( ( ev) => {
152 //console.log("button press?");
153 this.lastEventSource = "tree";
154 if (! _this.before_node_change(null) ) {
160 if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button != 3) {
161 //print("click" + ev.type);
165 if (!_this.view.el.get_path_at_pos((int)ev.x,(int)ev.y, out res, null, null, null) ) {
169 this.el.get_selection().select_path(res);
171 //if (!this.get('/LeftTreeMenu').el) {
172 // this.get('/LeftTreeMenu').init();
175 _this.LeftTreeMenu.el.set_screen(Gdk.Screen.get_default());
176 _this.LeftTreeMenu.el.show_all();
177 _this.LeftTreeMenu.el.popup(null, null, null, 3, ev.time);
178 // print("click:" + res.path.to_string());
181 this.el.cursor_changed.connect( ( ) => {
184 if (this.blockChanges) { // probably not needed..
187 if (!_this.before_node_change(null) ) {
188 this.blockChanges = true;
189 this.el.get_selection().unselect_all();
190 this.blockChanges = false;
193 if (_this.main_window.windowstate.file == null) {
197 //var render = this.get('/LeftTree').getRenderer();
198 print("LEFT TREE -> view -> selection changed called\n");
201 // -- it appears that the selection is not updated.
203 GLib.Timeout.add_full(GLib.Priority.DEFAULT,10 , () => {
206 if (this.el.get_selection().count_selected_rows() < 1) {
208 print("selected rows < 1\n");
209 //??this.model.load( false);
210 _this.node_selected(null, this.lastEventSource);
215 //console.log('changed');
216 var s = this.el.get_selection();
219 s.get_selected(out mod, out iter);
224 _this.model.el.get_value(iter, 2, out value);
225 _this.model.activePath = mod.get_path(iter).to_string();
227 var node = (JsRender.Node)value.dup_object();
228 _this.node_selected(node);
229 while (Gtk.events_pending()) {
230 Gtk.main_iteration();
232 var cp = mod.get_path(iter);
234 this.el.get_visible_range(out sp, out ep);
235 // if sp is before cp then retuns 1.
236 // if cp is before ep then retuns 1.
237 if (cp.compare(sp) >= 0 && ep.compare(cp) >=1) {
243 this.el.scroll_to_cell(new Gtk.TreePath.from_string(_this.model.activePath), null, true, 0.1f,0.0f);
247 //_this.after_node_change(node);
249 // _this.model.file.changed(node, "tree");
251 //Seed.print( value.get_string());
255 this.el.drag_begin.connect( ( ctx) => {
256 //print('SOURCE: drag-begin');
259 //this.targetData = "";
261 // find what is selected in our tree...
263 var s = _this.view.el.get_selection();
264 if (s.count_selected_rows() < 1) {
269 s.get_selected(out mod, out iter);
273 // set some properties of the tree for use by the dropped element.
275 _this.model.el.get_value(iter, 2, out value);
276 var tp = mod.get_path(iter).to_string();
277 var data = (JsRender.Node)(value.dup_object());
278 var xname = data.fqn();
279 print ("XNAME IS " + xname+ "\n");
281 this.dropList = _this.main_window.windowstate.file.palete().getDropList(xname);
283 print ("DROP LIST IS " + string.joinv(", ", this.dropList) + "\n");
286 // make the drag icon a picture of the node that was selected
289 // by default returns the path..
290 var path = _this.model.el.get_path(iter);
293 var pix = this.el.create_row_drag_icon ( path);
295 Gtk.drag_set_icon_surface (ctx, pix) ;
299 this.el.drag_end.connect( (drag_context) => {
300 //Seed.print('LEFT-TREE: drag-end');
302 this.dropList = null;
303 // this.targetData = "";
304 this.highlightDropPath("",0);
307 this.el.drag_motion.connect( ( ctx, x, y, time) => {
308 print("got drag motion\n");
309 var src = Gtk.drag_get_source_widget(ctx);
313 if (src != this.el) {
317 // the point of this is to detect where an item could be dropped..
318 print("requesting drag data\n");
319 this.drag_in_motion = true;
321 // request data that will be recieved by the recieve...
324 this.el, // will receive 'drag-data-received' signal
325 ctx, // represents the current state of the DnD
326 Gdk.Atom.intern("STRING",true), // the target type we want
333 print("action: %d\n", ctx.get_actions());
334 //print("GETTING POS");
338 Gtk.TreeViewDropPosition pos;
339 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
341 // if there are not items in the tree.. the we have to set isOver to true for anything..
343 if (_this.model.el.iter_n_children(null) < 1) {
344 print("got NO children?\n");
347 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
351 // ------------- a drag from self..
354 //var action = Gdk.DragAction.COPY;
355 // unless we are copying!!! ctl button..
357 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
358 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
359 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
362 if (_this.model.el.iter_n_children(null) < 1) {
363 // no children.. -- asume it's ok..
365 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
367 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
368 Gdk.drag_status(ctx, action ,time);
371 // continue through to allow drop...
379 //print("ISOVER? " + isOver);
382 Gdk.drag_status(ctx, 0 ,time);
383 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
388 // drag node is parent of child..
389 //console.log("SRC TREEPATH: " + src.treepath);
390 //console.log("TARGET TREEPATH: " + data.path.to_string());
392 // nned to check a few here..
393 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
394 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
395 //Gtk.TreeViewDropPosition.AFTER
396 //Gtk.TreeViewDropPosition.BEFORE
398 // locally dragged items to not really use the
399 var selection_text = this.dragData;
403 if (selection_text == null || selection_text.length < 1) {
404 //print("Error - drag selection text returned NULL");
405 Gdk.drag_status(ctx, 0 ,time);
406 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
411 // see if we are dragging into ourself?
412 var target_path = path.to_string();
413 print ("Drag %s onto %s--%d\n ", selection_text, target_path, pos);
415 // pos : 3 = ontop - 0 = after, 1 = before
416 //print("target_path="+target_path);
419 if (selection_text == target_path) {
420 print("self drag ?? == we should perhaps allow copy onto self..\n");
422 Gdk.drag_status(ctx, 0 ,time);
423 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
425 // -- fixme -- this is not really correct..
430 //print("DUMPING DATA");
431 //console.dump(data);
434 //print(data.path.to_string() +' => '+ data.pos);
436 // dropList is a list of xtypes that this node could be dropped on.
437 // it is set up when we start to drag..
440 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
442 print("targetDAta: " + targetData +"\n");
444 if (targetData.length < 1) {
445 //print("Can not find drop node path");
447 Gdk.drag_status(ctx, 0, time);
448 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
452 var td_ar = targetData.split("|");
456 Gdk.drag_status(ctx, action ,time);
457 this.highlightDropPath(td_ar[0], (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
462 this.el.drag_data_get.connect( ( drag_context, data, info, time) => {
465 //print("drag-data-get");
466 var s = this.el.get_selection();
467 if (s.count_selected_rows() < 1) {
469 print("return empty string - no selection..");
476 s.get_selected(out mod, out iter);
481 _this.model.el.get_value(iter, 2, out value);
482 var ndata = (JsRender.Node)(value.dup_object());
486 var tp = mod.get_path(iter).to_string();
487 // by default returns the path..
489 if ( info != Gdk.Atom.intern("STRING",true) ) {
490 tp = ndata.toJsonString();
493 //data.set_text(tp,tp.length);
495 data.set (data.get_target (), 8, (uchar[]) tp.to_utf8 ());
498 // print("return " + tp);
500 this.el.drag_data_received.connect( (ctx, x, y, sel, info, time) => {
502 // THIS CODE ONLY RELATES TO drag or drop of "NEW" elements or "FROM another tree.."
505 // print("Tree: drag-data-received\n");
506 var selection_text = (string)sel.get_data();
507 //print("selection_text= %s\n",selection_text);
509 var is_drag = this.drag_in_motion;
513 print("Is Drag %s\n", is_drag ? "Y": "N");
517 Gtk.TreeViewDropPosition pos;
518 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
520 // if there are not items in the tree.. the we have to set isOver to true for anything..
522 if (_this.model.el.iter_n_children(null) < 1) {
523 print("got NO children?\n");
526 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
530 //console.log("LEFT-TREE: drag-motion");
531 var src = Gtk.drag_get_source_widget(ctx);
533 // a drag from self - this should be handled by drop and motion.
534 if (src == this.el) {
535 print("Source == this element should not happen.. ? \n");
538 //print("drag_data_recieved from another element");
543 if (selection_text == null || selection_text.length < 1 || !isOver) {
544 // nothing valid foudn to drop...
545 print("empty sel text or not over");
547 Gdk.drag_status(ctx, 0, time);
548 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
551 Gtk.drag_finish (ctx, false, false, time); // drop failed..
556 var dropNode = new JsRender.Node();
558 var dropNodeType = selection_text;
559 var show_templates = true;
561 if (dropNodeType[0] == '{') {
562 var pa = new Json.Parser();
564 pa.load_from_data(dropNodeType);
566 Gtk.drag_finish (ctx, false, false, time); // drop failed..
571 dropNode.loadFromJson( pa.get_root().get_object(), 2);
572 dropNodeType = dropNode.fqn();
573 show_templates = false;
578 dropNode.setFqn(selection_text);
582 // dropList --- need to gather this ...
583 print("get dropList for : %s\n",dropNodeType);
584 var dropList = _this.main_window.windowstate.file.palete().getDropList(dropNodeType);
586 print("dropList: %s\n", string.joinv(" , ", dropList));
588 // if drag action is link ... then we can drop it anywahere...
589 if ((ctx.get_actions() & Gdk.DragAction.LINK) > 0) {
590 // if path is null?? dragging into an empty tree?
591 targetData = (path == null ? "" : path.to_string()) + "|%d".printf((int)pos);
595 targetData = _this.model.findDropNodeByPath( isEmpty ? "" : path.to_string(), dropList, pos);
600 print("targetDAta: " + targetData +"\n");
602 if (targetData.length < 1) {
604 // invalid drop path..
605 if (this.drag_in_motion) {
606 Gdk.drag_status(ctx, 0, time);
607 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
610 Gtk.drag_finish (ctx, false, false, time); // drop failed..
616 var td_ar = targetData.split("|");
619 if (this.drag_in_motion) {
620 Gdk.drag_status(ctx, Gdk.DragAction.COPY ,time);
622 this.highlightDropPath( td_ar[0] , (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
625 // continue on to allow drop..
628 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
631 _this.model.dropNode(targetData, dropNode, show_templates);
632 print("ADD new node!!!\n");
634 ///Xcls_DialogTemplateSelect.singleton().show( _this.model.file.palete(), node);
636 Gtk.drag_finish (ctx, false, false,time);
643 this.el.drag_drop.connect( ( ctx, x, y, time) => {
644 //Seed.print("TARGET: drag-drop");
647 var src = Gtk.drag_get_source_widget(ctx);
649 if (src != this.el) {
653 this.drag_in_motion = false;
654 // request data that will be recieved by the recieve...
657 this.el, // will receive 'drag-data-received' signal
658 ctx, // represents the current state of the DnD
659 Gdk.Atom.intern("application/json",true), // the target type we want
664 // No target offered by source => error
670 // handle drop around self..
674 //print("GETTING POS");
678 Gtk.TreeViewDropPosition pos;
679 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
681 // if there are not items in the tree.. the we have to set isOver to true for anything..
683 if (_this.model.el.iter_n_children(null) < 1) {
684 print("got NO children?\n");
687 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
692 //var action = Gdk.DragAction.COPY;
693 // unless we are copying!!! ctl button..
695 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
696 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
697 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
700 if (_this.model.el.iter_n_children(null) < 1) {
701 // no children.. -- asume it's ok..
703 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
705 // continue through to allow drop...
713 //print("ISOVER? " + isOver);
716 Gtk.drag_finish (ctx, false, false, time); // drop failed..
717 return true; // not over apoint!?! - no action on drop or motion..
720 // drag node is parent of child..
721 //console.log("SRC TREEPATH: " + src.treepath);
722 //console.log("TARGET TREEPATH: " + data.path.to_string());
724 // nned to check a few here..
725 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
726 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
727 //Gtk.TreeViewDropPosition.AFTER
728 //Gtk.TreeViewDropPosition.BEFORE
730 // locally dragged items to not really use the
731 var selection_text = this.dragData;
735 if (selection_text == null || selection_text.length < 1) {
736 //print("Error - drag selection text returned NULL");
738 Gtk.drag_finish (ctx, false, false, time); // drop failed..
739 return true; /// -- fixme -- this is not really correct..
742 // see if we are dragging into ourself?
743 print ("got selection text of " + selection_text);
745 var target_path = path.to_string();
746 //print("target_path="+target_path);
749 if (selection_text == target_path) {
750 print("self drag ?? == we should perhaps allow copy onto self..\n");
752 Gtk.drag_finish (ctx, false, false, time); // drop failed..
754 return true; /// -- fixme -- this is not really correct..
759 //print("DUMPING DATA");
760 //console.dump(data);
763 //print(data.path.to_string() +' => '+ data.pos);
765 // dropList is a list of xtypes that this node could be dropped on.
766 // it is set up when we start to drag..
769 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
771 print("targetDAta: " + targetData +"\n");
773 if (targetData.length < 1) {
774 //print("Can not find drop node path");
776 Gtk.drag_finish (ctx, false, false, time); // drop failed..
782 // continue on to allow drop..
784 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
787 var delete_selection_data = false;
789 if (action == Gdk.DragAction.ASK) {
790 /* Ask the user to move or copy, then set the ctx action. */
793 if (action == Gdk.DragAction.MOVE) {
794 delete_selection_data = true;
797 // drag around.. - reorder..
798 _this.model.moveNode(targetData, action);
804 // we can send stuff to souce here...
807 // do we always say failure, so we handle the reall drop?
808 Gtk.drag_finish (ctx, false, false,time); //delete_selection_data, time);
820 // user defined functions
821 public void highlightDropPath ( string treepath, Gtk.TreeViewDropPosition pos) {
823 // highlighting for drag/drop
824 if (treepath.length > 0) {
825 this.el.set_drag_dest_row( new Gtk.TreePath.from_string( treepath ), pos);
827 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
831 public void selectNode (string treepath_str, string source) {
832 this.lastEventSource = source;
833 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
834 var tp = new Gtk.TreePath.from_string(treepath_str);
836 this.el.set_cursor(tp, null, false);
837 this.el.scroll_to_cell(tp, null, false, 0,0);
840 public class Xcls_model : Object
842 public Gtk.TreeStore el;
843 private Xcls_WindowLeftTree _this;
847 public DialogTemplateSelect template_select;
848 public string activePath;
851 public Xcls_model(Xcls_WindowLeftTree _owner )
855 this.el = new Gtk.TreeStore( 3, typeof(string),typeof(string),typeof(Object) );
858 this.template_select = null;
859 this.activePath = "";
861 // set gobject values
865 print("model initialized");
868 // user defined functions
869 public string findDropNode (string treepath_str, string[] targets) {
871 // this is used by the dragdrop code in the roo version AFAIR..
873 //var path = treepath_str.replace(/^builder-/, '');
874 // treemap is depreciated... - should really check if model has any entries..
876 if (this.el.iter_n_children(null) < 1) {
878 return "|%d".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
880 //print("FIND treepath: " + path);
881 //console.dump(this.treemap);
883 //if (!treepath_str.match(/^builder-/)) {
884 // return []; // nothing!
886 if (targets.length > 0 && targets[0] == "*") {
889 return this.findDropNodeByPath(treepath_str,targets, -1);
891 public void loadFile (JsRender.JsRender f) {
896 _this.main_window.windowstate.file = f;
899 if (f.tree == null) {
906 // if it's still null?
907 if (f.tree == null) {
911 var o = new Gee.ArrayList<JsRender.Node>();
915 _this.view.el.expand_all();
917 if (f.tree.items.size < 1) {
920 //this.get('/Window.leftvpaned').el.set_position(80);
922 _this.view.el.set_cursor(
923 new Gtk.TreePath.from_string("0"), null, false);
927 //this.get('/Window.leftvpaned').el.set_position(200);
934 public void updateSelected () {
937 var s = _this.view.el.get_selection();
944 if (!s.get_selected(out mod, out iter)) {
945 return; // nothing seleted..
949 this.el.get_value(iter, 2, out value);
950 var node = (JsRender.Node)(value.get_object());
952 this.el.set(iter, 0, node.nodeTitle(),
953 1, node.nodeTip(), -1
956 public string findDropNodeByPath (string treepath_str, string[] targets, int in_pref = -1) {
958 var path = treepath_str; // dupe it..
961 // pref : 3 = ontop - 0 = after, 1 = before
962 int pref = in_pref < 0 ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : in_pref;
966 //console.dump(this.treemap);
968 print("findDropNodeByPath : got path length %d / %s\n", path.length, path);
970 if (path.length == 0) {
971 // top drop. // just return empty..
972 return "|%d".printf((int)pref) ;
977 while (path.length > 0) {
979 if (path.length == treepath_str.length && pref != Gtk.TreeViewDropPosition.INTO_OR_AFTER) {
980 if (path.last_index_of(":") < 0 ) {
983 path = path.substring(0, path.last_index_of(":"));
985 print("DROP before or after : using %s\n",path);
989 //print("LOOKING FOR PATH: " + path);
990 var node_data = this.pathToNode(path);
992 if (node_data == null) {
993 print("node not found");
997 var xname = node_data.fqn();
1001 for (var i =0; i < targets.length; i++) {
1002 var tg = targets[i];
1003 if ((tg == xname) ) {
1007 // if target is "xxxx:name"
1008 if (tg.contains(xname +":")) {
1010 var ar = tg.split(":");
1016 if (match.length > 0) {
1017 if (last.length > 0) { // pref is after/before..
1018 // then it's after last
1022 return last + "|%d".printf((int)pref) + "|" + prop;
1026 // we need to add prop - as :store -> needs to bee added when dropping onto.
1027 return path + "|%d".printf( (int) Gtk.TreeViewDropPosition.INTO_OR_AFTER) + "|" + prop;
1031 var par = path.split(":");
1032 string [] ppar = {};
1033 for (var i = 0; i < par.length-1; i++) {
1037 path = string.joinv(":", ppar);
1046 public void moveNode (string target_data, Gdk.DragAction action)
1049 /// target_data = "path|pos");
1052 //print("MOVE NODE");
1053 // console.dump(target_data);
1054 Gtk.TreeIter old_iter;
1057 var s = _this.view.el.get_selection();
1058 s.get_selected(out mod , out old_iter);
1059 mod.get_path(old_iter);
1061 var node = this.pathToNode(mod.get_path(old_iter).to_string());
1062 //console.dump(node);
1064 print("moveNode: ERROR - node is null?");
1069 // needs to drop first, otherwise the target_data
1070 // treepath will be invalid.
1073 if ((action & Gdk.DragAction.MOVE) > 0) {
1074 print("REMOVING OLD NODE : " + target_data + "\n");
1076 this.dropNode(target_data, node, false);
1077 this.el.remove(ref old_iter);
1082 print("DROPPING NODE // copy: " + target_data + "\n");
1083 node = node.deepClone();
1084 this.dropNode(target_data, node, false);
1087 this.activePath= "";
1088 //this.updateNode(false,true);
1090 public void load (Gee.ArrayList<JsRender.Node> tr, Gtk.TreeIter? iter)
1093 //this.insert(citer,iter,0);
1094 for(var i =0 ; i < tr.size; i++) {
1096 this.el.insert(out citer,iter,-1); // why not append?
1098 this.el.append(out citer,null);
1101 this.el.set(citer, 0, tr.get(i).nodeTitle(),
1102 1, tr.get(i).nodeTip(), -1
1104 var o = GLib.Value(typeof(Object));
1105 o.set_object((Object)tr.get(i));
1107 this.el.set_value(citer, 2, o);
1109 if (tr.get(i).items.size > 0) {
1110 this.load(tr.get(i).items, citer);
1117 public void deleteSelected () {
1119 print("DELETE SELECTED?");
1120 //_this.view.blockChanges = true;
1121 print("GET SELECTION?");
1123 var s = _this.view.el.get_selection();
1125 print("GET SELECTED?");
1130 if (!s.get_selected(out mod, out iter)) {
1131 return; // nothing seleted..
1136 this.activePath= "";
1137 print("GET vnode value?");
1140 this.el.get_value(iter, 2, out value);
1141 var data = (JsRender.Node)(value.get_object());
1142 print("removing node from Render\n");
1143 if (data.parent == null) {
1144 _this.main_window.windowstate.file.tree = null;
1148 print("removing node from Tree\n");
1150 this.el.remove(ref iter);
1160 this.activePath= ""; // again!?!?
1161 //this.changed(null,true);
1165 _this.view.blockChanges = false;
1167 public JsRender.Node pathToNode (string path) {
1171 _this.model.el.get_iter_from_string(out iter, path);
1174 _this.model.el.get_value(iter, 2, out value);
1176 return (JsRender.Node)value.dup_object();
1179 public void dropNode (string target_data_str, JsRender.Node node, bool show_templates) {
1180 // print("drop Node");
1181 // console.dump(node);
1182 // console.dump(target_data);
1185 // 0 = before , 1=after 2/3 onto
1188 var target_data= target_data_str.split("|");
1190 var parent_str = target_data[0].length > 0 ? target_data[0] : "";
1191 var pos = target_data.length > 1 ? int.parse(target_data[1]) : 2; // ontop..
1194 Gtk.TreePath tree_path = parent_str.length > 0 ? new Gtk.TreePath.from_string( parent_str ) : null;
1198 //print("add " + tp + "@" + target_data[1] );
1200 JsRender.Node parentNode = null;
1202 Gtk.TreeIter iter_after;
1203 Gtk.TreeIter iter_par ;
1206 if (target_data.length == 3 && target_data[2].length > 0) {
1207 node.props.set("* prop", target_data[2]);
1210 Gtk.TreePath expand_parent = null;
1212 // we only need to show the template if it's come from else where?
1213 if (show_templates) {
1215 var ts = _this.main_window.windowstate.template_select;
1217 var new_node = ts.show(
1218 _this.main_window, // (Gtk.Window) _this.el.get_toplevel (),
1219 _this.main_window.windowstate.file.palete(),
1221 _this.main_window.windowstate.project);
1223 if (new_node == null) {
1224 return; // do not add?
1229 //print("pos is %d \n".printf(pos));
1231 Gtk.TreeIter n_iter;
1233 if ( parent_str.length < 1) {
1234 this.el.append(out n_iter, null); // drop at top level..
1236 _this.main_window.windowstate.file.tree = node;
1239 } else if (pos < 2) {
1240 //print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
1242 this.el.get_iter(out iter_after, tree_path );
1243 this.el.iter_parent(out iter_par, iter_after);
1244 expand_parent = this.el.get_path(iter_par);
1247 this.el.get_value( iter_par, 2, out value);
1248 parentNode = (JsRender.Node)value.dup_object();
1251 this.el.get_value( iter_after, 2, out value);
1252 var relNode = (JsRender.Node)value.dup_object();
1256 this.el.insert_after(out n_iter, iter_par , iter_after);
1257 var ix = parentNode.items.index_of(relNode);
1258 parentNode.items.insert(ix+1, node);
1261 this.el.insert_before(out n_iter, iter_par , iter_after);
1262 var ix = parentNode.items.index_of(relNode);
1263 parentNode.items.insert(ix, node);
1266 node.parent = parentNode;
1271 // print("appending to " + parent_str);
1272 this.el.get_iter(out iter_par, tree_path);
1273 this.el.append(out n_iter, iter_par );
1274 expand_parent = this.el.get_path(iter_par);
1277 this.el.get_value( iter_par, 2, out value);
1278 parentNode = (JsRender.Node)value.dup_object();
1279 node.parent = parentNode;
1280 parentNode.items.add(node);
1283 // reparent node in tree...
1286 // why only on no parent???
1288 //if (node.parent = null) {
1295 // work out what kind of packing to use.. -- should be in
1296 if (!node.has("pack") && parent_str.length > 1) {
1298 _this.main_window.windowstate.file.palete().fillPack(node,parentNode);
1305 this.el.set(n_iter, 0, node.nodeTitle(), 1, node.nodeTip(), -1 );
1306 var o = GLib.Value(typeof(Object));
1307 o.set_object((Object)node);
1309 this.el.set_value(n_iter, 2, o);
1314 // load children - if it has any..
1316 if (node.items.size > 0) {
1317 this.load(node.items, n_iter);
1318 _this.view.el.expand_row(this.el.get_path(n_iter), true);
1319 } else if (expand_parent != null && !_this.view.el.is_row_expanded(expand_parent)) {
1320 _this.view.el.expand_row(expand_parent,true);
1323 //if (tp != null && (node.items.length() > 0 || pos > 1)) {
1324 // _this.view.el.expand_row(this.el.get_path(iter_par), true);
1326 // wee need to get the empty proptypes from somewhere..
1328 //var olditer = this.activeIter;
1329 this.activePath = this.el.get_path(n_iter).to_string();
1334 _this.view.el.set_cursor(this.el.get_path(n_iter), null, false);
1340 public string treePathFromNode (JsRender.Node node) {
1341 // iterate through the tree and find the node
1344 this.el.foreach((mod, pth, iter) => {
1349 _this.model.el.get_value(iter, 2, out value);
1353 var n = (JsRender.Node)value;
1355 print("compare %s to %s\n", n.fqn(), node.fqn());
1357 ret = pth.to_string();
1367 public class Xcls_TreeViewColumn4 : Object
1369 public Gtk.TreeViewColumn el;
1370 private Xcls_WindowLeftTree _this;
1376 public Xcls_TreeViewColumn4(Xcls_WindowLeftTree _owner )
1379 this.el = new Gtk.TreeViewColumn();
1383 // set gobject values
1384 this.el.title = "test";
1385 var child_0 = new Xcls_renderer( _this );
1387 this.el.pack_start ( child_0.el , true );
1391 this.el.add_attribute(_this.renderer.el , "markup", 0 );
1394 // user defined functions
1396 public class Xcls_renderer : Object
1398 public Gtk.CellRendererText el;
1399 private Xcls_WindowLeftTree _this;
1405 public Xcls_renderer(Xcls_WindowLeftTree _owner )
1408 _this.renderer = this;
1409 this.el = new Gtk.CellRendererText();
1413 // set gobject values
1416 // user defined functions
1421 public class Xcls_LeftTreeMenu : Object
1424 private Xcls_WindowLeftTree _this;
1430 public Xcls_LeftTreeMenu(Xcls_WindowLeftTree _owner )
1433 _this.LeftTreeMenu = this;
1434 this.el = new Gtk.Menu();
1438 // set gobject values
1439 var child_0 = new Xcls_MenuItem7( _this );
1441 this.el.add ( child_0.el );
1442 var child_1 = new Xcls_MenuItem8( _this );
1444 this.el.add ( child_1.el );
1445 var child_2 = new Xcls_MenuItem9( _this );
1447 this.el.add ( child_2.el );
1450 // user defined functions
1452 public class Xcls_MenuItem7 : Object
1454 public Gtk.MenuItem el;
1455 private Xcls_WindowLeftTree _this;
1461 public Xcls_MenuItem7(Xcls_WindowLeftTree _owner )
1464 this.el = new Gtk.MenuItem();
1468 // set gobject values
1469 this.el.label = "Delete Element";
1472 this.el.activate.connect( ( ) => {
1477 _this.model.deleteSelected();
1481 // user defined functions
1484 public class Xcls_MenuItem8 : Object
1486 public Gtk.MenuItem el;
1487 private Xcls_WindowLeftTree _this;
1493 public Xcls_MenuItem8(Xcls_WindowLeftTree _owner )
1496 this.el = new Gtk.MenuItem();
1500 // set gobject values
1501 this.el.label = "Save as Template";
1504 this.el.activate.connect( () => {
1506 DialogSaveTemplate.singleton().show(
1507 (Gtk.Window) _this.el.get_toplevel (),
1508 _this.main_window.windowstate.file.palete(),
1509 _this.getActiveElement()
1516 // user defined functions
1519 public class Xcls_MenuItem9 : Object
1521 public Gtk.MenuItem el;
1522 private Xcls_WindowLeftTree _this;
1528 public Xcls_MenuItem9(Xcls_WindowLeftTree _owner )
1531 this.el = new Gtk.MenuItem();
1535 // set gobject values
1536 this.el.label = "Save as Module";
1539 this.el.activate.connect( () => {
1540 var node = _this.getActiveElement();
1541 var name = DialogSaveModule.singleton().show(
1542 (Gtk.Window) _this.el.get_toplevel (),
1543 _this.main_window.windowstate.project,
1546 if (name.length < 1) {
1550 node.props.set("* xinclude", name);
1554 var s = _this.view.el.get_selection();
1556 print("GET SELECTED?");
1561 if (!s.get_selected(out mod, out iter)) {
1562 return; // nothing seleted..
1565 var n_cn = mod.iter_n_children(iter) -1;
1566 for (var i = n_cn; i > -1; i--) {
1567 mod.iter_nth_child(out citer, iter, i);
1570 print("removing node from Tree\n");
1572 _this.model.el.remove(ref citer);
1575 _this.node_selected(node, "tree");
1581 // user defined functions