1 static Xcls_WindowLeftTree _WindowLeftTree;
3 public class Xcls_WindowLeftTree : Object
5 public Gtk.ScrolledWindow el;
6 private Xcls_WindowLeftTree _this;
8 public static Xcls_WindowLeftTree singleton()
10 if (_WindowLeftTree == null) {
11 _WindowLeftTree= new Xcls_WindowLeftTree();
13 return _WindowLeftTree;
15 public Xcls_view view;
16 public Xcls_model model;
17 public Xcls_renderer renderer;
18 public Xcls_LeftTreeMenu LeftTreeMenu;
21 public signal bool before_node_change (JsRender.Node? node);
22 public signal void changed ();
23 public signal void node_selected (JsRender.Node? node, string source);
24 public Xcls_MainWindow main_window;
27 public Xcls_WindowLeftTree()
30 this.el = new Gtk.ScrolledWindow( null, null );
33 this.main_window = null;
36 this.el.shadow_type = Gtk.ShadowType.IN;
37 var child_0 = new Xcls_view( _this );
39 this.el.add ( child_0.el );
40 var child_1 = new Xcls_LeftTreeMenu( _this );
45 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
48 // user defined functions
49 public JsRender.Node? getActiveElement () { // return path to actie node.
51 var path = this.getActivePath();
52 if (path.length < 1) {
55 return _this.model.pathToNode(path);
58 public JsRender.JsRender getActiveFile () {
59 return this.main_window.windowstate.file;
61 public string getActivePath () {
63 var view = this.view.el;
64 if (view.get_selection().count_selected_rows() < 1) {
69 view.get_selection().get_selected(out mod, out iter);
70 return mod.get_path(iter).to_string();
72 public class Xcls_view : Object
74 public Gtk.TreeView el;
75 private Xcls_WindowLeftTree _this;
79 public string dragData;
80 public string[] dropList;
83 public bool drag_in_motion;
84 public bool blockChanges;
87 public Xcls_view(Xcls_WindowLeftTree _owner )
91 this.el = new Gtk.TreeView();
94 this.blockChanges = false;
97 this.el.expand = true;
98 this.el.tooltip_column = 1;
99 this.el.enable_tree_lines = true;
100 this.el.headers_visible = false;
101 var child_0 = new Xcls_model( _this );
103 this.el.set_model ( child_0.el );
104 var child_1 = new Xcls_TreeViewColumn4( _this );
106 this.el.append_column ( child_1.el );
111 var description = new Pango.FontDescription();
112 description.set_size(8000);
113 this.el.override_font(description);
115 var selection = this.el.get_selection();
116 selection.set_mode( Gtk.SelectionMode.SINGLE);
119 // is this really needed??
121 this.selection.signal['changed'].connect(function() {
122 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
123 _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
127 Gtk.drag_source_set (
128 this.el, /* widget will be drag-able */
129 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
130 BuilderApplication.targetList, /* lists of target to support */
131 Gdk.DragAction.COPY | Gdk.DragAction.MOVE | Gdk.DragAction.LINK /* what to do with data after dropped */
135 //Gtk.drag_source_add_text_targets(this.el);
139 this.el, /* widget that will accept a drop */
140 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
141 BuilderApplication.targetList, /* lists of target to support */
142 Gdk.DragAction.COPY | Gdk.DragAction.MOVE | Gdk.DragAction.LINK /* what to do with data after dropped */
145 //Gtk.drag_dest_set_target_list(this.el, Builder.Application.targetList);
146 //Gtk.drag_dest_add_text_targets(this.el);
150 this.el.button_press_event.connect( ( ev) => {
151 //console.log("button press?");
152 this.lastEventSource = "tree";
153 if (! _this.before_node_change(null) ) {
159 if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button != 3) {
160 //print("click" + ev.type);
164 if (!_this.view.el.get_path_at_pos((int)ev.x,(int)ev.y, out res, null, null, null) ) {
168 this.el.get_selection().select_path(res);
170 //if (!this.get('/LeftTreeMenu').el) {
171 // this.get('/LeftTreeMenu').init();
174 _this.LeftTreeMenu.el.set_screen(Gdk.Screen.get_default());
175 _this.LeftTreeMenu.el.show_all();
176 _this.LeftTreeMenu.el.popup(null, null, null, 3, ev.time);
177 // print("click:" + res.path.to_string());
180 this.el.cursor_changed.connect( ( ) => {
183 if (this.blockChanges) { // probably not needed..
186 if (!_this.before_node_change(null) ) {
187 this.blockChanges = true;
188 this.el.get_selection().unselect_all();
189 this.blockChanges = false;
192 if (_this.main_window.windowstate.file == null) {
196 //var render = this.get('/LeftTree').getRenderer();
197 print("LEFT TREE -> view -> selection changed called\n");
200 // -- it appears that the selection is not updated.
202 GLib.Timeout.add_full(GLib.Priority.DEFAULT,10 , () => {
205 if (this.el.get_selection().count_selected_rows() < 1) {
207 print("selected rows < 1\n");
208 //??this.model.load( false);
209 _this.node_selected(null, this.lastEventSource);
214 //console.log('changed');
215 var s = this.el.get_selection();
218 s.get_selected(out mod, out iter);
223 _this.model.el.get_value(iter, 2, out value);
224 _this.model.activePath = mod.get_path(iter).to_string();
226 var node = (JsRender.Node)value.dup_object();
227 _this.node_selected(node);
228 while (Gtk.events_pending()) {
229 Gtk.main_iteration();
231 var cp = mod.get_path(iter);
233 this.el.get_visible_range(out sp, out ep);
234 // if sp is before cp then retuns 1.
235 // if cp is before ep then retuns 1.
236 if (cp.compare(sp) >= 0 && ep.compare(cp) >=1) {
242 this.el.scroll_to_cell(new Gtk.TreePath.from_string(_this.model.activePath), null, true, 0.1f,0.0f);
246 //_this.after_node_change(node);
248 // _this.model.file.changed(node, "tree");
250 //Seed.print( value.get_string());
254 this.el.drag_begin.connect( ( ctx) => {
255 //print('SOURCE: drag-begin');
258 //this.targetData = "";
260 // find what is selected in our tree...
262 var s = _this.view.el.get_selection();
263 if (s.count_selected_rows() < 1) {
268 s.get_selected(out mod, out iter);
272 // set some properties of the tree for use by the dropped element.
274 _this.model.el.get_value(iter, 2, out value);
275 var tp = mod.get_path(iter).to_string();
276 var data = (JsRender.Node)(value.dup_object());
277 var xname = data.fqn();
278 print ("XNAME IS " + xname+ "\n");
280 this.dropList = _this.main_window.windowstate.file.palete().getDropList(xname);
282 print ("DROP LIST IS " + string.joinv(", ", this.dropList) + "\n");
285 // make the drag icon a picture of the node that was selected
288 // by default returns the path..
289 var path = _this.model.el.get_path(iter);
292 var pix = this.el.create_row_drag_icon ( path);
294 Gtk.drag_set_icon_surface (ctx, pix) ;
298 this.el.drag_end.connect( (drag_context) => {
299 //Seed.print('LEFT-TREE: drag-end');
301 this.dropList = null;
302 // this.targetData = "";
303 this.highlightDropPath("",0);
306 this.el.drag_motion.connect( ( ctx, x, y, time) => {
307 print("got drag motion\n");
308 var src = Gtk.drag_get_source_widget(ctx);
312 if (src != this.el) {
316 // the point of this is to detect where an item could be dropped..
317 print("requesting drag data\n");
318 this.drag_in_motion = true;
320 // request data that will be recieved by the recieve...
323 this.el, // will receive 'drag-data-received' signal
324 ctx, // represents the current state of the DnD
325 Gdk.Atom.intern("STRING",true), // the target type we want
332 print("action: %d\n", ctx.get_actions());
333 //print("GETTING POS");
337 Gtk.TreeViewDropPosition pos;
338 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
340 // if there are not items in the tree.. the we have to set isOver to true for anything..
342 if (_this.model.el.iter_n_children(null) < 1) {
343 print("got NO children?\n");
346 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
350 // ------------- a drag from self..
353 //var action = Gdk.DragAction.COPY;
354 // unless we are copying!!! ctl button..
356 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
357 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
358 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
361 if (_this.model.el.iter_n_children(null) < 1) {
362 // no children.. -- asume it's ok..
364 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
366 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
367 Gdk.drag_status(ctx, action ,time);
370 // continue through to allow drop...
378 //print("ISOVER? " + isOver);
381 Gdk.drag_status(ctx, 0 ,time);
382 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
387 // drag node is parent of child..
388 //console.log("SRC TREEPATH: " + src.treepath);
389 //console.log("TARGET TREEPATH: " + data.path.to_string());
391 // nned to check a few here..
392 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
393 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
394 //Gtk.TreeViewDropPosition.AFTER
395 //Gtk.TreeViewDropPosition.BEFORE
397 // locally dragged items to not really use the
398 var selection_text = this.dragData;
402 if (selection_text == null || selection_text.length < 1) {
403 //print("Error - drag selection text returned NULL");
404 Gdk.drag_status(ctx, 0 ,time);
405 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
410 // see if we are dragging into ourself?
411 var target_path = path.to_string();
412 print ("Drag %s onto %s--%d\n ", selection_text, target_path, pos);
414 // pos : 3 = ontop - 0 = after, 1 = before
415 //print("target_path="+target_path);
418 if (selection_text == target_path) {
419 print("self drag ?? == we should perhaps allow copy onto self..\n");
421 Gdk.drag_status(ctx, 0 ,time);
422 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
424 // -- fixme -- this is not really correct..
429 //print("DUMPING DATA");
430 //console.dump(data);
433 //print(data.path.to_string() +' => '+ data.pos);
435 // dropList is a list of xtypes that this node could be dropped on.
436 // it is set up when we start to drag..
439 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
441 print("targetDAta: " + targetData +"\n");
443 if (targetData.length < 1) {
444 //print("Can not find drop node path");
446 Gdk.drag_status(ctx, 0, time);
447 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
451 var td_ar = targetData.split("|");
455 Gdk.drag_status(ctx, action ,time);
456 this.highlightDropPath(td_ar[0], (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
461 this.el.drag_data_get.connect( ( drag_context, data, info, time) => {
464 //print("drag-data-get");
465 var s = this.el.get_selection();
466 if (s.count_selected_rows() < 1) {
468 print("return empty string - no selection..");
475 s.get_selected(out mod, out iter);
480 _this.model.el.get_value(iter, 2, out value);
481 var ndata = (JsRender.Node)(value.dup_object());
485 var tp = mod.get_path(iter).to_string();
486 // by default returns the path..
488 if ( info != Gdk.Atom.intern("STRING",true) ) {
489 tp = ndata.toJsonString();
492 //data.set_text(tp,tp.length);
494 data.set (data.get_target (), 8, (uchar[]) tp.to_utf8 ());
497 // print("return " + tp);
499 this.el.drag_data_received.connect( (ctx, x, y, sel, info, time) => {
501 // THIS CODE ONLY RELATES TO drag or drop of "NEW" elements or "FROM another tree.."
504 // print("Tree: drag-data-received\n");
505 var selection_text = (string)sel.get_data();
506 //print("selection_text= %s\n",selection_text);
508 var is_drag = this.drag_in_motion;
512 print("Is Drag %s\n", is_drag ? "Y": "N");
516 Gtk.TreeViewDropPosition pos;
517 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
519 // if there are not items in the tree.. the we have to set isOver to true for anything..
521 if (_this.model.el.iter_n_children(null) < 1) {
522 print("got NO children?\n");
525 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
529 //console.log("LEFT-TREE: drag-motion");
530 var src = Gtk.drag_get_source_widget(ctx);
532 // a drag from self - this should be handled by drop and motion.
533 if (src == this.el) {
534 print("Source == this element should not happen.. ? \n");
537 //print("drag_data_recieved from another element");
542 if (selection_text == null || selection_text.length < 1 || !isOver) {
543 // nothing valid foudn to drop...
544 print("empty sel text or not over");
546 Gdk.drag_status(ctx, 0, time);
547 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
550 Gtk.drag_finish (ctx, false, false, time); // drop failed..
555 var dropNode = new JsRender.Node();
557 var dropNodeType = selection_text;
558 var show_templates = true;
560 if (dropNodeType[0] == '{') {
561 var pa = new Json.Parser();
563 pa.load_from_data(dropNodeType);
565 Gtk.drag_finish (ctx, false, false, time); // drop failed..
570 dropNode.loadFromJson( pa.get_root().get_object(), 2);
571 dropNodeType = dropNode.fqn();
572 show_templates = false;
577 dropNode.setFqn(selection_text);
581 // dropList --- need to gather this ...
582 print("get dropList for : %s\n",dropNodeType);
583 var dropList = _this.main_window.windowstate.file.palete().getDropList(dropNodeType);
585 print("dropList: %s\n", string.joinv(" , ", dropList));
587 // if drag action is link ... then we can drop it anywahere...
588 if ((ctx.get_actions() & Gdk.DragAction.LINK) > 0) {
589 // if path is null?? dragging into an empty tree?
590 targetData = (path == null ? "" : path.to_string()) + "|%d".printf((int)pos);
594 targetData = _this.model.findDropNodeByPath( isEmpty ? "" : path.to_string(), dropList, pos);
599 print("targetDAta: " + targetData +"\n");
601 if (targetData.length < 1) {
603 // invalid drop path..
604 if (this.drag_in_motion) {
605 Gdk.drag_status(ctx, 0, time);
606 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
609 Gtk.drag_finish (ctx, false, false, time); // drop failed..
615 var td_ar = targetData.split("|");
618 if (this.drag_in_motion) {
619 Gdk.drag_status(ctx, Gdk.DragAction.COPY ,time);
621 this.highlightDropPath( td_ar[0] , (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
624 // continue on to allow drop..
627 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
630 _this.model.dropNode(targetData, dropNode, show_templates);
631 print("ADD new node!!!\n");
633 ///Xcls_DialogTemplateSelect.singleton().show( _this.model.file.palete(), node);
635 Gtk.drag_finish (ctx, false, false,time);
642 this.el.drag_drop.connect( ( ctx, x, y, time) => {
643 //Seed.print("TARGET: drag-drop");
646 var src = Gtk.drag_get_source_widget(ctx);
648 if (src != this.el) {
652 this.drag_in_motion = false;
653 // request data that will be recieved by the recieve...
656 this.el, // will receive 'drag-data-received' signal
657 ctx, // represents the current state of the DnD
658 Gdk.Atom.intern("application/json",true), // the target type we want
663 // No target offered by source => error
669 // handle drop around self..
673 //print("GETTING POS");
677 Gtk.TreeViewDropPosition pos;
678 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
680 // if there are not items in the tree.. the we have to set isOver to true for anything..
682 if (_this.model.el.iter_n_children(null) < 1) {
683 print("got NO children?\n");
686 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
691 //var action = Gdk.DragAction.COPY;
692 // unless we are copying!!! ctl button..
694 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
695 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
696 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
699 if (_this.model.el.iter_n_children(null) < 1) {
700 // no children.. -- asume it's ok..
702 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
704 // continue through to allow drop...
712 //print("ISOVER? " + isOver);
715 Gtk.drag_finish (ctx, false, false, time); // drop failed..
716 return true; // not over apoint!?! - no action on drop or motion..
719 // drag node is parent of child..
720 //console.log("SRC TREEPATH: " + src.treepath);
721 //console.log("TARGET TREEPATH: " + data.path.to_string());
723 // nned to check a few here..
724 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
725 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
726 //Gtk.TreeViewDropPosition.AFTER
727 //Gtk.TreeViewDropPosition.BEFORE
729 // locally dragged items to not really use the
730 var selection_text = this.dragData;
734 if (selection_text == null || selection_text.length < 1) {
735 //print("Error - drag selection text returned NULL");
737 Gtk.drag_finish (ctx, false, false, time); // drop failed..
738 return true; /// -- fixme -- this is not really correct..
741 // see if we are dragging into ourself?
742 print ("got selection text of " + selection_text);
744 var target_path = path.to_string();
745 //print("target_path="+target_path);
748 if (selection_text == target_path) {
749 print("self drag ?? == we should perhaps allow copy onto self..\n");
751 Gtk.drag_finish (ctx, false, false, time); // drop failed..
753 return true; /// -- fixme -- this is not really correct..
758 //print("DUMPING DATA");
759 //console.dump(data);
762 //print(data.path.to_string() +' => '+ data.pos);
764 // dropList is a list of xtypes that this node could be dropped on.
765 // it is set up when we start to drag..
768 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
770 print("targetDAta: " + targetData +"\n");
772 if (targetData.length < 1) {
773 //print("Can not find drop node path");
775 Gtk.drag_finish (ctx, false, false, time); // drop failed..
781 // continue on to allow drop..
783 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
786 var delete_selection_data = false;
788 if (action == Gdk.DragAction.ASK) {
789 /* Ask the user to move or copy, then set the ctx action. */
792 if (action == Gdk.DragAction.MOVE) {
793 delete_selection_data = true;
796 // drag around.. - reorder..
797 _this.model.moveNode(targetData, action);
803 // we can send stuff to souce here...
806 // do we always say failure, so we handle the reall drop?
807 Gtk.drag_finish (ctx, false, false,time); //delete_selection_data, time);
819 // user defined functions
820 public void highlightDropPath ( string treepath, Gtk.TreeViewDropPosition pos) {
822 // highlighting for drag/drop
823 if (treepath.length > 0) {
824 this.el.set_drag_dest_row( new Gtk.TreePath.from_string( treepath ), pos);
826 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
830 public void selectNode (string treepath_str) {
831 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
832 var tp = new Gtk.TreePath.from_string(treepath_str);
834 this.el.set_cursor(tp, null, false);
835 this.el.scroll_to_cell(tp, null, false, 0,0);
838 public class Xcls_model : Object
840 public Gtk.TreeStore el;
841 private Xcls_WindowLeftTree _this;
845 public DialogTemplateSelect template_select;
846 public string activePath;
849 public Xcls_model(Xcls_WindowLeftTree _owner )
853 this.el = new Gtk.TreeStore( 3, typeof(string),typeof(string),typeof(Object) );
856 this.template_select = null;
857 this.activePath = "";
859 // set gobject values
863 print("model initialized");
866 // user defined functions
867 public string findDropNode (string treepath_str, string[] targets) {
869 // this is used by the dragdrop code in the roo version AFAIR..
871 //var path = treepath_str.replace(/^builder-/, '');
872 // treemap is depreciated... - should really check if model has any entries..
874 if (this.el.iter_n_children(null) < 1) {
876 return "|%d".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
878 //print("FIND treepath: " + path);
879 //console.dump(this.treemap);
881 //if (!treepath_str.match(/^builder-/)) {
882 // return []; // nothing!
884 if (targets.length > 0 && targets[0] == "*") {
887 return this.findDropNodeByPath(treepath_str,targets, -1);
889 public void loadFile (JsRender.JsRender f) {
894 _this.main_window.windowstate.file = f;
897 if (f.tree == null) {
904 // if it's still null?
905 if (f.tree == null) {
909 var o = new Gee.ArrayList<JsRender.Node>();
913 _this.view.el.expand_all();
915 if (f.tree.items.size < 1) {
918 //this.get('/Window.leftvpaned').el.set_position(80);
920 _this.view.el.set_cursor(
921 new Gtk.TreePath.from_string("0"), null, false);
925 //this.get('/Window.leftvpaned').el.set_position(200);
932 public void updateSelected () {
935 var s = _this.view.el.get_selection();
942 if (!s.get_selected(out mod, out iter)) {
943 return; // nothing seleted..
947 this.el.get_value(iter, 2, out value);
948 var node = (JsRender.Node)(value.get_object());
950 this.el.set(iter, 0, node.nodeTitle(),
951 1, node.nodeTip(), -1
954 public string findDropNodeByPath (string treepath_str, string[] targets, int in_pref = -1) {
956 var path = treepath_str; // dupe it..
959 // pref : 3 = ontop - 0 = after, 1 = before
960 int pref = in_pref < 0 ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : in_pref;
964 //console.dump(this.treemap);
966 print("findDropNodeByPath : got path length %d / %s\n", path.length, path);
968 if (path.length == 0) {
969 // top drop. // just return empty..
970 return "|%d".printf((int)pref) ;
975 while (path.length > 0) {
977 if (path.length == treepath_str.length && pref != Gtk.TreeViewDropPosition.INTO_OR_AFTER) {
978 if (path.last_index_of(":") < 0 ) {
981 path = path.substring(0, path.last_index_of(":"));
983 print("DROP before or after : using %s\n",path);
987 //print("LOOKING FOR PATH: " + path);
988 var node_data = this.pathToNode(path);
990 if (node_data == null) {
991 print("node not found");
995 var xname = node_data.fqn();
999 for (var i =0; i < targets.length; i++) {
1000 var tg = targets[i];
1001 if ((tg == xname) ) {
1005 // if target is "xxxx:name"
1006 if (tg.contains(xname +":")) {
1008 var ar = tg.split(":");
1014 if (match.length > 0) {
1015 if (last.length > 0) { // pref is after/before..
1016 // then it's after last
1020 return last + "|%d".printf((int)pref) + "|" + prop;
1024 // we need to add prop - as :store -> needs to bee added when dropping onto.
1025 return path + "|%d".printf( (int) Gtk.TreeViewDropPosition.INTO_OR_AFTER) + "|" + prop;
1029 var par = path.split(":");
1030 string [] ppar = {};
1031 for (var i = 0; i < par.length-1; i++) {
1035 path = string.joinv(":", ppar);
1044 public void moveNode (string target_data, Gdk.DragAction action)
1047 /// target_data = "path|pos");
1050 //print("MOVE NODE");
1051 // console.dump(target_data);
1052 Gtk.TreeIter old_iter;
1055 var s = _this.view.el.get_selection();
1056 s.get_selected(out mod , out old_iter);
1057 mod.get_path(old_iter);
1059 var node = this.pathToNode(mod.get_path(old_iter).to_string());
1060 //console.dump(node);
1062 print("moveNode: ERROR - node is null?");
1067 // needs to drop first, otherwise the target_data
1068 // treepath will be invalid.
1071 if ((action & Gdk.DragAction.MOVE) > 0) {
1072 print("REMOVING OLD NODE : " + target_data + "\n");
1074 this.dropNode(target_data, node, false);
1075 this.el.remove(ref old_iter);
1080 print("DROPPING NODE // copy: " + target_data + "\n");
1081 node = node.deepClone();
1082 this.dropNode(target_data, node, false);
1085 this.activePath= "";
1086 //this.updateNode(false,true);
1088 public void load (Gee.ArrayList<JsRender.Node> tr, Gtk.TreeIter? iter)
1091 //this.insert(citer,iter,0);
1092 for(var i =0 ; i < tr.size; i++) {
1094 this.el.insert(out citer,iter,-1); // why not append?
1096 this.el.append(out citer,null);
1099 this.el.set(citer, 0, tr.get(i).nodeTitle(),
1100 1, tr.get(i).nodeTip(), -1
1102 var o = GLib.Value(typeof(Object));
1103 o.set_object((Object)tr.get(i));
1105 this.el.set_value(citer, 2, o);
1107 if (tr.get(i).items.size > 0) {
1108 this.load(tr.get(i).items, citer);
1115 public void deleteSelected () {
1117 print("DELETE SELECTED?");
1118 //_this.view.blockChanges = true;
1119 print("GET SELECTION?");
1121 var s = _this.view.el.get_selection();
1123 print("GET SELECTED?");
1128 if (!s.get_selected(out mod, out iter)) {
1129 return; // nothing seleted..
1134 this.activePath= "";
1135 print("GET vnode value?");
1138 this.el.get_value(iter, 2, out value);
1139 var data = (JsRender.Node)(value.get_object());
1140 print("removing node from Render\n");
1141 if (data.parent == null) {
1142 _this.main_window.windowstate.file.tree = null;
1146 print("removing node from Tree\n");
1148 this.el.remove(ref iter);
1158 this.activePath= ""; // again!?!?
1159 //this.changed(null,true);
1163 _this.view.blockChanges = false;
1165 public JsRender.Node pathToNode (string path) {
1169 _this.model.el.get_iter_from_string(out iter, path);
1172 _this.model.el.get_value(iter, 2, out value);
1174 return (JsRender.Node)value.dup_object();
1177 public void dropNode (string target_data_str, JsRender.Node node, bool show_templates) {
1178 // print("drop Node");
1179 // console.dump(node);
1180 // console.dump(target_data);
1183 // 0 = before , 1=after 2/3 onto
1186 var target_data= target_data_str.split("|");
1188 var parent_str = target_data[0].length > 0 ? target_data[0] : "";
1189 var pos = target_data.length > 1 ? int.parse(target_data[1]) : 2; // ontop..
1192 Gtk.TreePath tree_path = parent_str.length > 0 ? new Gtk.TreePath.from_string( parent_str ) : null;
1196 //print("add " + tp + "@" + target_data[1] );
1198 JsRender.Node parentNode = null;
1200 Gtk.TreeIter iter_after;
1201 Gtk.TreeIter iter_par ;
1204 if (target_data.length == 3 && target_data[2].length > 0) {
1205 node.props.set("* prop", target_data[2]);
1208 Gtk.TreePath expand_parent = null;
1210 // we only need to show the template if it's come from else where?
1211 if (show_templates) {
1213 var ts = _this.main_window.windowstate.template_select;
1215 var new_node = ts.show(
1216 _this.main_window, // (Gtk.Window) _this.el.get_toplevel (),
1217 _this.main_window.windowstate.file.palete(),
1219 _this.main_window.windowstate.project);
1221 if (new_node == null) {
1222 return; // do not add?
1227 //print("pos is %d \n".printf(pos));
1229 Gtk.TreeIter n_iter;
1231 if ( parent_str.length < 1) {
1232 this.el.append(out n_iter, null); // drop at top level..
1234 _this.main_window.windowstate.file.tree = node;
1237 } else if (pos < 2) {
1238 //print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
1240 this.el.get_iter(out iter_after, tree_path );
1241 this.el.iter_parent(out iter_par, iter_after);
1242 expand_parent = this.el.get_path(iter_par);
1245 this.el.get_value( iter_par, 2, out value);
1246 parentNode = (JsRender.Node)value.dup_object();
1249 this.el.get_value( iter_after, 2, out value);
1250 var relNode = (JsRender.Node)value.dup_object();
1254 this.el.insert_after(out n_iter, iter_par , iter_after);
1255 var ix = parentNode.items.index_of(relNode);
1256 parentNode.items.insert(ix+1, node);
1259 this.el.insert_before(out n_iter, iter_par , iter_after);
1260 var ix = parentNode.items.index_of(relNode);
1261 parentNode.items.insert(ix, node);
1264 node.parent = parentNode;
1269 // print("appending to " + parent_str);
1270 this.el.get_iter(out iter_par, tree_path);
1271 this.el.append(out n_iter, iter_par );
1272 expand_parent = this.el.get_path(iter_par);
1275 this.el.get_value( iter_par, 2, out value);
1276 parentNode = (JsRender.Node)value.dup_object();
1277 node.parent = parentNode;
1278 parentNode.items.add(node);
1281 // reparent node in tree...
1284 // why only on no parent???
1286 //if (node.parent = null) {
1293 // work out what kind of packing to use.. -- should be in
1294 if (!node.has("pack") && parent_str.length > 1) {
1296 _this.main_window.windowstate.file.palete().fillPack(node,parentNode);
1303 this.el.set(n_iter, 0, node.nodeTitle(), 1, node.nodeTip(), -1 );
1304 var o = GLib.Value(typeof(Object));
1305 o.set_object((Object)node);
1307 this.el.set_value(n_iter, 2, o);
1312 // load children - if it has any..
1314 if (node.items.size > 0) {
1315 this.load(node.items, n_iter);
1316 _this.view.el.expand_row(this.el.get_path(n_iter), true);
1317 } else if (expand_parent != null && !_this.view.el.is_row_expanded(expand_parent)) {
1318 _this.view.el.expand_row(expand_parent,true);
1321 //if (tp != null && (node.items.length() > 0 || pos > 1)) {
1322 // _this.view.el.expand_row(this.el.get_path(iter_par), true);
1324 // wee need to get the empty proptypes from somewhere..
1326 //var olditer = this.activeIter;
1327 this.activePath = this.el.get_path(n_iter).to_string();
1332 _this.view.el.set_cursor(this.el.get_path(n_iter), null, false);
1338 public string treePathFromNode (JsRender.Node node) {
1339 // iterate through the tree and find the node
1342 this.el.foreach((mod, pth, iter) => {
1347 _this.model.el.get_value(iter, 2, out value);
1351 var n = (JsRender.Node)value;
1353 print("compare %s to %s\n", n.fqn(), node.fqn());
1355 ret = pth.to_string();
1365 public class Xcls_TreeViewColumn4 : Object
1367 public Gtk.TreeViewColumn el;
1368 private Xcls_WindowLeftTree _this;
1374 public Xcls_TreeViewColumn4(Xcls_WindowLeftTree _owner )
1377 this.el = new Gtk.TreeViewColumn();
1381 // set gobject values
1382 this.el.title = "test";
1383 var child_0 = new Xcls_renderer( _this );
1385 this.el.pack_start ( child_0.el , true );
1389 this.el.add_attribute(_this.renderer.el , "markup", 0 );
1392 // user defined functions
1394 public class Xcls_renderer : Object
1396 public Gtk.CellRendererText el;
1397 private Xcls_WindowLeftTree _this;
1403 public Xcls_renderer(Xcls_WindowLeftTree _owner )
1406 _this.renderer = this;
1407 this.el = new Gtk.CellRendererText();
1411 // set gobject values
1414 // user defined functions
1419 public class Xcls_LeftTreeMenu : Object
1422 private Xcls_WindowLeftTree _this;
1428 public Xcls_LeftTreeMenu(Xcls_WindowLeftTree _owner )
1431 _this.LeftTreeMenu = this;
1432 this.el = new Gtk.Menu();
1436 // set gobject values
1437 var child_0 = new Xcls_MenuItem7( _this );
1439 this.el.add ( child_0.el );
1440 var child_1 = new Xcls_MenuItem8( _this );
1442 this.el.add ( child_1.el );
1443 var child_2 = new Xcls_MenuItem9( _this );
1445 this.el.add ( child_2.el );
1448 // user defined functions
1450 public class Xcls_MenuItem7 : Object
1452 public Gtk.MenuItem el;
1453 private Xcls_WindowLeftTree _this;
1459 public Xcls_MenuItem7(Xcls_WindowLeftTree _owner )
1462 this.el = new Gtk.MenuItem();
1466 // set gobject values
1467 this.el.label = "Delete Element";
1470 this.el.activate.connect( ( ) => {
1475 _this.model.deleteSelected();
1479 // user defined functions
1482 public class Xcls_MenuItem8 : Object
1484 public Gtk.MenuItem el;
1485 private Xcls_WindowLeftTree _this;
1491 public Xcls_MenuItem8(Xcls_WindowLeftTree _owner )
1494 this.el = new Gtk.MenuItem();
1498 // set gobject values
1499 this.el.label = "Save as Template";
1502 this.el.activate.connect( () => {
1504 DialogSaveTemplate.singleton().show(
1505 (Gtk.Window) _this.el.get_toplevel (),
1506 _this.main_window.windowstate.file.palete(),
1507 _this.getActiveElement()
1514 // user defined functions
1517 public class Xcls_MenuItem9 : Object
1519 public Gtk.MenuItem el;
1520 private Xcls_WindowLeftTree _this;
1526 public Xcls_MenuItem9(Xcls_WindowLeftTree _owner )
1529 this.el = new Gtk.MenuItem();
1533 // set gobject values
1534 this.el.label = "Save as Module";
1537 this.el.activate.connect( () => {
1538 var node = _this.getActiveElement();
1539 var name = DialogSaveModule.singleton().show(
1540 (Gtk.Window) _this.el.get_toplevel (),
1541 _this.main_window.windowstate.project,
1544 if (name.length < 1) {
1548 node.props.set("* xinclude", name);
1552 var s = _this.view.el.get_selection();
1554 print("GET SELECTED?");
1559 if (!s.get_selected(out mod, out iter)) {
1560 return; // nothing seleted..
1563 var n_cn = mod.iter_n_children(iter) -1;
1564 for (var i = n_cn; i > -1; i--) {
1565 mod.iter_nth_child(out citer, iter, i);
1568 print("removing node from Tree\n");
1570 _this.model.el.remove(ref citer);
1573 _this.node_selected(node, "tree");
1579 // user defined functions