1 static Xcls_WindowLeftTree _WindowLeftTree;
3 public class Xcls_WindowLeftTree : Object
5 public Gtk.ScrolledWindow el;
6 private Xcls_WindowLeftTree _this;
8 public static Xcls_WindowLeftTree singleton()
10 if (_WindowLeftTree == null) {
11 _WindowLeftTree= new Xcls_WindowLeftTree();
13 return _WindowLeftTree;
15 public Xcls_view view;
16 public Xcls_model model;
17 public Xcls_renderer renderer;
18 public Xcls_LeftTreeMenu LeftTreeMenu;
21 public signal bool before_node_change (JsRender.Node? node);
22 public signal void changed ();
23 public signal void node_selected (JsRender.Node? node);
24 public Xcls_MainWindow main_window;
27 public Xcls_WindowLeftTree()
30 this.el = new Gtk.ScrolledWindow( null, null );
33 this.main_window = null;
36 this.el.shadow_type = Gtk.ShadowType.IN;
37 var child_0 = new Xcls_view( _this );
39 this.el.add ( child_0.el );
40 var child_1 = new Xcls_LeftTreeMenu( _this );
45 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
48 // user defined functions
49 public JsRender.Node? getActiveElement () { // return path to actie node.
51 var path = this.getActivePath();
52 if (path.length < 1) {
55 return _this.model.pathToNode(path);
58 public JsRender.JsRender getActiveFile () {
59 return this.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.tooltip_column = 1;
98 this.el.enable_tree_lines = true;
99 this.el.headers_visible = false;
100 var child_0 = new Xcls_model( _this );
102 this.el.set_model ( child_0.el );
103 var child_1 = new Xcls_TreeViewColumn4( _this );
105 this.el.append_column ( child_1.el );
110 var description = new Pango.FontDescription();
111 description.set_size(8000);
112 this.el.override_font(description);
114 var selection = this.el.get_selection();
115 selection.set_mode( Gtk.SelectionMode.SINGLE);
118 // is this really needed??
120 this.selection.signal['changed'].connect(function() {
121 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
122 _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
126 Gtk.drag_source_set (
127 this.el, /* widget will be drag-able */
128 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
129 BuilderApplication.targetList, /* lists of target to support */
130 Gdk.DragAction.COPY | Gdk.DragAction.MOVE | Gdk.DragAction.LINK /* what to do with data after dropped */
134 //Gtk.drag_source_add_text_targets(this.el);
138 this.el, /* widget that will accept a drop */
139 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
140 BuilderApplication.targetList, /* lists of target to support */
141 Gdk.DragAction.COPY | Gdk.DragAction.MOVE | Gdk.DragAction.LINK /* what to do with data after dropped */
144 //Gtk.drag_dest_set_target_list(this.el, Builder.Application.targetList);
145 //Gtk.drag_dest_add_text_targets(this.el);
149 this.el.button_press_event.connect( ( ev) => {
150 //console.log("button press?");
151 if (! _this.before_node_change(null) ) {
156 if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button != 3) {
157 //print("click" + ev.type);
161 if (!_this.view.el.get_path_at_pos((int)ev.x,(int)ev.y, out res, null, null, null) ) {
165 this.el.get_selection().select_path(res);
167 //if (!this.get('/LeftTreeMenu').el) {
168 // this.get('/LeftTreeMenu').init();
171 _this.LeftTreeMenu.el.set_screen(Gdk.Screen.get_default());
172 _this.LeftTreeMenu.el.show_all();
173 _this.LeftTreeMenu.el.popup(null, null, null, 3, ev.time);
174 // print("click:" + res.path.to_string());
177 this.el.cursor_changed.connect( ( ) => {
180 if (this.blockChanges) { // probably not needed..
183 if (!_this.before_node_change(null) ) {
184 this.blockChanges = true;
185 this.el.get_selection().unselect_all();
186 this.blockChanges = false;
189 if (_this.main_window.windowstate.file == null) {
193 //var render = this.get('/LeftTree').getRenderer();
194 print("LEFT TREE -> view -> selection changed called\n");
197 // -- it appears that the selection is not updated.
198 while (Gtk.events_pending()) {
199 Gtk.main_iteration();
201 GLib.Timeout.add_full(GLib.Priority.DEFAULT,10 , () => {
204 if (this.el.get_selection().count_selected_rows() < 1) {
206 print("selected rows < 1\n");
207 //??this.model.load( false);
208 _this.node_selected(null);
213 //console.log('changed');
214 var s = this.el.get_selection();
217 s.get_selected(out mod, out iter);
222 _this.model.el.get_value(iter, 2, out value);
223 _this.model.activePath = mod.get_path(iter).to_string();
225 var node = (JsRender.Node)value.dup_object();
226 _this.node_selected(node);
227 //while (Gtk.events_pending()) {
228 // Gtk.main_iteration();
230 var cp = mod.get_path(iter);
232 this.el.get_visible_range(out sp, out ep);
233 // if sp is before cp then retuns 1.
234 // if cp is before ep then retuns 1.
235 if (cp.compare(sp) >= 0 && ep.compare(cp) >=1) {
241 this.el.scroll_to_cell(new Gtk.TreePath.from_string(_this.model.activePath), null, true, 0.1f,0.0f);
245 //_this.after_node_change(node);
247 // _this.model.file.changed(node, "tree");
249 //Seed.print( value.get_string());
253 this.el.drag_begin.connect( ( ctx) => {
254 //print('SOURCE: drag-begin');
257 //this.targetData = "";
259 // find what is selected in our tree...
261 var s = _this.view.el.get_selection();
262 if (s.count_selected_rows() < 1) {
267 s.get_selected(out mod, out iter);
271 // set some properties of the tree for use by the dropped element.
273 _this.model.el.get_value(iter, 2, out value);
274 var tp = mod.get_path(iter).to_string();
275 var data = (JsRender.Node)(value.dup_object());
276 var xname = data.fqn();
277 print ("XNAME IS " + xname+ "\n");
279 this.dropList = _this.main_window.windowstate.file.palete().getDropList(xname);
281 print ("DROP LIST IS " + string.joinv(", ", this.dropList) + "\n");
284 // make the drag icon a picture of the node that was selected
287 // by default returns the path..
288 var path = _this.model.el.get_path(iter);
291 var pix = this.el.create_row_drag_icon ( path);
293 Gtk.drag_set_icon_surface (ctx, pix) ;
297 this.el.drag_end.connect( (drag_context) => {
298 //Seed.print('LEFT-TREE: drag-end');
300 this.dropList = null;
301 // this.targetData = "";
302 this.highlightDropPath("",0);
305 this.el.drag_motion.connect( ( ctx, x, y, time) => {
306 print("got drag motion\n");
307 var src = Gtk.drag_get_source_widget(ctx);
311 if (src != this.el) {
315 // the point of this is to detect where an item could be dropped..
316 print("requesting drag data\n");
317 this.drag_in_motion = true;
319 // request data that will be recieved by the recieve...
322 this.el, // will receive 'drag-data-received' signal
323 ctx, // represents the current state of the DnD
324 Gdk.Atom.intern("STRING",true), // the target type we want
331 print("action: %d\n", ctx.get_actions());
332 //print("GETTING POS");
336 Gtk.TreeViewDropPosition pos;
337 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
339 // if there are not items in the tree.. the we have to set isOver to true for anything..
341 if (_this.model.el.iter_n_children(null) < 1) {
342 print("got NO children?\n");
345 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
349 // ------------- a drag from self..
352 //var action = Gdk.DragAction.COPY;
353 // unless we are copying!!! ctl button..
355 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
356 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
357 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
360 if (_this.model.el.iter_n_children(null) < 1) {
361 // no children.. -- asume it's ok..
363 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
365 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
366 Gdk.drag_status(ctx, action ,time);
369 // continue through to allow drop...
377 //print("ISOVER? " + isOver);
380 Gdk.drag_status(ctx, 0 ,time);
381 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
386 // drag node is parent of child..
387 //console.log("SRC TREEPATH: " + src.treepath);
388 //console.log("TARGET TREEPATH: " + data.path.to_string());
390 // nned to check a few here..
391 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
392 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
393 //Gtk.TreeViewDropPosition.AFTER
394 //Gtk.TreeViewDropPosition.BEFORE
396 // locally dragged items to not really use the
397 var selection_text = this.dragData;
401 if (selection_text == null || selection_text.length < 1) {
402 //print("Error - drag selection text returned NULL");
403 Gdk.drag_status(ctx, 0 ,time);
404 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
409 // see if we are dragging into ourself?
410 var target_path = path.to_string();
411 print ("Drag %s onto %s--%d\n ", selection_text, target_path, pos);
413 // pos : 3 = ontop - 0 = after, 1 = before
414 //print("target_path="+target_path);
417 if (selection_text == target_path) {
418 print("self drag ?? == we should perhaps allow copy onto self..\n");
420 Gdk.drag_status(ctx, 0 ,time);
421 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
423 // -- fixme -- this is not really correct..
428 //print("DUMPING DATA");
429 //console.dump(data);
432 //print(data.path.to_string() +' => '+ data.pos);
434 // dropList is a list of xtypes that this node could be dropped on.
435 // it is set up when we start to drag..
438 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
440 print("targetDAta: " + targetData +"\n");
442 if (targetData.length < 1) {
443 //print("Can not find drop node path");
445 Gdk.drag_status(ctx, 0, time);
446 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
450 var td_ar = targetData.split("|");
454 Gdk.drag_status(ctx, action ,time);
455 this.highlightDropPath(td_ar[0], (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
460 this.el.drag_data_get.connect( ( drag_context, data, info, time) => {
463 //print("drag-data-get");
464 var s = this.el.get_selection();
465 if (s.count_selected_rows() < 1) {
467 print("return empty string - no selection..");
474 s.get_selected(out mod, out iter);
479 _this.model.el.get_value(iter, 2, out value);
480 var ndata = (JsRender.Node)(value.dup_object());
484 var tp = mod.get_path(iter).to_string();
485 // by default returns the path..
487 if ( info != Gdk.Atom.intern("STRING",true) ) {
488 tp = ndata.toJsonString();
491 //data.set_text(tp,tp.length);
493 data.set (data.get_target (), 8, (uchar[]) tp.to_utf8 ());
496 // print("return " + tp);
498 this.el.drag_data_received.connect( (ctx, x, y, sel, info, time) => {
500 // THIS CODE ONLY RELATES TO drag or drop of "NEW" elements or "FROM another tree.."
503 // print("Tree: drag-data-received\n");
504 var selection_text = (string)sel.get_data();
505 //print("selection_text= %s\n",selection_text);
507 var is_drag = this.drag_in_motion;
511 print("Is Drag %s\n", is_drag ? "Y": "N");
515 Gtk.TreeViewDropPosition pos;
516 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
518 // if there are not items in the tree.. the we have to set isOver to true for anything..
520 if (_this.model.el.iter_n_children(null) < 1) {
521 print("got NO children?\n");
524 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
528 //console.log("LEFT-TREE: drag-motion");
529 var src = Gtk.drag_get_source_widget(ctx);
531 // a drag from self - this should be handled by drop and motion.
532 if (src == this.el) {
533 print("Source == this element should not happen.. ? \n");
536 //print("drag_data_recieved from another element");
541 if (selection_text == null || selection_text.length < 1 || !isOver) {
542 // nothing valid foudn to drop...
543 print("empty sel text or not over");
545 Gdk.drag_status(ctx, 0, time);
546 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
549 Gtk.drag_finish (ctx, false, false, time); // drop failed..
554 var dropNode = new JsRender.Node();
556 var dropNodeType = selection_text;
557 var show_templates = true;
559 if (dropNodeType[0] == '{') {
560 var pa = new Json.Parser();
562 pa.load_from_data(dropNodeType);
564 Gtk.drag_finish (ctx, false, false, time); // drop failed..
569 dropNode.loadFromJson( pa.get_root().get_object(), 2);
570 dropNodeType = dropNode.fqn();
571 show_templates = false;
576 dropNode.setFqn(selection_text);
580 // dropList --- need to gather this ...
581 print("get dropList for : %s\n",dropNodeType);
582 var dropList = _this.main_window.windowstate.file.palete().getDropList(dropNodeType);
584 print("dropList: %s\n", string.joinv(" , ", dropList));
586 // if drag action is link ... then we can drop it anywahere...
587 if ((ctx.get_actions() & Gdk.DragAction.LINK) > 0) {
588 // if path is null?? dragging into an empty tree?
589 targetData = (path == null ? "" : path.to_string()) + "|%d".printf((int)pos);
593 targetData = _this.model.findDropNodeByPath( isEmpty ? "" : path.to_string(), dropList, pos);
598 print("targetDAta: " + targetData +"\n");
600 if (targetData.length < 1) {
602 // invalid drop path..
603 if (this.drag_in_motion) {
604 Gdk.drag_status(ctx, 0, time);
605 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
608 Gtk.drag_finish (ctx, false, false, time); // drop failed..
614 var td_ar = targetData.split("|");
617 if (this.drag_in_motion) {
618 Gdk.drag_status(ctx, Gdk.DragAction.COPY ,time);
620 this.highlightDropPath( td_ar[0] , (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
623 // continue on to allow drop..
626 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
629 _this.model.dropNode(targetData, dropNode, show_templates);
630 print("ADD new node!!!\n");
632 ///Xcls_DialogTemplateSelect.singleton().show( _this.model.file.palete(), node);
634 Gtk.drag_finish (ctx, false, false,time);
641 this.el.drag_drop.connect( ( ctx, x, y, time) => {
642 //Seed.print("TARGET: drag-drop");
645 var src = Gtk.drag_get_source_widget(ctx);
647 if (src != this.el) {
651 this.drag_in_motion = false;
652 // request data that will be recieved by the recieve...
655 this.el, // will receive 'drag-data-received' signal
656 ctx, // represents the current state of the DnD
657 Gdk.Atom.intern("application/json",true), // the target type we want
662 // No target offered by source => error
668 // handle drop around self..
672 //print("GETTING POS");
676 Gtk.TreeViewDropPosition pos;
677 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
679 // if there are not items in the tree.. the we have to set isOver to true for anything..
681 if (_this.model.el.iter_n_children(null) < 1) {
682 print("got NO children?\n");
685 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
690 //var action = Gdk.DragAction.COPY;
691 // unless we are copying!!! ctl button..
693 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
694 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
695 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
698 if (_this.model.el.iter_n_children(null) < 1) {
699 // no children.. -- asume it's ok..
701 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
703 // continue through to allow drop...
711 //print("ISOVER? " + isOver);
714 Gtk.drag_finish (ctx, false, false, time); // drop failed..
715 return true; // not over apoint!?! - no action on drop or motion..
718 // drag node is parent of child..
719 //console.log("SRC TREEPATH: " + src.treepath);
720 //console.log("TARGET TREEPATH: " + data.path.to_string());
722 // nned to check a few here..
723 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
724 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
725 //Gtk.TreeViewDropPosition.AFTER
726 //Gtk.TreeViewDropPosition.BEFORE
728 // locally dragged items to not really use the
729 var selection_text = this.dragData;
733 if (selection_text == null || selection_text.length < 1) {
734 //print("Error - drag selection text returned NULL");
736 Gtk.drag_finish (ctx, false, false, time); // drop failed..
737 return true; /// -- fixme -- this is not really correct..
740 // see if we are dragging into ourself?
741 print ("got selection text of " + selection_text);
743 var target_path = path.to_string();
744 //print("target_path="+target_path);
747 if (selection_text == target_path) {
748 print("self drag ?? == we should perhaps allow copy onto self..\n");
750 Gtk.drag_finish (ctx, false, false, time); // drop failed..
752 return true; /// -- fixme -- this is not really correct..
757 //print("DUMPING DATA");
758 //console.dump(data);
761 //print(data.path.to_string() +' => '+ data.pos);
763 // dropList is a list of xtypes that this node could be dropped on.
764 // it is set up when we start to drag..
767 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
769 print("targetDAta: " + targetData +"\n");
771 if (targetData.length < 1) {
772 //print("Can not find drop node path");
774 Gtk.drag_finish (ctx, false, false, time); // drop failed..
780 // continue on to allow drop..
782 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
785 var delete_selection_data = false;
787 if (action == Gdk.DragAction.ASK) {
788 /* Ask the user to move or copy, then set the ctx action. */
791 if (action == Gdk.DragAction.MOVE) {
792 delete_selection_data = true;
795 // drag around.. - reorder..
796 _this.model.moveNode(targetData, action);
802 // we can send stuff to souce here...
805 // do we always say failure, so we handle the reall drop?
806 Gtk.drag_finish (ctx, false, false,time); //delete_selection_data, time);
818 // user defined functions
819 public void highlightDropPath ( string treepath, Gtk.TreeViewDropPosition pos) {
821 // highlighting for drag/drop
822 if (treepath.length > 0) {
823 this.el.set_drag_dest_row( new Gtk.TreePath.from_string( treepath ), pos);
825 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
829 public void selectNode (string treepath_str) {
830 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
831 var tp = new Gtk.TreePath.from_string(treepath_str);
833 this.el.set_cursor(tp, null, false);
834 this.el.scroll_to_cell(tp, null, false, 0,0);
837 public class Xcls_model : Object
839 public Gtk.TreeStore el;
840 private Xcls_WindowLeftTree _this;
844 public DialogTemplateSelect template_select;
845 public string activePath;
848 public Xcls_model(Xcls_WindowLeftTree _owner )
852 this.el = new Gtk.TreeStore( 3, typeof(string),typeof(string),typeof(Object) );
855 this.template_select = null;
856 this.activePath = "";
858 // set gobject values
862 print("model initialized");
865 // user defined functions
866 public string findDropNode (string treepath_str, string[] targets) {
868 // this is used by the dragdrop code in the roo version AFAIR..
870 //var path = treepath_str.replace(/^builder-/, '');
871 // treemap is depreciated... - should really check if model has any entries..
873 if (this.el.iter_n_children(null) < 1) {
875 return "|%d".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
877 //print("FIND treepath: " + path);
878 //console.dump(this.treemap);
880 //if (!treepath_str.match(/^builder-/)) {
881 // return []; // nothing!
883 if (targets.length > 0 && targets[0] == "*") {
886 return this.findDropNodeByPath(treepath_str,targets, -1);
888 public void loadFile (JsRender.JsRender f) {
893 _this.main_window.windowstate.file = f;
896 if (f.tree == null) {
899 // if it's still null?
900 if (f.tree == null) {
904 var o = new Gee.ArrayList<JsRender.Node>();
908 _this.view.el.expand_all();
910 if (f.tree.items.size < 1) {
913 //this.get('/Window.leftvpaned').el.set_position(80);
915 _this.view.el.set_cursor(
916 new Gtk.TreePath.from_string("0"), null, false);
920 //this.get('/Window.leftvpaned').el.set_position(200);
927 public void updateSelected () {
930 var s = _this.view.el.get_selection();
937 if (!s.get_selected(out mod, out iter)) {
938 return; // nothing seleted..
942 this.el.get_value(iter, 2, out value);
943 var node = (JsRender.Node)(value.get_object());
945 this.el.set(iter, 0, node.nodeTitle(),
946 1, node.nodeTip(), -1
949 public string findDropNodeByPath (string treepath_str, string[] targets, int in_pref = -1) {
951 var path = treepath_str; // dupe it..
954 // pref : 3 = ontop - 0 = after, 1 = before
955 int pref = in_pref < 0 ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : in_pref;
959 //console.dump(this.treemap);
961 print("findDropNodeByPath : got path length %d / %s\n", path.length, path);
963 if (path.length == 0) {
964 // top drop. // just return empty..
965 return "|%d".printf((int)pref) ;
970 while (path.length > 0) {
972 if (path.length == treepath_str.length && pref != Gtk.TreeViewDropPosition.INTO_OR_AFTER) {
973 if (path.last_index_of(":") < 0 ) {
976 path = path.substring(0, path.last_index_of(":"));
978 print("DROP before or after : using %s\n",path);
982 //print("LOOKING FOR PATH: " + path);
983 var node_data = this.pathToNode(path);
985 if (node_data == null) {
986 print("node not found");
990 var xname = node_data.fqn();
994 for (var i =0; i < targets.length; i++) {
996 if ((tg == xname) ) {
1000 // if target is "xxxx:name"
1001 if (tg.contains(xname +":")) {
1003 var ar = tg.split(":");
1009 if (match.length > 0) {
1010 if (last.length > 0) { // pref is after/before..
1011 // then it's after last
1015 return last + "|%d".printf((int)pref) + "|" + prop;
1019 // we need to add prop - as :store -> needs to bee added when dropping onto.
1020 return path + "|%d".printf( (int) Gtk.TreeViewDropPosition.INTO_OR_AFTER) + "|" + prop;
1024 var par = path.split(":");
1025 string [] ppar = {};
1026 for (var i = 0; i < par.length-1; i++) {
1030 path = string.joinv(":", ppar);
1039 public void moveNode (string target_data, Gdk.DragAction action)
1042 /// target_data = "path|pos");
1045 //print("MOVE NODE");
1046 // console.dump(target_data);
1047 Gtk.TreeIter old_iter;
1050 var s = _this.view.el.get_selection();
1051 s.get_selected(out mod , out old_iter);
1052 mod.get_path(old_iter);
1054 var node = this.pathToNode(mod.get_path(old_iter).to_string());
1055 //console.dump(node);
1057 print("moveNode: ERROR - node is null?");
1062 // needs to drop first, otherwise the target_data
1063 // treepath will be invalid.
1066 if ((action & Gdk.DragAction.MOVE) > 0) {
1067 print("REMOVING OLD NODE : " + target_data + "\n");
1069 this.dropNode(target_data, node, false);
1070 this.el.remove(ref old_iter);
1075 print("DROPPING NODE // copy: " + target_data + "\n");
1076 node = node.deepClone();
1077 this.dropNode(target_data, node, false);
1080 this.activePath= "";
1081 //this.updateNode(false,true);
1083 public void load (Gee.ArrayList<JsRender.Node> tr, Gtk.TreeIter? iter)
1086 //this.insert(citer,iter,0);
1087 for(var i =0 ; i < tr.size; i++) {
1089 this.el.insert(out citer,iter,-1); // why not append?
1091 this.el.append(out citer,null);
1094 this.el.set(citer, 0, tr.get(i).nodeTitle(),
1095 1, tr.get(i).nodeTip(), -1
1097 var o = GLib.Value(typeof(Object));
1098 o.set_object((Object)tr.get(i));
1100 this.el.set_value(citer, 2, o);
1102 if (tr.get(i).items.size > 0) {
1103 this.load(tr.get(i).items, citer);
1110 public void deleteSelected () {
1112 print("DELETE SELECTED?");
1113 //_this.view.blockChanges = true;
1114 print("GET SELECTION?");
1116 var s = _this.view.el.get_selection();
1118 print("GET SELECTED?");
1123 if (!s.get_selected(out mod, out iter)) {
1124 return; // nothing seleted..
1129 this.activePath= "";
1130 print("GET vnode value?");
1133 this.el.get_value(iter, 2, out value);
1134 var data = (JsRender.Node)(value.get_object());
1135 print("removing node from Render\n");
1136 if (data.parent == null) {
1137 _this.main_window.windowstate.file.tree = null;
1141 print("removing node from Tree\n");
1143 this.el.remove(ref iter);
1153 this.activePath= ""; // again!?!?
1154 //this.changed(null,true);
1158 _this.view.blockChanges = false;
1160 public JsRender.Node pathToNode (string path) {
1164 _this.model.el.get_iter_from_string(out iter, path);
1167 _this.model.el.get_value(iter, 2, out value);
1169 return (JsRender.Node)value.dup_object();
1172 public void dropNode (string target_data_str, JsRender.Node node, bool show_templates) {
1173 // print("drop Node");
1174 // console.dump(node);
1175 // console.dump(target_data);
1178 // 0 = before , 1=after 2/3 onto
1181 var target_data= target_data_str.split("|");
1183 var parent_str = target_data[0].length > 0 ? target_data[0] : "";
1184 var pos = target_data.length > 1 ? int.parse(target_data[1]) : 2; // ontop..
1187 Gtk.TreePath tree_path = parent_str.length > 0 ? new Gtk.TreePath.from_string( parent_str ) : null;
1191 //print("add " + tp + "@" + target_data[1] );
1193 JsRender.Node parentNode = null;
1195 Gtk.TreeIter iter_after;
1196 Gtk.TreeIter iter_par ;
1199 if (target_data.length == 3 && target_data[2].length > 0) {
1200 node.props.set("* prop", target_data[2]);
1203 Gtk.TreePath expand_parent = null;
1205 // we only need to show the template if it's come from else where?
1206 if (show_templates) {
1208 var ts = _this.main_window.windowstate.template_select;
1210 var new_node = ts.show(
1211 _this.main_window, // (Gtk.Window) _this.el.get_toplevel (),
1212 _this.main_window.windowstate.file.palete(),
1214 _this.main_window.windowstate.project);
1216 if (new_node == null) {
1217 return; // do not add?
1222 //print("pos is %d \n".printf(pos));
1224 Gtk.TreeIter n_iter;
1226 if ( parent_str.length < 1) {
1227 this.el.append(out n_iter, null); // drop at top level..
1229 _this.main_window.windowstate.file.tree = node;
1232 } else if (pos < 2) {
1233 //print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
1235 this.el.get_iter(out iter_after, tree_path );
1236 this.el.iter_parent(out iter_par, iter_after);
1237 expand_parent = this.el.get_path(iter_par);
1240 this.el.get_value( iter_par, 2, out value);
1241 parentNode = (JsRender.Node)value.dup_object();
1244 this.el.get_value( iter_after, 2, out value);
1245 var relNode = (JsRender.Node)value.dup_object();
1249 this.el.insert_after(out n_iter, iter_par , iter_after);
1250 var ix = parentNode.items.index_of(relNode);
1251 parentNode.items.insert(ix+1, node);
1254 this.el.insert_before(out n_iter, iter_par , iter_after);
1255 var ix = parentNode.items.index_of(relNode);
1256 parentNode.items.insert(ix, node);
1259 node.parent = parentNode;
1264 // print("appending to " + parent_str);
1265 this.el.get_iter(out iter_par, tree_path);
1266 this.el.append(out n_iter, iter_par );
1267 expand_parent = this.el.get_path(iter_par);
1270 this.el.get_value( iter_par, 2, out value);
1271 parentNode = (JsRender.Node)value.dup_object();
1272 node.parent = parentNode;
1273 parentNode.items.add(node);
1276 // reparent node in tree...
1279 // why only on no parent???
1281 //if (node.parent = null) {
1288 // work out what kind of packing to use.. -- should be in
1289 if (!node.has("pack") && parent_str.length > 1) {
1291 _this.main_window.windowstate.file.palete().fillPack(node,parentNode);
1298 this.el.set(n_iter, 0, node.nodeTitle(), 1, node.nodeTip(), -1 );
1299 var o = GLib.Value(typeof(Object));
1300 o.set_object((Object)node);
1302 this.el.set_value(n_iter, 2, o);
1307 // load children - if it has any..
1309 if (node.items.size > 0) {
1310 this.load(node.items, n_iter);
1311 _this.view.el.expand_row(this.el.get_path(n_iter), true);
1312 } else if (expand_parent != null && !_this.view.el.is_row_expanded(expand_parent)) {
1313 _this.view.el.expand_row(expand_parent,true);
1316 //if (tp != null && (node.items.length() > 0 || pos > 1)) {
1317 // _this.view.el.expand_row(this.el.get_path(iter_par), true);
1319 // wee need to get the empty proptypes from somewhere..
1321 //var olditer = this.activeIter;
1322 this.activePath = this.el.get_path(n_iter).to_string();
1327 _this.view.el.set_cursor(this.el.get_path(n_iter), null, false);
1333 public string treePathFromNode (JsRender.Node node) {
1334 // iterate through the tree and find the node
1337 this.el.foreach((mod, pth, iter) => {
1342 _this.model.el.get_value(iter, 2, out value);
1346 var n = (JsRender.Node)value;
1348 print("compare %s to %s\n", n.fqn(), node.fqn());
1350 ret = pth.to_string();
1360 public class Xcls_TreeViewColumn4 : Object
1362 public Gtk.TreeViewColumn el;
1363 private Xcls_WindowLeftTree _this;
1369 public Xcls_TreeViewColumn4(Xcls_WindowLeftTree _owner )
1372 this.el = new Gtk.TreeViewColumn();
1376 // set gobject values
1377 this.el.title = "test";
1378 var child_0 = new Xcls_renderer( _this );
1380 this.el.pack_start ( child_0.el , true );
1384 this.el.add_attribute(_this.renderer.el , "markup", 0 );
1387 // user defined functions
1389 public class Xcls_renderer : Object
1391 public Gtk.CellRendererText el;
1392 private Xcls_WindowLeftTree _this;
1398 public Xcls_renderer(Xcls_WindowLeftTree _owner )
1401 _this.renderer = this;
1402 this.el = new Gtk.CellRendererText();
1406 // set gobject values
1409 // user defined functions
1414 public class Xcls_LeftTreeMenu : Object
1417 private Xcls_WindowLeftTree _this;
1423 public Xcls_LeftTreeMenu(Xcls_WindowLeftTree _owner )
1426 _this.LeftTreeMenu = this;
1427 this.el = new Gtk.Menu();
1431 // set gobject values
1432 var child_0 = new Xcls_MenuItem7( _this );
1434 this.el.add ( child_0.el );
1435 var child_1 = new Xcls_MenuItem8( _this );
1437 this.el.add ( child_1.el );
1438 var child_2 = new Xcls_MenuItem9( _this );
1440 this.el.add ( child_2.el );
1443 // user defined functions
1445 public class Xcls_MenuItem7 : Object
1447 public Gtk.MenuItem el;
1448 private Xcls_WindowLeftTree _this;
1454 public Xcls_MenuItem7(Xcls_WindowLeftTree _owner )
1457 this.el = new Gtk.MenuItem();
1461 // set gobject values
1462 this.el.label = "Delete Element";
1465 this.el.activate.connect( ( ) => {
1470 _this.model.deleteSelected();
1474 // user defined functions
1477 public class Xcls_MenuItem8 : Object
1479 public Gtk.MenuItem el;
1480 private Xcls_WindowLeftTree _this;
1486 public Xcls_MenuItem8(Xcls_WindowLeftTree _owner )
1489 this.el = new Gtk.MenuItem();
1493 // set gobject values
1494 this.el.label = "Save as Template";
1497 this.el.activate.connect( () => {
1499 DialogSaveTemplate.singleton().show(
1500 (Gtk.Window) _this.el.get_toplevel (),
1501 _this.main_window.windowstate.file.palete(),
1502 _this.getActiveElement()
1509 // user defined functions
1512 public class Xcls_MenuItem9 : Object
1514 public Gtk.MenuItem el;
1515 private Xcls_WindowLeftTree _this;
1521 public Xcls_MenuItem9(Xcls_WindowLeftTree _owner )
1524 this.el = new Gtk.MenuItem();
1528 // set gobject values
1529 this.el.label = "Save as Module";
1532 this.el.activate.connect( () => {
1533 var node = _this.getActiveElement();
1534 var name = DialogSaveModule.singleton().show(
1535 (Gtk.Window) _this.el.get_toplevel (),
1536 _this.main_window.windowstate.project,
1539 if (name.length < 1) {
1543 node.props.set("* xinclude", name);
1547 var s = _this.view.el.get_selection();
1549 print("GET SELECTED?");
1554 if (!s.get_selected(out mod, out iter)) {
1555 return; // nothing seleted..
1558 var n_cn = mod.iter_n_children(iter) -1;
1559 for (var i = n_cn; i > -1; i--) {
1560 mod.iter_nth_child(out citer, iter, i);
1563 print("removing node from Tree\n");
1565 _this.model.el.remove(ref citer);
1568 _this.node_selected(node);
1574 // user defined functions