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);
269 while (Gtk.events_pending()) {
270 Gtk.main_iteration();
272 this.el.scroll_to_cell(new Gtk.TreePath.from_string(_this.model.activePath), null, true, 0.1f,0.0f);
276 //_this.after_node_change(node);
278 // _this.model.file.changed(node, "tree");
280 //Seed.print( value.get_string());
284 this.el.drag_end.connect( (drag_context) => {
285 //Seed.print('LEFT-TREE: drag-end');
287 this.dropList = null;
288 // this.targetData = "";
289 this.highlightDropPath("",0);
292 this.el.drag_motion.connect( ( ctx, x, y, time) => {
293 print("got drag motion\n");
294 var src = Gtk.drag_get_source_widget(ctx);
298 if (src != this.el) {
302 // the point of this is to detect where an item could be dropped..
303 print("requesting drag data\n");
304 this.drag_in_motion = true;
306 // request data that will be recieved by the recieve...
309 this.el, // will receive 'drag-data-received' signal
310 ctx, // represents the current state of the DnD
311 Gdk.Atom.intern("STRING",true), // the target type we want
318 print("action: %d\n", ctx.get_actions());
319 //print("GETTING POS");
323 Gtk.TreeViewDropPosition pos;
324 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
326 // if there are not items in the tree.. the we have to set isOver to true for anything..
328 if (_this.model.el.iter_n_children(null) < 1) {
329 print("got NO children?\n");
332 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
336 // ------------- a drag from self..
339 //var action = Gdk.DragAction.COPY;
340 // unless we are copying!!! ctl button..
342 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
343 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
344 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
347 if (_this.model.el.iter_n_children(null) < 1) {
348 // no children.. -- asume it's ok..
350 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
352 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
353 Gdk.drag_status(ctx, action ,time);
356 // continue through to allow drop...
364 //print("ISOVER? " + isOver);
367 Gdk.drag_status(ctx, 0 ,time);
368 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
373 // drag node is parent of child..
374 //console.log("SRC TREEPATH: " + src.treepath);
375 //console.log("TARGET TREEPATH: " + data.path.to_string());
377 // nned to check a few here..
378 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
379 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
380 //Gtk.TreeViewDropPosition.AFTER
381 //Gtk.TreeViewDropPosition.BEFORE
383 // locally dragged items to not really use the
384 var selection_text = this.dragData;
388 if (selection_text == null || selection_text.length < 1) {
389 //print("Error - drag selection text returned NULL");
390 Gdk.drag_status(ctx, 0 ,time);
391 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
396 // see if we are dragging into ourself?
397 var target_path = path.to_string();
398 print ("Drag %s onto %s--%d\n ", selection_text, target_path, pos);
400 // pos : 3 = ontop - 0 = after, 1 = before
401 //print("target_path="+target_path);
404 if (selection_text == target_path) {
405 print("self drag ?? == we should perhaps allow copy onto self..\n");
407 Gdk.drag_status(ctx, 0 ,time);
408 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
410 // -- fixme -- this is not really correct..
415 //print("DUMPING DATA");
416 //console.dump(data);
419 //print(data.path.to_string() +' => '+ data.pos);
421 // dropList is a list of xtypes that this node could be dropped on.
422 // it is set up when we start to drag..
425 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
427 print("targetDAta: " + targetData +"\n");
429 if (targetData.length < 1) {
430 //print("Can not find drop node path");
432 Gdk.drag_status(ctx, 0, time);
433 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
437 var td_ar = targetData.split("|");
441 Gdk.drag_status(ctx, action ,time);
442 this.highlightDropPath(td_ar[0], (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
447 this.el.drag_data_get.connect( ( drag_context, data, info, time) => {
450 //print("drag-data-get");
451 var s = this.el.get_selection();
452 if (s.count_selected_rows() < 1) {
454 print("return empty string - no selection..");
461 s.get_selected(out mod, out iter);
466 _this.model.el.get_value(iter, 2, out value);
467 var ndata = (JsRender.Node)(value.dup_object());
468 var xname = ndata.fqn();
471 var tp = mod.get_path(iter).to_string();
472 // by default returns the path..
474 if ( info != Gdk.Atom.intern("STRING",true) ) {
475 tp = ndata.toJsonString();
478 //data.set_text(tp,tp.length);
480 data.set (data.get_target (), 8, (uchar[]) tp.to_utf8 ());
483 // print("return " + tp);
485 this.el.drag_data_received.connect( (ctx, x, y, sel, info, time) => {
487 // THIS CODE ONLY RELATES TO drag or drop of "NEW" elements or "FROM another tree.."
490 // print("Tree: drag-data-received\n");
491 var selection_text = (string)sel.get_data();
492 //print("selection_text= %s\n",selection_text);
494 var is_drag = this.drag_in_motion;
498 print("Is Drag %s\n", is_drag ? "Y": "N");
502 Gtk.TreeViewDropPosition pos;
503 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
505 // if there are not items in the tree.. the we have to set isOver to true for anything..
507 if (_this.model.el.iter_n_children(null) < 1) {
508 print("got NO children?\n");
511 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
515 //console.log("LEFT-TREE: drag-motion");
516 var src = Gtk.drag_get_source_widget(ctx);
518 // a drag from self - this should be handled by drop and motion.
519 if (src == this.el) {
520 print("Source == this element should not happen.. ? \n");
523 //print("drag_data_recieved from another element");
528 if (selection_text == null || selection_text.length < 1 || !isOver) {
529 // nothing valid foudn to drop...
530 print("empty sel text or not over");
532 Gdk.drag_status(ctx, 0, time);
533 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
536 Gtk.drag_finish (ctx, false, false, time); // drop failed..
541 var dropNode = new JsRender.Node();
543 var dropNodeType = selection_text;
544 var show_templates = true;
546 if (dropNodeType[0] == '{') {
547 var pa = new Json.Parser();
548 pa.load_from_data(dropNodeType);
550 dropNode.loadFromJson( pa.get_root().get_object(), 2);
551 dropNodeType = dropNode.fqn();
552 show_templates = false;
557 dropNode.setFqn(selection_text);
561 // dropList --- need to gather this ...
562 print("get dropList for : %s\n",dropNodeType);
563 var dropList = _this.model.file.palete().getDropList(dropNodeType);
565 print("dropList: %s\n", string.joinv(" , ", dropList));
567 // if drag action is link ... then we can drop it anywahere...
568 if ((ctx.get_actions() & Gdk.DragAction.LINK) > 0) {
569 // if path is null?? dragging into an empty tree?
570 targetData = (path == null ? "" : path.to_string()) + "|%d".printf((int)pos);
574 targetData = _this.model.findDropNodeByPath( isEmpty ? "" : path.to_string(), dropList, pos);
579 print("targetDAta: " + targetData +"\n");
581 if (targetData.length < 1) {
583 // invalid drop path..
584 if (this.drag_in_motion) {
585 Gdk.drag_status(ctx, 0, time);
586 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
589 Gtk.drag_finish (ctx, false, false, time); // drop failed..
595 var td_ar = targetData.split("|");
598 if (this.drag_in_motion) {
599 Gdk.drag_status(ctx, Gdk.DragAction.COPY ,time);
601 this.highlightDropPath( td_ar[0] , (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
604 // continue on to allow drop..
607 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
610 _this.model.dropNode(targetData, dropNode, show_templates);
611 print("ADD new node!!!\n");
613 ///Xcls_DialogTemplateSelect.singleton().show( _this.model.file.palete(), node);
615 Gtk.drag_finish (ctx, false, false,time);
622 this.el.drag_drop.connect( ( ctx, x, y, time) => {
623 //Seed.print("TARGET: drag-drop");
626 var src = Gtk.drag_get_source_widget(ctx);
628 if (src != this.el) {
632 this.drag_in_motion = false;
633 // request data that will be recieved by the recieve...
636 this.el, // will receive 'drag-data-received' signal
637 ctx, // represents the current state of the DnD
638 Gdk.Atom.intern("application/json",true), // the target type we want
643 // No target offered by source => error
649 // handle drop around self..
653 //print("GETTING POS");
657 Gtk.TreeViewDropPosition pos;
658 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
660 // if there are not items in the tree.. the we have to set isOver to true for anything..
662 if (_this.model.el.iter_n_children(null) < 1) {
663 print("got NO children?\n");
666 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
671 //var action = Gdk.DragAction.COPY;
672 // unless we are copying!!! ctl button..
674 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
675 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
676 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
679 if (_this.model.el.iter_n_children(null) < 1) {
680 // no children.. -- asume it's ok..
682 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
684 // continue through to allow drop...
692 //print("ISOVER? " + isOver);
695 Gtk.drag_finish (ctx, false, false, time); // drop failed..
696 return true; // not over apoint!?! - no action on drop or motion..
699 // drag node is parent of child..
700 //console.log("SRC TREEPATH: " + src.treepath);
701 //console.log("TARGET TREEPATH: " + data.path.to_string());
703 // nned to check a few here..
704 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
705 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
706 //Gtk.TreeViewDropPosition.AFTER
707 //Gtk.TreeViewDropPosition.BEFORE
709 // locally dragged items to not really use the
710 var selection_text = this.dragData;
714 if (selection_text == null || selection_text.length < 1) {
715 //print("Error - drag selection text returned NULL");
717 Gtk.drag_finish (ctx, false, false, time); // drop failed..
718 return true; /// -- fixme -- this is not really correct..
721 // see if we are dragging into ourself?
722 print ("got selection text of " + selection_text);
724 var target_path = path.to_string();
725 //print("target_path="+target_path);
728 if (selection_text == target_path) {
729 print("self drag ?? == we should perhaps allow copy onto self..\n");
731 Gtk.drag_finish (ctx, false, false, time); // drop failed..
733 return true; /// -- fixme -- this is not really correct..
738 //print("DUMPING DATA");
739 //console.dump(data);
742 //print(data.path.to_string() +' => '+ data.pos);
744 // dropList is a list of xtypes that this node could be dropped on.
745 // it is set up when we start to drag..
748 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
750 print("targetDAta: " + targetData +"\n");
752 if (targetData.length < 1) {
753 //print("Can not find drop node path");
755 Gtk.drag_finish (ctx, false, false, time); // drop failed..
759 var td_ar = targetData.split("|");
763 // continue on to allow drop..
765 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
768 var delete_selection_data = false;
770 if (action == Gdk.DragAction.ASK) {
771 /* Ask the user to move or copy, then set the ctx action. */
774 if (action == Gdk.DragAction.MOVE) {
775 delete_selection_data = true;
778 // drag around.. - reorder..
779 _this.model.moveNode(targetData, action);
785 // we can send stuff to souce here...
788 // do we always say failure, so we handle the reall drop?
789 Gtk.drag_finish (ctx, false, false,time); //delete_selection_data, time);
801 // user defined functions
802 public void highlightDropPath ( string treepath, Gtk.TreeViewDropPosition pos) {
804 // highlighting for drag/drop
805 if (treepath.length > 0) {
806 this.el.set_drag_dest_row( new Gtk.TreePath.from_string( treepath ), pos);
808 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
812 public void selectNode (string treepath_str) {
813 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
814 var tp = new Gtk.TreePath.from_string(treepath_str);
816 this.el.set_cursor(tp, null, false);
817 this.el.scroll_to_cell(tp, null, false, 0,0);
820 public class Xcls_model : Object
822 public Gtk.TreeStore el;
823 private Xcls_WindowLeftTree _this;
827 public DialogTemplateSelect template_select;
828 public JsRender.JsRender? file;
829 public string activePath;
830 public Project.Project? project;
833 public Xcls_model(Xcls_WindowLeftTree _owner )
837 this.el = new Gtk.TreeStore( 3, typeof(string),typeof(string),typeof(Object) );
840 this.template_select = null;
842 this.activePath = "";
845 // set gobject values
849 print("model initialized");
852 // user defined functions
853 public string findDropNode (string treepath_str, string[] targets) {
855 // this is used by the dragdrop code in the roo version AFAIR..
857 //var path = treepath_str.replace(/^builder-/, '');
858 // treemap is depreciated... - should really check if model has any entries..
860 if (this.el.iter_n_children(null) < 1) {
862 return "|%d".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
864 //print("FIND treepath: " + path);
865 //console.dump(this.treemap);
867 //if (!treepath_str.match(/^builder-/)) {
868 // return []; // nothing!
870 if (targets.length > 0 && targets[0] == "*") {
873 return this.findDropNodeByPath(treepath_str,targets, -1);
875 public void loadFile (JsRender.JsRender f) {
882 // console.log('missing file');
886 // load the file if not loaded..
887 if (f.tree == null) {
890 // if it's still null?
891 if (f.tree == null) {
895 /// this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name);
897 //if (f.items.length && typeof(f.items[0]) == 'string') {
899 //this.get('/RightEditor').el.show();
900 //this.get('/RightEditor.view').load( f.items[0]);
904 //print(JSON.stringify(f.items, null,4));
905 //console.dump(f.items);
906 var o = new Gee.ArrayList<JsRender.Node>();
910 _this.view.el.expand_all();
912 if (f.tree.items.size < 1) {
915 //this.get('/Window.leftvpaned').el.set_position(80);
917 _this.view.el.set_cursor(
918 new Gtk.TreePath.from_string("0"), null, false);
922 //this.get('/Window.leftvpaned').el.set_position(200);
928 //print("hide right editior");
929 //this.get('/RightEditor').el.hide();
930 //this.get('/Editor').el.hide();
931 //print("set current tree");
932 //this.currentTree = this.toJS(false, false)[0];
933 //console.dump(this.currentTree);
934 //this.currentTree = this.currentTree || { items: [] };
935 //_this.renderView();
936 //console.dump(this.map);
937 //var RightPalete = imports.Builder.RightPalete.RightPalete;
940 var pm = this.get('/RightPalete.model');
943 this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
945 if (!this.get('/RightPalete').provider) {
946 print ("********* PALETE PROVIDER MISSING?!!");
948 this.get('/LeftTree').renderView();
950 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
954 this.get('/Window.view-notebook').el.set_current_page(
955 this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
959 public void updateSelected () {
962 var s = _this.view.el.get_selection();
969 if (!s.get_selected(out mod, out iter)) {
970 return; // nothing seleted..
974 this.el.get_value(iter, 2, out value);
975 var node = (JsRender.Node)(value.get_object());
977 this.el.set(iter, 0, node.nodeTitle(),
978 1, node.nodeTip(), -1
981 public string findDropNodeByPath (string treepath_str, string[] targets, int in_pref = -1) {
983 var path = treepath_str; // dupe it..
986 // pref : 3 = ontop - 0 = after, 1 = before
987 int pref = in_pref < 0 ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : in_pref;
991 //console.dump(this.treemap);
993 print("findDropNodeByPath : got path length %d / %s\n", path.length, path);
995 if (path.length == 0) {
996 // top drop. // just return empty..
997 return "|%d".printf((int)pref) ;
1002 while (path.length > 0) {
1004 if (path.length == treepath_str.length && pref != Gtk.TreeViewDropPosition.INTO_OR_AFTER) {
1005 if (path.last_index_of(":") < 0 ) {
1008 path = path.substring(0, path.last_index_of(":"));
1009 last = treepath_str;
1010 print("DROP before or after : using %s\n",path);
1014 //print("LOOKING FOR PATH: " + path);
1015 var node_data = this.pathToNode(path);
1017 if (node_data == null) {
1018 print("node not found");
1022 var xname = node_data.fqn();
1026 for (var i =0; i < targets.length; i++) {
1027 var tg = targets[i];
1028 if ((tg == xname) ) {
1032 // if target is "xxxx:name"
1033 if (tg.contains(xname +":")) {
1035 var ar = tg.split(":");
1041 if (match.length > 0) {
1042 if (last.length > 0) { // pref is after/before..
1043 // then it's after last
1047 return last + "|%d".printf((int)pref) + "|" + prop;
1051 // we need to add prop - as :store -> needs to bee added when dropping onto.
1052 return path + "|%d".printf( (int) Gtk.TreeViewDropPosition.INTO_OR_AFTER) + "|" + prop;
1056 var par = path.split(":");
1057 string [] ppar = {};
1058 for (var i = 0; i < par.length-1; i++) {
1062 path = string.joinv(":", ppar);
1071 public void moveNode (string target_data, Gdk.DragAction action)
1074 /// target_data = "path|pos");
1077 //print("MOVE NODE");
1078 // console.dump(target_data);
1079 Gtk.TreeIter old_iter;
1082 var s = _this.view.el.get_selection();
1083 s.get_selected(out mod , out old_iter);
1084 mod.get_path(old_iter);
1086 var node = this.pathToNode(mod.get_path(old_iter).to_string());
1087 //console.dump(node);
1089 print("moveNode: ERROR - node is null?");
1094 // needs to drop first, otherwise the target_data
1095 // treepath will be invalid.
1098 if ((action & Gdk.DragAction.MOVE) > 0) {
1099 print("REMOVING OLD NODE : " + target_data + "\n");
1101 this.dropNode(target_data, node, false);
1102 this.el.remove(ref old_iter);
1107 print("DROPPING NODE // copy: " + target_data + "\n");
1108 node = node.deepClone();
1109 this.dropNode(target_data, node, false);
1112 this.activePath= "";
1113 //this.updateNode(false,true);
1115 public void load (Gee.ArrayList<JsRender.Node> tr, Gtk.TreeIter? iter)
1118 //this.insert(citer,iter,0);
1119 for(var i =0 ; i < tr.size; i++) {
1121 this.el.insert(out citer,iter,-1); // why not append?
1123 this.el.append(out citer,null);
1126 this.el.set(citer, 0, tr.get(i).nodeTitle(),
1127 1, tr.get(i).nodeTip(), -1
1129 var o = new GLib.Value(typeof(Object));
1130 o.set_object((Object)tr.get(i));
1132 this.el.set_value(citer, 2, o);
1134 if (tr.get(i).items.size > 0) {
1135 this.load(tr.get(i).items, citer);
1142 public void deleteSelected () {
1144 print("DELETE SELECTED?");
1145 //_this.view.blockChanges = true;
1146 print("GET SELECTION?");
1148 var s = _this.view.el.get_selection();
1150 print("GET SELECTED?");
1155 if (!s.get_selected(out mod, out iter)) {
1156 return; // nothing seleted..
1161 this.activePath= "";
1162 print("GET vnode value?");
1165 this.el.get_value(iter, 2, out value);
1166 var data = (JsRender.Node)(value.get_object());
1167 print("removing node from Render\n");
1168 if (data.parent == null) {
1169 this.file.tree = null;
1173 print("removing node from Tree\n");
1175 this.el.remove(ref iter);
1185 this.activePath= ""; // again!?!?
1186 //this.changed(null,true);
1190 _this.view.blockChanges = false;
1192 public JsRender.Node pathToNode (string path) {
1196 _this.model.el.get_iter_from_string(out iter, path);
1199 _this.model.el.get_value(iter, 2, out value);
1201 return (JsRender.Node)value.dup_object();
1204 public void dropNode (string target_data_str, JsRender.Node node, bool show_templates) {
1205 // print("drop Node");
1206 // console.dump(node);
1207 // console.dump(target_data);
1210 // 0 = before , 1=after 2/3 onto
1213 var target_data= target_data_str.split("|");
1215 var parent_str = target_data[0].length > 0 ? target_data[0] : "";
1216 var pos = target_data.length > 1 ? int.parse(target_data[1]) : 2; // ontop..
1219 Gtk.TreePath tree_path = parent_str.length > 0 ? new Gtk.TreePath.from_string( parent_str ) : null;
1223 //print("add " + tp + "@" + target_data[1] );
1225 JsRender.Node parentNode = null;
1227 Gtk.TreeIter iter_after;
1228 Gtk.TreeIter iter_par ;
1231 if (target_data.length == 3 && target_data[2].length > 0) {
1232 node.props.set("* prop", target_data[2]);
1235 Gtk.TreePath expand_parent = null;
1237 // we only need to show the template if it's come from else where?
1238 if (show_templates) {
1240 if (this.template_select == null) {
1241 this.template_select = new DialogTemplateSelect();
1244 var new_node = this.template_select.show(
1245 (Gtk.Window) _this.el.get_toplevel (),
1250 if (new_node == null) {
1251 return; // do not add?
1256 //print("pos is %d \n".printf(pos));
1258 Gtk.TreeIter n_iter;
1260 if ( parent_str.length < 1) {
1261 this.el.append(out n_iter, null); // drop at top level..
1263 this.file.tree = node;
1266 } else if (pos < 2) {
1267 //print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
1269 this.el.get_iter(out iter_after, tree_path );
1270 this.el.iter_parent(out iter_par, iter_after);
1271 expand_parent = this.el.get_path(iter_par);
1274 this.el.get_value( iter_par, 2, out value);
1275 parentNode = (JsRender.Node)value.dup_object();
1278 this.el.get_value( iter_after, 2, out value);
1279 var relNode = (JsRender.Node)value.dup_object();
1283 this.el.insert_after(out n_iter, iter_par , iter_after);
1284 var ix = parentNode.items.index_of(relNode);
1285 parentNode.items.insert(ix+1, node);
1288 this.el.insert_before(out n_iter, iter_par , iter_after);
1289 var ix = parentNode.items.index_of(relNode);
1290 parentNode.items.insert(ix, node);
1293 node.parent = parentNode;
1298 // print("appending to " + parent_str);
1299 this.el.get_iter(out iter_par, tree_path);
1300 this.el.append(out n_iter, iter_par );
1301 expand_parent = this.el.get_path(iter_par);
1304 this.el.get_value( iter_par, 2, out value);
1305 parentNode = (JsRender.Node)value.dup_object();
1306 node.parent = parentNode;
1307 parentNode.items.add(node);
1310 // reparent node in tree...
1313 // why only on no parent???
1315 //if (node.parent = null) {
1322 // work out what kind of packing to use.. -- should be in
1323 if (!node.has("pack") && parent_str.length > 1) {
1325 this.file.palete().fillPack(node,parentNode);
1332 this.el.set(n_iter, 0, node.nodeTitle(), 1, node.nodeTip(), -1 );
1333 var o = new GLib.Value(typeof(Object));
1334 o.set_object((Object)node);
1336 this.el.set_value(n_iter, 2, o);
1341 // load children - if it has any..
1343 if (node.items.size > 0) {
1344 this.load(node.items, n_iter);
1345 _this.view.el.expand_row(this.el.get_path(n_iter), true);
1346 } else if (expand_parent != null && !_this.view.el.is_row_expanded(expand_parent)) {
1347 _this.view.el.expand_row(expand_parent,true);
1350 //if (tp != null && (node.items.length() > 0 || pos > 1)) {
1351 // _this.view.el.expand_row(this.el.get_path(iter_par), true);
1353 // wee need to get the empty proptypes from somewhere..
1355 //var olditer = this.activeIter;
1356 this.activePath = this.el.get_path(n_iter).to_string();
1361 _this.view.el.set_cursor(this.el.get_path(n_iter), null, false);
1368 public class Xcls_TreeViewColumn4 : Object
1370 public Gtk.TreeViewColumn el;
1371 private Xcls_WindowLeftTree _this;
1377 public Xcls_TreeViewColumn4(Xcls_WindowLeftTree _owner )
1380 this.el = new Gtk.TreeViewColumn();
1384 // set gobject values
1385 this.el.title = "test";
1386 var child_0 = new Xcls_renderer( _this );
1388 this.el.pack_start ( child_0.el , true );
1392 this.el.add_attribute(_this.renderer.el , "markup", 0 );
1395 // user defined functions
1397 public class Xcls_renderer : Object
1399 public Gtk.CellRendererText el;
1400 private Xcls_WindowLeftTree _this;
1406 public Xcls_renderer(Xcls_WindowLeftTree _owner )
1409 _this.renderer = this;
1410 this.el = new Gtk.CellRendererText();
1414 // set gobject values
1417 // user defined functions
1419 public class Xcls_LeftTreeMenu : Object
1422 private Xcls_WindowLeftTree _this;
1428 public Xcls_LeftTreeMenu(Xcls_WindowLeftTree _owner )
1431 _this.LeftTreeMenu = this;
1432 this.el = new Gtk.Menu();
1436 // set gobject values
1437 var child_0 = new Xcls_MenuItem7( _this );
1439 this.el.add ( child_0.el );
1440 var child_1 = new Xcls_MenuItem8( _this );
1442 this.el.add ( child_1.el );
1443 var child_2 = new Xcls_MenuItem9( _this );
1445 this.el.add ( child_2.el );
1448 // user defined functions
1450 public class Xcls_MenuItem7 : Object
1452 public Gtk.MenuItem el;
1453 private Xcls_WindowLeftTree _this;
1459 public Xcls_MenuItem7(Xcls_WindowLeftTree _owner )
1462 this.el = new Gtk.MenuItem();
1466 // set gobject values
1467 this.el.label = "Delete Element";
1470 this.el.activate.connect( ( ) => {
1475 _this.model.deleteSelected();
1479 // user defined functions
1481 public class Xcls_MenuItem8 : Object
1483 public Gtk.MenuItem el;
1484 private Xcls_WindowLeftTree _this;
1490 public Xcls_MenuItem8(Xcls_WindowLeftTree _owner )
1493 this.el = new Gtk.MenuItem();
1497 // set gobject values
1498 this.el.label = "Save as Template";
1501 this.el.activate.connect( () => {
1503 DialogSaveTemplate.singleton().show(
1504 (Gtk.Window) _this.el.get_toplevel (),
1505 _this.model.file.palete(),
1506 _this.getActiveElement()
1513 // 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.model.file.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