1 static Xcls_WindowLeftTree _WindowLeftTree;
3 public class Xcls_WindowLeftTree : Object
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.Box( Gtk.Orientation.VERTICAL, 0 );
33 this.main_window = null;
36 var child_0 = new Xcls_Button2( _this );
38 this.el.add ( child_0.el );
39 var child_1 = new Xcls_ScrolledWindow4( _this );
41 this.el.add ( child_1.el );
44 // user defined functions
45 public JsRender.Node? getActiveElement () { // return path to actie node.
47 var path = this.getActivePath();
48 if (path.length < 1) {
51 return _this.model.pathToNode(path);
54 public JsRender.JsRender getActiveFile () {
55 return this.main_window.windowstate.file;
57 public string getActivePath () {
59 var view = this.view.el;
60 if (view.get_selection().count_selected_rows() < 1) {
65 view.get_selection().get_selected(out mod, out iter);
66 return mod.get_path(iter).to_string();
68 public class Xcls_Button2 : Object
71 private Xcls_WindowLeftTree _this;
77 public Xcls_Button2(Xcls_WindowLeftTree _owner )
80 this.el = new Gtk.Button();
85 this.el.hexpand = true;
86 this.el.always_show_image = true;
87 this.el.label = "Add Child Element";
88 var child_0 = new Xcls_Image3( _this );
90 this.el.set_image ( child_0.el );
93 this.el.clicked.connect( ( ) => {
96 _this.main_window.windowstate.showAddObject(this.el);
101 // user defined functions
103 public class Xcls_Image3 : Object
106 private Xcls_WindowLeftTree _this;
112 public Xcls_Image3(Xcls_WindowLeftTree _owner )
115 this.el = new Gtk.Image();
119 // set gobject values
120 this.el.icon_name = "list-add";
123 // user defined functions
127 public class Xcls_ScrolledWindow4 : Object
129 public Gtk.ScrolledWindow el;
130 private Xcls_WindowLeftTree _this;
136 public Xcls_ScrolledWindow4(Xcls_WindowLeftTree _owner )
139 this.el = new Gtk.ScrolledWindow( null, null );
143 // set gobject values
144 this.el.shadow_type = Gtk.ShadowType.IN;
145 var child_0 = new Xcls_view( _this );
147 this.el.add ( child_0.el );
148 var child_1 = new Xcls_LeftTreeMenu( _this );
153 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
156 // user defined functions
158 public class Xcls_view : Object
160 public Gtk.TreeView el;
161 private Xcls_WindowLeftTree _this;
165 public string dragData;
167 public string[] dropList;
169 public bool button_is_pressed;
170 public string lastEventSource;
171 public bool key_is_pressed;
172 public bool drag_in_motion;
173 public bool blockChanges;
176 public Xcls_view(Xcls_WindowLeftTree _owner )
180 this.el = new Gtk.TreeView();
183 this.button_is_pressed = false;
184 this.lastEventSource = "";
185 this.key_is_pressed = false;
186 this.blockChanges = false;
188 // set gobject values
189 this.el.expand = true;
190 this.el.tooltip_column = 1;
191 this.el.enable_tree_lines = true;
192 this.el.headers_visible = false;
193 var child_0 = new Xcls_model( _this );
195 this.el.set_model ( child_0.el );
196 var child_1 = new Xcls_TreeViewColumn7( _this );
198 this.el.append_column ( child_1.el );
203 var description = new Pango.FontDescription();
204 description.set_size(8000);
205 this.el.override_font(description);
207 var selection = this.el.get_selection();
208 selection.set_mode( Gtk.SelectionMode.SINGLE);
211 // is this really needed??
213 this.selection.signal['changed'].connect(function() {
214 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
215 _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
219 Gtk.drag_source_set (
220 this.el, /* widget will be drag-able */
221 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
222 BuilderApplication.targetList, /* lists of target to support */
223 Gdk.DragAction.COPY | Gdk.DragAction.MOVE | Gdk.DragAction.LINK /* what to do with data after dropped */
227 //Gtk.drag_source_add_text_targets(this.el);
231 this.el, /* widget that will accept a drop */
232 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
233 BuilderApplication.targetList, /* lists of target to support */
234 Gdk.DragAction.COPY | Gdk.DragAction.MOVE | Gdk.DragAction.LINK /* what to do with data after dropped */
237 //Gtk.drag_dest_set_target_list(this.el, Builder.Application.targetList);
238 //Gtk.drag_dest_add_text_targets(this.el);
242 this.el.button_release_event.connect( (ev) => {
243 this.button_is_pressed = false;
246 this.el.button_press_event.connect( ( ev) => {
247 //console.log("button press?");
248 this.button_is_pressed = true;
249 print("BUTTON DOWN\n");
251 this.lastEventSource = "tree";
252 if (! _this.before_node_change() ) {
259 if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button != 3) {
260 //print("click" + ev.type);
264 if (!_this.view.el.get_path_at_pos((int)ev.x,(int)ev.y, out res, null, null, null) ) {
268 this.el.get_selection().select_path(res);
270 //if (!this.get('/LeftTreeMenu').el) {
271 // this.get('/LeftTreeMenu').init();
274 _this.LeftTreeMenu.el.set_screen(Gdk.Screen.get_default());
275 _this.LeftTreeMenu.el.show_all();
276 _this.LeftTreeMenu.el.popup(null, null, null, 3, ev.time);
277 // print("click:" + res.path.to_string());
280 this.el.cursor_changed.connect( ( ) => {
281 print("LEFT TREE Cursor Changed\n");
282 if (!this.button_is_pressed && !this.key_is_pressed) {
283 // then event was started by some other action
284 // which should manually trigger all the events..
285 print("SKIPPING select - no button or key pressed\n");
290 if (this.blockChanges) { // probably not needed..
291 print("SKIPPING select - blockchanges set..\n");
294 if (!_this.before_node_change( ) ) {
295 this.blockChanges = true;
296 this.el.get_selection().unselect_all();
297 this.blockChanges = false;
301 if (_this.main_window.windowstate.file == null) {
302 print("SKIPPING select windowstate file is not set...\n");
306 //var render = this.get('/LeftTree').getRenderer();
307 print("LEFT TREE -> view -> selection changed called\n");
310 // -- it appears that the selection is not updated.
312 GLib.Timeout.add_full(GLib.Priority.DEFAULT,10 , () => {
313 print("LEFT TREE -> view -> selection changed TIMEOUT CALLED\n");
315 if (this.el.get_selection().count_selected_rows() < 1) {
317 print("selected rows < 1\n");
318 //??this.model.load( false);
319 _this.node_selected(null, this.lastEventSource);
324 //console.log('changed');
325 var s = this.el.get_selection();
328 s.get_selected(out mod, out iter);
333 _this.model.el.get_value(iter, 2, out value);
334 _this.model.activePath = mod.get_path(iter).to_string();
336 var node = (JsRender.Node)value.dup_object();
337 print ("calling left_tree.node_selected\n");
338 _this.node_selected(node, this.lastEventSource);
339 while (Gtk.events_pending()) {
340 Gtk.main_iteration();
342 var cp = mod.get_path(iter);
344 this.el.get_visible_range(out sp, out ep);
345 // if sp is before cp then retuns 1.
346 // if cp is before ep then retuns 1.
347 if (cp.compare(sp) >= 0 && ep.compare(cp) >=1) {
353 this.el.scroll_to_cell(new Gtk.TreePath.from_string(_this.model.activePath), null, true, 0.1f,0.0f);
357 //_this.after_node_change(node);
359 // _this.model.file.changed(node, "tree");
361 //Seed.print( value.get_string());
365 this.el.drag_begin.connect( ( ctx) => {
366 //print('SOURCE: drag-begin');
369 //this.targetData = "";
371 // find what is selected in our tree...
373 var s = _this.view.el.get_selection();
374 if (s.count_selected_rows() < 1) {
379 s.get_selected(out mod, out iter);
383 // set some properties of the tree for use by the dropped element.
385 _this.model.el.get_value(iter, 2, out value);
386 var tp = mod.get_path(iter).to_string();
387 var data = (JsRender.Node)(value.dup_object());
388 var xname = data.fqn();
389 print ("XNAME IS " + xname+ "\n");
391 this.dropList = _this.main_window.windowstate.file.palete().getDropList(xname);
393 print ("DROP LIST IS " + string.joinv(", ", this.dropList) + "\n");
396 // make the drag icon a picture of the node that was selected
399 // by default returns the path..
400 var path = _this.model.el.get_path(iter);
403 var pix = this.el.create_row_drag_icon ( path);
405 Gtk.drag_set_icon_surface (ctx, pix) ;
409 this.el.drag_data_get.connect( ( drag_context, data, info, time) => {
412 //print("drag-data-get");
413 var s = this.el.get_selection();
414 if (s.count_selected_rows() < 1) {
416 print("return empty string - no selection..");
423 s.get_selected(out mod, out iter);
428 _this.model.el.get_value(iter, 2, out value);
429 var ndata = (JsRender.Node)(value.dup_object());
433 var tp = mod.get_path(iter).to_string();
434 // by default returns the path..
436 if ( info != Gdk.Atom.intern("STRING",true) ) {
437 tp = ndata.toJsonString();
440 //data.set_text(tp,tp.length);
442 data.set (data.get_target (), 8, (uchar[]) tp.to_utf8 ());
445 // print("return " + tp);
447 this.el.drag_end.connect( (drag_context) => {
448 //Seed.print('LEFT-TREE: drag-end');
450 this.dropList = null;
451 // this.targetData = "";
452 this.highlightDropPath("",0);
455 this.el.drag_motion.connect( ( ctx, x, y, time) => {
456 print("got drag motion\n");
457 var src = Gtk.drag_get_source_widget(ctx);
461 if (src != this.el) {
465 // the point of this is to detect where an item could be dropped..
466 print("requesting drag data\n");
467 this.drag_in_motion = true;
469 // request data that will be recieved by the recieve...
472 this.el, // will receive 'drag-data-received' signal
473 ctx, // represents the current state of the DnD
474 Gdk.Atom.intern("STRING",true), // the target type we want
481 print("action: %d\n", ctx.get_actions());
482 //print("GETTING POS");
486 Gtk.TreeViewDropPosition pos;
487 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
489 // if there are not items in the tree.. the we have to set isOver to true for anything..
491 if (_this.model.el.iter_n_children(null) < 1) {
492 print("got NO children?\n");
495 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
499 // ------------- a drag from self..
502 //var action = Gdk.DragAction.COPY;
503 // unless we are copying!!! ctl button..
505 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
506 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
507 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
510 if (_this.model.el.iter_n_children(null) < 1) {
511 // no children.. -- asume it's ok..
513 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
515 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
516 Gdk.drag_status(ctx, action ,time);
519 // continue through to allow drop...
527 //print("ISOVER? " + isOver);
530 Gdk.drag_status(ctx, 0 ,time);
531 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
536 // drag node is parent of child..
537 //console.log("SRC TREEPATH: " + src.treepath);
538 //console.log("TARGET TREEPATH: " + data.path.to_string());
540 // nned to check a few here..
541 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
542 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
543 //Gtk.TreeViewDropPosition.AFTER
544 //Gtk.TreeViewDropPosition.BEFORE
546 // locally dragged items to not really use the
547 var selection_text = this.dragData;
551 if (selection_text == null || selection_text.length < 1) {
552 //print("Error - drag selection text returned NULL");
553 Gdk.drag_status(ctx, 0 ,time);
554 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
559 // see if we are dragging into ourself?
560 var target_path = path.to_string();
561 print ("Drag %s onto %s--%d\n ", selection_text, target_path, pos);
563 // pos : 3 = ontop - 0 = after, 1 = before
564 //print("target_path="+target_path);
567 if (selection_text == target_path) {
568 print("self drag ?? == we should perhaps allow copy onto self..\n");
570 Gdk.drag_status(ctx, 0 ,time);
571 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
573 // -- fixme -- this is not really correct..
578 //print("DUMPING DATA");
579 //console.dump(data);
582 //print(data.path.to_string() +' => '+ data.pos);
584 // dropList is a list of xtypes that this node could be dropped on.
585 // it is set up when we start to drag..
588 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
590 print("targetDAta: " + targetData +"\n");
592 if (targetData.length < 1) {
593 //print("Can not find drop node path");
595 Gdk.drag_status(ctx, 0, time);
596 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
600 var td_ar = targetData.split("|");
604 Gdk.drag_status(ctx, action ,time);
605 this.highlightDropPath(td_ar[0], (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
610 this.el.key_press_event.connect( (ev) => {
611 this.key_is_pressed = true;
614 this.el.key_release_event.connect( (ev) => {
615 this.key_is_pressed = false;
618 this.el.drag_data_received.connect( (ctx, x, y, sel, info, time) => {
620 // THIS CODE ONLY RELATES TO drag or drop of "NEW" elements or "FROM another tree.."
623 // print("Tree: drag-data-received\n");
624 var selection_text = (string)sel.get_data();
625 //print("selection_text= %s\n",selection_text);
627 var is_drag = this.drag_in_motion;
631 GLib.debug("Is Drag %s\n", is_drag ? "Y": "N");
635 Gtk.TreeViewDropPosition pos;
636 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
638 // if there are not items in the tree.. the we have to set isOver to true for anything..
640 if (_this.model.el.iter_n_children(null) < 1) {
641 GLib.debug("got NO children?\n");
644 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
648 //console.log("LEFT-TREE: drag-motion");
649 var src = Gtk.drag_get_source_widget(ctx);
651 // a drag from self - this should be handled by drop and motion.
652 if (src == this.el) {
653 GLib.debug("Source == this element should not happen.. ? \n");
656 //print("drag_data_recieved from another element");
661 if (selection_text == null || selection_text.length < 1 || !isOver) {
662 // nothing valid foudn to drop...
663 GLib.debug("empty sel text or not over");
665 Gdk.drag_status(ctx, 0, time);
666 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
669 Gtk.drag_finish (ctx, false, false, time); // drop failed..
674 var dropNode = new JsRender.Node();
676 var dropNodeType = selection_text;
677 var show_templates = true;
679 if (dropNodeType[0] == '{') {
680 var pa = new Json.Parser();
682 pa.load_from_data(dropNodeType);
684 Gtk.drag_finish (ctx, false, false, time); // drop failed..
689 dropNode.loadFromJson( pa.get_root().get_object(), 2);
690 dropNodeType = dropNode.fqn();
691 show_templates = false;
695 if (selection_text.contains(":")) {
696 var bits = selection_text.split(":");
697 dropNode.setFqn(bits[0]);
698 dropNode.props.set("* prop", bits[1]);
701 dropNode.setFqn(selection_text);
706 // dropList --- need to gather this ...
707 GLib.debug("get dropList for : %s\n",dropNodeType);
708 var dropList = _this.main_window.windowstate.file.palete().getDropList(dropNodeType);
710 GLib.debug("dropList: %s\n", string.joinv(" , ", dropList));
712 // if drag action is link ... then we can drop it anywahere...
713 if ((ctx.get_actions() & Gdk.DragAction.LINK) > 0) {
714 // if path is null?? dragging into an empty tree?
715 targetData = (path == null ? "" : path.to_string()) + "|%d".printf((int)pos);
719 targetData = _this.model.findDropNodeByPath( isEmpty ? "" : path.to_string(), dropList, pos);
724 GLib.debug("targetDAta: %s", targetData );
726 if (targetData.length < 1) {
728 // invalid drop path..
729 if (this.drag_in_motion) {
730 Gdk.drag_status(ctx, 0, time);
731 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
734 Gtk.drag_finish (ctx, false, false, time); // drop failed..
741 var td_ar = targetData.split("|");
744 if (this.drag_in_motion) {
745 Gdk.drag_status(ctx, Gdk.DragAction.COPY ,time);
747 this.highlightDropPath( td_ar[0] , (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
750 // continue on to allow drop..
753 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
755 // {parent}|{pos}|{prop}
758 _this.model.dropNode(targetData, dropNode, show_templates);
759 GLib.debug("ADD new node!!!\n");
761 ///Xcls_DialogTemplateSelect.singleton().show( _this.model.file.palete(), node);
763 Gtk.drag_finish (ctx, false, false,time);
770 this.el.drag_drop.connect( ( ctx, x, y, time) => {
771 //Seed.print("TARGET: drag-drop");
774 var src = Gtk.drag_get_source_widget(ctx);
776 if (src != this.el) {
780 this.drag_in_motion = false;
781 // request data that will be recieved by the recieve...
784 this.el, // will receive 'drag-data-received' signal
785 ctx, // represents the current state of the DnD
786 Gdk.Atom.intern("application/json",true), // the target type we want
791 // No target offered by source => error
797 // handle drop around self..
801 //print("GETTING POS");
805 Gtk.TreeViewDropPosition pos;
806 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
808 // if there are not items in the tree.. the we have to set isOver to true for anything..
810 if (_this.model.el.iter_n_children(null) < 1) {
811 print("got NO children?\n");
814 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
819 //var action = Gdk.DragAction.COPY;
820 // unless we are copying!!! ctl button..
822 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
823 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
824 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
827 if (_this.model.el.iter_n_children(null) < 1) {
828 // no children.. -- asume it's ok..
830 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
832 // continue through to allow drop...
840 //print("ISOVER? " + isOver);
843 Gtk.drag_finish (ctx, false, false, time); // drop failed..
844 return true; // not over apoint!?! - no action on drop or motion..
847 // drag node is parent of child..
848 //console.log("SRC TREEPATH: " + src.treepath);
849 //console.log("TARGET TREEPATH: " + data.path.to_string());
851 // nned to check a few here..
852 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
853 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
854 //Gtk.TreeViewDropPosition.AFTER
855 //Gtk.TreeViewDropPosition.BEFORE
857 // locally dragged items to not really use the
858 var selection_text = this.dragData;
862 if (selection_text == null || selection_text.length < 1) {
863 //print("Error - drag selection text returned NULL");
865 Gtk.drag_finish (ctx, false, false, time); // drop failed..
866 return true; /// -- fixme -- this is not really correct..
869 // see if we are dragging into ourself?
870 print ("got selection text of " + selection_text);
872 var target_path = path.to_string();
873 //print("target_path="+target_path);
876 if (selection_text == target_path) {
877 print("self drag ?? == we should perhaps allow copy onto self..\n");
879 Gtk.drag_finish (ctx, false, false, time); // drop failed..
881 return true; /// -- fixme -- this is not really correct..
886 //print("DUMPING DATA");
887 //console.dump(data);
890 //print(data.path.to_string() +' => '+ data.pos);
892 // dropList is a list of xtypes that this node could be dropped on.
893 // it is set up when we start to drag..
896 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
898 print("targetDAta: " + targetData +"\n");
900 if (targetData.length < 1) {
901 //print("Can not find drop node path");
903 Gtk.drag_finish (ctx, false, false, time); // drop failed..
909 // continue on to allow drop..
911 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
914 var delete_selection_data = false;
916 if (action == Gdk.DragAction.ASK) {
917 /* Ask the user to move or copy, then set the ctx action. */
920 if (action == Gdk.DragAction.MOVE) {
921 delete_selection_data = true;
924 // drag around.. - reorder..
925 _this.model.moveNode(targetData, action);
931 // we can send stuff to souce here...
934 // do we always say failure, so we handle the reall drop?
935 Gtk.drag_finish (ctx, false, false,time); //delete_selection_data, time);
947 // user defined functions
948 public void highlightDropPath ( string treepath, Gtk.TreeViewDropPosition pos) {
950 // highlighting for drag/drop
951 if (treepath.length > 0) {
952 this.el.set_drag_dest_row( new Gtk.TreePath.from_string( treepath ), pos);
954 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
958 public void setCursor (string treepath, string sourceEvent) {
959 this.lastEventSource = sourceEvent;
960 //this.blockChanges = true; << block changes prevents loading of 'node data' and firing of node_selected..
961 this.el.set_cursor(new Gtk.TreePath.from_string(treepath), null, false);
962 // fire node_selected..
963 //this.blockChanges = false;
964 this.lastEventSource = "";
966 public void selectNode (string treepath_str, string source) {
967 this.lastEventSource = source;
968 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
969 var tp = new Gtk.TreePath.from_string(treepath_str);
971 this.el.set_cursor(tp, null, false);
972 this.el.scroll_to_cell(tp, null, false, 0,0);
975 public class Xcls_model : Object
977 public Gtk.TreeStore el;
978 private Xcls_WindowLeftTree _this;
982 public DialogTemplateSelect template_select;
983 public string activePath;
986 public Xcls_model(Xcls_WindowLeftTree _owner )
990 this.el = new Gtk.TreeStore( 3, typeof(string),typeof(string),typeof(Object) );
993 this.template_select = null;
994 this.activePath = "";
996 // set gobject values
1000 print("model initialized");
1003 // user defined functions
1004 public string findDropNode (string treepath_str, string[] targets) {
1006 // this is used by the dragdrop code in the roo version AFAIR..
1008 //var path = treepath_str.replace(/^builder-/, '');
1009 // treemap is depreciated... - should really check if model has any entries..
1011 if (this.el.iter_n_children(null) < 1) {
1013 return "|%d".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
1015 //print("FIND treepath: " + path);
1016 //console.dump(this.treemap);
1018 //if (!treepath_str.match(/^builder-/)) {
1019 // return []; // nothing!
1021 if (targets.length > 0 && targets[0] == "*") {
1022 return treepath_str;
1024 return this.findDropNodeByPath(treepath_str,targets, -1);
1026 public void loadFile (JsRender.JsRender f) {
1029 _this.main_window.windowstate.leftTreeNodeSelected(null, "");
1031 _this.main_window.windowstate.file = f;
1034 if (f.tree == null) {
1041 // if it's still null?
1042 if (f.tree == null) {
1046 var o = new Gee.ArrayList<JsRender.Node>();
1050 _this.view.el.expand_all();
1052 if (f.tree.items.size < 1) {
1055 //this.get('/Window.leftvpaned').el.set_position(80);
1057 _this.view.el.set_cursor(
1058 new Gtk.TreePath.from_string("0"), null, false);
1062 //this.get('/Window.leftvpaned').el.set_position(200);
1069 public void updateSelected () {
1072 var s = _this.view.el.get_selection();
1079 if (!s.get_selected(out mod, out iter)) {
1080 return; // nothing seleted..
1084 this.el.get_value(iter, 2, out value);
1085 var node = (JsRender.Node)(value.get_object());
1087 this.el.set(iter, 0, node.nodeTitle(),
1088 1, node.nodeTip(), -1
1091 public string findDropNodeByPath (string treepath_str, string[] targets, int in_pref = -1) {
1093 var path = treepath_str; // dupe it..
1096 // pref : 3 = ontop - 0 = after, 1 = before
1097 int pref = in_pref < 0 ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : in_pref;
1101 //console.dump(this.treemap);
1103 print("findDropNodeByPath : got path length %d / %s\n", path.length, path);
1105 if (path.length == 0) {
1106 // top drop. // just return empty..
1107 return "|%d".printf((int)pref) ;
1112 while (path.length > 0) {
1114 if (path.length == treepath_str.length && pref != Gtk.TreeViewDropPosition.INTO_OR_AFTER) {
1115 if (path.last_index_of(":") < 0 ) {
1118 path = path.substring(0, path.last_index_of(":"));
1119 last = treepath_str;
1120 print("DROP before or after : using %s\n",path);
1124 //print("LOOKING FOR PATH: " + path);
1125 var node_data = this.pathToNode(path);
1127 if (node_data == null) {
1128 print("node not found");
1132 var xname = node_data.fqn();
1136 for (var i =0; i < targets.length; i++) {
1137 var tg = targets[i];
1138 if ((tg == xname) ) {
1142 // if target is "xxxx:name"
1143 if (tg.contains(xname +":")) {
1145 var ar = tg.split(":");
1151 if (match.length > 0) {
1152 if (last.length > 0) { // pref is after/before..
1153 // then it's after last
1157 return last + "|%d".printf((int)pref) + "|" + prop;
1161 // we need to add prop - as :store -> needs to bee added when dropping onto.
1162 return path + "|%d".printf( (int) Gtk.TreeViewDropPosition.INTO_OR_AFTER) + "|" + prop;
1166 var par = path.split(":");
1167 string [] ppar = {};
1168 for (var i = 0; i < par.length-1; i++) {
1172 path = string.joinv(":", ppar);
1181 public void moveNode (string target_data, Gdk.DragAction action)
1184 /// target_data = "path|pos");
1187 //print("MOVE NODE");
1188 // console.dump(target_data);
1189 Gtk.TreeIter old_iter;
1192 var s = _this.view.el.get_selection();
1193 s.get_selected(out mod , out old_iter);
1194 mod.get_path(old_iter);
1196 var node = this.pathToNode(mod.get_path(old_iter).to_string());
1197 //console.dump(node);
1199 print("moveNode: ERROR - node is null?");
1204 // needs to drop first, otherwise the target_data
1205 // treepath will be invalid.
1208 if ((action & Gdk.DragAction.MOVE) > 0) {
1209 print("REMOVING OLD NODE : " + target_data + "\n");
1211 this.dropNode(target_data, node, false);
1212 this.el.remove(ref old_iter);
1217 print("DROPPING NODE // copy: " + target_data + "\n");
1218 node = node.deepClone();
1219 this.dropNode(target_data, node, false);
1222 this.activePath= "";
1223 //this.updateNode(false,true);
1225 public void deleteSelected () {
1227 print("DELETE SELECTED?");
1228 //_this.view.blockChanges = true;
1229 print("GET SELECTION?");
1231 var s = _this.view.el.get_selection();
1233 print("GET SELECTED?");
1238 if (!s.get_selected(out mod, out iter)) {
1239 return; // nothing seleted..
1244 this.activePath= "";
1245 print("GET vnode value?");
1248 this.el.get_value(iter, 2, out value);
1249 var data = (JsRender.Node)(value.get_object());
1250 print("removing node from Render\n");
1251 if (data.parent == null) {
1252 _this.main_window.windowstate.file.tree = null;
1256 print("removing node from Tree\n");
1258 this.el.remove(ref iter);
1268 this.activePath= ""; // again!?!?
1269 //this.changed(null,true);
1273 _this.view.blockChanges = false;
1275 public void load (Gee.ArrayList<JsRender.Node> tr, Gtk.TreeIter? iter)
1278 //this.insert(citer,iter,0);
1279 for(var i =0 ; i < tr.size; i++) {
1281 this.el.insert(out citer,iter,-1); // why not append?
1283 this.el.append(out citer,null);
1286 this.el.set(citer, 0, tr.get(i).nodeTitle(),
1287 1, tr.get(i).nodeTip(), -1
1289 var o = GLib.Value(typeof(Object));
1290 o.set_object((Object)tr.get(i));
1292 this.el.set_value(citer, 2, o);
1294 if (tr.get(i).items.size > 0) {
1295 this.load(tr.get(i).items, citer);
1302 public JsRender.Node pathToNode (string path) {
1306 _this.model.el.get_iter_from_string(out iter, path);
1309 _this.model.el.get_value(iter, 2, out value);
1311 return (JsRender.Node)value.dup_object();
1314 public void dropNode (string target_data_str, JsRender.Node node, bool show_templates) {
1315 // print("drop Node");
1316 // console.dump(node);
1317 // console.dump(target_data);
1320 // {parent}|{pos}|{prop}
1323 // 0 = before , 1=after 2/3 onto
1325 GLib.debug("dropNode %s", target_data_str);
1326 var target_data= target_data_str.split("|");
1328 var parent_str = target_data[0].length > 0 ? target_data[0] : "";
1329 var pos = target_data.length > 1 ? int.parse(target_data[1]) : 2; // ontop..
1332 Gtk.TreePath tree_path = parent_str.length > 0 ? new Gtk.TreePath.from_string( parent_str ) : null;
1336 //print("add " + tp + "@" + target_data[1] );
1338 JsRender.Node parentNode = null;
1340 Gtk.TreeIter iter_after;
1341 Gtk.TreeIter iter_par ;
1344 if (target_data.length == 3 && target_data[2].length > 0) {
1345 node.props.set("* prop", target_data[2]);
1348 Gtk.TreePath expand_parent = null;
1350 // we only need to show the template if it's come from else where?
1351 if (show_templates) {
1353 var ts = _this.main_window.windowstate.template_select;
1355 var new_node = ts.show(
1356 _this.main_window, // (Gtk.Window) _this.el.get_toplevel (),
1357 _this.main_window.windowstate.file.palete(),
1359 _this.main_window.windowstate.project);
1361 if (new_node == null) {
1362 return; // do not add?
1367 //print("pos is %d \n".printf(pos));
1369 Gtk.TreeIter n_iter;
1371 if ( parent_str.length < 1) {
1372 this.el.append(out n_iter, null); // drop at top level..
1374 _this.main_window.windowstate.file.tree = node;
1377 } else if (pos < 2) {
1378 //print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
1380 this.el.get_iter(out iter_after, tree_path );
1381 this.el.iter_parent(out iter_par, iter_after);
1382 expand_parent = this.el.get_path(iter_par);
1385 this.el.get_value( iter_par, 2, out value);
1386 parentNode = (JsRender.Node)value.dup_object();
1389 this.el.get_value( iter_after, 2, out value);
1390 var relNode = (JsRender.Node)value.dup_object();
1394 this.el.insert_after(out n_iter, iter_par , iter_after);
1395 var ix = parentNode.items.index_of(relNode);
1396 parentNode.items.insert(ix+1, node);
1399 this.el.insert_before(out n_iter, iter_par , iter_after);
1400 var ix = parentNode.items.index_of(relNode);
1401 parentNode.items.insert(ix, node);
1404 node.parent = parentNode;
1409 // print("appending to " + parent_str);
1410 this.el.get_iter(out iter_par, tree_path);
1411 this.el.append(out n_iter, iter_par );
1412 expand_parent = this.el.get_path(iter_par);
1415 this.el.get_value( iter_par, 2, out value);
1416 parentNode = (JsRender.Node)value.dup_object();
1417 node.parent = parentNode;
1418 parentNode.items.add(node);
1421 // reparent node in tree...
1424 // why only on no parent???
1426 //if (node.parent = null) {
1433 // work out what kind of packing to use.. -- should be in
1434 if (!node.has("pack") && parent_str.length > 1) {
1436 _this.main_window.windowstate.file.palete().fillPack(node,parentNode);
1443 this.el.set(n_iter, 0, node.nodeTitle(), 1, node.nodeTip(), -1 );
1444 var o = GLib.Value(typeof(Object));
1445 o.set_object((Object)node);
1447 this.el.set_value(n_iter, 2, o);
1452 // load children - if it has any..
1454 if (node.items.size > 0) {
1455 this.load(node.items, n_iter);
1456 _this.view.el.expand_row(this.el.get_path(n_iter), true);
1457 } else if (expand_parent != null && !_this.view.el.is_row_expanded(expand_parent)) {
1458 _this.view.el.expand_row(expand_parent,true);
1461 //if (tp != null && (node.items.length() > 0 || pos > 1)) {
1462 // _this.view.el.expand_row(this.el.get_path(iter_par), true);
1464 // wee need to get the empty proptypes from somewhere..
1466 //var olditer = this.activeIter;
1467 this.activePath = this.el.get_path(n_iter).to_string();
1470 // pretend button was pressed, so that we can trigger select node...
1471 _this.view.button_is_pressed = true;
1472 _this.view.lastEventSource = "";
1473 _this.view.el.set_cursor(this.el.get_path(n_iter), null, false);
1474 _this.view.button_is_pressed = false;
1480 public string treePathFromNode (JsRender.Node node) {
1481 // iterate through the tree and find the node
1484 this.el.foreach((mod, pth, iter) => {
1489 _this.model.el.get_value(iter, 2, out value);
1493 var n = (JsRender.Node)value;
1495 print("compare %s to %s\n", n.fqn(), node.fqn());
1497 ret = pth.to_string();
1507 public class Xcls_TreeViewColumn7 : Object
1509 public Gtk.TreeViewColumn el;
1510 private Xcls_WindowLeftTree _this;
1516 public Xcls_TreeViewColumn7(Xcls_WindowLeftTree _owner )
1519 this.el = new Gtk.TreeViewColumn();
1523 // set gobject values
1524 this.el.title = "test";
1525 var child_0 = new Xcls_renderer( _this );
1527 this.el.pack_start ( child_0.el , true );
1531 this.el.add_attribute(_this.renderer.el , "markup", 0 );
1534 // user defined functions
1536 public class Xcls_renderer : Object
1538 public Gtk.CellRendererText el;
1539 private Xcls_WindowLeftTree _this;
1545 public Xcls_renderer(Xcls_WindowLeftTree _owner )
1548 _this.renderer = this;
1549 this.el = new Gtk.CellRendererText();
1553 // set gobject values
1556 // user defined functions
1561 public class Xcls_LeftTreeMenu : Object
1564 private Xcls_WindowLeftTree _this;
1570 public Xcls_LeftTreeMenu(Xcls_WindowLeftTree _owner )
1573 _this.LeftTreeMenu = this;
1574 this.el = new Gtk.Menu();
1578 // set gobject values
1579 var child_0 = new Xcls_MenuItem10( _this );
1581 this.el.add ( child_0.el );
1582 var child_1 = new Xcls_MenuItem11( _this );
1584 this.el.add ( child_1.el );
1585 var child_2 = new Xcls_MenuItem12( _this );
1587 this.el.add ( child_2.el );
1590 // user defined functions
1592 public class Xcls_MenuItem10 : Object
1594 public Gtk.MenuItem el;
1595 private Xcls_WindowLeftTree _this;
1601 public Xcls_MenuItem10(Xcls_WindowLeftTree _owner )
1604 this.el = new Gtk.MenuItem();
1608 // set gobject values
1609 this.el.label = "Delete Element";
1612 this.el.activate.connect( ( ) => {
1617 _this.model.deleteSelected();
1621 // user defined functions
1624 public class Xcls_MenuItem11 : Object
1626 public Gtk.MenuItem el;
1627 private Xcls_WindowLeftTree _this;
1633 public Xcls_MenuItem11(Xcls_WindowLeftTree _owner )
1636 this.el = new Gtk.MenuItem();
1640 // set gobject values
1641 this.el.label = "Save as Template";
1644 this.el.activate.connect( () => {
1646 DialogSaveTemplate.singleton().show(
1647 (Gtk.Window) _this.el.get_toplevel (),
1648 _this.main_window.windowstate.file.palete(),
1649 _this.getActiveElement()
1656 // user defined functions
1659 public class Xcls_MenuItem12 : Object
1661 public Gtk.MenuItem el;
1662 private Xcls_WindowLeftTree _this;
1668 public Xcls_MenuItem12(Xcls_WindowLeftTree _owner )
1671 this.el = new Gtk.MenuItem();
1675 // set gobject values
1676 this.el.label = "Save as Module";
1679 this.el.activate.connect( () => {
1680 var node = _this.getActiveElement();
1681 var name = DialogSaveModule.singleton().show(
1682 (Gtk.Window) _this.el.get_toplevel (),
1683 _this.main_window.windowstate.project,
1686 if (name.length < 1) {
1690 node.props.set("* xinclude", name);
1694 var s = _this.view.el.get_selection();
1696 print("GET SELECTED?");
1701 if (!s.get_selected(out mod, out iter)) {
1702 return; // nothing seleted..
1705 var n_cn = mod.iter_n_children(iter) -1;
1706 for (var i = n_cn; i > -1; i--) {
1707 mod.iter_nth_child(out citer, iter, i);
1710 print("removing node from Tree\n");
1712 _this.model.el.remove(ref citer);
1715 _this.node_selected(node, "tree");
1721 // user defined functions