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.model.file;
61 public string getActivePath () {
62 var model = this.model;
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.tooltip_column = 1;
98 this.el.enable_tree_lines = true;
99 this.el.headers_visible = false;
100 var child_0 = new Xcls_model( _this );
102 this.el.set_model ( child_0.el );
103 var child_1 = new Xcls_TreeViewColumn4( _this );
105 this.el.append_column ( child_1.el );
110 var description = new Pango.FontDescription();
111 description.set_size(8000);
112 this.el.modify_font(description);
114 var selection = this.el.get_selection();
115 selection.set_mode( Gtk.SelectionMode.SINGLE);
118 // is this really needed??
120 this.selection.signal['changed'].connect(function() {
121 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
122 _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
126 Gtk.drag_source_set (
127 this.el, /* widget will be drag-able */
128 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
129 BuilderApplication.targetList, /* lists of target to support */
130 Gdk.DragAction.COPY | Gdk.DragAction.MOVE | Gdk.DragAction.LINK /* what to do with data after dropped */
134 //Gtk.drag_source_add_text_targets(this.el);
138 this.el, /* widget that will accept a drop */
139 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
140 BuilderApplication.targetList, /* lists of target to support */
141 Gdk.DragAction.COPY | Gdk.DragAction.MOVE | Gdk.DragAction.LINK /* what to do with data after dropped */
144 //Gtk.drag_dest_set_target_list(this.el, Builder.Application.targetList);
145 //Gtk.drag_dest_add_text_targets(this.el);
149 this.el.button_press_event.connect( ( ev) => {
150 //console.log("button press?");
151 if (! _this.before_node_change(null) ) {
156 if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button != 3) {
157 //print("click" + ev.type);
161 if (!_this.view.el.get_path_at_pos((int)ev.x,(int)ev.y, out res, null, null, null) ) {
165 this.el.get_selection().select_path(res);
167 //if (!this.get('/LeftTreeMenu').el) {
168 // this.get('/LeftTreeMenu').init();
171 _this.LeftTreeMenu.el.set_screen(Gdk.Screen.get_default());
172 _this.LeftTreeMenu.el.show_all();
173 _this.LeftTreeMenu.el.popup(null, null, null, 3, ev.time);
174 // print("click:" + res.path.to_string());
177 this.el.drag_begin.connect( ( ctx) => {
178 //print('SOURCE: drag-begin');
181 //this.targetData = "";
183 // find what is selected in our tree...
185 var s = _this.view.el.get_selection();
186 if (s.count_selected_rows() < 1) {
191 s.get_selected(out mod, out iter);
195 // set some properties of the tree for use by the dropped element.
197 _this.model.el.get_value(iter, 2, out value);
198 var tp = mod.get_path(iter).to_string();
199 var data = (JsRender.Node)(value.dup_object());
200 var xname = data.fqn();
201 print ("XNAME IS " + xname+ "\n");
203 this.dropList = _this.model.file.palete().getDropList(xname);
205 print ("DROP LIST IS " + string.joinv(", ", this.dropList) + "\n");
208 // make the drag icon a picture of the node that was selected
211 // by default returns the path..
212 var path = _this.model.el.get_path(iter);
215 var pix = this.el.create_row_drag_icon ( path);
217 Gtk.drag_set_icon_surface (ctx, pix) ;
221 this.el.cursor_changed.connect( ( ) => {
224 if (this.blockChanges) { // probably not needed..
227 if (!_this.before_node_change(null) ) {
228 this.blockChanges = true;
229 this.el.get_selection().unselect_all();
230 this.blockChanges = false;
233 if (_this.model.file == null) {
237 //var render = this.get('/LeftTree').getRenderer();
238 print("LEFT TREE -> view -> selection changed called\n");
241 // -- it appears that the selection is not updated.
243 GLib.Timeout.add_full(GLib.Priority.DEFAULT,10 , () => {
246 if (this.el.get_selection().count_selected_rows() < 1) {
248 print("selected rows < 1\n");
249 //??this.model.load( false);
250 _this.node_selected(null);
255 //console.log('changed');
256 var s = this.el.get_selection();
259 s.get_selected(out mod, out iter);
264 _this.model.el.get_value(iter, 2, out value);
265 _this.model.activePath = mod.get_path(iter).to_string();
267 var node = (JsRender.Node)value.dup_object();
268 _this.node_selected(node);
271 //_this.after_node_change(node);
273 // _this.model.file.changed(node, "tree");
275 //Seed.print( value.get_string());
279 this.el.drag_end.connect( (drag_context) => {
280 //Seed.print('LEFT-TREE: drag-end');
282 this.dropList = null;
283 // this.targetData = "";
284 this.highlightDropPath("",0);
287 this.el.drag_motion.connect( ( ctx, x, y, time) => {
288 print("got drag motion\n");
289 var src = Gtk.drag_get_source_widget(ctx);
293 if (src != this.el) {
297 // the point of this is to detect where an item could be dropped..
298 print("requesting drag data\n");
299 this.drag_in_motion = true;
301 // request data that will be recieved by the recieve...
304 this.el, // will receive 'drag-data-received' signal
305 ctx, // represents the current state of the DnD
306 Gdk.Atom.intern("STRING",true), // the target type we want
313 print("action: %d\n", ctx.get_actions());
314 //print("GETTING POS");
318 Gtk.TreeViewDropPosition pos;
319 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
321 // if there are not items in the tree.. the we have to set isOver to true for anything..
323 if (_this.model.el.iter_n_children(null) < 1) {
324 print("got NO children?\n");
327 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
331 // ------------- a drag from self..
334 //var action = Gdk.DragAction.COPY;
335 // unless we are copying!!! ctl button..
337 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
338 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
339 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
342 if (_this.model.el.iter_n_children(null) < 1) {
343 // no children.. -- asume it's ok..
345 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
347 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
348 Gdk.drag_status(ctx, action ,time);
351 // continue through to allow drop...
359 //print("ISOVER? " + isOver);
362 Gdk.drag_status(ctx, 0 ,time);
363 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
368 // drag node is parent of child..
369 //console.log("SRC TREEPATH: " + src.treepath);
370 //console.log("TARGET TREEPATH: " + data.path.to_string());
372 // nned to check a few here..
373 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
374 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
375 //Gtk.TreeViewDropPosition.AFTER
376 //Gtk.TreeViewDropPosition.BEFORE
378 // locally dragged items to not really use the
379 var selection_text = this.dragData;
383 if (selection_text == null || selection_text.length < 1) {
384 //print("Error - drag selection text returned NULL");
385 Gdk.drag_status(ctx, 0 ,time);
386 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
391 // see if we are dragging into ourself?
392 var target_path = path.to_string();
393 print ("Drag %s onto %s--%d\n ", selection_text, target_path, pos);
395 // pos : 3 = ontop - 0 = after, 1 = before
396 //print("target_path="+target_path);
399 if (selection_text == target_path) {
400 print("self drag ?? == we should perhaps allow copy onto self..\n");
402 Gdk.drag_status(ctx, 0 ,time);
403 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
405 // -- fixme -- this is not really correct..
410 //print("DUMPING DATA");
411 //console.dump(data);
414 //print(data.path.to_string() +' => '+ data.pos);
416 // dropList is a list of xtypes that this node could be dropped on.
417 // it is set up when we start to drag..
420 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
422 print("targetDAta: " + targetData +"\n");
424 if (targetData.length < 1) {
425 //print("Can not find drop node path");
427 Gdk.drag_status(ctx, 0, time);
428 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
432 var td_ar = targetData.split("|");
436 Gdk.drag_status(ctx, action ,time);
437 this.highlightDropPath(td_ar[0], (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
442 this.el.drag_data_get.connect( ( drag_context, data, info, time) => {
445 //print("drag-data-get");
446 var s = this.el.get_selection();
447 if (s.count_selected_rows() < 1) {
449 print("return empty string - no selection..");
456 s.get_selected(out mod, out iter);
461 _this.model.el.get_value(iter, 2, out value);
462 var ndata = (JsRender.Node)(value.dup_object());
463 var xname = ndata.fqn();
466 var tp = mod.get_path(iter).to_string();
467 // by default returns the path..
469 if ( info != Gdk.Atom.intern("STRING",true) ) {
470 tp = ndata.toJsonString();
473 //data.set_text(tp,tp.length);
475 data.set (data.get_target (), 8, (uchar[]) tp.to_utf8 ());
478 // print("return " + tp);
480 this.el.drag_data_received.connect( (ctx, x, y, sel, info, time) => {
482 // THIS CODE ONLY RELATES TO drag or drop of "NEW" elements or "FROM another tree.."
485 // print("Tree: drag-data-received\n");
486 var selection_text = (string)sel.get_data();
487 //print("selection_text= %s\n",selection_text);
489 var is_drag = this.drag_in_motion;
493 print("Is Drag %s\n", is_drag ? "Y": "N");
497 Gtk.TreeViewDropPosition pos;
498 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
500 // if there are not items in the tree.. the we have to set isOver to true for anything..
502 if (_this.model.el.iter_n_children(null) < 1) {
503 print("got NO children?\n");
506 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
510 //console.log("LEFT-TREE: drag-motion");
511 var src = Gtk.drag_get_source_widget(ctx);
513 // a drag from self - this should be handled by drop and motion.
514 if (src == this.el) {
515 print("Source == this element should not happen.. ? \n");
518 //print("drag_data_recieved from another element");
523 if (selection_text == null || selection_text.length < 1 || !isOver) {
524 // nothing valid foudn to drop...
525 print("empty sel text or not over");
527 Gdk.drag_status(ctx, 0, time);
528 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
531 Gtk.drag_finish (ctx, false, false, time); // drop failed..
536 var dropNode = new JsRender.Node();
538 var dropNodeType = selection_text;
539 var show_templates = true;
541 if (dropNodeType[0] == '{') {
542 var pa = new Json.Parser();
543 pa.load_from_data(dropNodeType);
545 dropNode.loadFromJson( pa.get_root().get_object(), 2);
546 dropNodeType = dropNode.fqn();
547 show_templates = false;
552 dropNode.setFqn(selection_text);
556 // dropList --- need to gather this ...
557 print("get dropList for : %s\n",dropNodeType);
558 var dropList = _this.model.file.palete().getDropList(dropNodeType);
560 print("dropList: %s\n", string.joinv(" , ", dropList));
562 // if drag action is link ... then we can drop it anywahere...
563 if ((ctx.get_actions() & Gdk.DragAction.LINK) > 0) {
564 // if path is null?? dragging into an empty tree?
565 targetData = (path == null ? "" : path.to_string()) + "|%d".printf((int)pos);
569 targetData = _this.model.findDropNodeByPath( isEmpty ? "" : path.to_string(), dropList, pos);
574 print("targetDAta: " + targetData +"\n");
576 if (targetData.length < 1) {
578 // invalid drop path..
579 if (this.drag_in_motion) {
580 Gdk.drag_status(ctx, 0, time);
581 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
584 Gtk.drag_finish (ctx, false, false, time); // drop failed..
590 var td_ar = targetData.split("|");
593 if (this.drag_in_motion) {
594 Gdk.drag_status(ctx, Gdk.DragAction.COPY ,time);
596 this.highlightDropPath( td_ar[0] , (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
599 // continue on to allow drop..
602 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
605 _this.model.dropNode(targetData, dropNode, show_templates);
606 print("ADD new node!!!\n");
608 ///Xcls_DialogTemplateSelect.singleton().show( _this.model.file.palete(), node);
610 Gtk.drag_finish (ctx, false, false,time);
617 this.el.drag_drop.connect( ( ctx, x, y, time) => {
618 //Seed.print("TARGET: drag-drop");
621 var src = Gtk.drag_get_source_widget(ctx);
623 if (src != this.el) {
627 this.drag_in_motion = false;
628 // request data that will be recieved by the recieve...
631 this.el, // will receive 'drag-data-received' signal
632 ctx, // represents the current state of the DnD
633 Gdk.Atom.intern("application/json",true), // the target type we want
638 // No target offered by source => error
644 // handle drop around self..
648 //print("GETTING POS");
652 Gtk.TreeViewDropPosition pos;
653 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
655 // if there are not items in the tree.. the we have to set isOver to true for anything..
657 if (_this.model.el.iter_n_children(null) < 1) {
658 print("got NO children?\n");
661 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
666 //var action = Gdk.DragAction.COPY;
667 // unless we are copying!!! ctl button..
669 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
670 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
671 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
674 if (_this.model.el.iter_n_children(null) < 1) {
675 // no children.. -- asume it's ok..
677 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
679 // continue through to allow drop...
687 //print("ISOVER? " + isOver);
690 Gtk.drag_finish (ctx, false, false, time); // drop failed..
691 return true; // not over apoint!?! - no action on drop or motion..
694 // drag node is parent of child..
695 //console.log("SRC TREEPATH: " + src.treepath);
696 //console.log("TARGET TREEPATH: " + data.path.to_string());
698 // nned to check a few here..
699 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
700 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
701 //Gtk.TreeViewDropPosition.AFTER
702 //Gtk.TreeViewDropPosition.BEFORE
704 // locally dragged items to not really use the
705 var selection_text = this.dragData;
709 if (selection_text == null || selection_text.length < 1) {
710 //print("Error - drag selection text returned NULL");
712 Gtk.drag_finish (ctx, false, false, time); // drop failed..
713 return true; /// -- fixme -- this is not really correct..
716 // see if we are dragging into ourself?
717 print ("got selection text of " + selection_text);
719 var target_path = path.to_string();
720 //print("target_path="+target_path);
723 if (selection_text == target_path) {
724 print("self drag ?? == we should perhaps allow copy onto self..\n");
726 Gtk.drag_finish (ctx, false, false, time); // drop failed..
728 return true; /// -- fixme -- this is not really correct..
733 //print("DUMPING DATA");
734 //console.dump(data);
737 //print(data.path.to_string() +' => '+ data.pos);
739 // dropList is a list of xtypes that this node could be dropped on.
740 // it is set up when we start to drag..
743 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
745 print("targetDAta: " + targetData +"\n");
747 if (targetData.length < 1) {
748 //print("Can not find drop node path");
750 Gtk.drag_finish (ctx, false, false, time); // drop failed..
754 var td_ar = targetData.split("|");
758 // continue on to allow drop..
760 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
763 var delete_selection_data = false;
765 if (action == Gdk.DragAction.ASK) {
766 /* Ask the user to move or copy, then set the ctx action. */
769 if (action == Gdk.DragAction.MOVE) {
770 delete_selection_data = true;
773 // drag around.. - reorder..
774 _this.model.moveNode(targetData, action);
780 // we can send stuff to souce here...
783 // do we always say failure, so we handle the reall drop?
784 Gtk.drag_finish (ctx, false, false,time); //delete_selection_data, time);
796 // user defined functions
797 public void highlightDropPath ( string treepath, Gtk.TreeViewDropPosition pos) {
799 // highlighting for drag/drop
800 if (treepath.length > 0) {
801 this.el.set_drag_dest_row( new Gtk.TreePath.from_string( treepath ), pos);
803 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
807 public void selectNode (string treepath_str) {
808 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
809 var tp = new Gtk.TreePath.from_string(treepath_str);
811 this.el.set_cursor(tp, null, false);
812 this.el.scroll_to_cell(tp, null, false, 0,0);
815 public class Xcls_model : Object
817 public Gtk.TreeStore el;
818 private Xcls_WindowLeftTree _this;
822 public DialogTemplateSelect template_select;
823 public JsRender.JsRender? file;
824 public string activePath;
825 public Project.Project? project;
828 public Xcls_model(Xcls_WindowLeftTree _owner )
832 this.el = new Gtk.TreeStore( 3, typeof(string),typeof(string),typeof(Object) );
835 this.template_select = null;
837 this.activePath = "";
840 // set gobject values
844 print("model initialized");
847 // user defined functions
848 public string findDropNode (string treepath_str, string[] targets) {
850 // this is used by the dragdrop code in the roo version AFAIR..
852 //var path = treepath_str.replace(/^builder-/, '');
853 // treemap is depreciated... - should really check if model has any entries..
855 if (this.el.iter_n_children(null) < 1) {
857 return "|%d".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
859 //print("FIND treepath: " + path);
860 //console.dump(this.treemap);
862 //if (!treepath_str.match(/^builder-/)) {
863 // return []; // nothing!
865 if (targets.length > 0 && targets[0] == "*") {
868 return this.findDropNodeByPath(treepath_str,targets, -1);
870 public void loadFile (JsRender.JsRender f) {
877 // console.log('missing file');
881 // load the file if not loaded..
882 if (f.tree == null) {
885 // if it's still null?
886 if (f.tree == null) {
890 /// this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name);
892 //if (f.items.length && typeof(f.items[0]) == 'string') {
894 //this.get('/RightEditor').el.show();
895 //this.get('/RightEditor.view').load( f.items[0]);
899 //print(JSON.stringify(f.items, null,4));
900 //console.dump(f.items);
901 var o = new Gee.ArrayList<JsRender.Node>();
905 _this.view.el.expand_all();
907 if (f.tree.items.size < 1) {
910 //this.get('/Window.leftvpaned').el.set_position(80);
912 _this.view.el.set_cursor(
913 new Gtk.TreePath.from_string("0"), null, false);
917 //this.get('/Window.leftvpaned').el.set_position(200);
923 //print("hide right editior");
924 //this.get('/RightEditor').el.hide();
925 //this.get('/Editor').el.hide();
926 //print("set current tree");
927 //this.currentTree = this.toJS(false, false)[0];
928 //console.dump(this.currentTree);
929 //this.currentTree = this.currentTree || { items: [] };
930 //_this.renderView();
931 //console.dump(this.map);
932 //var RightPalete = imports.Builder.RightPalete.RightPalete;
935 var pm = this.get('/RightPalete.model');
938 this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
940 if (!this.get('/RightPalete').provider) {
941 print ("********* PALETE PROVIDER MISSING?!!");
943 this.get('/LeftTree').renderView();
945 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
949 this.get('/Window.view-notebook').el.set_current_page(
950 this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
954 public void updateSelected () {
957 var s = _this.view.el.get_selection();
964 if (!s.get_selected(out mod, out iter)) {
965 return; // nothing seleted..
969 this.el.get_value(iter, 2, out value);
970 var node = (JsRender.Node)(value.get_object());
972 this.el.set(iter, 0, node.nodeTitle(),
973 1, node.nodeTip(), -1
976 public string findDropNodeByPath (string treepath_str, string[] targets, int in_pref = -1) {
978 var path = treepath_str; // dupe it..
981 // pref : 3 = ontop - 0 = after, 1 = before
982 int pref = in_pref < 0 ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : in_pref;
986 //console.dump(this.treemap);
988 print("findDropNodeByPath : got path length %d / %s\n", path.length, path);
990 if (path.length == 0) {
991 // top drop. // just return empty..
992 return "|%d".printf((int)pref) ;
997 while (path.length > 0) {
999 if (path.length == treepath_str.length && pref != Gtk.TreeViewDropPosition.INTO_OR_AFTER) {
1000 if (path.last_index_of(":") < 0 ) {
1003 path = path.substring(0, path.last_index_of(":"));
1004 last = treepath_str;
1005 print("DROP before or after : using %s\n",path);
1009 //print("LOOKING FOR PATH: " + path);
1010 var node_data = this.pathToNode(path);
1012 if (node_data == null) {
1013 print("node not found");
1017 var xname = node_data.fqn();
1021 for (var i =0; i < targets.length; i++) {
1022 var tg = targets[i];
1023 if ((tg == xname) ) {
1027 // if target is "xxxx:name"
1028 if (tg.contains(xname +":")) {
1030 var ar = tg.split(":");
1036 if (match.length > 0) {
1037 if (last.length > 0) { // pref is after/before..
1038 // then it's after last
1042 return last + "|%d".printf((int)pref) + "|" + prop;
1046 // we need to add prop - as :store -> needs to bee added when dropping onto.
1047 return path + "|%d".printf( (int) Gtk.TreeViewDropPosition.INTO_OR_AFTER) + "|" + prop;
1051 var par = path.split(":");
1052 string [] ppar = {};
1053 for (var i = 0; i < par.length-1; i++) {
1057 path = string.joinv(":", ppar);
1066 public void moveNode (string target_data, Gdk.DragAction action)
1069 /// target_data = "path|pos");
1072 //print("MOVE NODE");
1073 // console.dump(target_data);
1074 Gtk.TreeIter old_iter;
1077 var s = _this.view.el.get_selection();
1078 s.get_selected(out mod , out old_iter);
1079 mod.get_path(old_iter);
1081 var node = this.pathToNode(mod.get_path(old_iter).to_string());
1082 //console.dump(node);
1084 print("moveNode: ERROR - node is null?");
1089 // needs to drop first, otherwise the target_data
1090 // treepath will be invalid.
1093 if ((action & Gdk.DragAction.MOVE) > 0) {
1094 print("REMOVING OLD NODE : " + target_data + "\n");
1096 this.dropNode(target_data, node, false);
1097 this.el.remove(ref old_iter);
1102 print("DROPPING NODE // copy: " + target_data + "\n");
1103 node = node.deepClone();
1104 this.dropNode(target_data, node, false);
1107 this.activePath= "";
1108 //this.updateNode(false,true);
1110 public void load (Gee.ArrayList<JsRender.Node> tr, Gtk.TreeIter? iter)
1113 //this.insert(citer,iter,0);
1114 for(var i =0 ; i < tr.size; i++) {
1116 this.el.insert(out citer,iter,-1); // why not append?
1118 this.el.append(out citer,null);
1121 this.el.set(citer, 0, tr.get(i).nodeTitle(),
1122 1, tr.get(i).nodeTip(), -1
1124 var o = new GLib.Value(typeof(Object));
1125 o.set_object((Object)tr.get(i));
1127 this.el.set_value(citer, 2, o);
1129 if (tr.get(i).items.size > 0) {
1130 this.load(tr.get(i).items, citer);
1137 public void deleteSelected () {
1139 print("DELETE SELECTED?");
1140 //_this.view.blockChanges = true;
1141 print("GET SELECTION?");
1143 var s = _this.view.el.get_selection();
1145 print("GET SELECTED?");
1150 if (!s.get_selected(out mod, out iter)) {
1151 return; // nothing seleted..
1156 this.activePath= "";
1157 print("GET vnode value?");
1160 this.el.get_value(iter, 2, out value);
1161 var data = (JsRender.Node)(value.get_object());
1162 print("removing node from Render\n");
1163 if (data.parent == null) {
1164 this.file.tree = null;
1168 print("removing node from Tree\n");
1170 this.el.remove(ref iter);
1180 this.activePath= ""; // again!?!?
1181 //this.changed(null,true);
1185 _this.view.blockChanges = false;
1187 public JsRender.Node pathToNode (string path) {
1191 _this.model.el.get_iter_from_string(out iter, path);
1194 _this.model.el.get_value(iter, 2, out value);
1196 return (JsRender.Node)value.dup_object();
1199 public void dropNode (string target_data_str, JsRender.Node node, bool show_templates) {
1200 // print("drop Node");
1201 // console.dump(node);
1202 // console.dump(target_data);
1205 // 0 = before , 1=after 2/3 onto
1208 var target_data= target_data_str.split("|");
1210 var parent_str = target_data[0].length > 0 ? target_data[0] : "";
1211 var pos = target_data.length > 1 ? int.parse(target_data[1]) : 2; // ontop..
1214 Gtk.TreePath tree_path = parent_str.length > 0 ? new Gtk.TreePath.from_string( parent_str ) : null;
1218 //print("add " + tp + "@" + target_data[1] );
1220 JsRender.Node parentNode = null;
1222 Gtk.TreeIter iter_after;
1223 Gtk.TreeIter iter_par ;
1226 if (target_data.length == 3 && target_data[2].length > 0) {
1227 node.props.set("* prop", target_data[2]);
1230 Gtk.TreePath expand_parent = null;
1232 // we only need to show the template if it's come from else where?
1233 if (show_templates) {
1235 if (this.template_select == null) {
1236 this.template_select = new DialogTemplateSelect();
1239 var new_node = this.template_select.show(
1240 (Gtk.Window) _this.el.get_toplevel (),
1244 if (new_node != null) {
1249 //print("pos is %d \n".printf(pos));
1251 Gtk.TreeIter n_iter;
1253 if ( parent_str.length < 1) {
1254 this.el.append(out n_iter, null); // drop at top level..
1256 this.file.tree = node;
1259 } else if (pos < 2) {
1260 //print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
1262 this.el.get_iter(out iter_after, tree_path );
1263 this.el.iter_parent(out iter_par, iter_after);
1264 expand_parent = this.el.get_path(iter_par);
1267 this.el.get_value( iter_par, 2, out value);
1268 parentNode = (JsRender.Node)value.dup_object();
1271 this.el.get_value( iter_after, 2, out value);
1272 var relNode = (JsRender.Node)value.dup_object();
1276 this.el.insert_after(out n_iter, iter_par , iter_after);
1277 var ix = parentNode.items.index_of(relNode);
1278 parentNode.items.insert(ix+1, node);
1281 this.el.insert_before(out n_iter, iter_par , iter_after);
1282 var ix = parentNode.items.index_of(relNode);
1283 parentNode.items.insert(ix, node);
1286 node.parent = parentNode;
1291 // print("appending to " + parent_str);
1292 this.el.get_iter(out iter_par, tree_path);
1293 this.el.append(out n_iter, iter_par );
1294 expand_parent = this.el.get_path(iter_par);
1297 this.el.get_value( iter_par, 2, out value);
1298 parentNode = (JsRender.Node)value.dup_object();
1299 node.parent = parentNode;
1300 parentNode.items.add(node);
1303 // reparent node in tree...
1306 // why only on no parent???
1308 //if (node.parent = null) {
1315 // work out what kind of packing to use.. -- should be in
1316 if (!node.has("pack") && parent_str.length > 1) {
1318 this.file.palete().fillPack(node,parentNode);
1325 this.el.set(n_iter, 0, node.nodeTitle(), 1, node.nodeTip(), -1 );
1326 var o = new GLib.Value(typeof(Object));
1327 o.set_object((Object)node);
1329 this.el.set_value(n_iter, 2, o);
1334 // load children - if it has any..
1336 if (node.items.size > 0) {
1337 this.load(node.items, n_iter);
1338 _this.view.el.expand_row(this.el.get_path(n_iter), true);
1339 } else if (expand_parent != null && !_this.view.el.is_row_expanded(expand_parent)) {
1340 _this.view.el.expand_row(expand_parent,true);
1343 //if (tp != null && (node.items.length() > 0 || pos > 1)) {
1344 // _this.view.el.expand_row(this.el.get_path(iter_par), true);
1346 // wee need to get the empty proptypes from somewhere..
1348 //var olditer = this.activeIter;
1349 this.activePath = this.el.get_path(n_iter).to_string();
1354 _this.view.el.set_cursor(this.el.get_path(n_iter), null, false);
1361 public class Xcls_TreeViewColumn4 : Object
1363 public Gtk.TreeViewColumn el;
1364 private Xcls_WindowLeftTree _this;
1370 public Xcls_TreeViewColumn4(Xcls_WindowLeftTree _owner )
1373 this.el = new Gtk.TreeViewColumn();
1377 // set gobject values
1378 this.el.title = "test";
1379 var child_0 = new Xcls_renderer( _this );
1381 this.el.pack_start ( child_0.el , true );
1385 this.el.add_attribute(_this.renderer.el , "markup", 0 );
1388 // user defined functions
1390 public class Xcls_renderer : Object
1392 public Gtk.CellRendererText el;
1393 private Xcls_WindowLeftTree _this;
1399 public Xcls_renderer(Xcls_WindowLeftTree _owner )
1402 _this.renderer = this;
1403 this.el = new Gtk.CellRendererText();
1407 // set gobject values
1410 // user defined functions
1412 public class Xcls_LeftTreeMenu : Object
1415 private Xcls_WindowLeftTree _this;
1421 public Xcls_LeftTreeMenu(Xcls_WindowLeftTree _owner )
1424 _this.LeftTreeMenu = this;
1425 this.el = new Gtk.Menu();
1429 // set gobject values
1430 var child_0 = new Xcls_MenuItem7( _this );
1432 this.el.add ( child_0.el );
1433 var child_1 = new Xcls_MenuItem8( _this );
1435 this.el.add ( child_1.el );
1436 var child_2 = new Xcls_MenuItem9( _this );
1438 this.el.add ( child_2.el );
1441 // user defined functions
1443 public class Xcls_MenuItem7 : Object
1445 public Gtk.MenuItem el;
1446 private Xcls_WindowLeftTree _this;
1452 public Xcls_MenuItem7(Xcls_WindowLeftTree _owner )
1455 this.el = new Gtk.MenuItem();
1459 // set gobject values
1460 this.el.label = "Delete Element";
1463 this.el.activate.connect( ( ) => {
1468 _this.model.deleteSelected();
1472 // user defined functions
1474 public class Xcls_MenuItem8 : Object
1476 public Gtk.MenuItem el;
1477 private Xcls_WindowLeftTree _this;
1483 public Xcls_MenuItem8(Xcls_WindowLeftTree _owner )
1486 this.el = new Gtk.MenuItem();
1490 // set gobject values
1491 this.el.label = "Save as Template";
1494 this.el.activate.connect( () => {
1496 DialogSaveTemplate.singleton().show(
1497 (Gtk.Window) _this.el.get_toplevel (),
1498 _this.model.file.palete(),
1499 _this.getActiveElement()
1506 // user defined functions
1508 public class Xcls_MenuItem9 : Object
1510 public Gtk.MenuItem el;
1511 private Xcls_WindowLeftTree _this;
1517 public Xcls_MenuItem9(Xcls_WindowLeftTree _owner )
1520 this.el = new Gtk.MenuItem();
1524 // set gobject values
1525 this.el.label = "Save as Module";
1528 this.el.activate.connect( () => {
1529 var node = _this.getActiveElement();
1530 var name = DialogSaveModule.singleton().show(
1531 (Gtk.Window) _this.el.get_toplevel (),
1532 _this.model.file.project,
1535 if (name.length < 1) {
1539 node.props.set("* xinclude", name);
1543 var s = _this.view.el.get_selection();
1545 print("GET SELECTED?");
1550 if (!s.get_selected(out mod, out iter)) {
1551 return; // nothing seleted..
1554 var n_cn = mod.iter_n_children(iter) -1;
1555 for (var i = n_cn; i > -1; i--) {
1556 mod.iter_nth_child(out citer, iter, i);
1559 print("removing node from Tree\n");
1561 _this.model.el.remove(ref citer);
1564 _this.node_selected(node);
1570 // user defined functions