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;
80 public string[] dropList;
83 public bool button_is_pressed;
84 public string lastEventSource;
85 public bool key_is_pressed;
86 public bool drag_in_motion;
87 public bool blockChanges;
90 public Xcls_view(Xcls_WindowLeftTree _owner )
94 this.el = new Gtk.TreeView();
97 this.button_is_pressed = false;
98 this.lastEventSource = "";
99 this.key_is_pressed = false;
100 this.blockChanges = false;
102 // set gobject values
103 this.el.expand = true;
104 this.el.tooltip_column = 1;
105 this.el.enable_tree_lines = true;
106 this.el.headers_visible = false;
107 var child_0 = new Xcls_model( _this );
109 this.el.set_model ( child_0.el );
110 var child_1 = new Xcls_TreeViewColumn4( _this );
112 this.el.append_column ( child_1.el );
117 var description = new Pango.FontDescription();
118 description.set_size(8000);
119 this.el.override_font(description);
121 var selection = this.el.get_selection();
122 selection.set_mode( Gtk.SelectionMode.SINGLE);
125 // is this really needed??
127 this.selection.signal['changed'].connect(function() {
128 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
129 _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
133 Gtk.drag_source_set (
134 this.el, /* widget will be drag-able */
135 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
136 BuilderApplication.targetList, /* lists of target to support */
137 Gdk.DragAction.COPY | Gdk.DragAction.MOVE | Gdk.DragAction.LINK /* what to do with data after dropped */
141 //Gtk.drag_source_add_text_targets(this.el);
145 this.el, /* widget that will accept a drop */
146 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
147 BuilderApplication.targetList, /* lists of target to support */
148 Gdk.DragAction.COPY | Gdk.DragAction.MOVE | Gdk.DragAction.LINK /* what to do with data after dropped */
151 //Gtk.drag_dest_set_target_list(this.el, Builder.Application.targetList);
152 //Gtk.drag_dest_add_text_targets(this.el);
156 this.el.button_release_event.connect( (ev) => {
157 this.button_is_pressed = false;
160 this.el.button_press_event.connect( ( ev) => {
161 //console.log("button press?");
162 this.button_is_pressed = true;
163 print("BUTTON DOWN\n");
165 this.lastEventSource = "tree";
166 if (! _this.before_node_change() ) {
173 if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button != 3) {
174 //print("click" + ev.type);
178 if (!_this.view.el.get_path_at_pos((int)ev.x,(int)ev.y, out res, null, null, null) ) {
182 this.el.get_selection().select_path(res);
184 //if (!this.get('/LeftTreeMenu').el) {
185 // this.get('/LeftTreeMenu').init();
188 _this.LeftTreeMenu.el.set_screen(Gdk.Screen.get_default());
189 _this.LeftTreeMenu.el.show_all();
190 _this.LeftTreeMenu.el.popup(null, null, null, 3, ev.time);
191 // print("click:" + res.path.to_string());
194 this.el.cursor_changed.connect( ( ) => {
195 print("LEFT TREE Cursor Changed\n");
196 if (!this.button_is_pressed && !this.key_is_pressed) {
197 // then event was started by some other action
198 // which should manually trigger all the events..
199 print("SKIPPING select - no button or key pressed\n");
204 if (this.blockChanges) { // probably not needed..
205 print("SKIPPING select - blockchanges set..\n");
208 if (!_this.before_node_change( ) ) {
209 this.blockChanges = true;
210 this.el.get_selection().unselect_all();
211 this.blockChanges = false;
215 if (_this.main_window.windowstate.file == null) {
216 print("SKIPPING select windowstate file is not set...\n");
220 //var render = this.get('/LeftTree').getRenderer();
221 print("LEFT TREE -> view -> selection changed called\n");
224 // -- it appears that the selection is not updated.
226 GLib.Timeout.add_full(GLib.Priority.DEFAULT,10 , () => {
227 print("LEFT TREE -> view -> selection changed TIMEOUT CALLED\n");
229 if (this.el.get_selection().count_selected_rows() < 1) {
231 print("selected rows < 1\n");
232 //??this.model.load( false);
233 _this.node_selected(null, this.lastEventSource);
238 //console.log('changed');
239 var s = this.el.get_selection();
242 s.get_selected(out mod, out iter);
247 _this.model.el.get_value(iter, 2, out value);
248 _this.model.activePath = mod.get_path(iter).to_string();
250 var node = (JsRender.Node)value.dup_object();
251 print ("calling left_tree.node_selected\n");
252 _this.node_selected(node, this.lastEventSource);
253 while (Gtk.events_pending()) {
254 Gtk.main_iteration();
256 var cp = mod.get_path(iter);
258 this.el.get_visible_range(out sp, out ep);
259 // if sp is before cp then retuns 1.
260 // if cp is before ep then retuns 1.
261 if (cp.compare(sp) >= 0 && ep.compare(cp) >=1) {
267 this.el.scroll_to_cell(new Gtk.TreePath.from_string(_this.model.activePath), null, true, 0.1f,0.0f);
271 //_this.after_node_change(node);
273 // _this.model.file.changed(node, "tree");
275 //Seed.print( value.get_string());
279 this.el.drag_begin.connect( ( ctx) => {
280 //print('SOURCE: drag-begin');
283 //this.targetData = "";
285 // find what is selected in our tree...
287 var s = _this.view.el.get_selection();
288 if (s.count_selected_rows() < 1) {
293 s.get_selected(out mod, out iter);
297 // set some properties of the tree for use by the dropped element.
299 _this.model.el.get_value(iter, 2, out value);
300 var tp = mod.get_path(iter).to_string();
301 var data = (JsRender.Node)(value.dup_object());
302 var xname = data.fqn();
303 print ("XNAME IS " + xname+ "\n");
305 this.dropList = _this.main_window.windowstate.file.palete().getDropList(xname);
307 print ("DROP LIST IS " + string.joinv(", ", this.dropList) + "\n");
310 // make the drag icon a picture of the node that was selected
313 // by default returns the path..
314 var path = _this.model.el.get_path(iter);
317 var pix = this.el.create_row_drag_icon ( path);
319 Gtk.drag_set_icon_surface (ctx, pix) ;
323 this.el.drag_end.connect( (drag_context) => {
324 //Seed.print('LEFT-TREE: drag-end');
326 this.dropList = null;
327 // this.targetData = "";
328 this.highlightDropPath("",0);
331 this.el.drag_motion.connect( ( ctx, x, y, time) => {
332 print("got drag motion\n");
333 var src = Gtk.drag_get_source_widget(ctx);
337 if (src != this.el) {
341 // the point of this is to detect where an item could be dropped..
342 print("requesting drag data\n");
343 this.drag_in_motion = true;
345 // request data that will be recieved by the recieve...
348 this.el, // will receive 'drag-data-received' signal
349 ctx, // represents the current state of the DnD
350 Gdk.Atom.intern("STRING",true), // the target type we want
357 print("action: %d\n", ctx.get_actions());
358 //print("GETTING POS");
362 Gtk.TreeViewDropPosition pos;
363 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
365 // if there are not items in the tree.. the we have to set isOver to true for anything..
367 if (_this.model.el.iter_n_children(null) < 1) {
368 print("got NO children?\n");
371 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
375 // ------------- a drag from self..
378 //var action = Gdk.DragAction.COPY;
379 // unless we are copying!!! ctl button..
381 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
382 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
383 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
386 if (_this.model.el.iter_n_children(null) < 1) {
387 // no children.. -- asume it's ok..
389 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
391 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
392 Gdk.drag_status(ctx, action ,time);
395 // continue through to allow drop...
403 //print("ISOVER? " + isOver);
406 Gdk.drag_status(ctx, 0 ,time);
407 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
412 // drag node is parent of child..
413 //console.log("SRC TREEPATH: " + src.treepath);
414 //console.log("TARGET TREEPATH: " + data.path.to_string());
416 // nned to check a few here..
417 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
418 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
419 //Gtk.TreeViewDropPosition.AFTER
420 //Gtk.TreeViewDropPosition.BEFORE
422 // locally dragged items to not really use the
423 var selection_text = this.dragData;
427 if (selection_text == null || selection_text.length < 1) {
428 //print("Error - drag selection text returned NULL");
429 Gdk.drag_status(ctx, 0 ,time);
430 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
435 // see if we are dragging into ourself?
436 var target_path = path.to_string();
437 print ("Drag %s onto %s--%d\n ", selection_text, target_path, pos);
439 // pos : 3 = ontop - 0 = after, 1 = before
440 //print("target_path="+target_path);
443 if (selection_text == target_path) {
444 print("self drag ?? == we should perhaps allow copy onto self..\n");
446 Gdk.drag_status(ctx, 0 ,time);
447 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
449 // -- fixme -- this is not really correct..
454 //print("DUMPING DATA");
455 //console.dump(data);
458 //print(data.path.to_string() +' => '+ data.pos);
460 // dropList is a list of xtypes that this node could be dropped on.
461 // it is set up when we start to drag..
464 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
466 print("targetDAta: " + targetData +"\n");
468 if (targetData.length < 1) {
469 //print("Can not find drop node path");
471 Gdk.drag_status(ctx, 0, time);
472 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
476 var td_ar = targetData.split("|");
480 Gdk.drag_status(ctx, action ,time);
481 this.highlightDropPath(td_ar[0], (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
486 this.el.drag_data_get.connect( ( drag_context, data, info, time) => {
489 //print("drag-data-get");
490 var s = this.el.get_selection();
491 if (s.count_selected_rows() < 1) {
493 print("return empty string - no selection..");
500 s.get_selected(out mod, out iter);
505 _this.model.el.get_value(iter, 2, out value);
506 var ndata = (JsRender.Node)(value.dup_object());
510 var tp = mod.get_path(iter).to_string();
511 // by default returns the path..
513 if ( info != Gdk.Atom.intern("STRING",true) ) {
514 tp = ndata.toJsonString();
517 //data.set_text(tp,tp.length);
519 data.set (data.get_target (), 8, (uchar[]) tp.to_utf8 ());
522 // print("return " + tp);
524 this.el.key_press_event.connect( (ev) => {
525 this.key_is_pressed = true;
528 this.el.key_release_event.connect( (ev) => {
529 this.key_is_pressed = false;
532 this.el.drag_data_received.connect( (ctx, x, y, sel, info, time) => {
534 // THIS CODE ONLY RELATES TO drag or drop of "NEW" elements or "FROM another tree.."
537 // print("Tree: drag-data-received\n");
538 var selection_text = (string)sel.get_data();
539 //print("selection_text= %s\n",selection_text);
541 var is_drag = this.drag_in_motion;
545 GLib.debug("Is Drag %s\n", is_drag ? "Y": "N");
549 Gtk.TreeViewDropPosition pos;
550 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
552 // if there are not items in the tree.. the we have to set isOver to true for anything..
554 if (_this.model.el.iter_n_children(null) < 1) {
555 GLib.debug("got NO children?\n");
558 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
562 //console.log("LEFT-TREE: drag-motion");
563 var src = Gtk.drag_get_source_widget(ctx);
565 // a drag from self - this should be handled by drop and motion.
566 if (src == this.el) {
567 GLib.debug("Source == this element should not happen.. ? \n");
570 //print("drag_data_recieved from another element");
575 if (selection_text == null || selection_text.length < 1 || !isOver) {
576 // nothing valid foudn to drop...
577 GLib.debug("empty sel text or not over");
579 Gdk.drag_status(ctx, 0, time);
580 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
583 Gtk.drag_finish (ctx, false, false, time); // drop failed..
588 var dropNode = new JsRender.Node();
590 var dropNodeType = selection_text;
591 var show_templates = true;
593 if (dropNodeType[0] == '{') {
594 var pa = new Json.Parser();
596 pa.load_from_data(dropNodeType);
598 Gtk.drag_finish (ctx, false, false, time); // drop failed..
603 dropNode.loadFromJson( pa.get_root().get_object(), 2);
604 dropNodeType = dropNode.fqn();
605 show_templates = false;
609 if (selection_text.contains(":")) {
610 var bits = selection_text.split(":");
611 dropNode.setFqn(bits[0]);
612 dropNode.props.set("* prop", bits[1]);
615 dropNode.setFqn(selection_text);
620 // dropList --- need to gather this ...
621 GLib.debug("get dropList for : %s\n",dropNodeType);
622 var dropList = _this.main_window.windowstate.file.palete().getDropList(dropNodeType);
624 GLib.debug("dropList: %s\n", string.joinv(" , ", dropList));
626 // if drag action is link ... then we can drop it anywahere...
627 if ((ctx.get_actions() & Gdk.DragAction.LINK) > 0) {
628 // if path is null?? dragging into an empty tree?
629 targetData = (path == null ? "" : path.to_string()) + "|%d".printf((int)pos);
633 targetData = _this.model.findDropNodeByPath( isEmpty ? "" : path.to_string(), dropList, pos);
638 GLib.debug("targetDAta: %s", targetData );
640 if (targetData.length < 1) {
642 // invalid drop path..
643 if (this.drag_in_motion) {
644 Gdk.drag_status(ctx, 0, time);
645 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
648 Gtk.drag_finish (ctx, false, false, time); // drop failed..
655 var td_ar = targetData.split("|");
658 if (this.drag_in_motion) {
659 Gdk.drag_status(ctx, Gdk.DragAction.COPY ,time);
661 this.highlightDropPath( td_ar[0] , (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
664 // continue on to allow drop..
667 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
669 // {parent}|{pos}|{prop}
672 _this.model.dropNode(targetData, dropNode, show_templates);
673 GLib.debug("ADD new node!!!\n");
675 ///Xcls_DialogTemplateSelect.singleton().show( _this.model.file.palete(), node);
677 Gtk.drag_finish (ctx, false, false,time);
684 this.el.drag_drop.connect( ( ctx, x, y, time) => {
685 //Seed.print("TARGET: drag-drop");
688 var src = Gtk.drag_get_source_widget(ctx);
690 if (src != this.el) {
694 this.drag_in_motion = false;
695 // request data that will be recieved by the recieve...
698 this.el, // will receive 'drag-data-received' signal
699 ctx, // represents the current state of the DnD
700 Gdk.Atom.intern("application/json",true), // the target type we want
705 // No target offered by source => error
711 // handle drop around self..
715 //print("GETTING POS");
719 Gtk.TreeViewDropPosition pos;
720 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
722 // if there are not items in the tree.. the we have to set isOver to true for anything..
724 if (_this.model.el.iter_n_children(null) < 1) {
725 print("got NO children?\n");
728 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
733 //var action = Gdk.DragAction.COPY;
734 // unless we are copying!!! ctl button..
736 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
737 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
738 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
741 if (_this.model.el.iter_n_children(null) < 1) {
742 // no children.. -- asume it's ok..
744 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
746 // continue through to allow drop...
754 //print("ISOVER? " + isOver);
757 Gtk.drag_finish (ctx, false, false, time); // drop failed..
758 return true; // not over apoint!?! - no action on drop or motion..
761 // drag node is parent of child..
762 //console.log("SRC TREEPATH: " + src.treepath);
763 //console.log("TARGET TREEPATH: " + data.path.to_string());
765 // nned to check a few here..
766 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
767 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
768 //Gtk.TreeViewDropPosition.AFTER
769 //Gtk.TreeViewDropPosition.BEFORE
771 // locally dragged items to not really use the
772 var selection_text = this.dragData;
776 if (selection_text == null || selection_text.length < 1) {
777 //print("Error - drag selection text returned NULL");
779 Gtk.drag_finish (ctx, false, false, time); // drop failed..
780 return true; /// -- fixme -- this is not really correct..
783 // see if we are dragging into ourself?
784 print ("got selection text of " + selection_text);
786 var target_path = path.to_string();
787 //print("target_path="+target_path);
790 if (selection_text == target_path) {
791 print("self drag ?? == we should perhaps allow copy onto self..\n");
793 Gtk.drag_finish (ctx, false, false, time); // drop failed..
795 return true; /// -- fixme -- this is not really correct..
800 //print("DUMPING DATA");
801 //console.dump(data);
804 //print(data.path.to_string() +' => '+ data.pos);
806 // dropList is a list of xtypes that this node could be dropped on.
807 // it is set up when we start to drag..
810 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
812 print("targetDAta: " + targetData +"\n");
814 if (targetData.length < 1) {
815 //print("Can not find drop node path");
817 Gtk.drag_finish (ctx, false, false, time); // drop failed..
823 // continue on to allow drop..
825 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
828 var delete_selection_data = false;
830 if (action == Gdk.DragAction.ASK) {
831 /* Ask the user to move or copy, then set the ctx action. */
834 if (action == Gdk.DragAction.MOVE) {
835 delete_selection_data = true;
838 // drag around.. - reorder..
839 _this.model.moveNode(targetData, action);
845 // we can send stuff to souce here...
848 // do we always say failure, so we handle the reall drop?
849 Gtk.drag_finish (ctx, false, false,time); //delete_selection_data, time);
861 // user defined functions
862 public void highlightDropPath ( string treepath, Gtk.TreeViewDropPosition pos) {
864 // highlighting for drag/drop
865 if (treepath.length > 0) {
866 this.el.set_drag_dest_row( new Gtk.TreePath.from_string( treepath ), pos);
868 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
872 public void setCursor (string treepath, string sourceEvent) {
873 this.lastEventSource = sourceEvent;
874 //this.blockChanges = true; << block changes prevents loading of 'node data' and firing of node_selected..
875 this.el.set_cursor(new Gtk.TreePath.from_string(treepath), null, false);
876 // fire node_selected..
877 //this.blockChanges = false;
878 this.lastEventSource = "";
880 public void selectNode (string treepath_str, string source) {
881 this.lastEventSource = source;
882 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
883 var tp = new Gtk.TreePath.from_string(treepath_str);
885 this.el.set_cursor(tp, null, false);
886 this.el.scroll_to_cell(tp, null, false, 0,0);
889 public class Xcls_model : Object
891 public Gtk.TreeStore el;
892 private Xcls_WindowLeftTree _this;
896 public DialogTemplateSelect template_select;
897 public string activePath;
900 public Xcls_model(Xcls_WindowLeftTree _owner )
904 this.el = new Gtk.TreeStore( 3, typeof(string),typeof(string),typeof(Object) );
907 this.template_select = null;
908 this.activePath = "";
910 // set gobject values
914 print("model initialized");
917 // user defined functions
918 public string findDropNode (string treepath_str, string[] targets) {
920 // this is used by the dragdrop code in the roo version AFAIR..
922 //var path = treepath_str.replace(/^builder-/, '');
923 // treemap is depreciated... - should really check if model has any entries..
925 if (this.el.iter_n_children(null) < 1) {
927 return "|%d".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
929 //print("FIND treepath: " + path);
930 //console.dump(this.treemap);
932 //if (!treepath_str.match(/^builder-/)) {
933 // return []; // nothing!
935 if (targets.length > 0 && targets[0] == "*") {
938 return this.findDropNodeByPath(treepath_str,targets, -1);
940 public void loadFile (JsRender.JsRender f) {
945 _this.main_window.windowstate.file = f;
948 if (f.tree == null) {
955 // if it's still null?
956 if (f.tree == null) {
960 var o = new Gee.ArrayList<JsRender.Node>();
964 _this.view.el.expand_all();
966 if (f.tree.items.size < 1) {
969 //this.get('/Window.leftvpaned').el.set_position(80);
971 _this.view.el.set_cursor(
972 new Gtk.TreePath.from_string("0"), null, false);
976 //this.get('/Window.leftvpaned').el.set_position(200);
983 public void updateSelected () {
986 var s = _this.view.el.get_selection();
993 if (!s.get_selected(out mod, out iter)) {
994 return; // nothing seleted..
998 this.el.get_value(iter, 2, out value);
999 var node = (JsRender.Node)(value.get_object());
1001 this.el.set(iter, 0, node.nodeTitle(),
1002 1, node.nodeTip(), -1
1005 public string findDropNodeByPath (string treepath_str, string[] targets, int in_pref = -1) {
1007 var path = treepath_str; // dupe it..
1010 // pref : 3 = ontop - 0 = after, 1 = before
1011 int pref = in_pref < 0 ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : in_pref;
1015 //console.dump(this.treemap);
1017 print("findDropNodeByPath : got path length %d / %s\n", path.length, path);
1019 if (path.length == 0) {
1020 // top drop. // just return empty..
1021 return "|%d".printf((int)pref) ;
1026 while (path.length > 0) {
1028 if (path.length == treepath_str.length && pref != Gtk.TreeViewDropPosition.INTO_OR_AFTER) {
1029 if (path.last_index_of(":") < 0 ) {
1032 path = path.substring(0, path.last_index_of(":"));
1033 last = treepath_str;
1034 print("DROP before or after : using %s\n",path);
1038 //print("LOOKING FOR PATH: " + path);
1039 var node_data = this.pathToNode(path);
1041 if (node_data == null) {
1042 print("node not found");
1046 var xname = node_data.fqn();
1050 for (var i =0; i < targets.length; i++) {
1051 var tg = targets[i];
1052 if ((tg == xname) ) {
1056 // if target is "xxxx:name"
1057 if (tg.contains(xname +":")) {
1059 var ar = tg.split(":");
1065 if (match.length > 0) {
1066 if (last.length > 0) { // pref is after/before..
1067 // then it's after last
1071 return last + "|%d".printf((int)pref) + "|" + prop;
1075 // we need to add prop - as :store -> needs to bee added when dropping onto.
1076 return path + "|%d".printf( (int) Gtk.TreeViewDropPosition.INTO_OR_AFTER) + "|" + prop;
1080 var par = path.split(":");
1081 string [] ppar = {};
1082 for (var i = 0; i < par.length-1; i++) {
1086 path = string.joinv(":", ppar);
1095 public void moveNode (string target_data, Gdk.DragAction action)
1098 /// target_data = "path|pos");
1101 //print("MOVE NODE");
1102 // console.dump(target_data);
1103 Gtk.TreeIter old_iter;
1106 var s = _this.view.el.get_selection();
1107 s.get_selected(out mod , out old_iter);
1108 mod.get_path(old_iter);
1110 var node = this.pathToNode(mod.get_path(old_iter).to_string());
1111 //console.dump(node);
1113 print("moveNode: ERROR - node is null?");
1118 // needs to drop first, otherwise the target_data
1119 // treepath will be invalid.
1122 if ((action & Gdk.DragAction.MOVE) > 0) {
1123 print("REMOVING OLD NODE : " + target_data + "\n");
1125 this.dropNode(target_data, node, false);
1126 this.el.remove(ref old_iter);
1131 print("DROPPING NODE // copy: " + target_data + "\n");
1132 node = node.deepClone();
1133 this.dropNode(target_data, node, false);
1136 this.activePath= "";
1137 //this.updateNode(false,true);
1139 public void load (Gee.ArrayList<JsRender.Node> tr, Gtk.TreeIter? iter)
1142 //this.insert(citer,iter,0);
1143 for(var i =0 ; i < tr.size; i++) {
1145 this.el.insert(out citer,iter,-1); // why not append?
1147 this.el.append(out citer,null);
1150 this.el.set(citer, 0, tr.get(i).nodeTitle(),
1151 1, tr.get(i).nodeTip(), -1
1153 var o = GLib.Value(typeof(Object));
1154 o.set_object((Object)tr.get(i));
1156 this.el.set_value(citer, 2, o);
1158 if (tr.get(i).items.size > 0) {
1159 this.load(tr.get(i).items, citer);
1166 public void deleteSelected () {
1168 print("DELETE SELECTED?");
1169 //_this.view.blockChanges = true;
1170 print("GET SELECTION?");
1172 var s = _this.view.el.get_selection();
1174 print("GET SELECTED?");
1179 if (!s.get_selected(out mod, out iter)) {
1180 return; // nothing seleted..
1185 this.activePath= "";
1186 print("GET vnode value?");
1189 this.el.get_value(iter, 2, out value);
1190 var data = (JsRender.Node)(value.get_object());
1191 print("removing node from Render\n");
1192 if (data.parent == null) {
1193 _this.main_window.windowstate.file.tree = null;
1197 print("removing node from Tree\n");
1199 this.el.remove(ref iter);
1209 this.activePath= ""; // again!?!?
1210 //this.changed(null,true);
1214 _this.view.blockChanges = false;
1216 public JsRender.Node pathToNode (string path) {
1220 _this.model.el.get_iter_from_string(out iter, path);
1223 _this.model.el.get_value(iter, 2, out value);
1225 return (JsRender.Node)value.dup_object();
1228 public void dropNode (string target_data_str, JsRender.Node node, bool show_templates) {
1229 // print("drop Node");
1230 // console.dump(node);
1231 // console.dump(target_data);
1234 // {parent}|{pos}|{prop}
1237 // 0 = before , 1=after 2/3 onto
1239 GLib.debug("dropNode %s", target_data_str);
1240 var target_data= target_data_str.split("|");
1242 var parent_str = target_data[0].length > 0 ? target_data[0] : "";
1243 var pos = target_data.length > 1 ? int.parse(target_data[1]) : 2; // ontop..
1246 Gtk.TreePath tree_path = parent_str.length > 0 ? new Gtk.TreePath.from_string( parent_str ) : null;
1250 //print("add " + tp + "@" + target_data[1] );
1252 JsRender.Node parentNode = null;
1254 Gtk.TreeIter iter_after;
1255 Gtk.TreeIter iter_par ;
1258 if (target_data.length == 3 && target_data[2].length > 0) {
1259 node.props.set("* prop", target_data[2]);
1262 Gtk.TreePath expand_parent = null;
1264 // we only need to show the template if it's come from else where?
1265 if (show_templates) {
1267 var ts = _this.main_window.windowstate.template_select;
1269 var new_node = ts.show(
1270 _this.main_window, // (Gtk.Window) _this.el.get_toplevel (),
1271 _this.main_window.windowstate.file.palete(),
1273 _this.main_window.windowstate.project);
1275 if (new_node == null) {
1276 return; // do not add?
1281 //print("pos is %d \n".printf(pos));
1283 Gtk.TreeIter n_iter;
1285 if ( parent_str.length < 1) {
1286 this.el.append(out n_iter, null); // drop at top level..
1288 _this.main_window.windowstate.file.tree = node;
1291 } else if (pos < 2) {
1292 //print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
1294 this.el.get_iter(out iter_after, tree_path );
1295 this.el.iter_parent(out iter_par, iter_after);
1296 expand_parent = this.el.get_path(iter_par);
1299 this.el.get_value( iter_par, 2, out value);
1300 parentNode = (JsRender.Node)value.dup_object();
1303 this.el.get_value( iter_after, 2, out value);
1304 var relNode = (JsRender.Node)value.dup_object();
1308 this.el.insert_after(out n_iter, iter_par , iter_after);
1309 var ix = parentNode.items.index_of(relNode);
1310 parentNode.items.insert(ix+1, node);
1313 this.el.insert_before(out n_iter, iter_par , iter_after);
1314 var ix = parentNode.items.index_of(relNode);
1315 parentNode.items.insert(ix, node);
1318 node.parent = parentNode;
1323 // print("appending to " + parent_str);
1324 this.el.get_iter(out iter_par, tree_path);
1325 this.el.append(out n_iter, iter_par );
1326 expand_parent = this.el.get_path(iter_par);
1329 this.el.get_value( iter_par, 2, out value);
1330 parentNode = (JsRender.Node)value.dup_object();
1331 node.parent = parentNode;
1332 parentNode.items.add(node);
1335 // reparent node in tree...
1338 // why only on no parent???
1340 //if (node.parent = null) {
1347 // work out what kind of packing to use.. -- should be in
1348 if (!node.has("pack") && parent_str.length > 1) {
1350 _this.main_window.windowstate.file.palete().fillPack(node,parentNode);
1357 this.el.set(n_iter, 0, node.nodeTitle(), 1, node.nodeTip(), -1 );
1358 var o = GLib.Value(typeof(Object));
1359 o.set_object((Object)node);
1361 this.el.set_value(n_iter, 2, o);
1366 // load children - if it has any..
1368 if (node.items.size > 0) {
1369 this.load(node.items, n_iter);
1370 _this.view.el.expand_row(this.el.get_path(n_iter), true);
1371 } else if (expand_parent != null && !_this.view.el.is_row_expanded(expand_parent)) {
1372 _this.view.el.expand_row(expand_parent,true);
1375 //if (tp != null && (node.items.length() > 0 || pos > 1)) {
1376 // _this.view.el.expand_row(this.el.get_path(iter_par), true);
1378 // wee need to get the empty proptypes from somewhere..
1380 //var olditer = this.activeIter;
1381 this.activePath = this.el.get_path(n_iter).to_string();
1384 // pretend button was pressed, so that we can trigger select node...
1385 _this.view.button_is_pressed = true;
1386 _this.view.lastEventSource = "";
1387 _this.view.el.set_cursor(this.el.get_path(n_iter), null, false);
1388 _this.view.button_is_pressed = false;
1394 public string treePathFromNode (JsRender.Node node) {
1395 // iterate through the tree and find the node
1398 this.el.foreach((mod, pth, iter) => {
1403 _this.model.el.get_value(iter, 2, out value);
1407 var n = (JsRender.Node)value;
1409 print("compare %s to %s\n", n.fqn(), node.fqn());
1411 ret = pth.to_string();
1421 public class Xcls_TreeViewColumn4 : Object
1423 public Gtk.TreeViewColumn el;
1424 private Xcls_WindowLeftTree _this;
1430 public Xcls_TreeViewColumn4(Xcls_WindowLeftTree _owner )
1433 this.el = new Gtk.TreeViewColumn();
1437 // set gobject values
1438 this.el.title = "test";
1439 var child_0 = new Xcls_renderer( _this );
1441 this.el.pack_start ( child_0.el , true );
1445 this.el.add_attribute(_this.renderer.el , "markup", 0 );
1448 // user defined functions
1450 public class Xcls_renderer : Object
1452 public Gtk.CellRendererText el;
1453 private Xcls_WindowLeftTree _this;
1459 public Xcls_renderer(Xcls_WindowLeftTree _owner )
1462 _this.renderer = this;
1463 this.el = new Gtk.CellRendererText();
1467 // set gobject values
1470 // user defined functions
1475 public class Xcls_LeftTreeMenu : Object
1478 private Xcls_WindowLeftTree _this;
1484 public Xcls_LeftTreeMenu(Xcls_WindowLeftTree _owner )
1487 _this.LeftTreeMenu = this;
1488 this.el = new Gtk.Menu();
1492 // set gobject values
1493 var child_0 = new Xcls_MenuItem7( _this );
1495 this.el.add ( child_0.el );
1496 var child_1 = new Xcls_MenuItem8( _this );
1498 this.el.add ( child_1.el );
1499 var child_2 = new Xcls_MenuItem9( _this );
1501 this.el.add ( child_2.el );
1504 // user defined functions
1506 public class Xcls_MenuItem7 : Object
1508 public Gtk.MenuItem el;
1509 private Xcls_WindowLeftTree _this;
1515 public Xcls_MenuItem7(Xcls_WindowLeftTree _owner )
1518 this.el = new Gtk.MenuItem();
1522 // set gobject values
1523 this.el.label = "Delete Element";
1526 this.el.activate.connect( ( ) => {
1531 _this.model.deleteSelected();
1535 // user defined functions
1538 public class Xcls_MenuItem8 : Object
1540 public Gtk.MenuItem el;
1541 private Xcls_WindowLeftTree _this;
1547 public Xcls_MenuItem8(Xcls_WindowLeftTree _owner )
1550 this.el = new Gtk.MenuItem();
1554 // set gobject values
1555 this.el.label = "Save as Template";
1558 this.el.activate.connect( () => {
1560 DialogSaveTemplate.singleton().show(
1561 (Gtk.Window) _this.el.get_toplevel (),
1562 _this.main_window.windowstate.file.palete(),
1563 _this.getActiveElement()
1570 // user defined functions
1573 public class Xcls_MenuItem9 : Object
1575 public Gtk.MenuItem el;
1576 private Xcls_WindowLeftTree _this;
1582 public Xcls_MenuItem9(Xcls_WindowLeftTree _owner )
1585 this.el = new Gtk.MenuItem();
1589 // set gobject values
1590 this.el.label = "Save as Module";
1593 this.el.activate.connect( () => {
1594 var node = _this.getActiveElement();
1595 var name = DialogSaveModule.singleton().show(
1596 (Gtk.Window) _this.el.get_toplevel (),
1597 _this.main_window.windowstate.project,
1600 if (name.length < 1) {
1604 node.props.set("* xinclude", name);
1608 var s = _this.view.el.get_selection();
1610 print("GET SELECTED?");
1615 if (!s.get_selected(out mod, out iter)) {
1616 return; // nothing seleted..
1619 var n_cn = mod.iter_n_children(iter) -1;
1620 for (var i = n_cn; i > -1; i--) {
1621 mod.iter_nth_child(out citer, iter, i);
1624 print("removing node from Tree\n");
1626 _this.model.el.remove(ref citer);
1629 _this.node_selected(node, "tree");
1635 // user defined functions