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_viewwin viewwin;
16 public Xcls_view view;
17 public Xcls_model model;
18 public Xcls_maincol maincol;
19 public Xcls_iconrender iconrender;
20 public Xcls_renderer renderer;
21 public Xcls_addiconrender addiconrender;
22 public Xcls_LeftTreeMenu LeftTreeMenu;
25 public signal bool before_node_change ();
26 public Xcls_MainWindow main_window;
27 public signal void changed ();
28 public signal void node_selected (JsRender.Node? node, string source);
31 public Xcls_WindowLeftTree()
34 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
37 this.main_window = null;
40 var child_0 = new Xcls_viewwin( _this );
42 this.el.add ( child_0.el );
45 // user defined functions
46 public string getActivePath () {
48 var view = this.view.el;
49 if (view.get_selection().count_selected_rows() < 1) {
54 view.get_selection().get_selected(out mod, out iter);
55 return mod.get_path(iter).to_string();
57 public JsRender.Node? getActiveElement () { // return path to actie node.
59 var path = this.getActivePath();
60 if (path.length < 1) {
63 return _this.model.pathToNode(path);
66 public JsRender.JsRender getActiveFile () {
67 return this.main_window.windowstate.file;
69 public class Xcls_viewwin : Object
71 public Gtk.ScrolledWindow el;
72 private Xcls_WindowLeftTree _this;
78 public Xcls_viewwin(Xcls_WindowLeftTree _owner )
82 this.el = new Gtk.ScrolledWindow( null, null );
87 this.el.shadow_type = Gtk.ShadowType.IN;
88 var child_0 = new Xcls_view( _this );
90 this.el.add ( child_0.el );
91 var child_1 = new Xcls_LeftTreeMenu( _this );
96 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
99 this.el.size_allocate.connect( (allocation) => {
102 //GLib.debug("Got allocation width of scrolled view %d", allocation.width );
103 _this.maincol.el.set_max_width(allocation.width - 32);
107 // user defined functions
109 public class Xcls_view : Object
111 public Gtk.TreeView el;
112 private Xcls_WindowLeftTree _this;
116 public bool blockChanges;
117 public bool drag_in_motion;
118 public string lastEventSource;
119 public string dragData;
120 public bool button_is_pressed;
121 public bool key_is_pressed;
124 public string[] dropList;
127 public Xcls_view(Xcls_WindowLeftTree _owner )
131 this.el = new Gtk.TreeView();
134 this.blockChanges = false;
135 this.lastEventSource = "";
136 this.button_is_pressed = false;
137 this.key_is_pressed = false;
139 // set gobject values
140 this.el.expand = true;
141 this.el.tooltip_column = 1;
142 this.el.enable_tree_lines = true;
143 this.el.headers_visible = false;
144 var child_0 = new Xcls_model( _this );
146 this.el.set_model ( child_0.el );
147 var child_1 = new Xcls_maincol( _this );
149 this.el.append_column ( child_1.el );
150 var child_2 = new Xcls_TreeViewColumn8( _this );
152 this.el.append_column ( child_2.el );
157 var description = new Pango.FontDescription();
158 description.set_size(8000);
159 this.el.override_font(description);
161 var selection = this.el.get_selection();
162 selection.set_mode( Gtk.SelectionMode.SINGLE);
165 // is this really needed??
167 this.selection.signal['changed'].connect(function() {
168 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
169 _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
173 Gtk.drag_source_set (
174 this.el, /* widget will be drag-able */
175 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
176 BuilderApplication.targetList, /* lists of target to support */
177 Gdk.DragAction.COPY | Gdk.DragAction.MOVE | Gdk.DragAction.LINK /* what to do with data after dropped */
181 //Gtk.drag_source_add_text_targets(this.el);
185 this.el, /* widget that will accept a drop */
186 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
187 BuilderApplication.targetList, /* lists of target to support */
188 Gdk.DragAction.COPY | Gdk.DragAction.MOVE | Gdk.DragAction.LINK /* what to do with data after dropped */
191 //Gtk.drag_dest_set_target_list(this.el, Builder.Application.targetList);
192 //Gtk.drag_dest_add_text_targets(this.el);
200 this.el.button_release_event.connect( (ev) => {
201 this.button_is_pressed = false;
204 this.el.button_press_event.connect( ( ev) => {
205 //console.log("button press?");
206 this.button_is_pressed = true;
207 print("BUTTON DOWN\n");
209 this.lastEventSource = "tree";
210 if (! _this.before_node_change() ) {
215 if (ev.type != Gdk.EventType.BUTTON_PRESS) {
218 if (_this.model.el.iter_n_children(null) < 1) {
219 _this.main_window.windowstate.showAddObject(_this.view.el);
225 Gtk.TreeViewColumn col;
226 if (!_this.view.el.get_path_at_pos((int)ev.x,(int)ev.y, out res, out col, null, null) ) {
230 if (col.title == "Add") {
234 _this.model.el.get_iter (out iter, res);
235 _this.model.el.get_value(iter, 2, out value);
236 // why dup_ - gets and and inc's ref count (which in theory should be freed at the end.?
238 var node = (JsRender.Node)value.dup_object();
239 var fqn = node.fqn();
240 var cn = _this.main_window.windowstate.project.palete.getChildList(fqn);
245 _this.main_window.windowstate.leftTreeBeforeChange();
246 this.el.get_selection().select_path(res);
247 _this.main_window.windowstate.showAddObject(this.el);
251 if ( ev.button != 3) {
252 //print("click" + ev.type);
255 _this.main_window.windowstate.leftTreeBeforeChange();
259 this.el.get_selection().select_path(res);
263 //if (!this.get('/LeftTreeMenu').el) {
264 // this.get('/LeftTreeMenu').init();
267 _this.LeftTreeMenu.el.set_screen(Gdk.Screen.get_default());
268 _this.LeftTreeMenu.el.show_all();
269 _this.LeftTreeMenu.el.popup(null, null, null, 3, ev.time);
270 // print("click:" + res.path.to_string());
273 this.el.cursor_changed.connect( ( ) => {
274 print("LEFT TREE Cursor Changed\n");
275 if (!this.button_is_pressed && !this.key_is_pressed) {
276 // then event was started by some other action
277 // which should manually trigger all the events..
278 print("SKIPPING select - no button or key pressed\n");
283 if (this.blockChanges) { // probably not needed..
284 print("SKIPPING select - blockchanges set..\n");
287 if (!_this.before_node_change( ) ) {
288 this.blockChanges = true;
289 this.el.get_selection().unselect_all();
290 this.blockChanges = false;
294 if (_this.main_window.windowstate.file == null) {
295 print("SKIPPING select windowstate file is not set...\n");
299 //var render = this.get('/LeftTree').getRenderer();
300 print("LEFT TREE -> view -> selection changed called\n");
303 // -- it appears that the selection is not updated.
305 GLib.Timeout.add_full(GLib.Priority.DEFAULT,10 , () => {
306 print("LEFT TREE -> view -> selection changed TIMEOUT CALLED\n");
308 if (this.el.get_selection().count_selected_rows() < 1) {
310 print("selected rows < 1\n");
311 //??this.model.load( false);
312 _this.node_selected(null, this.lastEventSource);
317 //console.log('changed');
318 var s = this.el.get_selection();
321 s.get_selected(out mod, out iter);
326 _this.model.el.get_value(iter, 2, out value);
327 _this.model.activePath = mod.get_path(iter).to_string();
331 var node = (JsRender.Node)value.dup_object();
332 print ("calling left_tree.node_selected\n");
333 _this.node_selected(node, this.lastEventSource);
334 while (Gtk.events_pending()) {
335 Gtk.main_iteration();
337 var cp = mod.get_path(iter);
339 this.el.get_visible_range(out sp, out ep);
340 // if sp is before cp then retuns 1.
341 // if cp is before ep then retuns 1.
342 if (cp.compare(sp) >= 0 && ep.compare(cp) >=1) {
348 this.el.scroll_to_cell(new Gtk.TreePath.from_string(_this.model.activePath), null, true, 0.1f,0.0f);
352 //_this.after_node_change(node);
354 // _this.model.file.changed(node, "tree");
356 //Seed.print( value.get_string());
360 this.el.drag_begin.connect( ( ctx) => {
361 //print('SOURCE: drag-begin');
364 //this.targetData = "";
366 // find what is selected in our tree...
368 var s = _this.view.el.get_selection();
369 if (s.count_selected_rows() < 1) {
374 s.get_selected(out mod, out iter);
378 // set some properties of the tree for use by the dropped element.
380 _this.model.el.get_value(iter, 2, out value);
381 var tp = mod.get_path(iter).to_string();
382 var data = (JsRender.Node)(value.dup_object());
383 var xname = data.fqn();
384 print ("XNAME IS " + xname+ "\n");
386 this.dropList = _this.main_window.windowstate.file.palete().getDropList(xname);
388 print ("DROP LIST IS " + string.joinv(", ", this.dropList) + "\n");
391 // make the drag icon a picture of the node that was selected
394 // by default returns the path..
395 var path = _this.model.el.get_path(iter);
398 var pix = this.el.create_row_drag_icon ( path);
400 Gtk.drag_set_icon_surface (ctx, pix) ;
404 this.el.drag_data_get.connect( ( drag_context, data, info, time) => {
407 //print("drag-data-get");
408 var s = this.el.get_selection();
409 if (s.count_selected_rows() < 1) {
411 print("return empty string - no selection..");
418 s.get_selected(out mod, out iter);
423 _this.model.el.get_value(iter, 2, out value);
424 var ndata = (JsRender.Node)(value.dup_object());
428 var tp = mod.get_path(iter).to_string();
429 // by default returns the path..
431 if ( info != Gdk.Atom.intern("STRING",true) ) {
432 tp = ndata.toJsonString();
435 //data.set_text(tp,tp.length);
437 data.set (data.get_target (), 8, (uchar[]) tp.to_utf8 ());
440 // print("return " + tp);
442 this.el.drag_end.connect( (drag_context) => {
443 //Seed.print('LEFT-TREE: drag-end');
445 this.dropList = null;
446 // this.targetData = "";
447 this.highlightDropPath("",0);
450 this.el.drag_motion.connect( ( ctx, x, y, time) => {
451 print("got drag motion\n");
452 var src = Gtk.drag_get_source_widget(ctx);
456 if (src != this.el) {
460 // the point of this is to detect where an item could be dropped..
461 print("requesting drag data\n");
462 this.drag_in_motion = true;
464 // request data that will be recieved by the recieve...
467 this.el, // will receive 'drag-data-received' signal
468 ctx, // represents the current state of the DnD
469 Gdk.Atom.intern("STRING",true), // the target type we want
476 print("action: %d\n", ctx.get_actions());
477 //print("GETTING POS");
481 Gtk.TreeViewDropPosition pos;
482 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
484 // if there are not items in the tree.. the we have to set isOver to true for anything..
486 if (_this.model.el.iter_n_children(null) < 1) {
487 print("got NO children?\n");
490 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
494 // ------------- a drag from self..
497 //var action = Gdk.DragAction.COPY;
498 // unless we are copying!!! ctl button..
500 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
501 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
502 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
505 if (_this.model.el.iter_n_children(null) < 1) {
506 // no children.. -- asume it's ok..
508 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
510 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
511 Gdk.drag_status(ctx, action ,time);
514 // continue through to allow drop...
522 //print("ISOVER? " + isOver);
525 Gdk.drag_status(ctx, 0 ,time);
526 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
531 // drag node is parent of child..
532 //console.log("SRC TREEPATH: " + src.treepath);
533 //console.log("TARGET TREEPATH: " + data.path.to_string());
535 // nned to check a few here..
536 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
537 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
538 //Gtk.TreeViewDropPosition.AFTER
539 //Gtk.TreeViewDropPosition.BEFORE
541 // locally dragged items to not really use the
542 var selection_text = this.dragData;
546 if (selection_text == null || selection_text.length < 1) {
547 //print("Error - drag selection text returned NULL");
548 Gdk.drag_status(ctx, 0 ,time);
549 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
554 // see if we are dragging into ourself?
555 var target_path = path.to_string();
556 print ("Drag %s onto %s--%d\n ", selection_text, target_path, pos);
558 // pos : 3 = ontop - 0 = after, 1 = before
559 //print("target_path="+target_path);
562 if (selection_text == target_path) {
563 print("self drag ?? == we should perhaps allow copy onto self..\n");
565 Gdk.drag_status(ctx, 0 ,time);
566 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
568 // -- fixme -- this is not really correct..
573 //print("DUMPING DATA");
574 //console.dump(data);
577 //print(data.path.to_string() +' => '+ data.pos);
579 // dropList is a list of xtypes that this node could be dropped on.
580 // it is set up when we start to drag..
583 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
585 print("targetDAta: " + targetData +"\n");
587 if (targetData.length < 1) {
588 //print("Can not find drop node path");
590 Gdk.drag_status(ctx, 0, time);
591 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
595 var td_ar = targetData.split("|");
599 Gdk.drag_status(ctx, action ,time);
600 this.highlightDropPath(td_ar[0], (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
605 this.el.key_press_event.connect( (ev) => {
606 this.key_is_pressed = true;
609 this.el.key_release_event.connect( (ev) => {
610 this.key_is_pressed = false;
613 this.el.drag_data_received.connect( (ctx, x, y, sel, info, time) => {
615 // THIS CODE ONLY RELATES TO drag or drop of "NEW" elements or "FROM another tree.."
618 // print("Tree: drag-data-received\n");
619 var selection_text = (string)sel.get_data();
620 //print("selection_text= %s\n",selection_text);
622 var is_drag = this.drag_in_motion;
626 GLib.debug("Is Drag %s\n", is_drag ? "Y": "N");
630 Gtk.TreeViewDropPosition pos;
631 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
633 // if there are not items in the tree.. the we have to set isOver to true for anything..
635 if (_this.model.el.iter_n_children(null) < 1) {
636 GLib.debug("got NO children?\n");
639 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
643 //console.log("LEFT-TREE: drag-motion");
644 var src = Gtk.drag_get_source_widget(ctx);
646 // a drag from self - this should be handled by drop and motion.
647 if (src == this.el) {
648 GLib.debug("Source == this element should not happen.. ? \n");
651 //print("drag_data_recieved from another element");
656 if (selection_text == null || selection_text.length < 1 || !isOver) {
657 // nothing valid foudn to drop...
658 GLib.debug("empty sel text or not over");
660 Gdk.drag_status(ctx, 0, time);
661 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
664 Gtk.drag_finish (ctx, false, false, time); // drop failed..
669 var dropNode = new JsRender.Node();
671 var dropNodeType = selection_text;
672 var show_templates = true;
674 if (dropNodeType[0] == '{') {
675 var pa = new Json.Parser();
677 pa.load_from_data(dropNodeType);
679 Gtk.drag_finish (ctx, false, false, time); // drop failed..
684 dropNode.loadFromJson( pa.get_root().get_object(), 2);
685 dropNodeType = dropNode.fqn();
686 show_templates = false;
690 // drop with property.
691 if (selection_text.contains(":")) {
692 var bits = selection_text.split(":");
693 dropNode.setFqn(bits[0]);
694 dropNode.set_prop(new JsRender.NodeProp.special("prop", bits[1]));
699 dropNode.setFqn(selection_text);
704 // dropList --- need to gather this ...
705 GLib.debug("get dropList for : %s\n",dropNodeType);
706 var dropList = _this.main_window.windowstate.file.palete().getDropList(dropNodeType);
708 GLib.debug("dropList: %s\n", string.joinv(" , ", dropList));
710 // if drag action is link ... then we can drop it anywahere...
711 if ((ctx.get_actions() & Gdk.DragAction.LINK) > 0) {
712 // if path is null?? dragging into an empty tree?
713 targetData = (path == null ? "" : path.to_string()) + "|%d".printf((int)pos);
717 targetData = _this.model.findDropNodeByPath( isEmpty ? "" : path.to_string(), dropList, pos);
722 GLib.debug("targetDAta: %s", targetData );
724 if (targetData.length < 1) {
726 // invalid drop path..
727 if (this.drag_in_motion) {
728 Gdk.drag_status(ctx, 0, time);
729 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
732 Gtk.drag_finish (ctx, false, false, time); // drop failed..
739 var td_ar = targetData.split("|");
742 if (this.drag_in_motion) {
743 Gdk.drag_status(ctx, Gdk.DragAction.COPY ,time);
745 this.highlightDropPath( td_ar[0] , (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
748 // continue on to allow drop..
751 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
753 // {parent}|{pos}|{prop}
756 _this.model.dropNode(targetData, dropNode, show_templates);
758 GLib.debug("ADD new node!!!\n");
760 ///Xcls_DialogTemplateSelect.singleton().show( _this.model.file.palete(), node);
762 Gtk.drag_finish (ctx, false, false,time);
769 this.el.drag_drop.connect( ( ctx, x, y, time) => {
770 //Seed.print("TARGET: drag-drop");
773 var src = Gtk.drag_get_source_widget(ctx);
775 if (src != this.el) {
779 this.drag_in_motion = false;
780 // request data that will be recieved by the recieve...
783 this.el, // will receive 'drag-data-received' signal
784 ctx, // represents the current state of the DnD
785 Gdk.Atom.intern("application/json",true), // the target type we want
790 // No target offered by source => error
796 // handle drop around self..
800 //print("GETTING POS");
804 Gtk.TreeViewDropPosition pos;
805 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
807 // if there are not items in the tree.. the we have to set isOver to true for anything..
809 if (_this.model.el.iter_n_children(null) < 1) {
810 print("got NO children?\n");
813 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
818 //var action = Gdk.DragAction.COPY;
819 // unless we are copying!!! ctl button..
821 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
822 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
823 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
826 if (_this.model.el.iter_n_children(null) < 1) {
827 // no children.. -- asume it's ok..
829 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
831 // continue through to allow drop...
839 //print("ISOVER? " + isOver);
842 Gtk.drag_finish (ctx, false, false, time); // drop failed..
843 return true; // not over apoint!?! - no action on drop or motion..
846 // drag node is parent of child..
847 //console.log("SRC TREEPATH: " + src.treepath);
848 //console.log("TARGET TREEPATH: " + data.path.to_string());
850 // nned to check a few here..
851 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
852 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
853 //Gtk.TreeViewDropPosition.AFTER
854 //Gtk.TreeViewDropPosition.BEFORE
856 // locally dragged items to not really use the
857 var selection_text = this.dragData;
861 if (selection_text == null || selection_text.length < 1) {
862 //print("Error - drag selection text returned NULL");
864 Gtk.drag_finish (ctx, false, false, time); // drop failed..
865 return true; /// -- fixme -- this is not really correct..
868 // see if we are dragging into ourself?
869 print ("got selection text of " + selection_text);
871 var target_path = path.to_string();
872 //print("target_path="+target_path);
875 if (selection_text == target_path) {
876 print("self drag ?? == we should perhaps allow copy onto self..\n");
878 Gtk.drag_finish (ctx, false, false, time); // drop failed..
880 return true; /// -- fixme -- this is not really correct..
885 //print("DUMPING DATA");
886 //console.dump(data);
889 //print(data.path.to_string() +' => '+ data.pos);
891 // dropList is a list of xtypes that this node could be dropped on.
892 // it is set up when we start to drag..
895 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
897 print("targetDAta: " + targetData +"\n");
899 if (targetData.length < 1) {
900 //print("Can not find drop node path");
902 Gtk.drag_finish (ctx, false, false, time); // drop failed..
908 // continue on to allow drop..
910 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
913 var delete_selection_data = false;
915 if (action == Gdk.DragAction.ASK) {
916 /* Ask the user to move or copy, then set the ctx action. */
919 if (action == Gdk.DragAction.MOVE) {
920 delete_selection_data = true;
923 // drag around.. - reorder..
924 _this.model.moveNode(targetData, action);
930 // we can send stuff to souce here...
933 // do we always say failure, so we handle the reall drop?
934 Gtk.drag_finish (ctx, false, false,time); //delete_selection_data, time);
946 // user defined functions
947 public void highlightDropPath ( string treepath, Gtk.TreeViewDropPosition pos) {
949 // highlighting for drag/drop
950 if (treepath.length > 0) {
951 this.el.set_drag_dest_row( new Gtk.TreePath.from_string( treepath ), pos);
953 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
957 public void selectNode (string treepath_str, string source) {
958 this.lastEventSource = source;
959 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
960 var tp = new Gtk.TreePath.from_string(treepath_str);
962 this.el.set_cursor(tp, null, false);
963 this.el.scroll_to_cell(tp, null, false, 0,0);
965 public void setCursor (string treepath, string sourceEvent) {
966 this.lastEventSource = sourceEvent;
967 //this.blockChanges = true; << block changes prevents loading of 'node data' and firing of node_selected..
968 this.el.set_cursor(new Gtk.TreePath.from_string(treepath), null, false);
969 // fire node_selected..
970 //this.blockChanges = false;
971 this.lastEventSource = "";
974 public class Xcls_model : Object
976 public Gtk.TreeStore el;
977 private Xcls_WindowLeftTree _this;
981 public DialogTemplateSelect template_select;
982 public string activePath;
985 public Xcls_model(Xcls_WindowLeftTree _owner )
989 this.el = new Gtk.TreeStore.newv( { typeof(string),
993 typeof(Gdk.Pixbuf) } );
996 this.template_select = null;
997 this.activePath = "";
999 // set gobject values
1003 print("model initialized");
1006 // user defined functions
1007 public void loadFile (JsRender.JsRender f) {
1010 _this.main_window.windowstate.leftTreeNodeSelected(null, "");
1012 _this.main_window.windowstate.file = f;
1015 if (f.tree == null) {
1022 // if it's still null?
1023 if (f.tree == null) {
1024 _this.main_window.windowstate.showAddObject(_this.view.el);
1029 var o = new Gee.ArrayList<JsRender.Node>();
1033 _this.view.el.expand_all();
1035 if (f.tree.items.size < 1) {
1038 //this.get('/Window.leftvpaned').el.set_position(80);
1040 _this.view.el.set_cursor(
1041 new Gtk.TreePath.from_string("0"), null, false);
1045 //this.get('/Window.leftvpaned').el.set_position(200);
1049 while (Gtk.events_pending()) {
1050 Gtk.main_iteration();
1053 _this.maincol.el.set_max_width(_this.viewwin.el.get_allocated_width() - 32);
1061 public string findDropNodeByPath (string treepath_str, string[] targets, int in_pref = -1) {
1063 var path = treepath_str; // dupe it..
1066 // pref : 3 = ontop - 0 = after, 1 = before
1067 int pref = in_pref < 0 ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : in_pref;
1071 //console.dump(this.treemap);
1073 print("findDropNodeByPath : got path length %d / %s\n", path.length, path);
1075 if (path.length == 0) {
1076 // top drop. // just return empty..
1077 return "|%d".printf((int)pref) ;
1082 while (path.length > 0) {
1084 if (path.length == treepath_str.length && pref != Gtk.TreeViewDropPosition.INTO_OR_AFTER) {
1085 if (path.last_index_of(":") < 0 ) {
1088 path = path.substring(0, path.last_index_of(":"));
1089 last = treepath_str;
1090 print("DROP before or after : using %s\n",path);
1094 //print("LOOKING FOR PATH: " + path);
1095 var node_data = this.pathToNode(path);
1097 if (node_data == null) {
1098 print("node not found");
1102 var xname = node_data.fqn();
1106 for (var i =0; i < targets.length; i++) {
1107 var tg = targets[i];
1108 if ((tg == xname) ) {
1112 // if target is "xxxx:name"
1113 if (tg.contains(xname +":")) {
1115 var ar = tg.split(":");
1121 if (match.length > 0) {
1122 if (last.length > 0) { // pref is after/before..
1123 // then it's after last
1127 return last + "|%d".printf((int)pref) + "|" + prop;
1131 // we need to add prop - as :store -> needs to bee added when dropping onto.
1132 return path + "|%d".printf( (int) Gtk.TreeViewDropPosition.INTO_OR_AFTER) + "|" + prop;
1136 var par = path.split(":");
1137 string [] ppar = {};
1138 for (var i = 0; i < par.length-1; i++) {
1142 path = string.joinv(":", ppar);
1151 public void iterSetValues (Gtk.TreeIter iter, JsRender.Node node) {
1152 var ic = Gtk.IconTheme.get_default();
1155 var o = GLib.Value(typeof(Object));
1156 o.set_object((Object)node);
1157 var clsname = node.fqn();
1159 var clsb = clsname.split(".");
1160 var sub = clsb.length > 1 ? clsb[1].down() : "";
1162 var addi = ic.load_icon("list-add", 16,0);
1163 var fn = "/usr/share/glade/pixmaps/hicolor/16x16/actions/widget-gtk-" + sub + ".png";
1164 if (FileUtils.test (fn, FileTest.IS_REGULAR)) {
1165 pix = new Gdk.Pixbuf.from_file (fn);
1167 pix = ic.load_icon("emblem-new", 16,0);
1170 var fqn = node.fqn();
1171 var cn = _this.main_window.windowstate.project.palete.getChildList(fqn);
1175 0, node.nodeTitle(),
1179 this.el.set_value(iter, 2,o);
1180 this.el.set_value(iter, 3,pix);
1181 this.el.set_value(iter, 4, cn.length > 0 ? addi : null);
1185 public string treePathFromNode (JsRender.Node node) {
1186 // iterate through the tree and find the node
1189 this.el.foreach((mod, pth, iter) => {
1194 _this.model.el.get_value(iter, 2, out value);
1198 var n = (JsRender.Node)value;
1200 print("compare %s to %s\n", n.fqn(), node.fqn());
1202 ret = pth.to_string();
1210 public void deleteSelected () {
1212 print("DELETE SELECTED?");
1213 //_this.view.blockChanges = true;
1214 print("GET SELECTION?");
1216 var s = _this.view.el.get_selection();
1218 print("GET SELECTED?");
1223 if (!s.get_selected(out mod, out iter)) {
1224 return; // nothing seleted..
1229 this.activePath= "";
1230 print("GET vnode value?");
1233 this.el.get_value(iter, 2, out value);
1234 var data = (JsRender.Node)(value.get_object());
1235 print("removing node from Render\n");
1236 if (data.parent == null) {
1237 _this.main_window.windowstate.file.tree = null;
1241 print("removing node from Tree\n");
1243 this.el.remove(ref iter);
1253 this.activePath= ""; // again!?!?
1254 //this.changed(null,true);
1258 _this.view.blockChanges = false;
1260 public void dropNode (string target_data_str, JsRender.Node node, bool show_templates) {
1261 // print("drop Node");
1262 // console.dump(node);
1263 // console.dump(target_data);
1266 // {parent}|{pos}|{prop}
1269 // 0 = before , 1=after 2/3 onto
1271 GLib.debug("dropNode %s", target_data_str);
1273 var target_data= target_data_str.split("|");
1275 var parent_str = target_data[0].length > 0 ? target_data[0] : "";
1276 var pos = target_data.length > 1 ? int.parse(target_data[1]) : 2; // ontop..
1279 Gtk.TreePath tree_path = parent_str.length > 0 ? new Gtk.TreePath.from_string( parent_str ) : null;
1283 //print("add " + tp + "@" + target_data[1] );
1285 JsRender.Node parentNode = null;
1287 Gtk.TreeIter iter_after;
1288 Gtk.TreeIter iter_par ;
1290 // this appears to be done in drag_ddata_recieved as well.
1291 if (target_data.length == 3 && target_data[2].length > 0) {
1292 node.set_prop(new JsRender.NodeProp.special("prop", target_data[2]));
1296 Gtk.TreePath expand_parent = null;
1298 // we only need to show the template if it's come from else where?
1299 if (show_templates) {
1301 var ts = _this.main_window.windowstate.template_select;
1303 var new_node = ts.show(
1304 _this.main_window, // (Gtk.Window) _this.el.get_toplevel (),
1305 _this.main_window.windowstate.file.palete(),
1307 _this.main_window.windowstate.project);
1309 if (new_node == null) {
1310 return; // do not add?
1315 //print("pos is %d \n".printf(pos));
1317 Gtk.TreeIter n_iter;
1319 if ( parent_str.length < 1) {
1320 this.el.append(out n_iter, null); // drop at top level..
1322 _this.main_window.windowstate.file.tree = node;
1325 } else if (pos < 2) {
1326 //print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
1328 this.el.get_iter(out iter_after, tree_path );
1329 this.el.iter_parent(out iter_par, iter_after);
1330 expand_parent = this.el.get_path(iter_par);
1333 // not sure why all the 'dup_object()' stuff? did it crash before?
1335 this.el.get_value( iter_par, 2, out value);
1336 parentNode = (JsRender.Node)value.dup_object();
1339 this.el.get_value( iter_after, 2, out value);
1340 var relNode = (JsRender.Node)value.dup_object();
1344 this.el.insert_after(out n_iter, iter_par , iter_after);
1345 var ix = parentNode.items.index_of(relNode);
1346 parentNode.items.insert(ix+1, node);
1349 this.el.insert_before(out n_iter, iter_par , iter_after);
1350 var ix = parentNode.items.index_of(relNode);
1351 parentNode.items.insert(ix, node);
1354 node.parent = parentNode;
1359 // print("appending to " + parent_str);
1360 this.el.get_iter(out iter_par, tree_path);
1361 this.el.append(out n_iter, iter_par );
1362 expand_parent = this.el.get_path(iter_par);
1365 this.el.get_value( iter_par, 2, out value);
1366 parentNode = (JsRender.Node)value.dup_object();
1367 node.parent = parentNode;
1368 parentNode.items.add(node);
1374 // work out what kind of packing to use.. -- should be in
1377 //_this.main_window.windowstate.file.palete().fillPack(node,parentNode);
1378 _this.main_window.windowstate.file.palete().on_child_added(parentNode,node);
1381 this.iterSetValues(n_iter, node);
1386 // load children - if it has any..
1388 if (node.items.size > 0) {
1389 this.load(node.items, n_iter);
1390 _this.view.el.expand_row(this.el.get_path(n_iter), true);
1391 } else if (expand_parent != null && !_this.view.el.is_row_expanded(expand_parent)) {
1392 _this.view.el.expand_row(expand_parent,true);
1395 //if (tp != null && (node.items.length() > 0 || pos > 1)) {
1396 // _this.view.el.expand_row(this.el.get_path(iter_par), true);
1398 // wee need to get the empty proptypes from somewhere..
1400 //var olditer = this.activeIter;
1401 this.activePath = this.el.get_path(n_iter).to_string();
1404 // pretend button was pressed, so that we can trigger select node...
1405 _this.view.button_is_pressed = true;
1406 _this.view.lastEventSource = "";
1407 _this.view.el.set_cursor(this.el.get_path(n_iter), null, false);
1408 _this.view.button_is_pressed = false;
1414 public void moveNode (string target_data, Gdk.DragAction action)
1417 /// target_data = "path|pos");
1420 //print("MOVE NODE");
1421 // console.dump(target_data);
1422 Gtk.TreeIter old_iter;
1425 var s = _this.view.el.get_selection();
1426 s.get_selected(out mod , out old_iter);
1427 mod.get_path(old_iter);
1429 var node = this.pathToNode(mod.get_path(old_iter).to_string());
1430 //console.dump(node);
1432 GLib.debug("moveNode: ERROR - node is null?");
1437 // needs to drop first, otherwise the target_data
1438 // treepath will be invalid.
1441 if ((action & Gdk.DragAction.MOVE) > 0) {
1442 GLib.debug("REMOVING OLD NODE : " + target_data + "\n");
1444 this.dropNode(target_data, node, false);
1445 this.el.remove(ref old_iter);
1450 GLib.debug("DROPPING NODE // copy: " + target_data + "\n");
1451 node = node.deepClone();
1452 this.dropNode(target_data, node, false);
1455 this.activePath= "";
1456 //this.updateNode(false,true);
1458 public void updateSelected () {
1461 var s = _this.view.el.get_selection();
1468 if (!s.get_selected(out mod, out iter)) {
1469 return; // nothing seleted..
1473 this.el.get_value(iter, 2, out value);
1474 var node = (JsRender.Node)(value.get_object());
1476 this.el.set(iter, 0, node.nodeTitle(),
1477 1, node.nodeTip(), -1
1480 public string findDropNode (string treepath_str, string[] targets) {
1482 // this is used by the dragdrop code in the roo version AFAIR..
1484 //var path = treepath_str.replace(/^builder-/, '');
1485 // treemap is depreciated... - should really check if model has any entries..
1487 if (this.el.iter_n_children(null) < 1) {
1489 return "|%d".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
1491 //print("FIND treepath: " + path);
1492 //console.dump(this.treemap);
1494 //if (!treepath_str.match(/^builder-/)) {
1495 // return []; // nothing!
1497 if (targets.length > 0 && targets[0] == "*") {
1498 return treepath_str;
1500 return this.findDropNodeByPath(treepath_str,targets, -1);
1502 public void load (Gee.ArrayList<JsRender.Node> tr, Gtk.TreeIter? iter)
1507 //this.insert(citer,iter,0);
1510 for(var i =0 ; i < tr.size; i++) {
1512 this.el.insert(out citer,iter,-1); // why not append?
1514 this.el.append(out citer,null);
1516 this.iterSetValues(citer, tr.get(i));
1520 if (tr.get(i).items.size > 0) {
1521 this.load(tr.get(i).items, citer);
1528 public JsRender.Node pathToNode (string path) {
1532 _this.model.el.get_iter_from_string(out iter, path);
1535 _this.model.el.get_value(iter, 2, out value);
1537 return (JsRender.Node)value.dup_object();
1542 public class Xcls_maincol : Object
1544 public Gtk.TreeViewColumn el;
1545 private Xcls_WindowLeftTree _this;
1551 public Xcls_maincol(Xcls_WindowLeftTree _owner )
1554 _this.maincol = this;
1555 this.el = new Gtk.TreeViewColumn();
1559 // set gobject values
1560 this.el.title = "Node";
1561 this.el.sizing = Gtk.TreeViewColumnSizing.FIXED;
1562 this.el.expand = true;
1563 this.el.resizable = true;
1564 var child_0 = new Xcls_iconrender( _this );
1566 this.el.pack_start ( child_0.el , false );
1567 var child_1 = new Xcls_renderer( _this );
1569 this.el.pack_start ( child_1.el , true );
1573 this.el.add_attribute(_this.renderer.el , "markup", 0 );
1574 this.el.add_attribute(_this.iconrender.el , "pixbuf", 3 );
1577 // user defined functions
1579 public class Xcls_iconrender : Object
1581 public Gtk.CellRendererPixbuf el;
1582 private Xcls_WindowLeftTree _this;
1588 public Xcls_iconrender(Xcls_WindowLeftTree _owner )
1591 _this.iconrender = this;
1592 this.el = new Gtk.CellRendererPixbuf();
1596 // set gobject values
1600 // user defined functions
1603 public class Xcls_renderer : Object
1605 public Gtk.CellRendererText el;
1606 private Xcls_WindowLeftTree _this;
1612 public Xcls_renderer(Xcls_WindowLeftTree _owner )
1615 _this.renderer = this;
1616 this.el = new Gtk.CellRendererText();
1620 // set gobject values
1623 // user defined functions
1627 public class Xcls_TreeViewColumn8 : Object
1629 public Gtk.TreeViewColumn el;
1630 private Xcls_WindowLeftTree _this;
1636 public Xcls_TreeViewColumn8(Xcls_WindowLeftTree _owner )
1639 this.el = new Gtk.TreeViewColumn();
1643 // set gobject values
1644 this.el.max_width = 24;
1645 this.el.title = "Add";
1646 this.el.sizing = Gtk.TreeViewColumnSizing.FIXED;
1647 this.el.expand = false;
1648 var child_0 = new Xcls_addiconrender( _this );
1650 this.el.pack_start ( child_0.el , true );
1654 this.el.add_attribute(_this.addiconrender.el , "pixbuf", 4 );
1657 // user defined functions
1659 public class Xcls_addiconrender : Object
1661 public Gtk.CellRendererPixbuf el;
1662 private Xcls_WindowLeftTree _this;
1668 public Xcls_addiconrender(Xcls_WindowLeftTree _owner )
1671 _this.addiconrender = this;
1672 this.el = new Gtk.CellRendererPixbuf();
1676 // set gobject values
1680 // user defined functions
1685 public class Xcls_LeftTreeMenu : Object
1688 private Xcls_WindowLeftTree _this;
1694 public Xcls_LeftTreeMenu(Xcls_WindowLeftTree _owner )
1697 _this.LeftTreeMenu = this;
1698 this.el = new Gtk.Menu();
1702 // set gobject values
1703 var child_0 = new Xcls_MenuItem11( _this );
1705 this.el.add ( child_0.el );
1706 var child_1 = new Xcls_MenuItem12( _this );
1708 this.el.add ( child_1.el );
1709 var child_2 = new Xcls_MenuItem13( _this );
1711 this.el.add ( child_2.el );
1714 // user defined functions
1716 public class Xcls_MenuItem11 : Object
1718 public Gtk.MenuItem el;
1719 private Xcls_WindowLeftTree _this;
1725 public Xcls_MenuItem11(Xcls_WindowLeftTree _owner )
1728 this.el = new Gtk.MenuItem();
1732 // set gobject values
1733 this.el.label = "Delete Element";
1736 this.el.activate.connect( ( ) => {
1741 _this.model.deleteSelected();
1745 // user defined functions
1748 public class Xcls_MenuItem12 : Object
1750 public Gtk.MenuItem el;
1751 private Xcls_WindowLeftTree _this;
1757 public Xcls_MenuItem12(Xcls_WindowLeftTree _owner )
1760 this.el = new Gtk.MenuItem();
1764 // set gobject values
1765 this.el.label = "Save as Template";
1768 this.el.activate.connect( () => {
1770 DialogSaveTemplate.singleton().show(
1771 (Gtk.Window) _this.el.get_toplevel (),
1772 _this.main_window.windowstate.file.palete(),
1773 _this.getActiveElement()
1780 // user defined functions
1783 public class Xcls_MenuItem13 : Object
1785 public Gtk.MenuItem el;
1786 private Xcls_WindowLeftTree _this;
1792 public Xcls_MenuItem13(Xcls_WindowLeftTree _owner )
1795 this.el = new Gtk.MenuItem();
1799 // set gobject values
1800 this.el.label = "Save as Module";
1803 this.el.activate.connect( () => {
1804 var node = _this.getActiveElement();
1805 var name = DialogSaveModule.singleton().show(
1806 (Gtk.Window) _this.el.get_toplevel (),
1807 _this.main_window.windowstate.project,
1810 if (name.length < 1) {
1814 node.set_prop( new JsRender.NodeProp.special("xinclude", name));
1818 var s = _this.view.el.get_selection();
1820 print("GET SELECTED?");
1825 if (!s.get_selected(out mod, out iter)) {
1826 return; // nothing seleted..
1829 var n_cn = mod.iter_n_children(iter) -1;
1830 for (var i = n_cn; i > -1; i--) {
1831 mod.iter_nth_child(out citer, iter, i);
1834 print("removing node from Tree\n");
1836 _this.model.el.remove(ref citer);
1839 _this.node_selected(node, "tree");
1845 // user defined functions