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 ();
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;
81 public string[] dropList;
83 public string lastEventSource;
84 public bool drag_in_motion;
85 public bool blockChanges;
88 public Xcls_view(Xcls_WindowLeftTree _owner )
92 this.el = new Gtk.TreeView();
95 this.lastEventSource = "";
96 this.blockChanges = false;
99 this.el.expand = true;
100 this.el.tooltip_column = 1;
101 this.el.enable_tree_lines = true;
102 this.el.headers_visible = false;
103 var child_0 = new Xcls_model( _this );
105 this.el.set_model ( child_0.el );
106 var child_1 = new Xcls_TreeViewColumn4( _this );
108 this.el.append_column ( child_1.el );
113 var description = new Pango.FontDescription();
114 description.set_size(8000);
115 this.el.override_font(description);
117 var selection = this.el.get_selection();
118 selection.set_mode( Gtk.SelectionMode.SINGLE);
121 // is this really needed??
123 this.selection.signal['changed'].connect(function() {
124 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
125 _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
129 Gtk.drag_source_set (
130 this.el, /* widget will be drag-able */
131 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
132 BuilderApplication.targetList, /* lists of target to support */
133 Gdk.DragAction.COPY | Gdk.DragAction.MOVE | Gdk.DragAction.LINK /* what to do with data after dropped */
137 //Gtk.drag_source_add_text_targets(this.el);
141 this.el, /* widget that will accept a drop */
142 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
143 BuilderApplication.targetList, /* lists of target to support */
144 Gdk.DragAction.COPY | Gdk.DragAction.MOVE | Gdk.DragAction.LINK /* what to do with data after dropped */
147 //Gtk.drag_dest_set_target_list(this.el, Builder.Application.targetList);
148 //Gtk.drag_dest_add_text_targets(this.el);
152 this.el.button_press_event.connect( ( ev) => {
153 //console.log("button press?");
154 this.lastEventSource = "tree";
155 if (! _this.before_node_change() ) {
162 if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button != 3) {
163 //print("click" + ev.type);
167 if (!_this.view.el.get_path_at_pos((int)ev.x,(int)ev.y, out res, null, null, null) ) {
171 this.el.get_selection().select_path(res);
173 //if (!this.get('/LeftTreeMenu').el) {
174 // this.get('/LeftTreeMenu').init();
177 _this.LeftTreeMenu.el.set_screen(Gdk.Screen.get_default());
178 _this.LeftTreeMenu.el.show_all();
179 _this.LeftTreeMenu.el.popup(null, null, null, 3, ev.time);
180 // print("click:" + res.path.to_string());
183 this.el.drag_begin.connect( ( ctx) => {
184 //print('SOURCE: drag-begin');
187 //this.targetData = "";
189 // find what is selected in our tree...
191 var s = _this.view.el.get_selection();
192 if (s.count_selected_rows() < 1) {
197 s.get_selected(out mod, out iter);
201 // set some properties of the tree for use by the dropped element.
203 _this.model.el.get_value(iter, 2, out value);
204 var tp = mod.get_path(iter).to_string();
205 var data = (JsRender.Node)(value.dup_object());
206 var xname = data.fqn();
207 print ("XNAME IS " + xname+ "\n");
209 this.dropList = _this.main_window.windowstate.file.palete().getDropList(xname);
211 print ("DROP LIST IS " + string.joinv(", ", this.dropList) + "\n");
214 // make the drag icon a picture of the node that was selected
217 // by default returns the path..
218 var path = _this.model.el.get_path(iter);
221 var pix = this.el.create_row_drag_icon ( path);
223 Gtk.drag_set_icon_surface (ctx, pix) ;
227 this.el.cursor_changed.connect( ( ) => {
230 if (this.blockChanges) { // probably not needed..
233 if (!_this.before_node_change( ) ) {
234 this.blockChanges = true;
235 this.el.get_selection().unselect_all();
236 this.blockChanges = false;
239 if (_this.main_window.windowstate.file == null) {
243 //var render = this.get('/LeftTree').getRenderer();
244 print("LEFT TREE -> view -> selection changed called\n");
247 // -- it appears that the selection is not updated.
249 GLib.Timeout.add_full(GLib.Priority.DEFAULT,10 , () => {
252 if (this.el.get_selection().count_selected_rows() < 1) {
254 print("selected rows < 1\n");
255 //??this.model.load( false);
256 _this.node_selected(null, this.lastEventSource);
261 //console.log('changed');
262 var s = this.el.get_selection();
265 s.get_selected(out mod, out iter);
270 _this.model.el.get_value(iter, 2, out value);
271 _this.model.activePath = mod.get_path(iter).to_string();
273 var node = (JsRender.Node)value.dup_object();
274 _this.node_selected(node, this.lastEventSource);
275 while (Gtk.events_pending()) {
276 Gtk.main_iteration();
278 var cp = mod.get_path(iter);
280 this.el.get_visible_range(out sp, out ep);
281 // if sp is before cp then retuns 1.
282 // if cp is before ep then retuns 1.
283 if (cp.compare(sp) >= 0 && ep.compare(cp) >=1) {
289 this.el.scroll_to_cell(new Gtk.TreePath.from_string(_this.model.activePath), null, true, 0.1f,0.0f);
293 //_this.after_node_change(node);
295 // _this.model.file.changed(node, "tree");
297 //Seed.print( value.get_string());
301 this.el.drag_end.connect( (drag_context) => {
302 //Seed.print('LEFT-TREE: drag-end');
304 this.dropList = null;
305 // this.targetData = "";
306 this.highlightDropPath("",0);
309 this.el.drag_motion.connect( ( ctx, x, y, time) => {
310 print("got drag motion\n");
311 var src = Gtk.drag_get_source_widget(ctx);
315 if (src != this.el) {
319 // the point of this is to detect where an item could be dropped..
320 print("requesting drag data\n");
321 this.drag_in_motion = true;
323 // request data that will be recieved by the recieve...
326 this.el, // will receive 'drag-data-received' signal
327 ctx, // represents the current state of the DnD
328 Gdk.Atom.intern("STRING",true), // the target type we want
335 print("action: %d\n", ctx.get_actions());
336 //print("GETTING POS");
340 Gtk.TreeViewDropPosition pos;
341 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
343 // if there are not items in the tree.. the we have to set isOver to true for anything..
345 if (_this.model.el.iter_n_children(null) < 1) {
346 print("got NO children?\n");
349 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
353 // ------------- a drag from self..
356 //var action = Gdk.DragAction.COPY;
357 // unless we are copying!!! ctl button..
359 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
360 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
361 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
364 if (_this.model.el.iter_n_children(null) < 1) {
365 // no children.. -- asume it's ok..
367 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
369 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
370 Gdk.drag_status(ctx, action ,time);
373 // continue through to allow drop...
381 //print("ISOVER? " + isOver);
384 Gdk.drag_status(ctx, 0 ,time);
385 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
390 // drag node is parent of child..
391 //console.log("SRC TREEPATH: " + src.treepath);
392 //console.log("TARGET TREEPATH: " + data.path.to_string());
394 // nned to check a few here..
395 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
396 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
397 //Gtk.TreeViewDropPosition.AFTER
398 //Gtk.TreeViewDropPosition.BEFORE
400 // locally dragged items to not really use the
401 var selection_text = this.dragData;
405 if (selection_text == null || selection_text.length < 1) {
406 //print("Error - drag selection text returned NULL");
407 Gdk.drag_status(ctx, 0 ,time);
408 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
413 // see if we are dragging into ourself?
414 var target_path = path.to_string();
415 print ("Drag %s onto %s--%d\n ", selection_text, target_path, pos);
417 // pos : 3 = ontop - 0 = after, 1 = before
418 //print("target_path="+target_path);
421 if (selection_text == target_path) {
422 print("self drag ?? == we should perhaps allow copy onto self..\n");
424 Gdk.drag_status(ctx, 0 ,time);
425 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
427 // -- fixme -- this is not really correct..
432 //print("DUMPING DATA");
433 //console.dump(data);
436 //print(data.path.to_string() +' => '+ data.pos);
438 // dropList is a list of xtypes that this node could be dropped on.
439 // it is set up when we start to drag..
442 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
444 print("targetDAta: " + targetData +"\n");
446 if (targetData.length < 1) {
447 //print("Can not find drop node path");
449 Gdk.drag_status(ctx, 0, time);
450 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
454 var td_ar = targetData.split("|");
458 Gdk.drag_status(ctx, action ,time);
459 this.highlightDropPath(td_ar[0], (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
464 this.el.drag_data_get.connect( ( drag_context, data, info, time) => {
467 //print("drag-data-get");
468 var s = this.el.get_selection();
469 if (s.count_selected_rows() < 1) {
471 print("return empty string - no selection..");
478 s.get_selected(out mod, out iter);
483 _this.model.el.get_value(iter, 2, out value);
484 var ndata = (JsRender.Node)(value.dup_object());
488 var tp = mod.get_path(iter).to_string();
489 // by default returns the path..
491 if ( info != Gdk.Atom.intern("STRING",true) ) {
492 tp = ndata.toJsonString();
495 //data.set_text(tp,tp.length);
497 data.set (data.get_target (), 8, (uchar[]) tp.to_utf8 ());
500 // print("return " + tp);
502 this.el.drag_data_received.connect( (ctx, x, y, sel, info, time) => {
504 // THIS CODE ONLY RELATES TO drag or drop of "NEW" elements or "FROM another tree.."
507 // print("Tree: drag-data-received\n");
508 var selection_text = (string)sel.get_data();
509 //print("selection_text= %s\n",selection_text);
511 var is_drag = this.drag_in_motion;
515 print("Is Drag %s\n", is_drag ? "Y": "N");
519 Gtk.TreeViewDropPosition pos;
520 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
522 // if there are not items in the tree.. the we have to set isOver to true for anything..
524 if (_this.model.el.iter_n_children(null) < 1) {
525 print("got NO children?\n");
528 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
532 //console.log("LEFT-TREE: drag-motion");
533 var src = Gtk.drag_get_source_widget(ctx);
535 // a drag from self - this should be handled by drop and motion.
536 if (src == this.el) {
537 print("Source == this element should not happen.. ? \n");
540 //print("drag_data_recieved from another element");
545 if (selection_text == null || selection_text.length < 1 || !isOver) {
546 // nothing valid foudn to drop...
547 print("empty sel text or not over");
549 Gdk.drag_status(ctx, 0, time);
550 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
553 Gtk.drag_finish (ctx, false, false, time); // drop failed..
558 var dropNode = new JsRender.Node();
560 var dropNodeType = selection_text;
561 var show_templates = true;
563 if (dropNodeType[0] == '{') {
564 var pa = new Json.Parser();
566 pa.load_from_data(dropNodeType);
568 Gtk.drag_finish (ctx, false, false, time); // drop failed..
573 dropNode.loadFromJson( pa.get_root().get_object(), 2);
574 dropNodeType = dropNode.fqn();
575 show_templates = false;
580 dropNode.setFqn(selection_text);
584 // dropList --- need to gather this ...
585 print("get dropList for : %s\n",dropNodeType);
586 var dropList = _this.main_window.windowstate.file.palete().getDropList(dropNodeType);
588 print("dropList: %s\n", string.joinv(" , ", dropList));
590 // if drag action is link ... then we can drop it anywahere...
591 if ((ctx.get_actions() & Gdk.DragAction.LINK) > 0) {
592 // if path is null?? dragging into an empty tree?
593 targetData = (path == null ? "" : path.to_string()) + "|%d".printf((int)pos);
597 targetData = _this.model.findDropNodeByPath( isEmpty ? "" : path.to_string(), dropList, pos);
602 print("targetDAta: " + targetData +"\n");
604 if (targetData.length < 1) {
606 // invalid drop path..
607 if (this.drag_in_motion) {
608 Gdk.drag_status(ctx, 0, time);
609 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
612 Gtk.drag_finish (ctx, false, false, time); // drop failed..
618 var td_ar = targetData.split("|");
621 if (this.drag_in_motion) {
622 Gdk.drag_status(ctx, Gdk.DragAction.COPY ,time);
624 this.highlightDropPath( td_ar[0] , (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
627 // continue on to allow drop..
630 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
633 _this.model.dropNode(targetData, dropNode, show_templates);
634 print("ADD new node!!!\n");
636 ///Xcls_DialogTemplateSelect.singleton().show( _this.model.file.palete(), node);
638 Gtk.drag_finish (ctx, false, false,time);
645 this.el.drag_drop.connect( ( ctx, x, y, time) => {
646 //Seed.print("TARGET: drag-drop");
649 var src = Gtk.drag_get_source_widget(ctx);
651 if (src != this.el) {
655 this.drag_in_motion = false;
656 // request data that will be recieved by the recieve...
659 this.el, // will receive 'drag-data-received' signal
660 ctx, // represents the current state of the DnD
661 Gdk.Atom.intern("application/json",true), // the target type we want
666 // No target offered by source => error
672 // handle drop around self..
676 //print("GETTING POS");
680 Gtk.TreeViewDropPosition pos;
681 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
683 // if there are not items in the tree.. the we have to set isOver to true for anything..
685 if (_this.model.el.iter_n_children(null) < 1) {
686 print("got NO children?\n");
689 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
694 //var action = Gdk.DragAction.COPY;
695 // unless we are copying!!! ctl button..
697 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
698 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
699 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
702 if (_this.model.el.iter_n_children(null) < 1) {
703 // no children.. -- asume it's ok..
705 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
707 // continue through to allow drop...
715 //print("ISOVER? " + isOver);
718 Gtk.drag_finish (ctx, false, false, time); // drop failed..
719 return true; // not over apoint!?! - no action on drop or motion..
722 // drag node is parent of child..
723 //console.log("SRC TREEPATH: " + src.treepath);
724 //console.log("TARGET TREEPATH: " + data.path.to_string());
726 // nned to check a few here..
727 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
728 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
729 //Gtk.TreeViewDropPosition.AFTER
730 //Gtk.TreeViewDropPosition.BEFORE
732 // locally dragged items to not really use the
733 var selection_text = this.dragData;
737 if (selection_text == null || selection_text.length < 1) {
738 //print("Error - drag selection text returned NULL");
740 Gtk.drag_finish (ctx, false, false, time); // drop failed..
741 return true; /// -- fixme -- this is not really correct..
744 // see if we are dragging into ourself?
745 print ("got selection text of " + selection_text);
747 var target_path = path.to_string();
748 //print("target_path="+target_path);
751 if (selection_text == target_path) {
752 print("self drag ?? == we should perhaps allow copy onto self..\n");
754 Gtk.drag_finish (ctx, false, false, time); // drop failed..
756 return true; /// -- fixme -- this is not really correct..
761 //print("DUMPING DATA");
762 //console.dump(data);
765 //print(data.path.to_string() +' => '+ data.pos);
767 // dropList is a list of xtypes that this node could be dropped on.
768 // it is set up when we start to drag..
771 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
773 print("targetDAta: " + targetData +"\n");
775 if (targetData.length < 1) {
776 //print("Can not find drop node path");
778 Gtk.drag_finish (ctx, false, false, time); // drop failed..
784 // continue on to allow drop..
786 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
789 var delete_selection_data = false;
791 if (action == Gdk.DragAction.ASK) {
792 /* Ask the user to move or copy, then set the ctx action. */
795 if (action == Gdk.DragAction.MOVE) {
796 delete_selection_data = true;
799 // drag around.. - reorder..
800 _this.model.moveNode(targetData, action);
806 // we can send stuff to souce here...
809 // do we always say failure, so we handle the reall drop?
810 Gtk.drag_finish (ctx, false, false,time); //delete_selection_data, time);
822 // user defined functions
823 public void highlightDropPath ( string treepath, Gtk.TreeViewDropPosition pos) {
825 // highlighting for drag/drop
826 if (treepath.length > 0) {
827 this.el.set_drag_dest_row( new Gtk.TreePath.from_string( treepath ), pos);
829 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
833 public void setCursor (string treepath, string sourceEvent) {
834 this.lastEventSource = sourceEvent;
835 //this.blockChanges = true; << block changes prevents loading of 'node data' and firing of node_selected..
836 this.el.set_cursor(new Gtk.TreePath.from_string(treepath), null, false);
837 // fire node_selected..
838 //this.blockChanges = false;
839 this.lastEventSource = "";
841 public void selectNode (string treepath_str, string source) {
842 this.lastEventSource = source;
843 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
844 var tp = new Gtk.TreePath.from_string(treepath_str);
846 this.el.set_cursor(tp, null, false);
847 this.el.scroll_to_cell(tp, null, false, 0,0);
850 public class Xcls_model : Object
852 public Gtk.TreeStore el;
853 private Xcls_WindowLeftTree _this;
857 public DialogTemplateSelect template_select;
858 public string activePath;
861 public Xcls_model(Xcls_WindowLeftTree _owner )
865 this.el = new Gtk.TreeStore( 3, typeof(string),typeof(string),typeof(Object) );
868 this.template_select = null;
869 this.activePath = "";
871 // set gobject values
875 print("model initialized");
878 // user defined functions
879 public string findDropNode (string treepath_str, string[] targets) {
881 // this is used by the dragdrop code in the roo version AFAIR..
883 //var path = treepath_str.replace(/^builder-/, '');
884 // treemap is depreciated... - should really check if model has any entries..
886 if (this.el.iter_n_children(null) < 1) {
888 return "|%d".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
890 //print("FIND treepath: " + path);
891 //console.dump(this.treemap);
893 //if (!treepath_str.match(/^builder-/)) {
894 // return []; // nothing!
896 if (targets.length > 0 && targets[0] == "*") {
899 return this.findDropNodeByPath(treepath_str,targets, -1);
901 public void loadFile (JsRender.JsRender f) {
906 _this.main_window.windowstate.file = f;
909 if (f.tree == null) {
916 // if it's still null?
917 if (f.tree == null) {
921 var o = new Gee.ArrayList<JsRender.Node>();
925 _this.view.el.expand_all();
927 if (f.tree.items.size < 1) {
930 //this.get('/Window.leftvpaned').el.set_position(80);
932 _this.view.el.set_cursor(
933 new Gtk.TreePath.from_string("0"), null, false);
937 //this.get('/Window.leftvpaned').el.set_position(200);
944 public void updateSelected () {
947 var s = _this.view.el.get_selection();
954 if (!s.get_selected(out mod, out iter)) {
955 return; // nothing seleted..
959 this.el.get_value(iter, 2, out value);
960 var node = (JsRender.Node)(value.get_object());
962 this.el.set(iter, 0, node.nodeTitle(),
963 1, node.nodeTip(), -1
966 public string findDropNodeByPath (string treepath_str, string[] targets, int in_pref = -1) {
968 var path = treepath_str; // dupe it..
971 // pref : 3 = ontop - 0 = after, 1 = before
972 int pref = in_pref < 0 ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : in_pref;
976 //console.dump(this.treemap);
978 print("findDropNodeByPath : got path length %d / %s\n", path.length, path);
980 if (path.length == 0) {
981 // top drop. // just return empty..
982 return "|%d".printf((int)pref) ;
987 while (path.length > 0) {
989 if (path.length == treepath_str.length && pref != Gtk.TreeViewDropPosition.INTO_OR_AFTER) {
990 if (path.last_index_of(":") < 0 ) {
993 path = path.substring(0, path.last_index_of(":"));
995 print("DROP before or after : using %s\n",path);
999 //print("LOOKING FOR PATH: " + path);
1000 var node_data = this.pathToNode(path);
1002 if (node_data == null) {
1003 print("node not found");
1007 var xname = node_data.fqn();
1011 for (var i =0; i < targets.length; i++) {
1012 var tg = targets[i];
1013 if ((tg == xname) ) {
1017 // if target is "xxxx:name"
1018 if (tg.contains(xname +":")) {
1020 var ar = tg.split(":");
1026 if (match.length > 0) {
1027 if (last.length > 0) { // pref is after/before..
1028 // then it's after last
1032 return last + "|%d".printf((int)pref) + "|" + prop;
1036 // we need to add prop - as :store -> needs to bee added when dropping onto.
1037 return path + "|%d".printf( (int) Gtk.TreeViewDropPosition.INTO_OR_AFTER) + "|" + prop;
1041 var par = path.split(":");
1042 string [] ppar = {};
1043 for (var i = 0; i < par.length-1; i++) {
1047 path = string.joinv(":", ppar);
1056 public void moveNode (string target_data, Gdk.DragAction action)
1059 /// target_data = "path|pos");
1062 //print("MOVE NODE");
1063 // console.dump(target_data);
1064 Gtk.TreeIter old_iter;
1067 var s = _this.view.el.get_selection();
1068 s.get_selected(out mod , out old_iter);
1069 mod.get_path(old_iter);
1071 var node = this.pathToNode(mod.get_path(old_iter).to_string());
1072 //console.dump(node);
1074 print("moveNode: ERROR - node is null?");
1079 // needs to drop first, otherwise the target_data
1080 // treepath will be invalid.
1083 if ((action & Gdk.DragAction.MOVE) > 0) {
1084 print("REMOVING OLD NODE : " + target_data + "\n");
1086 this.dropNode(target_data, node, false);
1087 this.el.remove(ref old_iter);
1092 print("DROPPING NODE // copy: " + target_data + "\n");
1093 node = node.deepClone();
1094 this.dropNode(target_data, node, false);
1097 this.activePath= "";
1098 //this.updateNode(false,true);
1100 public void load (Gee.ArrayList<JsRender.Node> tr, Gtk.TreeIter? iter)
1103 //this.insert(citer,iter,0);
1104 for(var i =0 ; i < tr.size; i++) {
1106 this.el.insert(out citer,iter,-1); // why not append?
1108 this.el.append(out citer,null);
1111 this.el.set(citer, 0, tr.get(i).nodeTitle(),
1112 1, tr.get(i).nodeTip(), -1
1114 var o = GLib.Value(typeof(Object));
1115 o.set_object((Object)tr.get(i));
1117 this.el.set_value(citer, 2, o);
1119 if (tr.get(i).items.size > 0) {
1120 this.load(tr.get(i).items, citer);
1127 public void deleteSelected () {
1129 print("DELETE SELECTED?");
1130 //_this.view.blockChanges = true;
1131 print("GET SELECTION?");
1133 var s = _this.view.el.get_selection();
1135 print("GET SELECTED?");
1140 if (!s.get_selected(out mod, out iter)) {
1141 return; // nothing seleted..
1146 this.activePath= "";
1147 print("GET vnode value?");
1150 this.el.get_value(iter, 2, out value);
1151 var data = (JsRender.Node)(value.get_object());
1152 print("removing node from Render\n");
1153 if (data.parent == null) {
1154 _this.main_window.windowstate.file.tree = null;
1158 print("removing node from Tree\n");
1160 this.el.remove(ref iter);
1170 this.activePath= ""; // again!?!?
1171 //this.changed(null,true);
1175 _this.view.blockChanges = false;
1177 public JsRender.Node pathToNode (string path) {
1181 _this.model.el.get_iter_from_string(out iter, path);
1184 _this.model.el.get_value(iter, 2, out value);
1186 return (JsRender.Node)value.dup_object();
1189 public void dropNode (string target_data_str, JsRender.Node node, bool show_templates) {
1190 // print("drop Node");
1191 // console.dump(node);
1192 // console.dump(target_data);
1195 // 0 = before , 1=after 2/3 onto
1198 var target_data= target_data_str.split("|");
1200 var parent_str = target_data[0].length > 0 ? target_data[0] : "";
1201 var pos = target_data.length > 1 ? int.parse(target_data[1]) : 2; // ontop..
1204 Gtk.TreePath tree_path = parent_str.length > 0 ? new Gtk.TreePath.from_string( parent_str ) : null;
1208 //print("add " + tp + "@" + target_data[1] );
1210 JsRender.Node parentNode = null;
1212 Gtk.TreeIter iter_after;
1213 Gtk.TreeIter iter_par ;
1216 if (target_data.length == 3 && target_data[2].length > 0) {
1217 node.props.set("* prop", target_data[2]);
1220 Gtk.TreePath expand_parent = null;
1222 // we only need to show the template if it's come from else where?
1223 if (show_templates) {
1225 var ts = _this.main_window.windowstate.template_select;
1227 var new_node = ts.show(
1228 _this.main_window, // (Gtk.Window) _this.el.get_toplevel (),
1229 _this.main_window.windowstate.file.palete(),
1231 _this.main_window.windowstate.project);
1233 if (new_node == null) {
1234 return; // do not add?
1239 //print("pos is %d \n".printf(pos));
1241 Gtk.TreeIter n_iter;
1243 if ( parent_str.length < 1) {
1244 this.el.append(out n_iter, null); // drop at top level..
1246 _this.main_window.windowstate.file.tree = node;
1249 } else if (pos < 2) {
1250 //print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
1252 this.el.get_iter(out iter_after, tree_path );
1253 this.el.iter_parent(out iter_par, iter_after);
1254 expand_parent = this.el.get_path(iter_par);
1257 this.el.get_value( iter_par, 2, out value);
1258 parentNode = (JsRender.Node)value.dup_object();
1261 this.el.get_value( iter_after, 2, out value);
1262 var relNode = (JsRender.Node)value.dup_object();
1266 this.el.insert_after(out n_iter, iter_par , iter_after);
1267 var ix = parentNode.items.index_of(relNode);
1268 parentNode.items.insert(ix+1, node);
1271 this.el.insert_before(out n_iter, iter_par , iter_after);
1272 var ix = parentNode.items.index_of(relNode);
1273 parentNode.items.insert(ix, node);
1276 node.parent = parentNode;
1281 // print("appending to " + parent_str);
1282 this.el.get_iter(out iter_par, tree_path);
1283 this.el.append(out n_iter, iter_par );
1284 expand_parent = this.el.get_path(iter_par);
1287 this.el.get_value( iter_par, 2, out value);
1288 parentNode = (JsRender.Node)value.dup_object();
1289 node.parent = parentNode;
1290 parentNode.items.add(node);
1293 // reparent node in tree...
1296 // why only on no parent???
1298 //if (node.parent = null) {
1305 // work out what kind of packing to use.. -- should be in
1306 if (!node.has("pack") && parent_str.length > 1) {
1308 _this.main_window.windowstate.file.palete().fillPack(node,parentNode);
1315 this.el.set(n_iter, 0, node.nodeTitle(), 1, node.nodeTip(), -1 );
1316 var o = GLib.Value(typeof(Object));
1317 o.set_object((Object)node);
1319 this.el.set_value(n_iter, 2, o);
1324 // load children - if it has any..
1326 if (node.items.size > 0) {
1327 this.load(node.items, n_iter);
1328 _this.view.el.expand_row(this.el.get_path(n_iter), true);
1329 } else if (expand_parent != null && !_this.view.el.is_row_expanded(expand_parent)) {
1330 _this.view.el.expand_row(expand_parent,true);
1333 //if (tp != null && (node.items.length() > 0 || pos > 1)) {
1334 // _this.view.el.expand_row(this.el.get_path(iter_par), true);
1336 // wee need to get the empty proptypes from somewhere..
1338 //var olditer = this.activeIter;
1339 this.activePath = this.el.get_path(n_iter).to_string();
1344 _this.view.el.set_cursor(this.el.get_path(n_iter), null, false);
1350 public string treePathFromNode (JsRender.Node node) {
1351 // iterate through the tree and find the node
1354 this.el.foreach((mod, pth, iter) => {
1359 _this.model.el.get_value(iter, 2, out value);
1363 var n = (JsRender.Node)value;
1365 print("compare %s to %s\n", n.fqn(), node.fqn());
1367 ret = pth.to_string();
1377 public class Xcls_TreeViewColumn4 : Object
1379 public Gtk.TreeViewColumn el;
1380 private Xcls_WindowLeftTree _this;
1386 public Xcls_TreeViewColumn4(Xcls_WindowLeftTree _owner )
1389 this.el = new Gtk.TreeViewColumn();
1393 // set gobject values
1394 this.el.title = "test";
1395 var child_0 = new Xcls_renderer( _this );
1397 this.el.pack_start ( child_0.el , true );
1401 this.el.add_attribute(_this.renderer.el , "markup", 0 );
1404 // user defined functions
1406 public class Xcls_renderer : Object
1408 public Gtk.CellRendererText el;
1409 private Xcls_WindowLeftTree _this;
1415 public Xcls_renderer(Xcls_WindowLeftTree _owner )
1418 _this.renderer = this;
1419 this.el = new Gtk.CellRendererText();
1423 // set gobject values
1426 // user defined functions
1431 public class Xcls_LeftTreeMenu : Object
1434 private Xcls_WindowLeftTree _this;
1440 public Xcls_LeftTreeMenu(Xcls_WindowLeftTree _owner )
1443 _this.LeftTreeMenu = this;
1444 this.el = new Gtk.Menu();
1448 // set gobject values
1449 var child_0 = new Xcls_MenuItem7( _this );
1451 this.el.add ( child_0.el );
1452 var child_1 = new Xcls_MenuItem8( _this );
1454 this.el.add ( child_1.el );
1455 var child_2 = new Xcls_MenuItem9( _this );
1457 this.el.add ( child_2.el );
1460 // user defined functions
1462 public class Xcls_MenuItem7 : Object
1464 public Gtk.MenuItem el;
1465 private Xcls_WindowLeftTree _this;
1471 public Xcls_MenuItem7(Xcls_WindowLeftTree _owner )
1474 this.el = new Gtk.MenuItem();
1478 // set gobject values
1479 this.el.label = "Delete Element";
1482 this.el.activate.connect( ( ) => {
1487 _this.model.deleteSelected();
1491 // user defined functions
1494 public class Xcls_MenuItem8 : Object
1496 public Gtk.MenuItem el;
1497 private Xcls_WindowLeftTree _this;
1503 public Xcls_MenuItem8(Xcls_WindowLeftTree _owner )
1506 this.el = new Gtk.MenuItem();
1510 // set gobject values
1511 this.el.label = "Save as Template";
1514 this.el.activate.connect( () => {
1516 DialogSaveTemplate.singleton().show(
1517 (Gtk.Window) _this.el.get_toplevel (),
1518 _this.main_window.windowstate.file.palete(),
1519 _this.getActiveElement()
1526 // user defined functions
1529 public class Xcls_MenuItem9 : Object
1531 public Gtk.MenuItem el;
1532 private Xcls_WindowLeftTree _this;
1538 public Xcls_MenuItem9(Xcls_WindowLeftTree _owner )
1541 this.el = new Gtk.MenuItem();
1545 // set gobject values
1546 this.el.label = "Save as Module";
1549 this.el.activate.connect( () => {
1550 var node = _this.getActiveElement();
1551 var name = DialogSaveModule.singleton().show(
1552 (Gtk.Window) _this.el.get_toplevel (),
1553 _this.main_window.windowstate.project,
1556 if (name.length < 1) {
1560 node.props.set("* xinclude", name);
1564 var s = _this.view.el.get_selection();
1566 print("GET SELECTED?");
1571 if (!s.get_selected(out mod, out iter)) {
1572 return; // nothing seleted..
1575 var n_cn = mod.iter_n_children(iter) -1;
1576 for (var i = n_cn; i > -1; i--) {
1577 mod.iter_nth_child(out citer, iter, i);
1580 print("removing node from Tree\n");
1582 _this.model.el.remove(ref citer);
1585 _this.node_selected(node, "tree");
1591 // user defined functions