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") {
231 _this.main_window.windowstate.leftTreeBeforeChange();
232 this.el.get_selection().select_path(res);
233 _this.main_window.windowstate.showAddObject(this.el);
237 if ( ev.button != 3) {
238 //print("click" + ev.type);
241 _this.main_window.windowstate.leftTreeBeforeChange();
245 this.el.get_selection().select_path(res);
249 //if (!this.get('/LeftTreeMenu').el) {
250 // this.get('/LeftTreeMenu').init();
253 _this.LeftTreeMenu.el.set_screen(Gdk.Screen.get_default());
254 _this.LeftTreeMenu.el.show_all();
255 _this.LeftTreeMenu.el.popup(null, null, null, 3, ev.time);
256 // print("click:" + res.path.to_string());
259 this.el.cursor_changed.connect( ( ) => {
260 print("LEFT TREE Cursor Changed\n");
261 if (!this.button_is_pressed && !this.key_is_pressed) {
262 // then event was started by some other action
263 // which should manually trigger all the events..
264 print("SKIPPING select - no button or key pressed\n");
269 if (this.blockChanges) { // probably not needed..
270 print("SKIPPING select - blockchanges set..\n");
273 if (!_this.before_node_change( ) ) {
274 this.blockChanges = true;
275 this.el.get_selection().unselect_all();
276 this.blockChanges = false;
280 if (_this.main_window.windowstate.file == null) {
281 print("SKIPPING select windowstate file is not set...\n");
285 //var render = this.get('/LeftTree').getRenderer();
286 print("LEFT TREE -> view -> selection changed called\n");
289 // -- it appears that the selection is not updated.
291 GLib.Timeout.add_full(GLib.Priority.DEFAULT,10 , () => {
292 print("LEFT TREE -> view -> selection changed TIMEOUT CALLED\n");
294 if (this.el.get_selection().count_selected_rows() < 1) {
296 print("selected rows < 1\n");
297 //??this.model.load( false);
298 _this.node_selected(null, this.lastEventSource);
303 //console.log('changed');
304 var s = this.el.get_selection();
307 s.get_selected(out mod, out iter);
312 _this.model.el.get_value(iter, 2, out value);
313 _this.model.activePath = mod.get_path(iter).to_string();
315 var node = (JsRender.Node)value.dup_object();
316 print ("calling left_tree.node_selected\n");
317 _this.node_selected(node, this.lastEventSource);
318 while (Gtk.events_pending()) {
319 Gtk.main_iteration();
321 var cp = mod.get_path(iter);
323 this.el.get_visible_range(out sp, out ep);
324 // if sp is before cp then retuns 1.
325 // if cp is before ep then retuns 1.
326 if (cp.compare(sp) >= 0 && ep.compare(cp) >=1) {
332 this.el.scroll_to_cell(new Gtk.TreePath.from_string(_this.model.activePath), null, true, 0.1f,0.0f);
336 //_this.after_node_change(node);
338 // _this.model.file.changed(node, "tree");
340 //Seed.print( value.get_string());
344 this.el.drag_begin.connect( ( ctx) => {
345 //print('SOURCE: drag-begin');
348 //this.targetData = "";
350 // find what is selected in our tree...
352 var s = _this.view.el.get_selection();
353 if (s.count_selected_rows() < 1) {
358 s.get_selected(out mod, out iter);
362 // set some properties of the tree for use by the dropped element.
364 _this.model.el.get_value(iter, 2, out value);
365 var tp = mod.get_path(iter).to_string();
366 var data = (JsRender.Node)(value.dup_object());
367 var xname = data.fqn();
368 print ("XNAME IS " + xname+ "\n");
370 this.dropList = _this.main_window.windowstate.file.palete().getDropList(xname);
372 print ("DROP LIST IS " + string.joinv(", ", this.dropList) + "\n");
375 // make the drag icon a picture of the node that was selected
378 // by default returns the path..
379 var path = _this.model.el.get_path(iter);
382 var pix = this.el.create_row_drag_icon ( path);
384 Gtk.drag_set_icon_surface (ctx, pix) ;
388 this.el.drag_data_get.connect( ( drag_context, data, info, time) => {
391 //print("drag-data-get");
392 var s = this.el.get_selection();
393 if (s.count_selected_rows() < 1) {
395 print("return empty string - no selection..");
402 s.get_selected(out mod, out iter);
407 _this.model.el.get_value(iter, 2, out value);
408 var ndata = (JsRender.Node)(value.dup_object());
412 var tp = mod.get_path(iter).to_string();
413 // by default returns the path..
415 if ( info != Gdk.Atom.intern("STRING",true) ) {
416 tp = ndata.toJsonString();
419 //data.set_text(tp,tp.length);
421 data.set (data.get_target (), 8, (uchar[]) tp.to_utf8 ());
424 // print("return " + tp);
426 this.el.drag_end.connect( (drag_context) => {
427 //Seed.print('LEFT-TREE: drag-end');
429 this.dropList = null;
430 // this.targetData = "";
431 this.highlightDropPath("",0);
434 this.el.drag_motion.connect( ( ctx, x, y, time) => {
435 print("got drag motion\n");
436 var src = Gtk.drag_get_source_widget(ctx);
440 if (src != this.el) {
444 // the point of this is to detect where an item could be dropped..
445 print("requesting drag data\n");
446 this.drag_in_motion = true;
448 // request data that will be recieved by the recieve...
451 this.el, // will receive 'drag-data-received' signal
452 ctx, // represents the current state of the DnD
453 Gdk.Atom.intern("STRING",true), // the target type we want
460 print("action: %d\n", ctx.get_actions());
461 //print("GETTING POS");
465 Gtk.TreeViewDropPosition pos;
466 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
468 // if there are not items in the tree.. the we have to set isOver to true for anything..
470 if (_this.model.el.iter_n_children(null) < 1) {
471 print("got NO children?\n");
474 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
478 // ------------- a drag from self..
481 //var action = Gdk.DragAction.COPY;
482 // unless we are copying!!! ctl button..
484 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
485 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
486 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
489 if (_this.model.el.iter_n_children(null) < 1) {
490 // no children.. -- asume it's ok..
492 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
494 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
495 Gdk.drag_status(ctx, action ,time);
498 // continue through to allow drop...
506 //print("ISOVER? " + isOver);
509 Gdk.drag_status(ctx, 0 ,time);
510 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
515 // drag node is parent of child..
516 //console.log("SRC TREEPATH: " + src.treepath);
517 //console.log("TARGET TREEPATH: " + data.path.to_string());
519 // nned to check a few here..
520 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
521 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
522 //Gtk.TreeViewDropPosition.AFTER
523 //Gtk.TreeViewDropPosition.BEFORE
525 // locally dragged items to not really use the
526 var selection_text = this.dragData;
530 if (selection_text == null || selection_text.length < 1) {
531 //print("Error - drag selection text returned NULL");
532 Gdk.drag_status(ctx, 0 ,time);
533 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
538 // see if we are dragging into ourself?
539 var target_path = path.to_string();
540 print ("Drag %s onto %s--%d\n ", selection_text, target_path, pos);
542 // pos : 3 = ontop - 0 = after, 1 = before
543 //print("target_path="+target_path);
546 if (selection_text == target_path) {
547 print("self drag ?? == we should perhaps allow copy onto self..\n");
549 Gdk.drag_status(ctx, 0 ,time);
550 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
552 // -- fixme -- this is not really correct..
557 //print("DUMPING DATA");
558 //console.dump(data);
561 //print(data.path.to_string() +' => '+ data.pos);
563 // dropList is a list of xtypes that this node could be dropped on.
564 // it is set up when we start to drag..
567 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
569 print("targetDAta: " + targetData +"\n");
571 if (targetData.length < 1) {
572 //print("Can not find drop node path");
574 Gdk.drag_status(ctx, 0, time);
575 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
579 var td_ar = targetData.split("|");
583 Gdk.drag_status(ctx, action ,time);
584 this.highlightDropPath(td_ar[0], (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
589 this.el.key_press_event.connect( (ev) => {
590 this.key_is_pressed = true;
593 this.el.key_release_event.connect( (ev) => {
594 this.key_is_pressed = false;
597 this.el.drag_data_received.connect( (ctx, x, y, sel, info, time) => {
599 // THIS CODE ONLY RELATES TO drag or drop of "NEW" elements or "FROM another tree.."
602 // print("Tree: drag-data-received\n");
603 var selection_text = (string)sel.get_data();
604 //print("selection_text= %s\n",selection_text);
606 var is_drag = this.drag_in_motion;
610 GLib.debug("Is Drag %s\n", is_drag ? "Y": "N");
614 Gtk.TreeViewDropPosition pos;
615 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
617 // if there are not items in the tree.. the we have to set isOver to true for anything..
619 if (_this.model.el.iter_n_children(null) < 1) {
620 GLib.debug("got NO children?\n");
623 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
627 //console.log("LEFT-TREE: drag-motion");
628 var src = Gtk.drag_get_source_widget(ctx);
630 // a drag from self - this should be handled by drop and motion.
631 if (src == this.el) {
632 GLib.debug("Source == this element should not happen.. ? \n");
635 //print("drag_data_recieved from another element");
640 if (selection_text == null || selection_text.length < 1 || !isOver) {
641 // nothing valid foudn to drop...
642 GLib.debug("empty sel text or not over");
644 Gdk.drag_status(ctx, 0, time);
645 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
648 Gtk.drag_finish (ctx, false, false, time); // drop failed..
653 var dropNode = new JsRender.Node();
655 var dropNodeType = selection_text;
656 var show_templates = true;
658 if (dropNodeType[0] == '{') {
659 var pa = new Json.Parser();
661 pa.load_from_data(dropNodeType);
663 Gtk.drag_finish (ctx, false, false, time); // drop failed..
668 dropNode.loadFromJson( pa.get_root().get_object(), 2);
669 dropNodeType = dropNode.fqn();
670 show_templates = false;
674 // drop with property.
675 if (selection_text.contains(":")) {
676 var bits = selection_text.split(":");
677 dropNode.setFqn(bits[0]);
678 dropNode.set_prop(new JsRender.NodeProp.special("prop", bits[1]));
683 dropNode.setFqn(selection_text);
688 // dropList --- need to gather this ...
689 GLib.debug("get dropList for : %s\n",dropNodeType);
690 var dropList = _this.main_window.windowstate.file.palete().getDropList(dropNodeType);
692 GLib.debug("dropList: %s\n", string.joinv(" , ", dropList));
694 // if drag action is link ... then we can drop it anywahere...
695 if ((ctx.get_actions() & Gdk.DragAction.LINK) > 0) {
696 // if path is null?? dragging into an empty tree?
697 targetData = (path == null ? "" : path.to_string()) + "|%d".printf((int)pos);
701 targetData = _this.model.findDropNodeByPath( isEmpty ? "" : path.to_string(), dropList, pos);
706 GLib.debug("targetDAta: %s", targetData );
708 if (targetData.length < 1) {
710 // invalid drop path..
711 if (this.drag_in_motion) {
712 Gdk.drag_status(ctx, 0, time);
713 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
716 Gtk.drag_finish (ctx, false, false, time); // drop failed..
723 var td_ar = targetData.split("|");
726 if (this.drag_in_motion) {
727 Gdk.drag_status(ctx, Gdk.DragAction.COPY ,time);
729 this.highlightDropPath( td_ar[0] , (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
732 // continue on to allow drop..
735 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
737 // {parent}|{pos}|{prop}
740 _this.model.dropNode(targetData, dropNode, show_templates);
742 GLib.debug("ADD new node!!!\n");
744 ///Xcls_DialogTemplateSelect.singleton().show( _this.model.file.palete(), node);
746 Gtk.drag_finish (ctx, false, false,time);
753 this.el.drag_drop.connect( ( ctx, x, y, time) => {
754 //Seed.print("TARGET: drag-drop");
757 var src = Gtk.drag_get_source_widget(ctx);
759 if (src != this.el) {
763 this.drag_in_motion = false;
764 // request data that will be recieved by the recieve...
767 this.el, // will receive 'drag-data-received' signal
768 ctx, // represents the current state of the DnD
769 Gdk.Atom.intern("application/json",true), // the target type we want
774 // No target offered by source => error
780 // handle drop around self..
784 //print("GETTING POS");
788 Gtk.TreeViewDropPosition pos;
789 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
791 // if there are not items in the tree.. the we have to set isOver to true for anything..
793 if (_this.model.el.iter_n_children(null) < 1) {
794 print("got NO children?\n");
797 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
802 //var action = Gdk.DragAction.COPY;
803 // unless we are copying!!! ctl button..
805 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
806 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
807 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
810 if (_this.model.el.iter_n_children(null) < 1) {
811 // no children.. -- asume it's ok..
813 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
815 // continue through to allow drop...
823 //print("ISOVER? " + isOver);
826 Gtk.drag_finish (ctx, false, false, time); // drop failed..
827 return true; // not over apoint!?! - no action on drop or motion..
830 // drag node is parent of child..
831 //console.log("SRC TREEPATH: " + src.treepath);
832 //console.log("TARGET TREEPATH: " + data.path.to_string());
834 // nned to check a few here..
835 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
836 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
837 //Gtk.TreeViewDropPosition.AFTER
838 //Gtk.TreeViewDropPosition.BEFORE
840 // locally dragged items to not really use the
841 var selection_text = this.dragData;
845 if (selection_text == null || selection_text.length < 1) {
846 //print("Error - drag selection text returned NULL");
848 Gtk.drag_finish (ctx, false, false, time); // drop failed..
849 return true; /// -- fixme -- this is not really correct..
852 // see if we are dragging into ourself?
853 print ("got selection text of " + selection_text);
855 var target_path = path.to_string();
856 //print("target_path="+target_path);
859 if (selection_text == target_path) {
860 print("self drag ?? == we should perhaps allow copy onto self..\n");
862 Gtk.drag_finish (ctx, false, false, time); // drop failed..
864 return true; /// -- fixme -- this is not really correct..
869 //print("DUMPING DATA");
870 //console.dump(data);
873 //print(data.path.to_string() +' => '+ data.pos);
875 // dropList is a list of xtypes that this node could be dropped on.
876 // it is set up when we start to drag..
879 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
881 print("targetDAta: " + targetData +"\n");
883 if (targetData.length < 1) {
884 //print("Can not find drop node path");
886 Gtk.drag_finish (ctx, false, false, time); // drop failed..
892 // continue on to allow drop..
894 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
897 var delete_selection_data = false;
899 if (action == Gdk.DragAction.ASK) {
900 /* Ask the user to move or copy, then set the ctx action. */
903 if (action == Gdk.DragAction.MOVE) {
904 delete_selection_data = true;
907 // drag around.. - reorder..
908 _this.model.moveNode(targetData, action);
914 // we can send stuff to souce here...
917 // do we always say failure, so we handle the reall drop?
918 Gtk.drag_finish (ctx, false, false,time); //delete_selection_data, time);
930 // user defined functions
931 public void highlightDropPath ( string treepath, Gtk.TreeViewDropPosition pos) {
933 // highlighting for drag/drop
934 if (treepath.length > 0) {
935 this.el.set_drag_dest_row( new Gtk.TreePath.from_string( treepath ), pos);
937 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
941 public void selectNode (string treepath_str, string source) {
942 this.lastEventSource = source;
943 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
944 var tp = new Gtk.TreePath.from_string(treepath_str);
946 this.el.set_cursor(tp, null, false);
947 this.el.scroll_to_cell(tp, null, false, 0,0);
949 public void setCursor (string treepath, string sourceEvent) {
950 this.lastEventSource = sourceEvent;
951 //this.blockChanges = true; << block changes prevents loading of 'node data' and firing of node_selected..
952 this.el.set_cursor(new Gtk.TreePath.from_string(treepath), null, false);
953 // fire node_selected..
954 //this.blockChanges = false;
955 this.lastEventSource = "";
958 public class Xcls_model : Object
960 public Gtk.TreeStore el;
961 private Xcls_WindowLeftTree _this;
965 public DialogTemplateSelect template_select;
966 public string activePath;
969 public Xcls_model(Xcls_WindowLeftTree _owner )
973 this.el = new Gtk.TreeStore.newv( { typeof(string),
977 typeof(Gdk.Pixbuf) } );
980 this.template_select = null;
981 this.activePath = "";
983 // set gobject values
987 print("model initialized");
990 // user defined functions
991 public void loadFile (JsRender.JsRender f) {
994 _this.main_window.windowstate.leftTreeNodeSelected(null, "");
996 _this.main_window.windowstate.file = f;
999 if (f.tree == null) {
1006 // if it's still null?
1007 if (f.tree == null) {
1008 _this.main_window.windowstate.showAddObject(_this.view.el);
1013 var o = new Gee.ArrayList<JsRender.Node>();
1017 _this.view.el.expand_all();
1019 if (f.tree.items.size < 1) {
1022 //this.get('/Window.leftvpaned').el.set_position(80);
1024 _this.view.el.set_cursor(
1025 new Gtk.TreePath.from_string("0"), null, false);
1029 //this.get('/Window.leftvpaned').el.set_position(200);
1033 while (Gtk.events_pending()) {
1034 Gtk.main_iteration();
1037 _this.maincol.el.set_max_width(_this.viewwin.el.get_allocated_width() - 32);
1045 public string findDropNodeByPath (string treepath_str, string[] targets, int in_pref = -1) {
1047 var path = treepath_str; // dupe it..
1050 // pref : 3 = ontop - 0 = after, 1 = before
1051 int pref = in_pref < 0 ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : in_pref;
1055 //console.dump(this.treemap);
1057 print("findDropNodeByPath : got path length %d / %s\n", path.length, path);
1059 if (path.length == 0) {
1060 // top drop. // just return empty..
1061 return "|%d".printf((int)pref) ;
1066 while (path.length > 0) {
1068 if (path.length == treepath_str.length && pref != Gtk.TreeViewDropPosition.INTO_OR_AFTER) {
1069 if (path.last_index_of(":") < 0 ) {
1072 path = path.substring(0, path.last_index_of(":"));
1073 last = treepath_str;
1074 print("DROP before or after : using %s\n",path);
1078 //print("LOOKING FOR PATH: " + path);
1079 var node_data = this.pathToNode(path);
1081 if (node_data == null) {
1082 print("node not found");
1086 var xname = node_data.fqn();
1090 for (var i =0; i < targets.length; i++) {
1091 var tg = targets[i];
1092 if ((tg == xname) ) {
1096 // if target is "xxxx:name"
1097 if (tg.contains(xname +":")) {
1099 var ar = tg.split(":");
1105 if (match.length > 0) {
1106 if (last.length > 0) { // pref is after/before..
1107 // then it's after last
1111 return last + "|%d".printf((int)pref) + "|" + prop;
1115 // we need to add prop - as :store -> needs to bee added when dropping onto.
1116 return path + "|%d".printf( (int) Gtk.TreeViewDropPosition.INTO_OR_AFTER) + "|" + prop;
1120 var par = path.split(":");
1121 string [] ppar = {};
1122 for (var i = 0; i < par.length-1; i++) {
1126 path = string.joinv(":", ppar);
1135 public void iterSetValues (Gtk.TreeIter iter, JsRender.Node node) {
1136 var ic = Gtk.IconTheme.get_default();
1139 var o = GLib.Value(typeof(Object));
1140 o.set_object((Object)node);
1141 var clsname = node.fqn();
1143 var clsb = clsname.split(".");
1144 var sub = clsb.length > 1 ? clsb[1].down() : "";
1146 var addi = ic.load_icon("list-add", 16,0);
1147 var fn = "/usr/share/glade/pixmaps/hicolor/16x16/actions/widget-gtk-" + sub + ".png";
1148 if (FileUtils.test (fn, FileTest.IS_REGULAR)) {
1149 pix = new Gdk.Pixbuf.from_file (fn);
1151 pix = ic.load_icon("emblem-new", 16,0);
1156 0, node.nodeTitle(),
1160 this.el.set_value(iter, 2,o);
1161 this.el.set_value(iter, 3,pix);
1162 this.el.set_value(iter, 4,addi);
1166 public string treePathFromNode (JsRender.Node node) {
1167 // iterate through the tree and find the node
1170 this.el.foreach((mod, pth, iter) => {
1175 _this.model.el.get_value(iter, 2, out value);
1179 var n = (JsRender.Node)value;
1181 print("compare %s to %s\n", n.fqn(), node.fqn());
1183 ret = pth.to_string();
1191 public void deleteSelected () {
1193 print("DELETE SELECTED?");
1194 //_this.view.blockChanges = true;
1195 print("GET SELECTION?");
1197 var s = _this.view.el.get_selection();
1199 print("GET SELECTED?");
1204 if (!s.get_selected(out mod, out iter)) {
1205 return; // nothing seleted..
1210 this.activePath= "";
1211 print("GET vnode value?");
1214 this.el.get_value(iter, 2, out value);
1215 var data = (JsRender.Node)(value.get_object());
1216 print("removing node from Render\n");
1217 if (data.parent == null) {
1218 _this.main_window.windowstate.file.tree = null;
1222 print("removing node from Tree\n");
1224 this.el.remove(ref iter);
1234 this.activePath= ""; // again!?!?
1235 //this.changed(null,true);
1239 _this.view.blockChanges = false;
1241 public void dropNode (string target_data_str, JsRender.Node node, bool show_templates) {
1242 // print("drop Node");
1243 // console.dump(node);
1244 // console.dump(target_data);
1247 // {parent}|{pos}|{prop}
1250 // 0 = before , 1=after 2/3 onto
1252 GLib.debug("dropNode %s", target_data_str);
1254 var target_data= target_data_str.split("|");
1256 var parent_str = target_data[0].length > 0 ? target_data[0] : "";
1257 var pos = target_data.length > 1 ? int.parse(target_data[1]) : 2; // ontop..
1260 Gtk.TreePath tree_path = parent_str.length > 0 ? new Gtk.TreePath.from_string( parent_str ) : null;
1264 //print("add " + tp + "@" + target_data[1] );
1266 JsRender.Node parentNode = null;
1268 Gtk.TreeIter iter_after;
1269 Gtk.TreeIter iter_par ;
1271 // this appears to be done in drag_ddata_recieved as well.
1272 if (target_data.length == 3 && target_data[2].length > 0) {
1273 node.set_prop(new JsRender.NodeProp.special("prop", target_data[2]));
1277 Gtk.TreePath expand_parent = null;
1279 // we only need to show the template if it's come from else where?
1280 if (show_templates) {
1282 var ts = _this.main_window.windowstate.template_select;
1284 var new_node = ts.show(
1285 _this.main_window, // (Gtk.Window) _this.el.get_toplevel (),
1286 _this.main_window.windowstate.file.palete(),
1288 _this.main_window.windowstate.project);
1290 if (new_node == null) {
1291 return; // do not add?
1296 //print("pos is %d \n".printf(pos));
1298 Gtk.TreeIter n_iter;
1300 if ( parent_str.length < 1) {
1301 this.el.append(out n_iter, null); // drop at top level..
1303 _this.main_window.windowstate.file.tree = node;
1306 } else if (pos < 2) {
1307 //print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
1309 this.el.get_iter(out iter_after, tree_path );
1310 this.el.iter_parent(out iter_par, iter_after);
1311 expand_parent = this.el.get_path(iter_par);
1314 // not sure why all the 'dup_object()' stuff? did it crash before?
1316 this.el.get_value( iter_par, 2, out value);
1317 parentNode = (JsRender.Node)value.dup_object();
1320 this.el.get_value( iter_after, 2, out value);
1321 var relNode = (JsRender.Node)value.dup_object();
1325 this.el.insert_after(out n_iter, iter_par , iter_after);
1326 var ix = parentNode.items.index_of(relNode);
1327 parentNode.items.insert(ix+1, node);
1330 this.el.insert_before(out n_iter, iter_par , iter_after);
1331 var ix = parentNode.items.index_of(relNode);
1332 parentNode.items.insert(ix, node);
1335 node.parent = parentNode;
1340 // print("appending to " + parent_str);
1341 this.el.get_iter(out iter_par, tree_path);
1342 this.el.append(out n_iter, iter_par );
1343 expand_parent = this.el.get_path(iter_par);
1346 this.el.get_value( iter_par, 2, out value);
1347 parentNode = (JsRender.Node)value.dup_object();
1348 node.parent = parentNode;
1349 parentNode.items.add(node);
1355 // work out what kind of packing to use.. -- should be in
1358 //_this.main_window.windowstate.file.palete().fillPack(node,parentNode);
1359 _this.main_window.windowstate.file.palete().on_child_added(parentNode,node);
1362 this.iterSetValues(n_iter, node);
1367 // load children - if it has any..
1369 if (node.items.size > 0) {
1370 this.load(node.items, n_iter);
1371 _this.view.el.expand_row(this.el.get_path(n_iter), true);
1372 } else if (expand_parent != null && !_this.view.el.is_row_expanded(expand_parent)) {
1373 _this.view.el.expand_row(expand_parent,true);
1376 //if (tp != null && (node.items.length() > 0 || pos > 1)) {
1377 // _this.view.el.expand_row(this.el.get_path(iter_par), true);
1379 // wee need to get the empty proptypes from somewhere..
1381 //var olditer = this.activeIter;
1382 this.activePath = this.el.get_path(n_iter).to_string();
1385 // pretend button was pressed, so that we can trigger select node...
1386 _this.view.button_is_pressed = true;
1387 _this.view.lastEventSource = "";
1388 _this.view.el.set_cursor(this.el.get_path(n_iter), null, false);
1389 _this.view.button_is_pressed = false;
1395 public void moveNode (string target_data, Gdk.DragAction action)
1398 /// target_data = "path|pos");
1401 //print("MOVE NODE");
1402 // console.dump(target_data);
1403 Gtk.TreeIter old_iter;
1406 var s = _this.view.el.get_selection();
1407 s.get_selected(out mod , out old_iter);
1408 mod.get_path(old_iter);
1410 var node = this.pathToNode(mod.get_path(old_iter).to_string());
1411 //console.dump(node);
1413 GLib.debug("moveNode: ERROR - node is null?");
1418 // needs to drop first, otherwise the target_data
1419 // treepath will be invalid.
1422 if ((action & Gdk.DragAction.MOVE) > 0) {
1423 GLib.debug("REMOVING OLD NODE : " + target_data + "\n");
1425 this.dropNode(target_data, node, false);
1426 this.el.remove(ref old_iter);
1431 GLib.debug("DROPPING NODE // copy: " + target_data + "\n");
1432 node = node.deepClone();
1433 this.dropNode(target_data, node, false);
1436 this.activePath= "";
1437 //this.updateNode(false,true);
1439 public void updateSelected () {
1442 var s = _this.view.el.get_selection();
1449 if (!s.get_selected(out mod, out iter)) {
1450 return; // nothing seleted..
1454 this.el.get_value(iter, 2, out value);
1455 var node = (JsRender.Node)(value.get_object());
1457 this.el.set(iter, 0, node.nodeTitle(),
1458 1, node.nodeTip(), -1
1461 public string findDropNode (string treepath_str, string[] targets) {
1463 // this is used by the dragdrop code in the roo version AFAIR..
1465 //var path = treepath_str.replace(/^builder-/, '');
1466 // treemap is depreciated... - should really check if model has any entries..
1468 if (this.el.iter_n_children(null) < 1) {
1470 return "|%d".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
1472 //print("FIND treepath: " + path);
1473 //console.dump(this.treemap);
1475 //if (!treepath_str.match(/^builder-/)) {
1476 // return []; // nothing!
1478 if (targets.length > 0 && targets[0] == "*") {
1479 return treepath_str;
1481 return this.findDropNodeByPath(treepath_str,targets, -1);
1483 public void load (Gee.ArrayList<JsRender.Node> tr, Gtk.TreeIter? iter)
1488 //this.insert(citer,iter,0);
1491 for(var i =0 ; i < tr.size; i++) {
1493 this.el.insert(out citer,iter,-1); // why not append?
1495 this.el.append(out citer,null);
1497 this.iterSetValues(citer, tr.get(i));
1501 if (tr.get(i).items.size > 0) {
1502 this.load(tr.get(i).items, citer);
1509 public JsRender.Node pathToNode (string path) {
1513 _this.model.el.get_iter_from_string(out iter, path);
1516 _this.model.el.get_value(iter, 2, out value);
1518 return (JsRender.Node)value.dup_object();
1523 public class Xcls_maincol : Object
1525 public Gtk.TreeViewColumn el;
1526 private Xcls_WindowLeftTree _this;
1532 public Xcls_maincol(Xcls_WindowLeftTree _owner )
1535 _this.maincol = this;
1536 this.el = new Gtk.TreeViewColumn();
1540 // set gobject values
1541 this.el.title = "Node";
1542 this.el.sizing = Gtk.TreeViewColumnSizing.FIXED;
1543 this.el.expand = true;
1544 this.el.resizable = true;
1545 var child_0 = new Xcls_iconrender( _this );
1547 this.el.pack_start ( child_0.el , false );
1548 var child_1 = new Xcls_renderer( _this );
1550 this.el.pack_start ( child_1.el , true );
1554 this.el.add_attribute(_this.renderer.el , "markup", 0 );
1555 this.el.add_attribute(_this.iconrender.el , "pixbuf", 3 );
1558 // user defined functions
1560 public class Xcls_iconrender : Object
1562 public Gtk.CellRendererPixbuf el;
1563 private Xcls_WindowLeftTree _this;
1569 public Xcls_iconrender(Xcls_WindowLeftTree _owner )
1572 _this.iconrender = this;
1573 this.el = new Gtk.CellRendererPixbuf();
1577 // set gobject values
1581 // user defined functions
1584 public class Xcls_renderer : Object
1586 public Gtk.CellRendererText el;
1587 private Xcls_WindowLeftTree _this;
1593 public Xcls_renderer(Xcls_WindowLeftTree _owner )
1596 _this.renderer = this;
1597 this.el = new Gtk.CellRendererText();
1601 // set gobject values
1604 // user defined functions
1608 public class Xcls_TreeViewColumn8 : Object
1610 public Gtk.TreeViewColumn el;
1611 private Xcls_WindowLeftTree _this;
1617 public Xcls_TreeViewColumn8(Xcls_WindowLeftTree _owner )
1620 this.el = new Gtk.TreeViewColumn();
1624 // set gobject values
1625 this.el.max_width = 24;
1626 this.el.title = "Add";
1627 this.el.sizing = Gtk.TreeViewColumnSizing.FIXED;
1628 this.el.expand = false;
1629 var child_0 = new Xcls_addiconrender( _this );
1631 this.el.pack_start ( child_0.el , true );
1635 this.el.add_attribute(_this.addiconrender.el , "pixbuf", 4 );
1638 // user defined functions
1640 public class Xcls_addiconrender : Object
1642 public Gtk.CellRendererPixbuf el;
1643 private Xcls_WindowLeftTree _this;
1649 public Xcls_addiconrender(Xcls_WindowLeftTree _owner )
1652 _this.addiconrender = this;
1653 this.el = new Gtk.CellRendererPixbuf();
1657 // set gobject values
1661 // user defined functions
1666 public class Xcls_LeftTreeMenu : Object
1669 private Xcls_WindowLeftTree _this;
1675 public Xcls_LeftTreeMenu(Xcls_WindowLeftTree _owner )
1678 _this.LeftTreeMenu = this;
1679 this.el = new Gtk.Menu();
1683 // set gobject values
1684 var child_0 = new Xcls_MenuItem11( _this );
1686 this.el.add ( child_0.el );
1687 var child_1 = new Xcls_MenuItem12( _this );
1689 this.el.add ( child_1.el );
1690 var child_2 = new Xcls_MenuItem13( _this );
1692 this.el.add ( child_2.el );
1695 // user defined functions
1697 public class Xcls_MenuItem11 : Object
1699 public Gtk.MenuItem el;
1700 private Xcls_WindowLeftTree _this;
1706 public Xcls_MenuItem11(Xcls_WindowLeftTree _owner )
1709 this.el = new Gtk.MenuItem();
1713 // set gobject values
1714 this.el.label = "Delete Element";
1717 this.el.activate.connect( ( ) => {
1722 _this.model.deleteSelected();
1726 // user defined functions
1729 public class Xcls_MenuItem12 : Object
1731 public Gtk.MenuItem el;
1732 private Xcls_WindowLeftTree _this;
1738 public Xcls_MenuItem12(Xcls_WindowLeftTree _owner )
1741 this.el = new Gtk.MenuItem();
1745 // set gobject values
1746 this.el.label = "Save as Template";
1749 this.el.activate.connect( () => {
1751 DialogSaveTemplate.singleton().show(
1752 (Gtk.Window) _this.el.get_toplevel (),
1753 _this.main_window.windowstate.file.palete(),
1754 _this.getActiveElement()
1761 // user defined functions
1764 public class Xcls_MenuItem13 : Object
1766 public Gtk.MenuItem el;
1767 private Xcls_WindowLeftTree _this;
1773 public Xcls_MenuItem13(Xcls_WindowLeftTree _owner )
1776 this.el = new Gtk.MenuItem();
1780 // set gobject values
1781 this.el.label = "Save as Module";
1784 this.el.activate.connect( () => {
1785 var node = _this.getActiveElement();
1786 var name = DialogSaveModule.singleton().show(
1787 (Gtk.Window) _this.el.get_toplevel (),
1788 _this.main_window.windowstate.project,
1791 if (name.length < 1) {
1795 node.set_prop( new JsRender.NodeProp.special("xinclude", name));
1799 var s = _this.view.el.get_selection();
1801 print("GET SELECTED?");
1806 if (!s.get_selected(out mod, out iter)) {
1807 return; // nothing seleted..
1810 var n_cn = mod.iter_n_children(iter) -1;
1811 for (var i = n_cn; i > -1; i--) {
1812 mod.iter_nth_child(out citer, iter, i);
1815 print("removing node from Tree\n");
1817 _this.model.el.remove(ref citer);
1820 _this.node_selected(node, "tree");
1826 // user defined functions