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 (JsRender.Node? node);
22 public signal void changed ();
23 public signal void node_selected (JsRender.Node? node);
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 bool drag_in_motion;
84 public bool blockChanges;
87 public Xcls_view(Xcls_WindowLeftTree _owner )
91 this.el = new Gtk.TreeView();
94 this.blockChanges = false;
97 this.el.expand = true;
98 this.el.tooltip_column = 1;
99 this.el.enable_tree_lines = true;
100 this.el.headers_visible = false;
101 var child_0 = new Xcls_model( _this );
103 this.el.set_model ( child_0.el );
104 var child_1 = new Xcls_TreeViewColumn4( _this );
106 this.el.append_column ( child_1.el );
111 var description = new Pango.FontDescription();
112 description.set_size(8000);
113 this.el.override_font(description);
115 var selection = this.el.get_selection();
116 selection.set_mode( Gtk.SelectionMode.SINGLE);
119 // is this really needed??
121 this.selection.signal['changed'].connect(function() {
122 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
123 _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
127 Gtk.drag_source_set (
128 this.el, /* widget will be drag-able */
129 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
130 BuilderApplication.targetList, /* lists of target to support */
131 Gdk.DragAction.COPY | Gdk.DragAction.MOVE | Gdk.DragAction.LINK /* what to do with data after dropped */
135 //Gtk.drag_source_add_text_targets(this.el);
139 this.el, /* widget that will accept a drop */
140 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
141 BuilderApplication.targetList, /* lists of target to support */
142 Gdk.DragAction.COPY | Gdk.DragAction.MOVE | Gdk.DragAction.LINK /* what to do with data after dropped */
145 //Gtk.drag_dest_set_target_list(this.el, Builder.Application.targetList);
146 //Gtk.drag_dest_add_text_targets(this.el);
150 this.el.button_press_event.connect( ( ev) => {
151 //console.log("button press?");
152 if (! _this.before_node_change(null) ) {
157 if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button != 3) {
158 //print("click" + ev.type);
162 if (!_this.view.el.get_path_at_pos((int)ev.x,(int)ev.y, out res, null, null, null) ) {
166 this.el.get_selection().select_path(res);
168 //if (!this.get('/LeftTreeMenu').el) {
169 // this.get('/LeftTreeMenu').init();
172 _this.LeftTreeMenu.el.set_screen(Gdk.Screen.get_default());
173 _this.LeftTreeMenu.el.show_all();
174 _this.LeftTreeMenu.el.popup(null, null, null, 3, ev.time);
175 // print("click:" + res.path.to_string());
178 this.el.drag_begin.connect( ( ctx) => {
179 //print('SOURCE: drag-begin');
182 //this.targetData = "";
184 // find what is selected in our tree...
186 var s = _this.view.el.get_selection();
187 if (s.count_selected_rows() < 1) {
192 s.get_selected(out mod, out iter);
196 // set some properties of the tree for use by the dropped element.
198 _this.model.el.get_value(iter, 2, out value);
199 var tp = mod.get_path(iter).to_string();
200 var data = (JsRender.Node)(value.dup_object());
201 var xname = data.fqn();
202 print ("XNAME IS " + xname+ "\n");
204 this.dropList = _this.main_window.windowstate.file.palete().getDropList(xname);
206 print ("DROP LIST IS " + string.joinv(", ", this.dropList) + "\n");
209 // make the drag icon a picture of the node that was selected
212 // by default returns the path..
213 var path = _this.model.el.get_path(iter);
216 var pix = this.el.create_row_drag_icon ( path);
218 Gtk.drag_set_icon_surface (ctx, pix) ;
222 this.el.cursor_changed.connect( ( ) => {
225 if (this.blockChanges) { // probably not needed..
228 if (!_this.before_node_change(null) ) {
229 this.blockChanges = true;
230 this.el.get_selection().unselect_all();
231 this.blockChanges = false;
234 if (_this.main_window.windowstate.file == null) {
238 //var render = this.get('/LeftTree').getRenderer();
239 print("LEFT TREE -> view -> selection changed called\n");
242 // -- it appears that the selection is not updated.
244 GLib.Timeout.add_full(GLib.Priority.DEFAULT,10 , () => {
247 if (this.el.get_selection().count_selected_rows() < 1) {
249 print("selected rows < 1\n");
250 //??this.model.load( false);
251 _this.node_selected(null);
256 //console.log('changed');
257 var s = this.el.get_selection();
260 s.get_selected(out mod, out iter);
265 _this.model.el.get_value(iter, 2, out value);
266 _this.model.activePath = mod.get_path(iter).to_string();
268 var node = (JsRender.Node)value.dup_object();
269 _this.node_selected(node);
270 while (Gtk.events_pending()) {
271 Gtk.main_iteration();
273 var cp = mod.get_path(iter);
275 this.el.get_visible_range(out sp, out ep);
276 // if sp is before cp then retuns 1.
277 // if cp is before ep then retuns 1.
278 if (cp.compare(sp) >= 0 && ep.compare(cp) >=1) {
284 this.el.scroll_to_cell(new Gtk.TreePath.from_string(_this.model.activePath), null, true, 0.1f,0.0f);
288 //_this.after_node_change(node);
290 // _this.model.file.changed(node, "tree");
292 //Seed.print( value.get_string());
296 this.el.drag_end.connect( (drag_context) => {
297 //Seed.print('LEFT-TREE: drag-end');
299 this.dropList = null;
300 // this.targetData = "";
301 this.highlightDropPath("",0);
304 this.el.drag_motion.connect( ( ctx, x, y, time) => {
305 print("got drag motion\n");
306 var src = Gtk.drag_get_source_widget(ctx);
310 if (src != this.el) {
314 // the point of this is to detect where an item could be dropped..
315 print("requesting drag data\n");
316 this.drag_in_motion = true;
318 // request data that will be recieved by the recieve...
321 this.el, // will receive 'drag-data-received' signal
322 ctx, // represents the current state of the DnD
323 Gdk.Atom.intern("STRING",true), // the target type we want
330 print("action: %d\n", ctx.get_actions());
331 //print("GETTING POS");
335 Gtk.TreeViewDropPosition pos;
336 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
338 // if there are not items in the tree.. the we have to set isOver to true for anything..
340 if (_this.model.el.iter_n_children(null) < 1) {
341 print("got NO children?\n");
344 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
348 // ------------- a drag from self..
351 //var action = Gdk.DragAction.COPY;
352 // unless we are copying!!! ctl button..
354 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
355 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
356 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
359 if (_this.model.el.iter_n_children(null) < 1) {
360 // no children.. -- asume it's ok..
362 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
364 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
365 Gdk.drag_status(ctx, action ,time);
368 // continue through to allow drop...
376 //print("ISOVER? " + isOver);
379 Gdk.drag_status(ctx, 0 ,time);
380 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
385 // drag node is parent of child..
386 //console.log("SRC TREEPATH: " + src.treepath);
387 //console.log("TARGET TREEPATH: " + data.path.to_string());
389 // nned to check a few here..
390 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
391 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
392 //Gtk.TreeViewDropPosition.AFTER
393 //Gtk.TreeViewDropPosition.BEFORE
395 // locally dragged items to not really use the
396 var selection_text = this.dragData;
400 if (selection_text == null || selection_text.length < 1) {
401 //print("Error - drag selection text returned NULL");
402 Gdk.drag_status(ctx, 0 ,time);
403 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
408 // see if we are dragging into ourself?
409 var target_path = path.to_string();
410 print ("Drag %s onto %s--%d\n ", selection_text, target_path, pos);
412 // pos : 3 = ontop - 0 = after, 1 = before
413 //print("target_path="+target_path);
416 if (selection_text == target_path) {
417 print("self drag ?? == we should perhaps allow copy onto self..\n");
419 Gdk.drag_status(ctx, 0 ,time);
420 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
422 // -- fixme -- this is not really correct..
427 //print("DUMPING DATA");
428 //console.dump(data);
431 //print(data.path.to_string() +' => '+ data.pos);
433 // dropList is a list of xtypes that this node could be dropped on.
434 // it is set up when we start to drag..
437 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
439 print("targetDAta: " + targetData +"\n");
441 if (targetData.length < 1) {
442 //print("Can not find drop node path");
444 Gdk.drag_status(ctx, 0, time);
445 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
449 var td_ar = targetData.split("|");
453 Gdk.drag_status(ctx, action ,time);
454 this.highlightDropPath(td_ar[0], (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
459 this.el.drag_data_get.connect( ( drag_context, data, info, time) => {
462 //print("drag-data-get");
463 var s = this.el.get_selection();
464 if (s.count_selected_rows() < 1) {
466 print("return empty string - no selection..");
473 s.get_selected(out mod, out iter);
478 _this.model.el.get_value(iter, 2, out value);
479 var ndata = (JsRender.Node)(value.dup_object());
483 var tp = mod.get_path(iter).to_string();
484 // by default returns the path..
486 if ( info != Gdk.Atom.intern("STRING",true) ) {
487 tp = ndata.toJsonString();
490 //data.set_text(tp,tp.length);
492 data.set (data.get_target (), 8, (uchar[]) tp.to_utf8 ());
495 // print("return " + tp);
497 this.el.drag_data_received.connect( (ctx, x, y, sel, info, time) => {
499 // THIS CODE ONLY RELATES TO drag or drop of "NEW" elements or "FROM another tree.."
502 // print("Tree: drag-data-received\n");
503 var selection_text = (string)sel.get_data();
504 //print("selection_text= %s\n",selection_text);
506 var is_drag = this.drag_in_motion;
510 print("Is Drag %s\n", is_drag ? "Y": "N");
514 Gtk.TreeViewDropPosition pos;
515 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
517 // if there are not items in the tree.. the we have to set isOver to true for anything..
519 if (_this.model.el.iter_n_children(null) < 1) {
520 print("got NO children?\n");
523 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
527 //console.log("LEFT-TREE: drag-motion");
528 var src = Gtk.drag_get_source_widget(ctx);
530 // a drag from self - this should be handled by drop and motion.
531 if (src == this.el) {
532 print("Source == this element should not happen.. ? \n");
535 //print("drag_data_recieved from another element");
540 if (selection_text == null || selection_text.length < 1 || !isOver) {
541 // nothing valid foudn to drop...
542 print("empty sel text or not over");
544 Gdk.drag_status(ctx, 0, time);
545 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
548 Gtk.drag_finish (ctx, false, false, time); // drop failed..
553 var dropNode = new JsRender.Node();
555 var dropNodeType = selection_text;
556 var show_templates = true;
558 if (dropNodeType[0] == '{') {
559 var pa = new Json.Parser();
561 pa.load_from_data(dropNodeType);
563 Gtk.drag_finish (ctx, false, false, time); // drop failed..
568 dropNode.loadFromJson( pa.get_root().get_object(), 2);
569 dropNodeType = dropNode.fqn();
570 show_templates = false;
575 dropNode.setFqn(selection_text);
579 // dropList --- need to gather this ...
580 print("get dropList for : %s\n",dropNodeType);
581 var dropList = _this.main_window.windowstate.file.palete().getDropList(dropNodeType);
583 print("dropList: %s\n", string.joinv(" , ", dropList));
585 // if drag action is link ... then we can drop it anywahere...
586 if ((ctx.get_actions() & Gdk.DragAction.LINK) > 0) {
587 // if path is null?? dragging into an empty tree?
588 targetData = (path == null ? "" : path.to_string()) + "|%d".printf((int)pos);
592 targetData = _this.model.findDropNodeByPath( isEmpty ? "" : path.to_string(), dropList, pos);
597 print("targetDAta: " + targetData +"\n");
599 if (targetData.length < 1) {
601 // invalid drop path..
602 if (this.drag_in_motion) {
603 Gdk.drag_status(ctx, 0, time);
604 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
607 Gtk.drag_finish (ctx, false, false, time); // drop failed..
613 var td_ar = targetData.split("|");
616 if (this.drag_in_motion) {
617 Gdk.drag_status(ctx, Gdk.DragAction.COPY ,time);
619 this.highlightDropPath( td_ar[0] , (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
622 // continue on to allow drop..
625 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
628 _this.model.dropNode(targetData, dropNode, show_templates);
629 print("ADD new node!!!\n");
631 ///Xcls_DialogTemplateSelect.singleton().show( _this.model.file.palete(), node);
633 Gtk.drag_finish (ctx, false, false,time);
640 this.el.drag_drop.connect( ( ctx, x, y, time) => {
641 //Seed.print("TARGET: drag-drop");
644 var src = Gtk.drag_get_source_widget(ctx);
646 if (src != this.el) {
650 this.drag_in_motion = false;
651 // request data that will be recieved by the recieve...
654 this.el, // will receive 'drag-data-received' signal
655 ctx, // represents the current state of the DnD
656 Gdk.Atom.intern("application/json",true), // the target type we want
661 // No target offered by source => error
667 // handle drop around self..
671 //print("GETTING POS");
675 Gtk.TreeViewDropPosition pos;
676 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
678 // if there are not items in the tree.. the we have to set isOver to true for anything..
680 if (_this.model.el.iter_n_children(null) < 1) {
681 print("got NO children?\n");
684 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
689 //var action = Gdk.DragAction.COPY;
690 // unless we are copying!!! ctl button..
692 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
693 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
694 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
697 if (_this.model.el.iter_n_children(null) < 1) {
698 // no children.. -- asume it's ok..
700 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
702 // continue through to allow drop...
710 //print("ISOVER? " + isOver);
713 Gtk.drag_finish (ctx, false, false, time); // drop failed..
714 return true; // not over apoint!?! - no action on drop or motion..
717 // drag node is parent of child..
718 //console.log("SRC TREEPATH: " + src.treepath);
719 //console.log("TARGET TREEPATH: " + data.path.to_string());
721 // nned to check a few here..
722 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
723 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
724 //Gtk.TreeViewDropPosition.AFTER
725 //Gtk.TreeViewDropPosition.BEFORE
727 // locally dragged items to not really use the
728 var selection_text = this.dragData;
732 if (selection_text == null || selection_text.length < 1) {
733 //print("Error - drag selection text returned NULL");
735 Gtk.drag_finish (ctx, false, false, time); // drop failed..
736 return true; /// -- fixme -- this is not really correct..
739 // see if we are dragging into ourself?
740 print ("got selection text of " + selection_text);
742 var target_path = path.to_string();
743 //print("target_path="+target_path);
746 if (selection_text == target_path) {
747 print("self drag ?? == we should perhaps allow copy onto self..\n");
749 Gtk.drag_finish (ctx, false, false, time); // drop failed..
751 return true; /// -- fixme -- this is not really correct..
756 //print("DUMPING DATA");
757 //console.dump(data);
760 //print(data.path.to_string() +' => '+ data.pos);
762 // dropList is a list of xtypes that this node could be dropped on.
763 // it is set up when we start to drag..
766 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
768 print("targetDAta: " + targetData +"\n");
770 if (targetData.length < 1) {
771 //print("Can not find drop node path");
773 Gtk.drag_finish (ctx, false, false, time); // drop failed..
779 // continue on to allow drop..
781 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
784 var delete_selection_data = false;
786 if (action == Gdk.DragAction.ASK) {
787 /* Ask the user to move or copy, then set the ctx action. */
790 if (action == Gdk.DragAction.MOVE) {
791 delete_selection_data = true;
794 // drag around.. - reorder..
795 _this.model.moveNode(targetData, action);
801 // we can send stuff to souce here...
804 // do we always say failure, so we handle the reall drop?
805 Gtk.drag_finish (ctx, false, false,time); //delete_selection_data, time);
817 // user defined functions
818 public void highlightDropPath ( string treepath, Gtk.TreeViewDropPosition pos) {
820 // highlighting for drag/drop
821 if (treepath.length > 0) {
822 this.el.set_drag_dest_row( new Gtk.TreePath.from_string( treepath ), pos);
824 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
828 public void selectNode (string treepath_str) {
829 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
830 var tp = new Gtk.TreePath.from_string(treepath_str);
832 this.el.set_cursor(tp, null, false);
833 this.el.scroll_to_cell(tp, null, false, 0,0);
836 public class Xcls_model : Object
838 public Gtk.TreeStore el;
839 private Xcls_WindowLeftTree _this;
843 public DialogTemplateSelect template_select;
844 public string activePath;
847 public Xcls_model(Xcls_WindowLeftTree _owner )
851 this.el = new Gtk.TreeStore( 3, typeof(string),typeof(string),typeof(Object) );
854 this.template_select = null;
855 this.activePath = "";
857 // set gobject values
861 print("model initialized");
864 // user defined functions
865 public string findDropNode (string treepath_str, string[] targets) {
867 // this is used by the dragdrop code in the roo version AFAIR..
869 //var path = treepath_str.replace(/^builder-/, '');
870 // treemap is depreciated... - should really check if model has any entries..
872 if (this.el.iter_n_children(null) < 1) {
874 return "|%d".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
876 //print("FIND treepath: " + path);
877 //console.dump(this.treemap);
879 //if (!treepath_str.match(/^builder-/)) {
880 // return []; // nothing!
882 if (targets.length > 0 && targets[0] == "*") {
885 return this.findDropNodeByPath(treepath_str,targets, -1);
887 public void loadFile (JsRender.JsRender f) {
892 _this.main_window.windowstate.file = f;
895 if (f.tree == null) {
902 // if it's still null?
903 if (f.tree == null) {
907 var o = new Gee.ArrayList<JsRender.Node>();
911 _this.view.el.expand_all();
913 if (f.tree.items.size < 1) {
916 //this.get('/Window.leftvpaned').el.set_position(80);
918 _this.view.el.set_cursor(
919 new Gtk.TreePath.from_string("0"), null, false);
923 //this.get('/Window.leftvpaned').el.set_position(200);
930 public void updateSelected () {
933 var s = _this.view.el.get_selection();
940 if (!s.get_selected(out mod, out iter)) {
941 return; // nothing seleted..
945 this.el.get_value(iter, 2, out value);
946 var node = (JsRender.Node)(value.get_object());
948 this.el.set(iter, 0, node.nodeTitle(),
949 1, node.nodeTip(), -1
952 public string findDropNodeByPath (string treepath_str, string[] targets, int in_pref = -1) {
954 var path = treepath_str; // dupe it..
957 // pref : 3 = ontop - 0 = after, 1 = before
958 int pref = in_pref < 0 ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : in_pref;
962 //console.dump(this.treemap);
964 print("findDropNodeByPath : got path length %d / %s\n", path.length, path);
966 if (path.length == 0) {
967 // top drop. // just return empty..
968 return "|%d".printf((int)pref) ;
973 while (path.length > 0) {
975 if (path.length == treepath_str.length && pref != Gtk.TreeViewDropPosition.INTO_OR_AFTER) {
976 if (path.last_index_of(":") < 0 ) {
979 path = path.substring(0, path.last_index_of(":"));
981 print("DROP before or after : using %s\n",path);
985 //print("LOOKING FOR PATH: " + path);
986 var node_data = this.pathToNode(path);
988 if (node_data == null) {
989 print("node not found");
993 var xname = node_data.fqn();
997 for (var i =0; i < targets.length; i++) {
999 if ((tg == xname) ) {
1003 // if target is "xxxx:name"
1004 if (tg.contains(xname +":")) {
1006 var ar = tg.split(":");
1012 if (match.length > 0) {
1013 if (last.length > 0) { // pref is after/before..
1014 // then it's after last
1018 return last + "|%d".printf((int)pref) + "|" + prop;
1022 // we need to add prop - as :store -> needs to bee added when dropping onto.
1023 return path + "|%d".printf( (int) Gtk.TreeViewDropPosition.INTO_OR_AFTER) + "|" + prop;
1027 var par = path.split(":");
1028 string [] ppar = {};
1029 for (var i = 0; i < par.length-1; i++) {
1033 path = string.joinv(":", ppar);
1042 public void moveNode (string target_data, Gdk.DragAction action)
1045 /// target_data = "path|pos");
1048 //print("MOVE NODE");
1049 // console.dump(target_data);
1050 Gtk.TreeIter old_iter;
1053 var s = _this.view.el.get_selection();
1054 s.get_selected(out mod , out old_iter);
1055 mod.get_path(old_iter);
1057 var node = this.pathToNode(mod.get_path(old_iter).to_string());
1058 //console.dump(node);
1060 print("moveNode: ERROR - node is null?");
1065 // needs to drop first, otherwise the target_data
1066 // treepath will be invalid.
1069 if ((action & Gdk.DragAction.MOVE) > 0) {
1070 print("REMOVING OLD NODE : " + target_data + "\n");
1072 this.dropNode(target_data, node, false);
1073 this.el.remove(ref old_iter);
1078 print("DROPPING NODE // copy: " + target_data + "\n");
1079 node = node.deepClone();
1080 this.dropNode(target_data, node, false);
1083 this.activePath= "";
1084 //this.updateNode(false,true);
1086 public void load (Gee.ArrayList<JsRender.Node> tr, Gtk.TreeIter? iter)
1089 //this.insert(citer,iter,0);
1090 for(var i =0 ; i < tr.size; i++) {
1092 this.el.insert(out citer,iter,-1); // why not append?
1094 this.el.append(out citer,null);
1097 this.el.set(citer, 0, tr.get(i).nodeTitle(),
1098 1, tr.get(i).nodeTip(), -1
1100 var o = GLib.Value(typeof(Object));
1101 o.set_object((Object)tr.get(i));
1103 this.el.set_value(citer, 2, o);
1105 if (tr.get(i).items.size > 0) {
1106 this.load(tr.get(i).items, citer);
1113 public void deleteSelected () {
1115 print("DELETE SELECTED?");
1116 //_this.view.blockChanges = true;
1117 print("GET SELECTION?");
1119 var s = _this.view.el.get_selection();
1121 print("GET SELECTED?");
1126 if (!s.get_selected(out mod, out iter)) {
1127 return; // nothing seleted..
1132 this.activePath= "";
1133 print("GET vnode value?");
1136 this.el.get_value(iter, 2, out value);
1137 var data = (JsRender.Node)(value.get_object());
1138 print("removing node from Render\n");
1139 if (data.parent == null) {
1140 _this.main_window.windowstate.file.tree = null;
1144 print("removing node from Tree\n");
1146 this.el.remove(ref iter);
1156 this.activePath= ""; // again!?!?
1157 //this.changed(null,true);
1161 _this.view.blockChanges = false;
1163 public JsRender.Node pathToNode (string path) {
1167 _this.model.el.get_iter_from_string(out iter, path);
1170 _this.model.el.get_value(iter, 2, out value);
1172 return (JsRender.Node)value.dup_object();
1175 public void dropNode (string target_data_str, JsRender.Node node, bool show_templates) {
1176 // print("drop Node");
1177 // console.dump(node);
1178 // console.dump(target_data);
1181 // 0 = before , 1=after 2/3 onto
1184 var target_data= target_data_str.split("|");
1186 var parent_str = target_data[0].length > 0 ? target_data[0] : "";
1187 var pos = target_data.length > 1 ? int.parse(target_data[1]) : 2; // ontop..
1190 Gtk.TreePath tree_path = parent_str.length > 0 ? new Gtk.TreePath.from_string( parent_str ) : null;
1194 //print("add " + tp + "@" + target_data[1] );
1196 JsRender.Node parentNode = null;
1198 Gtk.TreeIter iter_after;
1199 Gtk.TreeIter iter_par ;
1202 if (target_data.length == 3 && target_data[2].length > 0) {
1203 node.props.set("* prop", target_data[2]);
1206 Gtk.TreePath expand_parent = null;
1208 // we only need to show the template if it's come from else where?
1209 if (show_templates) {
1211 var ts = _this.main_window.windowstate.template_select;
1213 var new_node = ts.show(
1214 _this.main_window, // (Gtk.Window) _this.el.get_toplevel (),
1215 _this.main_window.windowstate.file.palete(),
1217 _this.main_window.windowstate.project);
1219 if (new_node == null) {
1220 return; // do not add?
1225 //print("pos is %d \n".printf(pos));
1227 Gtk.TreeIter n_iter;
1229 if ( parent_str.length < 1) {
1230 this.el.append(out n_iter, null); // drop at top level..
1232 _this.main_window.windowstate.file.tree = node;
1235 } else if (pos < 2) {
1236 //print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
1238 this.el.get_iter(out iter_after, tree_path );
1239 this.el.iter_parent(out iter_par, iter_after);
1240 expand_parent = this.el.get_path(iter_par);
1243 this.el.get_value( iter_par, 2, out value);
1244 parentNode = (JsRender.Node)value.dup_object();
1247 this.el.get_value( iter_after, 2, out value);
1248 var relNode = (JsRender.Node)value.dup_object();
1252 this.el.insert_after(out n_iter, iter_par , iter_after);
1253 var ix = parentNode.items.index_of(relNode);
1254 parentNode.items.insert(ix+1, node);
1257 this.el.insert_before(out n_iter, iter_par , iter_after);
1258 var ix = parentNode.items.index_of(relNode);
1259 parentNode.items.insert(ix, node);
1262 node.parent = parentNode;
1267 // print("appending to " + parent_str);
1268 this.el.get_iter(out iter_par, tree_path);
1269 this.el.append(out n_iter, iter_par );
1270 expand_parent = this.el.get_path(iter_par);
1273 this.el.get_value( iter_par, 2, out value);
1274 parentNode = (JsRender.Node)value.dup_object();
1275 node.parent = parentNode;
1276 parentNode.items.add(node);
1279 // reparent node in tree...
1282 // why only on no parent???
1284 //if (node.parent = null) {
1291 // work out what kind of packing to use.. -- should be in
1292 if (!node.has("pack") && parent_str.length > 1) {
1294 _this.main_window.windowstate.file.palete().fillPack(node,parentNode);
1301 this.el.set(n_iter, 0, node.nodeTitle(), 1, node.nodeTip(), -1 );
1302 var o = GLib.Value(typeof(Object));
1303 o.set_object((Object)node);
1305 this.el.set_value(n_iter, 2, o);
1310 // load children - if it has any..
1312 if (node.items.size > 0) {
1313 this.load(node.items, n_iter);
1314 _this.view.el.expand_row(this.el.get_path(n_iter), true);
1315 } else if (expand_parent != null && !_this.view.el.is_row_expanded(expand_parent)) {
1316 _this.view.el.expand_row(expand_parent,true);
1319 //if (tp != null && (node.items.length() > 0 || pos > 1)) {
1320 // _this.view.el.expand_row(this.el.get_path(iter_par), true);
1322 // wee need to get the empty proptypes from somewhere..
1324 //var olditer = this.activeIter;
1325 this.activePath = this.el.get_path(n_iter).to_string();
1330 _this.view.el.set_cursor(this.el.get_path(n_iter), null, false);
1336 public string treePathFromNode (JsRender.Node node) {
1337 // iterate through the tree and find the node
1340 this.el.foreach((mod, pth, iter) => {
1345 _this.model.el.get_value(iter, 2, out value);
1349 var n = (JsRender.Node)value;
1351 print("compare %s to %s\n", n.fqn(), node.fqn());
1353 ret = pth.to_string();
1363 public class Xcls_TreeViewColumn4 : Object
1365 public Gtk.TreeViewColumn el;
1366 private Xcls_WindowLeftTree _this;
1372 public Xcls_TreeViewColumn4(Xcls_WindowLeftTree _owner )
1375 this.el = new Gtk.TreeViewColumn();
1379 // set gobject values
1380 this.el.title = "test";
1381 var child_0 = new Xcls_renderer( _this );
1383 this.el.pack_start ( child_0.el , true );
1387 this.el.add_attribute(_this.renderer.el , "markup", 0 );
1390 // user defined functions
1392 public class Xcls_renderer : Object
1394 public Gtk.CellRendererText el;
1395 private Xcls_WindowLeftTree _this;
1401 public Xcls_renderer(Xcls_WindowLeftTree _owner )
1404 _this.renderer = this;
1405 this.el = new Gtk.CellRendererText();
1409 // set gobject values
1412 // user defined functions
1417 public class Xcls_LeftTreeMenu : Object
1420 private Xcls_WindowLeftTree _this;
1426 public Xcls_LeftTreeMenu(Xcls_WindowLeftTree _owner )
1429 _this.LeftTreeMenu = this;
1430 this.el = new Gtk.Menu();
1434 // set gobject values
1435 var child_0 = new Xcls_MenuItem7( _this );
1437 this.el.add ( child_0.el );
1438 var child_1 = new Xcls_MenuItem8( _this );
1440 this.el.add ( child_1.el );
1441 var child_2 = new Xcls_MenuItem9( _this );
1443 this.el.add ( child_2.el );
1446 // user defined functions
1448 public class Xcls_MenuItem7 : Object
1450 public Gtk.MenuItem el;
1451 private Xcls_WindowLeftTree _this;
1457 public Xcls_MenuItem7(Xcls_WindowLeftTree _owner )
1460 this.el = new Gtk.MenuItem();
1464 // set gobject values
1465 this.el.label = "Delete Element";
1468 this.el.activate.connect( ( ) => {
1473 _this.model.deleteSelected();
1477 // user defined functions
1480 public class Xcls_MenuItem8 : Object
1482 public Gtk.MenuItem el;
1483 private Xcls_WindowLeftTree _this;
1489 public Xcls_MenuItem8(Xcls_WindowLeftTree _owner )
1492 this.el = new Gtk.MenuItem();
1496 // set gobject values
1497 this.el.label = "Save as Template";
1500 this.el.activate.connect( () => {
1502 DialogSaveTemplate.singleton().show(
1503 (Gtk.Window) _this.el.get_toplevel (),
1504 _this.main_window.windowstate.file.palete(),
1505 _this.getActiveElement()
1512 // user defined functions
1515 public class Xcls_MenuItem9 : Object
1517 public Gtk.MenuItem el;
1518 private Xcls_WindowLeftTree _this;
1524 public Xcls_MenuItem9(Xcls_WindowLeftTree _owner )
1527 this.el = new Gtk.MenuItem();
1531 // set gobject values
1532 this.el.label = "Save as Module";
1535 this.el.activate.connect( () => {
1536 var node = _this.getActiveElement();
1537 var name = DialogSaveModule.singleton().show(
1538 (Gtk.Window) _this.el.get_toplevel (),
1539 _this.main_window.windowstate.project,
1542 if (name.length < 1) {
1546 node.props.set("* xinclude", name);
1550 var s = _this.view.el.get_selection();
1552 print("GET SELECTED?");
1557 if (!s.get_selected(out mod, out iter)) {
1558 return; // nothing seleted..
1561 var n_cn = mod.iter_n_children(iter) -1;
1562 for (var i = n_cn; i > -1; i--) {
1563 mod.iter_nth_child(out citer, iter, i);
1566 print("removing node from Tree\n");
1568 _this.model.el.remove(ref citer);
1571 _this.node_selected(node);
1577 // user defined functions