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, string source) {
831 this.lastEventSource = source;
832 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
833 var tp = new Gtk.TreePath.from_string(treepath_str);
835 this.el.set_cursor(tp, null, false);
836 this.el.scroll_to_cell(tp, null, false, 0,0);
839 public class Xcls_model : Object
841 public Gtk.TreeStore el;
842 private Xcls_WindowLeftTree _this;
846 public DialogTemplateSelect template_select;
847 public string activePath;
850 public Xcls_model(Xcls_WindowLeftTree _owner )
854 this.el = new Gtk.TreeStore( 3, typeof(string),typeof(string),typeof(Object) );
857 this.template_select = null;
858 this.activePath = "";
860 // set gobject values
864 print("model initialized");
867 // user defined functions
868 public string findDropNode (string treepath_str, string[] targets) {
870 // this is used by the dragdrop code in the roo version AFAIR..
872 //var path = treepath_str.replace(/^builder-/, '');
873 // treemap is depreciated... - should really check if model has any entries..
875 if (this.el.iter_n_children(null) < 1) {
877 return "|%d".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
879 //print("FIND treepath: " + path);
880 //console.dump(this.treemap);
882 //if (!treepath_str.match(/^builder-/)) {
883 // return []; // nothing!
885 if (targets.length > 0 && targets[0] == "*") {
888 return this.findDropNodeByPath(treepath_str,targets, -1);
890 public void loadFile (JsRender.JsRender f) {
895 _this.main_window.windowstate.file = f;
898 if (f.tree == null) {
905 // if it's still null?
906 if (f.tree == null) {
910 var o = new Gee.ArrayList<JsRender.Node>();
914 _this.view.el.expand_all();
916 if (f.tree.items.size < 1) {
919 //this.get('/Window.leftvpaned').el.set_position(80);
921 _this.view.el.set_cursor(
922 new Gtk.TreePath.from_string("0"), null, false);
926 //this.get('/Window.leftvpaned').el.set_position(200);
933 public void updateSelected () {
936 var s = _this.view.el.get_selection();
943 if (!s.get_selected(out mod, out iter)) {
944 return; // nothing seleted..
948 this.el.get_value(iter, 2, out value);
949 var node = (JsRender.Node)(value.get_object());
951 this.el.set(iter, 0, node.nodeTitle(),
952 1, node.nodeTip(), -1
955 public string findDropNodeByPath (string treepath_str, string[] targets, int in_pref = -1) {
957 var path = treepath_str; // dupe it..
960 // pref : 3 = ontop - 0 = after, 1 = before
961 int pref = in_pref < 0 ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : in_pref;
965 //console.dump(this.treemap);
967 print("findDropNodeByPath : got path length %d / %s\n", path.length, path);
969 if (path.length == 0) {
970 // top drop. // just return empty..
971 return "|%d".printf((int)pref) ;
976 while (path.length > 0) {
978 if (path.length == treepath_str.length && pref != Gtk.TreeViewDropPosition.INTO_OR_AFTER) {
979 if (path.last_index_of(":") < 0 ) {
982 path = path.substring(0, path.last_index_of(":"));
984 print("DROP before or after : using %s\n",path);
988 //print("LOOKING FOR PATH: " + path);
989 var node_data = this.pathToNode(path);
991 if (node_data == null) {
992 print("node not found");
996 var xname = node_data.fqn();
1000 for (var i =0; i < targets.length; i++) {
1001 var tg = targets[i];
1002 if ((tg == xname) ) {
1006 // if target is "xxxx:name"
1007 if (tg.contains(xname +":")) {
1009 var ar = tg.split(":");
1015 if (match.length > 0) {
1016 if (last.length > 0) { // pref is after/before..
1017 // then it's after last
1021 return last + "|%d".printf((int)pref) + "|" + prop;
1025 // we need to add prop - as :store -> needs to bee added when dropping onto.
1026 return path + "|%d".printf( (int) Gtk.TreeViewDropPosition.INTO_OR_AFTER) + "|" + prop;
1030 var par = path.split(":");
1031 string [] ppar = {};
1032 for (var i = 0; i < par.length-1; i++) {
1036 path = string.joinv(":", ppar);
1045 public void moveNode (string target_data, Gdk.DragAction action)
1048 /// target_data = "path|pos");
1051 //print("MOVE NODE");
1052 // console.dump(target_data);
1053 Gtk.TreeIter old_iter;
1056 var s = _this.view.el.get_selection();
1057 s.get_selected(out mod , out old_iter);
1058 mod.get_path(old_iter);
1060 var node = this.pathToNode(mod.get_path(old_iter).to_string());
1061 //console.dump(node);
1063 print("moveNode: ERROR - node is null?");
1068 // needs to drop first, otherwise the target_data
1069 // treepath will be invalid.
1072 if ((action & Gdk.DragAction.MOVE) > 0) {
1073 print("REMOVING OLD NODE : " + target_data + "\n");
1075 this.dropNode(target_data, node, false);
1076 this.el.remove(ref old_iter);
1081 print("DROPPING NODE // copy: " + target_data + "\n");
1082 node = node.deepClone();
1083 this.dropNode(target_data, node, false);
1086 this.activePath= "";
1087 //this.updateNode(false,true);
1089 public void load (Gee.ArrayList<JsRender.Node> tr, Gtk.TreeIter? iter)
1092 //this.insert(citer,iter,0);
1093 for(var i =0 ; i < tr.size; i++) {
1095 this.el.insert(out citer,iter,-1); // why not append?
1097 this.el.append(out citer,null);
1100 this.el.set(citer, 0, tr.get(i).nodeTitle(),
1101 1, tr.get(i).nodeTip(), -1
1103 var o = GLib.Value(typeof(Object));
1104 o.set_object((Object)tr.get(i));
1106 this.el.set_value(citer, 2, o);
1108 if (tr.get(i).items.size > 0) {
1109 this.load(tr.get(i).items, citer);
1116 public void deleteSelected () {
1118 print("DELETE SELECTED?");
1119 //_this.view.blockChanges = true;
1120 print("GET SELECTION?");
1122 var s = _this.view.el.get_selection();
1124 print("GET SELECTED?");
1129 if (!s.get_selected(out mod, out iter)) {
1130 return; // nothing seleted..
1135 this.activePath= "";
1136 print("GET vnode value?");
1139 this.el.get_value(iter, 2, out value);
1140 var data = (JsRender.Node)(value.get_object());
1141 print("removing node from Render\n");
1142 if (data.parent == null) {
1143 _this.main_window.windowstate.file.tree = null;
1147 print("removing node from Tree\n");
1149 this.el.remove(ref iter);
1159 this.activePath= ""; // again!?!?
1160 //this.changed(null,true);
1164 _this.view.blockChanges = false;
1166 public JsRender.Node pathToNode (string path) {
1170 _this.model.el.get_iter_from_string(out iter, path);
1173 _this.model.el.get_value(iter, 2, out value);
1175 return (JsRender.Node)value.dup_object();
1178 public void dropNode (string target_data_str, JsRender.Node node, bool show_templates) {
1179 // print("drop Node");
1180 // console.dump(node);
1181 // console.dump(target_data);
1184 // 0 = before , 1=after 2/3 onto
1187 var target_data= target_data_str.split("|");
1189 var parent_str = target_data[0].length > 0 ? target_data[0] : "";
1190 var pos = target_data.length > 1 ? int.parse(target_data[1]) : 2; // ontop..
1193 Gtk.TreePath tree_path = parent_str.length > 0 ? new Gtk.TreePath.from_string( parent_str ) : null;
1197 //print("add " + tp + "@" + target_data[1] );
1199 JsRender.Node parentNode = null;
1201 Gtk.TreeIter iter_after;
1202 Gtk.TreeIter iter_par ;
1205 if (target_data.length == 3 && target_data[2].length > 0) {
1206 node.props.set("* prop", target_data[2]);
1209 Gtk.TreePath expand_parent = null;
1211 // we only need to show the template if it's come from else where?
1212 if (show_templates) {
1214 var ts = _this.main_window.windowstate.template_select;
1216 var new_node = ts.show(
1217 _this.main_window, // (Gtk.Window) _this.el.get_toplevel (),
1218 _this.main_window.windowstate.file.palete(),
1220 _this.main_window.windowstate.project);
1222 if (new_node == null) {
1223 return; // do not add?
1228 //print("pos is %d \n".printf(pos));
1230 Gtk.TreeIter n_iter;
1232 if ( parent_str.length < 1) {
1233 this.el.append(out n_iter, null); // drop at top level..
1235 _this.main_window.windowstate.file.tree = node;
1238 } else if (pos < 2) {
1239 //print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
1241 this.el.get_iter(out iter_after, tree_path );
1242 this.el.iter_parent(out iter_par, iter_after);
1243 expand_parent = this.el.get_path(iter_par);
1246 this.el.get_value( iter_par, 2, out value);
1247 parentNode = (JsRender.Node)value.dup_object();
1250 this.el.get_value( iter_after, 2, out value);
1251 var relNode = (JsRender.Node)value.dup_object();
1255 this.el.insert_after(out n_iter, iter_par , iter_after);
1256 var ix = parentNode.items.index_of(relNode);
1257 parentNode.items.insert(ix+1, node);
1260 this.el.insert_before(out n_iter, iter_par , iter_after);
1261 var ix = parentNode.items.index_of(relNode);
1262 parentNode.items.insert(ix, node);
1265 node.parent = parentNode;
1270 // print("appending to " + parent_str);
1271 this.el.get_iter(out iter_par, tree_path);
1272 this.el.append(out n_iter, iter_par );
1273 expand_parent = this.el.get_path(iter_par);
1276 this.el.get_value( iter_par, 2, out value);
1277 parentNode = (JsRender.Node)value.dup_object();
1278 node.parent = parentNode;
1279 parentNode.items.add(node);
1282 // reparent node in tree...
1285 // why only on no parent???
1287 //if (node.parent = null) {
1294 // work out what kind of packing to use.. -- should be in
1295 if (!node.has("pack") && parent_str.length > 1) {
1297 _this.main_window.windowstate.file.palete().fillPack(node,parentNode);
1304 this.el.set(n_iter, 0, node.nodeTitle(), 1, node.nodeTip(), -1 );
1305 var o = GLib.Value(typeof(Object));
1306 o.set_object((Object)node);
1308 this.el.set_value(n_iter, 2, o);
1313 // load children - if it has any..
1315 if (node.items.size > 0) {
1316 this.load(node.items, n_iter);
1317 _this.view.el.expand_row(this.el.get_path(n_iter), true);
1318 } else if (expand_parent != null && !_this.view.el.is_row_expanded(expand_parent)) {
1319 _this.view.el.expand_row(expand_parent,true);
1322 //if (tp != null && (node.items.length() > 0 || pos > 1)) {
1323 // _this.view.el.expand_row(this.el.get_path(iter_par), true);
1325 // wee need to get the empty proptypes from somewhere..
1327 //var olditer = this.activeIter;
1328 this.activePath = this.el.get_path(n_iter).to_string();
1333 _this.view.el.set_cursor(this.el.get_path(n_iter), null, false);
1339 public string treePathFromNode (JsRender.Node node) {
1340 // iterate through the tree and find the node
1343 this.el.foreach((mod, pth, iter) => {
1348 _this.model.el.get_value(iter, 2, out value);
1352 var n = (JsRender.Node)value;
1354 print("compare %s to %s\n", n.fqn(), node.fqn());
1356 ret = pth.to_string();
1366 public class Xcls_TreeViewColumn4 : Object
1368 public Gtk.TreeViewColumn el;
1369 private Xcls_WindowLeftTree _this;
1375 public Xcls_TreeViewColumn4(Xcls_WindowLeftTree _owner )
1378 this.el = new Gtk.TreeViewColumn();
1382 // set gobject values
1383 this.el.title = "test";
1384 var child_0 = new Xcls_renderer( _this );
1386 this.el.pack_start ( child_0.el , true );
1390 this.el.add_attribute(_this.renderer.el , "markup", 0 );
1393 // user defined functions
1395 public class Xcls_renderer : Object
1397 public Gtk.CellRendererText el;
1398 private Xcls_WindowLeftTree _this;
1404 public Xcls_renderer(Xcls_WindowLeftTree _owner )
1407 _this.renderer = this;
1408 this.el = new Gtk.CellRendererText();
1412 // set gobject values
1415 // user defined functions
1420 public class Xcls_LeftTreeMenu : Object
1423 private Xcls_WindowLeftTree _this;
1429 public Xcls_LeftTreeMenu(Xcls_WindowLeftTree _owner )
1432 _this.LeftTreeMenu = this;
1433 this.el = new Gtk.Menu();
1437 // set gobject values
1438 var child_0 = new Xcls_MenuItem7( _this );
1440 this.el.add ( child_0.el );
1441 var child_1 = new Xcls_MenuItem8( _this );
1443 this.el.add ( child_1.el );
1444 var child_2 = new Xcls_MenuItem9( _this );
1446 this.el.add ( child_2.el );
1449 // user defined functions
1451 public class Xcls_MenuItem7 : Object
1453 public Gtk.MenuItem el;
1454 private Xcls_WindowLeftTree _this;
1460 public Xcls_MenuItem7(Xcls_WindowLeftTree _owner )
1463 this.el = new Gtk.MenuItem();
1467 // set gobject values
1468 this.el.label = "Delete Element";
1471 this.el.activate.connect( ( ) => {
1476 _this.model.deleteSelected();
1480 // user defined functions
1483 public class Xcls_MenuItem8 : Object
1485 public Gtk.MenuItem el;
1486 private Xcls_WindowLeftTree _this;
1492 public Xcls_MenuItem8(Xcls_WindowLeftTree _owner )
1495 this.el = new Gtk.MenuItem();
1499 // set gobject values
1500 this.el.label = "Save as Template";
1503 this.el.activate.connect( () => {
1505 DialogSaveTemplate.singleton().show(
1506 (Gtk.Window) _this.el.get_toplevel (),
1507 _this.main_window.windowstate.file.palete(),
1508 _this.getActiveElement()
1515 // user defined functions
1518 public class Xcls_MenuItem9 : Object
1520 public Gtk.MenuItem el;
1521 private Xcls_WindowLeftTree _this;
1527 public Xcls_MenuItem9(Xcls_WindowLeftTree _owner )
1530 this.el = new Gtk.MenuItem();
1534 // set gobject values
1535 this.el.label = "Save as Module";
1538 this.el.activate.connect( () => {
1539 var node = _this.getActiveElement();
1540 var name = DialogSaveModule.singleton().show(
1541 (Gtk.Window) _this.el.get_toplevel (),
1542 _this.main_window.windowstate.project,
1545 if (name.length < 1) {
1549 node.props.set("* xinclude", name);
1553 var s = _this.view.el.get_selection();
1555 print("GET SELECTED?");
1560 if (!s.get_selected(out mod, out iter)) {
1561 return; // nothing seleted..
1564 var n_cn = mod.iter_n_children(iter) -1;
1565 for (var i = n_cn; i > -1; i--) {
1566 mod.iter_nth_child(out citer, iter, i);
1569 print("removing node from Tree\n");
1571 _this.model.el.remove(ref citer);
1574 _this.node_selected(node, "tree");
1580 // user defined functions