1 static Xcls_WindowLeftTree _WindowLeftTree;
3 public class Xcls_WindowLeftTree : Object
5 public Gtk.ScrolledWindow el;
6 private Xcls_WindowLeftTree _this;
8 public static Xcls_WindowLeftTree singleton()
10 if (_WindowLeftTree == null) {
11 _WindowLeftTree= new Xcls_WindowLeftTree();
13 return _WindowLeftTree;
15 public Xcls_view view;
16 public Xcls_model model;
17 public Xcls_renderer renderer;
18 public Xcls_LeftTreeMenu LeftTreeMenu;
21 public signal bool before_node_change ();
22 public signal void changed ();
23 public signal void node_selected (JsRender.Node? node, string source);
24 public Xcls_MainWindow main_window;
27 public Xcls_WindowLeftTree()
30 this.el = new Gtk.ScrolledWindow( null, null );
33 this.main_window = null;
36 this.el.shadow_type = Gtk.ShadowType.IN;
37 var child_0 = new Xcls_view( _this );
39 this.el.add ( child_0.el );
40 var child_1 = new Xcls_LeftTreeMenu( _this );
45 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
48 // user defined functions
49 public JsRender.Node? getActiveElement () { // return path to actie node.
51 var path = this.getActivePath();
52 if (path.length < 1) {
55 return _this.model.pathToNode(path);
58 public JsRender.JsRender getActiveFile () {
59 return this.main_window.windowstate.file;
61 public string getActivePath () {
63 var view = this.view.el;
64 if (view.get_selection().count_selected_rows() < 1) {
69 view.get_selection().get_selected(out mod, out iter);
70 return mod.get_path(iter).to_string();
72 public class Xcls_view : Object
74 public Gtk.TreeView el;
75 private Xcls_WindowLeftTree _this;
79 public string dragData;
81 public string[] dropList;
83 public string lastEventSource;
84 public bool drag_in_motion;
85 public bool blockChanges;
88 public Xcls_view(Xcls_WindowLeftTree _owner )
92 this.el = new Gtk.TreeView();
95 this.lastEventSource = "";
96 this.blockChanges = false;
99 this.el.expand = true;
100 this.el.tooltip_column = 1;
101 this.el.enable_tree_lines = true;
102 this.el.headers_visible = false;
103 var child_0 = new Xcls_model( _this );
105 this.el.set_model ( child_0.el );
106 var child_1 = new Xcls_TreeViewColumn4( _this );
108 this.el.append_column ( child_1.el );
113 var description = new Pango.FontDescription();
114 description.set_size(8000);
115 this.el.override_font(description);
117 var selection = this.el.get_selection();
118 selection.set_mode( Gtk.SelectionMode.SINGLE);
121 // is this really needed??
123 this.selection.signal['changed'].connect(function() {
124 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
125 _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
129 Gtk.drag_source_set (
130 this.el, /* widget will be drag-able */
131 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
132 BuilderApplication.targetList, /* lists of target to support */
133 Gdk.DragAction.COPY | Gdk.DragAction.MOVE | Gdk.DragAction.LINK /* what to do with data after dropped */
137 //Gtk.drag_source_add_text_targets(this.el);
141 this.el, /* widget that will accept a drop */
142 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
143 BuilderApplication.targetList, /* lists of target to support */
144 Gdk.DragAction.COPY | Gdk.DragAction.MOVE | Gdk.DragAction.LINK /* what to do with data after dropped */
147 //Gtk.drag_dest_set_target_list(this.el, Builder.Application.targetList);
148 //Gtk.drag_dest_add_text_targets(this.el);
152 this.el.button_press_event.connect( ( ev) => {
153 //console.log("button press?");
154 this.lastEventSource = "tree";
155 if (! _this.before_node_change() ) {
162 if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button != 3) {
163 //print("click" + ev.type);
167 if (!_this.view.el.get_path_at_pos((int)ev.x,(int)ev.y, out res, null, null, null) ) {
171 this.el.get_selection().select_path(res);
173 //if (!this.get('/LeftTreeMenu').el) {
174 // this.get('/LeftTreeMenu').init();
177 _this.LeftTreeMenu.el.set_screen(Gdk.Screen.get_default());
178 _this.LeftTreeMenu.el.show_all();
179 _this.LeftTreeMenu.el.popup(null, null, null, 3, ev.time);
180 // print("click:" + res.path.to_string());
183 this.el.drag_begin.connect( ( ctx) => {
184 //print('SOURCE: drag-begin');
187 //this.targetData = "";
189 // find what is selected in our tree...
191 var s = _this.view.el.get_selection();
192 if (s.count_selected_rows() < 1) {
197 s.get_selected(out mod, out iter);
201 // set some properties of the tree for use by the dropped element.
203 _this.model.el.get_value(iter, 2, out value);
204 var tp = mod.get_path(iter).to_string();
205 var data = (JsRender.Node)(value.dup_object());
206 var xname = data.fqn();
207 print ("XNAME IS " + xname+ "\n");
209 this.dropList = _this.main_window.windowstate.file.palete().getDropList(xname);
211 print ("DROP LIST IS " + string.joinv(", ", this.dropList) + "\n");
214 // make the drag icon a picture of the node that was selected
217 // by default returns the path..
218 var path = _this.model.el.get_path(iter);
221 var pix = this.el.create_row_drag_icon ( path);
223 Gtk.drag_set_icon_surface (ctx, pix) ;
227 this.el.cursor_changed.connect( ( ) => {
230 if (this.blockChanges) { // probably not needed..
233 if (!_this.before_node_change( ) ) {
234 this.blockChanges = true;
235 this.el.get_selection().unselect_all();
236 this.blockChanges = false;
239 if (_this.main_window.windowstate.file == null) {
243 //var render = this.get('/LeftTree').getRenderer();
244 print("LEFT TREE -> view -> selection changed called\n");
247 // -- it appears that the selection is not updated.
249 GLib.Timeout.add_full(GLib.Priority.DEFAULT,10 , () => {
252 if (this.el.get_selection().count_selected_rows() < 1) {
254 print("selected rows < 1\n");
255 //??this.model.load( false);
256 _this.node_selected(null, this.lastEventSource);
261 //console.log('changed');
262 var s = this.el.get_selection();
265 s.get_selected(out mod, out iter);
270 _this.model.el.get_value(iter, 2, out value);
271 _this.model.activePath = mod.get_path(iter).to_string();
273 var node = (JsRender.Node)value.dup_object();
274 _this.node_selected(node, this.lastEventSource);
275 while (Gtk.events_pending()) {
276 Gtk.main_iteration();
278 var cp = mod.get_path(iter);
280 this.el.get_visible_range(out sp, out ep);
281 // if sp is before cp then retuns 1.
282 // if cp is before ep then retuns 1.
283 if (cp.compare(sp) >= 0 && ep.compare(cp) >=1) {
289 this.el.scroll_to_cell(new Gtk.TreePath.from_string(_this.model.activePath), null, true, 0.1f,0.0f);
293 //_this.after_node_change(node);
295 // _this.model.file.changed(node, "tree");
297 //Seed.print( value.get_string());
301 this.el.drag_end.connect( (drag_context) => {
302 //Seed.print('LEFT-TREE: drag-end');
304 this.dropList = null;
305 // this.targetData = "";
306 this.highlightDropPath("",0);
309 this.el.drag_motion.connect( ( ctx, x, y, time) => {
310 print("got drag motion\n");
311 var src = Gtk.drag_get_source_widget(ctx);
315 if (src != this.el) {
319 // the point of this is to detect where an item could be dropped..
320 print("requesting drag data\n");
321 this.drag_in_motion = true;
323 // request data that will be recieved by the recieve...
326 this.el, // will receive 'drag-data-received' signal
327 ctx, // represents the current state of the DnD
328 Gdk.Atom.intern("STRING",true), // the target type we want
335 print("action: %d\n", ctx.get_actions());
336 //print("GETTING POS");
340 Gtk.TreeViewDropPosition pos;
341 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
343 // if there are not items in the tree.. the we have to set isOver to true for anything..
345 if (_this.model.el.iter_n_children(null) < 1) {
346 print("got NO children?\n");
349 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
353 // ------------- a drag from self..
356 //var action = Gdk.DragAction.COPY;
357 // unless we are copying!!! ctl button..
359 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
360 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
361 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
364 if (_this.model.el.iter_n_children(null) < 1) {
365 // no children.. -- asume it's ok..
367 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
369 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
370 Gdk.drag_status(ctx, action ,time);
373 // continue through to allow drop...
381 //print("ISOVER? " + isOver);
384 Gdk.drag_status(ctx, 0 ,time);
385 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
390 // drag node is parent of child..
391 //console.log("SRC TREEPATH: " + src.treepath);
392 //console.log("TARGET TREEPATH: " + data.path.to_string());
394 // nned to check a few here..
395 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
396 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
397 //Gtk.TreeViewDropPosition.AFTER
398 //Gtk.TreeViewDropPosition.BEFORE
400 // locally dragged items to not really use the
401 var selection_text = this.dragData;
405 if (selection_text == null || selection_text.length < 1) {
406 //print("Error - drag selection text returned NULL");
407 Gdk.drag_status(ctx, 0 ,time);
408 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
413 // see if we are dragging into ourself?
414 var target_path = path.to_string();
415 print ("Drag %s onto %s--%d\n ", selection_text, target_path, pos);
417 // pos : 3 = ontop - 0 = after, 1 = before
418 //print("target_path="+target_path);
421 if (selection_text == target_path) {
422 print("self drag ?? == we should perhaps allow copy onto self..\n");
424 Gdk.drag_status(ctx, 0 ,time);
425 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
427 // -- fixme -- this is not really correct..
432 //print("DUMPING DATA");
433 //console.dump(data);
436 //print(data.path.to_string() +' => '+ data.pos);
438 // dropList is a list of xtypes that this node could be dropped on.
439 // it is set up when we start to drag..
442 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
444 print("targetDAta: " + targetData +"\n");
446 if (targetData.length < 1) {
447 //print("Can not find drop node path");
449 Gdk.drag_status(ctx, 0, time);
450 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
454 var td_ar = targetData.split("|");
458 Gdk.drag_status(ctx, action ,time);
459 this.highlightDropPath(td_ar[0], (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
464 this.el.drag_data_get.connect( ( drag_context, data, info, time) => {
467 //print("drag-data-get");
468 var s = this.el.get_selection();
469 if (s.count_selected_rows() < 1) {
471 print("return empty string - no selection..");
478 s.get_selected(out mod, out iter);
483 _this.model.el.get_value(iter, 2, out value);
484 var ndata = (JsRender.Node)(value.dup_object());
488 var tp = mod.get_path(iter).to_string();
489 // by default returns the path..
491 if ( info != Gdk.Atom.intern("STRING",true) ) {
492 tp = ndata.toJsonString();
495 //data.set_text(tp,tp.length);
497 data.set (data.get_target (), 8, (uchar[]) tp.to_utf8 ());
500 // print("return " + tp);
502 this.el.drag_data_received.connect( (ctx, x, y, sel, info, time) => {
504 // THIS CODE ONLY RELATES TO drag or drop of "NEW" elements or "FROM another tree.."
507 // print("Tree: drag-data-received\n");
508 var selection_text = (string)sel.get_data();
509 //print("selection_text= %s\n",selection_text);
511 var is_drag = this.drag_in_motion;
515 print("Is Drag %s\n", is_drag ? "Y": "N");
519 Gtk.TreeViewDropPosition pos;
520 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
522 // if there are not items in the tree.. the we have to set isOver to true for anything..
524 if (_this.model.el.iter_n_children(null) < 1) {
525 print("got NO children?\n");
528 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
532 //console.log("LEFT-TREE: drag-motion");
533 var src = Gtk.drag_get_source_widget(ctx);
535 // a drag from self - this should be handled by drop and motion.
536 if (src == this.el) {
537 print("Source == this element should not happen.. ? \n");
540 //print("drag_data_recieved from another element");
545 if (selection_text == null || selection_text.length < 1 || !isOver) {
546 // nothing valid foudn to drop...
547 print("empty sel text or not over");
549 Gdk.drag_status(ctx, 0, time);
550 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
553 Gtk.drag_finish (ctx, false, false, time); // drop failed..
558 var dropNode = new JsRender.Node();
560 var dropNodeType = selection_text;
561 var show_templates = true;
563 if (dropNodeType[0] == '{') {
564 var pa = new Json.Parser();
566 pa.load_from_data(dropNodeType);
568 Gtk.drag_finish (ctx, false, false, time); // drop failed..
573 dropNode.loadFromJson( pa.get_root().get_object(), 2);
574 dropNodeType = dropNode.fqn();
575 show_templates = false;
580 dropNode.setFqn(selection_text);
584 // dropList --- need to gather this ...
585 print("get dropList for : %s\n",dropNodeType);
586 var dropList = _this.main_window.windowstate.file.palete().getDropList(dropNodeType);
588 print("dropList: %s\n", string.joinv(" , ", dropList));
590 // if drag action is link ... then we can drop it anywahere...
591 if ((ctx.get_actions() & Gdk.DragAction.LINK) > 0) {
592 // if path is null?? dragging into an empty tree?
593 targetData = (path == null ? "" : path.to_string()) + "|%d".printf((int)pos);
597 targetData = _this.model.findDropNodeByPath( isEmpty ? "" : path.to_string(), dropList, pos);
602 print("targetDAta: " + targetData +"\n");
604 if (targetData.length < 1) {
606 // invalid drop path..
607 if (this.drag_in_motion) {
608 Gdk.drag_status(ctx, 0, time);
609 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
612 Gtk.drag_finish (ctx, false, false, time); // drop failed..
618 var td_ar = targetData.split("|");
621 if (this.drag_in_motion) {
622 Gdk.drag_status(ctx, Gdk.DragAction.COPY ,time);
624 this.highlightDropPath( td_ar[0] , (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
627 // continue on to allow drop..
630 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
633 _this.model.dropNode(targetData, dropNode, show_templates);
634 print("ADD new node!!!\n");
636 ///Xcls_DialogTemplateSelect.singleton().show( _this.model.file.palete(), node);
638 Gtk.drag_finish (ctx, false, false,time);
645 this.el.drag_drop.connect( ( ctx, x, y, time) => {
646 //Seed.print("TARGET: drag-drop");
649 var src = Gtk.drag_get_source_widget(ctx);
651 if (src != this.el) {
655 this.drag_in_motion = false;
656 // request data that will be recieved by the recieve...
659 this.el, // will receive 'drag-data-received' signal
660 ctx, // represents the current state of the DnD
661 Gdk.Atom.intern("application/json",true), // the target type we want
666 // No target offered by source => error
672 // handle drop around self..
676 //print("GETTING POS");
680 Gtk.TreeViewDropPosition pos;
681 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
683 // if there are not items in the tree.. the we have to set isOver to true for anything..
685 if (_this.model.el.iter_n_children(null) < 1) {
686 print("got NO children?\n");
689 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
694 //var action = Gdk.DragAction.COPY;
695 // unless we are copying!!! ctl button..
697 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
698 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
699 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
702 if (_this.model.el.iter_n_children(null) < 1) {
703 // no children.. -- asume it's ok..
705 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
707 // continue through to allow drop...
715 //print("ISOVER? " + isOver);
718 Gtk.drag_finish (ctx, false, false, time); // drop failed..
719 return true; // not over apoint!?! - no action on drop or motion..
722 // drag node is parent of child..
723 //console.log("SRC TREEPATH: " + src.treepath);
724 //console.log("TARGET TREEPATH: " + data.path.to_string());
726 // nned to check a few here..
727 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
728 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
729 //Gtk.TreeViewDropPosition.AFTER
730 //Gtk.TreeViewDropPosition.BEFORE
732 // locally dragged items to not really use the
733 var selection_text = this.dragData;
737 if (selection_text == null || selection_text.length < 1) {
738 //print("Error - drag selection text returned NULL");
740 Gtk.drag_finish (ctx, false, false, time); // drop failed..
741 return true; /// -- fixme -- this is not really correct..
744 // see if we are dragging into ourself?
745 print ("got selection text of " + selection_text);
747 var target_path = path.to_string();
748 //print("target_path="+target_path);
751 if (selection_text == target_path) {
752 print("self drag ?? == we should perhaps allow copy onto self..\n");
754 Gtk.drag_finish (ctx, false, false, time); // drop failed..
756 return true; /// -- fixme -- this is not really correct..
761 //print("DUMPING DATA");
762 //console.dump(data);
765 //print(data.path.to_string() +' => '+ data.pos);
767 // dropList is a list of xtypes that this node could be dropped on.
768 // it is set up when we start to drag..
771 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
773 print("targetDAta: " + targetData +"\n");
775 if (targetData.length < 1) {
776 //print("Can not find drop node path");
778 Gtk.drag_finish (ctx, false, false, time); // drop failed..
784 // continue on to allow drop..
786 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
789 var delete_selection_data = false;
791 if (action == Gdk.DragAction.ASK) {
792 /* Ask the user to move or copy, then set the ctx action. */
795 if (action == Gdk.DragAction.MOVE) {
796 delete_selection_data = true;
799 // drag around.. - reorder..
800 _this.model.moveNode(targetData, action);
806 // we can send stuff to souce here...
809 // do we always say failure, so we handle the reall drop?
810 Gtk.drag_finish (ctx, false, false,time); //delete_selection_data, time);
822 // user defined functions
823 public void highlightDropPath ( string treepath, Gtk.TreeViewDropPosition pos) {
825 // highlighting for drag/drop
826 if (treepath.length > 0) {
827 this.el.set_drag_dest_row( new Gtk.TreePath.from_string( treepath ), pos);
829 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
833 public void setCursor (string treepath, string sourceEvent) {
834 this.lastEventSource = sourceEvent;
835 this.blockChanges = true;
836 this.el.set_cursor(new Gtk.TreePath.from_string(treepath), null, false);
837 this.blockChanges = false;
838 this.lastEventSource = "";
840 public void selectNode (string treepath_str, string source) {
841 this.lastEventSource = source;
842 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
843 var tp = new Gtk.TreePath.from_string(treepath_str);
845 this.el.set_cursor(tp, null, false);
846 this.el.scroll_to_cell(tp, null, false, 0,0);
849 public class Xcls_model : Object
851 public Gtk.TreeStore el;
852 private Xcls_WindowLeftTree _this;
856 public DialogTemplateSelect template_select;
857 public string activePath;
860 public Xcls_model(Xcls_WindowLeftTree _owner )
864 this.el = new Gtk.TreeStore( 3, typeof(string),typeof(string),typeof(Object) );
867 this.template_select = null;
868 this.activePath = "";
870 // set gobject values
874 print("model initialized");
877 // user defined functions
878 public string findDropNode (string treepath_str, string[] targets) {
880 // this is used by the dragdrop code in the roo version AFAIR..
882 //var path = treepath_str.replace(/^builder-/, '');
883 // treemap is depreciated... - should really check if model has any entries..
885 if (this.el.iter_n_children(null) < 1) {
887 return "|%d".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
889 //print("FIND treepath: " + path);
890 //console.dump(this.treemap);
892 //if (!treepath_str.match(/^builder-/)) {
893 // return []; // nothing!
895 if (targets.length > 0 && targets[0] == "*") {
898 return this.findDropNodeByPath(treepath_str,targets, -1);
900 public void loadFile (JsRender.JsRender f) {
905 _this.main_window.windowstate.file = f;
908 if (f.tree == null) {
915 // if it's still null?
916 if (f.tree == null) {
920 var o = new Gee.ArrayList<JsRender.Node>();
924 _this.view.el.expand_all();
926 if (f.tree.items.size < 1) {
929 //this.get('/Window.leftvpaned').el.set_position(80);
931 _this.view.el.set_cursor(
932 new Gtk.TreePath.from_string("0"), null, false);
936 //this.get('/Window.leftvpaned').el.set_position(200);
943 public void updateSelected () {
946 var s = _this.view.el.get_selection();
953 if (!s.get_selected(out mod, out iter)) {
954 return; // nothing seleted..
958 this.el.get_value(iter, 2, out value);
959 var node = (JsRender.Node)(value.get_object());
961 this.el.set(iter, 0, node.nodeTitle(),
962 1, node.nodeTip(), -1
965 public string findDropNodeByPath (string treepath_str, string[] targets, int in_pref = -1) {
967 var path = treepath_str; // dupe it..
970 // pref : 3 = ontop - 0 = after, 1 = before
971 int pref = in_pref < 0 ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : in_pref;
975 //console.dump(this.treemap);
977 print("findDropNodeByPath : got path length %d / %s\n", path.length, path);
979 if (path.length == 0) {
980 // top drop. // just return empty..
981 return "|%d".printf((int)pref) ;
986 while (path.length > 0) {
988 if (path.length == treepath_str.length && pref != Gtk.TreeViewDropPosition.INTO_OR_AFTER) {
989 if (path.last_index_of(":") < 0 ) {
992 path = path.substring(0, path.last_index_of(":"));
994 print("DROP before or after : using %s\n",path);
998 //print("LOOKING FOR PATH: " + path);
999 var node_data = this.pathToNode(path);
1001 if (node_data == null) {
1002 print("node not found");
1006 var xname = node_data.fqn();
1010 for (var i =0; i < targets.length; i++) {
1011 var tg = targets[i];
1012 if ((tg == xname) ) {
1016 // if target is "xxxx:name"
1017 if (tg.contains(xname +":")) {
1019 var ar = tg.split(":");
1025 if (match.length > 0) {
1026 if (last.length > 0) { // pref is after/before..
1027 // then it's after last
1031 return last + "|%d".printf((int)pref) + "|" + prop;
1035 // we need to add prop - as :store -> needs to bee added when dropping onto.
1036 return path + "|%d".printf( (int) Gtk.TreeViewDropPosition.INTO_OR_AFTER) + "|" + prop;
1040 var par = path.split(":");
1041 string [] ppar = {};
1042 for (var i = 0; i < par.length-1; i++) {
1046 path = string.joinv(":", ppar);
1055 public void moveNode (string target_data, Gdk.DragAction action)
1058 /// target_data = "path|pos");
1061 //print("MOVE NODE");
1062 // console.dump(target_data);
1063 Gtk.TreeIter old_iter;
1066 var s = _this.view.el.get_selection();
1067 s.get_selected(out mod , out old_iter);
1068 mod.get_path(old_iter);
1070 var node = this.pathToNode(mod.get_path(old_iter).to_string());
1071 //console.dump(node);
1073 print("moveNode: ERROR - node is null?");
1078 // needs to drop first, otherwise the target_data
1079 // treepath will be invalid.
1082 if ((action & Gdk.DragAction.MOVE) > 0) {
1083 print("REMOVING OLD NODE : " + target_data + "\n");
1085 this.dropNode(target_data, node, false);
1086 this.el.remove(ref old_iter);
1091 print("DROPPING NODE // copy: " + target_data + "\n");
1092 node = node.deepClone();
1093 this.dropNode(target_data, node, false);
1096 this.activePath= "";
1097 //this.updateNode(false,true);
1099 public void load (Gee.ArrayList<JsRender.Node> tr, Gtk.TreeIter? iter)
1102 //this.insert(citer,iter,0);
1103 for(var i =0 ; i < tr.size; i++) {
1105 this.el.insert(out citer,iter,-1); // why not append?
1107 this.el.append(out citer,null);
1110 this.el.set(citer, 0, tr.get(i).nodeTitle(),
1111 1, tr.get(i).nodeTip(), -1
1113 var o = GLib.Value(typeof(Object));
1114 o.set_object((Object)tr.get(i));
1116 this.el.set_value(citer, 2, o);
1118 if (tr.get(i).items.size > 0) {
1119 this.load(tr.get(i).items, citer);
1126 public void deleteSelected () {
1128 print("DELETE SELECTED?");
1129 //_this.view.blockChanges = true;
1130 print("GET SELECTION?");
1132 var s = _this.view.el.get_selection();
1134 print("GET SELECTED?");
1139 if (!s.get_selected(out mod, out iter)) {
1140 return; // nothing seleted..
1145 this.activePath= "";
1146 print("GET vnode value?");
1149 this.el.get_value(iter, 2, out value);
1150 var data = (JsRender.Node)(value.get_object());
1151 print("removing node from Render\n");
1152 if (data.parent == null) {
1153 _this.main_window.windowstate.file.tree = null;
1157 print("removing node from Tree\n");
1159 this.el.remove(ref iter);
1169 this.activePath= ""; // again!?!?
1170 //this.changed(null,true);
1174 _this.view.blockChanges = false;
1176 public JsRender.Node pathToNode (string path) {
1180 _this.model.el.get_iter_from_string(out iter, path);
1183 _this.model.el.get_value(iter, 2, out value);
1185 return (JsRender.Node)value.dup_object();
1188 public void dropNode (string target_data_str, JsRender.Node node, bool show_templates) {
1189 // print("drop Node");
1190 // console.dump(node);
1191 // console.dump(target_data);
1194 // 0 = before , 1=after 2/3 onto
1197 var target_data= target_data_str.split("|");
1199 var parent_str = target_data[0].length > 0 ? target_data[0] : "";
1200 var pos = target_data.length > 1 ? int.parse(target_data[1]) : 2; // ontop..
1203 Gtk.TreePath tree_path = parent_str.length > 0 ? new Gtk.TreePath.from_string( parent_str ) : null;
1207 //print("add " + tp + "@" + target_data[1] );
1209 JsRender.Node parentNode = null;
1211 Gtk.TreeIter iter_after;
1212 Gtk.TreeIter iter_par ;
1215 if (target_data.length == 3 && target_data[2].length > 0) {
1216 node.props.set("* prop", target_data[2]);
1219 Gtk.TreePath expand_parent = null;
1221 // we only need to show the template if it's come from else where?
1222 if (show_templates) {
1224 var ts = _this.main_window.windowstate.template_select;
1226 var new_node = ts.show(
1227 _this.main_window, // (Gtk.Window) _this.el.get_toplevel (),
1228 _this.main_window.windowstate.file.palete(),
1230 _this.main_window.windowstate.project);
1232 if (new_node == null) {
1233 return; // do not add?
1238 //print("pos is %d \n".printf(pos));
1240 Gtk.TreeIter n_iter;
1242 if ( parent_str.length < 1) {
1243 this.el.append(out n_iter, null); // drop at top level..
1245 _this.main_window.windowstate.file.tree = node;
1248 } else if (pos < 2) {
1249 //print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
1251 this.el.get_iter(out iter_after, tree_path );
1252 this.el.iter_parent(out iter_par, iter_after);
1253 expand_parent = this.el.get_path(iter_par);
1256 this.el.get_value( iter_par, 2, out value);
1257 parentNode = (JsRender.Node)value.dup_object();
1260 this.el.get_value( iter_after, 2, out value);
1261 var relNode = (JsRender.Node)value.dup_object();
1265 this.el.insert_after(out n_iter, iter_par , iter_after);
1266 var ix = parentNode.items.index_of(relNode);
1267 parentNode.items.insert(ix+1, node);
1270 this.el.insert_before(out n_iter, iter_par , iter_after);
1271 var ix = parentNode.items.index_of(relNode);
1272 parentNode.items.insert(ix, node);
1275 node.parent = parentNode;
1280 // print("appending to " + parent_str);
1281 this.el.get_iter(out iter_par, tree_path);
1282 this.el.append(out n_iter, iter_par );
1283 expand_parent = this.el.get_path(iter_par);
1286 this.el.get_value( iter_par, 2, out value);
1287 parentNode = (JsRender.Node)value.dup_object();
1288 node.parent = parentNode;
1289 parentNode.items.add(node);
1292 // reparent node in tree...
1295 // why only on no parent???
1297 //if (node.parent = null) {
1304 // work out what kind of packing to use.. -- should be in
1305 if (!node.has("pack") && parent_str.length > 1) {
1307 _this.main_window.windowstate.file.palete().fillPack(node,parentNode);
1314 this.el.set(n_iter, 0, node.nodeTitle(), 1, node.nodeTip(), -1 );
1315 var o = GLib.Value(typeof(Object));
1316 o.set_object((Object)node);
1318 this.el.set_value(n_iter, 2, o);
1323 // load children - if it has any..
1325 if (node.items.size > 0) {
1326 this.load(node.items, n_iter);
1327 _this.view.el.expand_row(this.el.get_path(n_iter), true);
1328 } else if (expand_parent != null && !_this.view.el.is_row_expanded(expand_parent)) {
1329 _this.view.el.expand_row(expand_parent,true);
1332 //if (tp != null && (node.items.length() > 0 || pos > 1)) {
1333 // _this.view.el.expand_row(this.el.get_path(iter_par), true);
1335 // wee need to get the empty proptypes from somewhere..
1337 //var olditer = this.activeIter;
1338 this.activePath = this.el.get_path(n_iter).to_string();
1343 _this.view.el.set_cursor(this.el.get_path(n_iter), null, false);
1349 public string treePathFromNode (JsRender.Node node) {
1350 // iterate through the tree and find the node
1353 this.el.foreach((mod, pth, iter) => {
1358 _this.model.el.get_value(iter, 2, out value);
1362 var n = (JsRender.Node)value;
1364 print("compare %s to %s\n", n.fqn(), node.fqn());
1366 ret = pth.to_string();
1376 public class Xcls_TreeViewColumn4 : Object
1378 public Gtk.TreeViewColumn el;
1379 private Xcls_WindowLeftTree _this;
1385 public Xcls_TreeViewColumn4(Xcls_WindowLeftTree _owner )
1388 this.el = new Gtk.TreeViewColumn();
1392 // set gobject values
1393 this.el.title = "test";
1394 var child_0 = new Xcls_renderer( _this );
1396 this.el.pack_start ( child_0.el , true );
1400 this.el.add_attribute(_this.renderer.el , "markup", 0 );
1403 // user defined functions
1405 public class Xcls_renderer : Object
1407 public Gtk.CellRendererText el;
1408 private Xcls_WindowLeftTree _this;
1414 public Xcls_renderer(Xcls_WindowLeftTree _owner )
1417 _this.renderer = this;
1418 this.el = new Gtk.CellRendererText();
1422 // set gobject values
1425 // user defined functions
1430 public class Xcls_LeftTreeMenu : Object
1433 private Xcls_WindowLeftTree _this;
1439 public Xcls_LeftTreeMenu(Xcls_WindowLeftTree _owner )
1442 _this.LeftTreeMenu = this;
1443 this.el = new Gtk.Menu();
1447 // set gobject values
1448 var child_0 = new Xcls_MenuItem7( _this );
1450 this.el.add ( child_0.el );
1451 var child_1 = new Xcls_MenuItem8( _this );
1453 this.el.add ( child_1.el );
1454 var child_2 = new Xcls_MenuItem9( _this );
1456 this.el.add ( child_2.el );
1459 // user defined functions
1461 public class Xcls_MenuItem7 : Object
1463 public Gtk.MenuItem el;
1464 private Xcls_WindowLeftTree _this;
1470 public Xcls_MenuItem7(Xcls_WindowLeftTree _owner )
1473 this.el = new Gtk.MenuItem();
1477 // set gobject values
1478 this.el.label = "Delete Element";
1481 this.el.activate.connect( ( ) => {
1486 _this.model.deleteSelected();
1490 // user defined functions
1493 public class Xcls_MenuItem8 : Object
1495 public Gtk.MenuItem el;
1496 private Xcls_WindowLeftTree _this;
1502 public Xcls_MenuItem8(Xcls_WindowLeftTree _owner )
1505 this.el = new Gtk.MenuItem();
1509 // set gobject values
1510 this.el.label = "Save as Template";
1513 this.el.activate.connect( () => {
1515 DialogSaveTemplate.singleton().show(
1516 (Gtk.Window) _this.el.get_toplevel (),
1517 _this.main_window.windowstate.file.palete(),
1518 _this.getActiveElement()
1525 // user defined functions
1528 public class Xcls_MenuItem9 : Object
1530 public Gtk.MenuItem el;
1531 private Xcls_WindowLeftTree _this;
1537 public Xcls_MenuItem9(Xcls_WindowLeftTree _owner )
1540 this.el = new Gtk.MenuItem();
1544 // set gobject values
1545 this.el.label = "Save as Module";
1548 this.el.activate.connect( () => {
1549 var node = _this.getActiveElement();
1550 var name = DialogSaveModule.singleton().show(
1551 (Gtk.Window) _this.el.get_toplevel (),
1552 _this.main_window.windowstate.project,
1555 if (name.length < 1) {
1559 node.props.set("* xinclude", name);
1563 var s = _this.view.el.get_selection();
1565 print("GET SELECTED?");
1570 if (!s.get_selected(out mod, out iter)) {
1571 return; // nothing seleted..
1574 var n_cn = mod.iter_n_children(iter) -1;
1575 for (var i = n_cn; i > -1; i--) {
1576 mod.iter_nth_child(out citer, iter, i);
1579 print("removing node from Tree\n");
1581 _this.model.el.remove(ref citer);
1584 _this.node_selected(node, "tree");
1590 // user defined functions