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); }
47 // user defined functions
48 public JsRender.Node? getActiveElement () { // return path to actie node.
50 var path = this.getActivePath();
51 if (path.length < 1) {
54 return _this.model.pathToNode(path);
57 public JsRender.JsRender getActiveFile () {
58 return this.model.file;
60 public string getActivePath () {
61 var model = this.model;
62 var view = this.view.el;
63 if (view.get_selection().count_selected_rows() < 1) {
68 view.get_selection().get_selected(out mod, out iter);
69 return mod.get_path(iter).to_string();
71 public class Xcls_view : Object
73 public Gtk.TreeView el;
74 private Xcls_WindowLeftTree _this;
78 public string dragData;
79 public string[] dropList;
82 public bool drag_in_motion;
83 public bool blockChanges;
86 public Xcls_view(Xcls_WindowLeftTree _owner )
90 this.el = new Gtk.TreeView();
93 this.blockChanges = false;
96 this.el.tooltip_column = 1;
97 this.el.enable_tree_lines = true;
98 this.el.headers_visible = false;
99 var child_0 = new Xcls_model( _this );
101 this.el.set_model ( child_0.el );
102 var child_1 = new Xcls_TreeViewColumn4( _this );
104 this.el.append_column ( child_1.el );
109 var description = new Pango.FontDescription();
110 description.set_size(8000);
111 this.el.modify_font(description);
113 var selection = this.el.get_selection();
114 selection.set_mode( Gtk.SelectionMode.SINGLE);
117 // is this really needed??
119 this.selection.signal['changed'].connect(function() {
120 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
121 _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
125 Gtk.drag_source_set (
126 this.el, /* widget will be drag-able */
127 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
128 Builder4.Application.targetList, /* lists of target to support */
129 Gdk.DragAction.COPY | Gdk.DragAction.MOVE | Gdk.DragAction.LINK /* what to do with data after dropped */
133 //Gtk.drag_source_add_text_targets(this.el);
137 this.el, /* widget that will accept a drop */
138 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
139 Builder4.Application.targetList, /* lists of target to support */
140 Gdk.DragAction.COPY | Gdk.DragAction.MOVE | Gdk.DragAction.LINK /* what to do with data after dropped */
143 //Gtk.drag_dest_set_target_list(this.el, Builder.Application.targetList);
144 //Gtk.drag_dest_add_text_targets(this.el);
147 this.el.button_press_event.connect( ( ev) => {
148 //console.log("button press?");
149 if (! _this.before_node_change(null) ) {
154 if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button != 3) {
155 //print("click" + ev.type);
159 if (!_this.view.el.get_path_at_pos((int)ev.x,(int)ev.y, out res, null, null, null) ) {
163 this.el.get_selection().select_path(res);
165 //if (!this.get('/LeftTreeMenu').el) {
166 // this.get('/LeftTreeMenu').init();
169 _this.LeftTreeMenu.el.set_screen(Gdk.Screen.get_default());
170 _this.LeftTreeMenu.el.show_all();
171 _this.LeftTreeMenu.el.popup(null, null, null, 3, ev.time);
172 // print("click:" + res.path.to_string());
175 this.el.cursor_changed.connect( ( ) => {
178 if (this.blockChanges) { // probably not needed..
181 if (!_this.before_node_change(null) ) {
182 this.blockChanges = true;
183 this.el.get_selection().unselect_all();
184 this.blockChanges = false;
187 if (_this.model.file == null) {
191 //var render = this.get('/LeftTree').getRenderer();
192 print("LEFT TREE -> view -> selection changed called\n");
195 // -- it appears that the selection is not updated.
197 GLib.Timeout.add_full(GLib.Priority.DEFAULT,10 , () => {
200 if (this.el.get_selection().count_selected_rows() < 1) {
202 print("selected rows < 1\n");
203 //??this.model.load( false);
204 _this.node_selected(null);
209 //console.log('changed');
210 var s = this.el.get_selection();
213 s.get_selected(out mod, out iter);
218 _this.model.el.get_value(iter, 2, out value);
219 _this.model.activePath = mod.get_path(iter).to_string();
221 var node = (JsRender.Node)value.dup_object();
222 _this.node_selected(node);
225 //_this.after_node_change(node);
227 // _this.model.file.changed(node, "tree");
229 //Seed.print( value.get_string());
233 this.el.drag_begin.connect( ( ctx) => {
234 //print('SOURCE: drag-begin');
237 //this.targetData = "";
239 // find what is selected in our tree...
241 var s = _this.view.el.get_selection();
242 if (s.count_selected_rows() < 1) {
247 s.get_selected(out mod, out iter);
251 // set some properties of the tree for use by the dropped element.
253 _this.model.el.get_value(iter, 2, out value);
254 var tp = mod.get_path(iter).to_string();
255 var data = (JsRender.Node)(value.dup_object());
256 var xname = data.fqn();
257 print ("XNAME IS " + xname+ "\n");
259 this.dropList = _this.model.file.palete().getDropList(xname);
261 print ("DROP LIST IS " + string.joinv(", ", this.dropList) + "\n");
264 // make the drag icon a picture of the node that was selected
267 // by default returns the path..
268 var path = _this.model.el.get_path(iter);
271 var pix = this.el.create_row_drag_icon ( path);
273 Gtk.drag_set_icon_surface (ctx, pix) ;
277 this.el.drag_end.connect( (drag_context) => {
278 //Seed.print('LEFT-TREE: drag-end');
280 this.dropList = null;
281 // this.targetData = "";
282 this.highlightDropPath("",0);
285 this.el.drag_motion.connect( ( ctx, x, y, time) => {
286 print("got drag motion\n");
287 var src = Gtk.drag_get_source_widget(ctx);
291 if (src != this.el) {
295 // the point of this is to detect where an item could be dropped..
296 print("requesting drag data\n");
297 this.drag_in_motion = true;
299 // request data that will be recieved by the recieve...
302 this.el, // will receive 'drag-data-received' signal
303 ctx, // represents the current state of the DnD
304 Gdk.Atom.intern("STRING",true), // the target type we want
311 //print("button mask?: %d\n", this.el.get_modifier_mask());
312 //print("GETTING POS");
316 Gtk.TreeViewDropPosition pos;
317 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
319 // if there are not items in the tree.. the we have to set isOver to true for anything..
321 if (_this.model.el.iter_n_children(null) < 1) {
322 print("got NO children?\n");
325 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
329 // ------------- a drag from self..
332 //var action = Gdk.DragAction.COPY;
333 // unless we are copying!!! ctl button..
335 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
336 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
337 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
340 if (_this.model.el.iter_n_children(null) < 1) {
341 // no children.. -- asume it's ok..
343 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
345 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
346 Gdk.drag_status(ctx, action ,time);
349 // continue through to allow drop...
357 //print("ISOVER? " + isOver);
360 Gdk.drag_status(ctx, 0 ,time);
361 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
366 // drag node is parent of child..
367 //console.log("SRC TREEPATH: " + src.treepath);
368 //console.log("TARGET TREEPATH: " + data.path.to_string());
370 // nned to check a few here..
371 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
372 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
373 //Gtk.TreeViewDropPosition.AFTER
374 //Gtk.TreeViewDropPosition.BEFORE
376 // locally dragged items to not really use the
377 var selection_text = this.dragData;
381 if (selection_text == null || selection_text.length < 1) {
382 //print("Error - drag selection text returned NULL");
383 Gdk.drag_status(ctx, 0 ,time);
384 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
389 // see if we are dragging into ourself?
390 print ("got selection text of " + selection_text);
392 var target_path = path.to_string();
393 //print("target_path="+target_path);
396 if (selection_text == target_path) {
397 print("self drag ?? == we should perhaps allow copy onto self..\n");
399 Gdk.drag_status(ctx, 0 ,time);
400 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
402 // -- fixme -- this is not really correct..
407 //print("DUMPING DATA");
408 //console.dump(data);
411 //print(data.path.to_string() +' => '+ data.pos);
413 // dropList is a list of xtypes that this node could be dropped on.
414 // it is set up when we start to drag..
417 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
419 print("targetDAta: " + targetData +"\n");
421 if (targetData.length < 1) {
422 //print("Can not find drop node path");
424 Gdk.drag_status(ctx, 0, time);
425 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
429 var td_ar = targetData.split("|");
433 Gdk.drag_status(ctx, action ,time);
434 this.highlightDropPath(td_ar[0], (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
439 this.el.drag_data_get.connect( ( drag_context, data, info, time) => {
442 //print("drag-data-get");
443 var s = this.el.get_selection();
444 if (s.count_selected_rows() < 1) {
446 print("return empty string - no selection..");
453 s.get_selected(out mod, out iter);
458 _this.model.el.get_value(iter, 2, out value);
459 var ndata = (JsRender.Node)(value.dup_object());
460 var xname = ndata.fqn();
463 var tp = mod.get_path(iter).to_string();
464 // by default returns the path..
466 if ( info != Gdk.Atom.intern("STRING",true) ) {
467 tp = ndata.toJsonString();
470 //data.set_text(tp,tp.length);
472 data.set (data.get_target (), 8, (uchar[]) tp.to_utf8 ());
475 // print("return " + tp);
477 this.el.drag_data_received.connect( (ctx, x, y, sel, info, time) => {
479 // THIS CODE ONLY RELATES TO drag or drop of "NEW" elements or "FROM another tree.."
482 // print("Tree: drag-data-received\n");
483 var selection_text = (string)sel.get_data();
484 //print("selection_text= %s\n",selection_text);
486 var is_drag = this.drag_in_motion;
490 print("Is Drag %s\n", is_drag ? "Y": "N");
494 Gtk.TreeViewDropPosition pos;
495 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
497 // if there are not items in the tree.. the we have to set isOver to true for anything..
499 if (_this.model.el.iter_n_children(null) < 1) {
500 print("got NO children?\n");
503 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
507 //console.log("LEFT-TREE: drag-motion");
508 var src = Gtk.drag_get_source_widget(ctx);
510 // a drag from self - this should be handled by drop and motion.
511 if (src == this.el) {
512 print("Source == this element should not happen.. ? \n");
515 //print("drag_data_recieved from another element");
520 if (selection_text == null || selection_text.length < 1 || !isOver) {
521 // nothing valid foudn to drop...
522 print("empty sel text or not over");
524 Gdk.drag_status(ctx, 0, time);
525 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
528 Gtk.drag_finish (ctx, false, false, time); // drop failed..
533 var dropNode = new JsRender.Node();
535 var dropNodeType = selection_text;
536 var show_templates = true;
538 if (dropNodeType[0] == '{') {
539 var pa = new Json.Parser();
540 pa.load_from_data(dropNodeType);
542 dropNode.loadFromJson( pa.get_root().get_object(), 2);
543 dropNodeType = dropNode.fqn();
544 show_templates = false;
549 dropNode.setFqn(selection_text);
553 // dropList --- need to gather this ...
554 print("get dropList for : %s\n",dropNodeType);
555 var dropList = _this.model.file.palete().getDropList(dropNodeType);
557 print("dropList: %s\n", string.joinv(" , ", dropList));
558 //print("button mask?: %d\n", this.el.get_modifier_mask());
559 // if drag action is link ... then we can drop it anywahere...
560 //if ((ctx.get_actions() & Gdk.DragAction.LINK) > 0) {
561 // targetData = "%s|%d|".printf( path.to_string(), pos);
565 targetData = _this.model.findDropNodeByPath( isEmpty ? "" : path.to_string(), dropList, pos);
570 print("targetDAta: " + targetData +"\n");
572 if (targetData.length < 1) {
574 // invalid drop path..
575 if (this.drag_in_motion) {
576 Gdk.drag_status(ctx, 0, time);
577 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
580 Gtk.drag_finish (ctx, false, false, time); // drop failed..
586 var td_ar = targetData.split("|");
589 if (this.drag_in_motion) {
590 Gdk.drag_status(ctx, Gdk.DragAction.COPY ,time);
592 this.highlightDropPath( td_ar[0] , (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
595 // continue on to allow drop..
598 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
601 _this.model.dropNode(targetData, dropNode, show_templates);
602 print("ADD new node!!!\n");
604 ///Xcls_DialogTemplateSelect.singleton().show( _this.model.file.palete(), node);
606 Gtk.drag_finish (ctx, false, false,time);
613 this.el.drag_drop.connect( ( ctx, x, y, time) => {
614 //Seed.print("TARGET: drag-drop");
617 var src = Gtk.drag_get_source_widget(ctx);
619 if (src != this.el) {
623 this.drag_in_motion = false;
624 // request data that will be recieved by the recieve...
627 this.el, // will receive 'drag-data-received' signal
628 ctx, // represents the current state of the DnD
629 Gdk.Atom.intern("application/json",true), // the target type we want
634 // No target offered by source => error
640 // handle drop around self..
644 //print("GETTING POS");
648 Gtk.TreeViewDropPosition pos;
649 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
651 // if there are not items in the tree.. the we have to set isOver to true for anything..
653 if (_this.model.el.iter_n_children(null) < 1) {
654 print("got NO children?\n");
657 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
662 //var action = Gdk.DragAction.COPY;
663 // unless we are copying!!! ctl button..
665 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
666 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
667 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
670 if (_this.model.el.iter_n_children(null) < 1) {
671 // no children.. -- asume it's ok..
673 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
675 // continue through to allow drop...
683 //print("ISOVER? " + isOver);
686 Gtk.drag_finish (ctx, false, false, time); // drop failed..
687 return true; // not over apoint!?! - no action on drop or motion..
690 // drag node is parent of child..
691 //console.log("SRC TREEPATH: " + src.treepath);
692 //console.log("TARGET TREEPATH: " + data.path.to_string());
694 // nned to check a few here..
695 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
696 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
697 //Gtk.TreeViewDropPosition.AFTER
698 //Gtk.TreeViewDropPosition.BEFORE
700 // locally dragged items to not really use the
701 var selection_text = this.dragData;
705 if (selection_text == null || selection_text.length < 1) {
706 //print("Error - drag selection text returned NULL");
708 Gtk.drag_finish (ctx, false, false, time); // drop failed..
709 return true; /// -- fixme -- this is not really correct..
712 // see if we are dragging into ourself?
713 print ("got selection text of " + selection_text);
715 var target_path = path.to_string();
716 //print("target_path="+target_path);
719 if (selection_text == target_path) {
720 print("self drag ?? == we should perhaps allow copy onto self..\n");
722 Gtk.drag_finish (ctx, false, false, time); // drop failed..
724 return true; /// -- fixme -- this is not really correct..
729 //print("DUMPING DATA");
730 //console.dump(data);
733 //print(data.path.to_string() +' => '+ data.pos);
735 // dropList is a list of xtypes that this node could be dropped on.
736 // it is set up when we start to drag..
739 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
741 print("targetDAta: " + targetData +"\n");
743 if (targetData.length < 1) {
744 //print("Can not find drop node path");
746 Gtk.drag_finish (ctx, false, false, time); // drop failed..
750 var td_ar = targetData.split("|");
754 // continue on to allow drop..
756 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
759 var delete_selection_data = false;
761 if (action == Gdk.DragAction.ASK) {
762 /* Ask the user to move or copy, then set the ctx action. */
765 if (action == Gdk.DragAction.MOVE) {
766 delete_selection_data = true;
769 // drag around.. - reorder..
770 _this.model.moveNode(targetData, action);
776 // we can send stuff to souce here...
779 // do we always say failure, so we handle the reall drop?
780 Gtk.drag_finish (ctx, false, false,time); //delete_selection_data, time);
792 // user defined functions
793 public void highlightDropPath ( string treepath, Gtk.TreeViewDropPosition pos) {
795 // highlighting for drag/drop
796 if (treepath.length > 0) {
797 this.el.set_drag_dest_row( new Gtk.TreePath.from_string( treepath ), pos);
799 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
803 public void selectNode (string treepath_str) {
804 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
805 var tp = new Gtk.TreePath.from_string(treepath_str);
807 this.el.set_cursor(tp, null, false);
808 this.el.scroll_to_cell(tp, null, false, 0,0);
811 public class Xcls_model : Object
813 public Gtk.TreeStore el;
814 private Xcls_WindowLeftTree _this;
818 public DialogTemplateSelect template_select;
819 public JsRender.JsRender? file;
820 public string activePath;
821 public Project.Project? project;
824 public Xcls_model(Xcls_WindowLeftTree _owner )
828 this.el = new Gtk.TreeStore( 3, typeof(string),typeof(string),typeof(Object) );
831 this.template_select = null;
833 this.activePath = "";
836 // set gobject values
840 print("model initialized"); }
842 // user defined functions
843 public string findDropNode (string treepath_str, string[] targets) {
845 // this is used by the dragdrop code in the roo version AFAIR..
847 //var path = treepath_str.replace(/^builder-/, '');
848 // treemap is depreciated... - should really check if model has any entries..
850 if (this.el.iter_n_children(null) < 1) {
852 return "|%d".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
854 //print("FIND treepath: " + path);
855 //console.dump(this.treemap);
857 //if (!treepath_str.match(/^builder-/)) {
858 // return []; // nothing!
860 if (targets.length > 0 && targets[0] == "*") {
863 return this.findDropNodeByPath(treepath_str,targets, -1);
865 public void loadFile (JsRender.JsRender f) {
872 // console.log('missing file');
876 // load the file if not loaded..
877 if (f.tree == null) {
880 // if it's still null?
881 if (f.tree == null) {
885 /// this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name);
887 //if (f.items.length && typeof(f.items[0]) == 'string') {
889 //this.get('/RightEditor').el.show();
890 //this.get('/RightEditor.view').load( f.items[0]);
894 //print(JSON.stringify(f.items, null,4));
895 //console.dump(f.items);
896 var o = new Gee.ArrayList<JsRender.Node>();
900 _this.view.el.expand_all();
902 if (f.tree.items.size < 1) {
905 //this.get('/Window.leftvpaned').el.set_position(80);
907 _this.view.el.set_cursor(
908 new Gtk.TreePath.from_string("0"), null, false);
912 //this.get('/Window.leftvpaned').el.set_position(200);
918 //print("hide right editior");
919 //this.get('/RightEditor').el.hide();
920 //this.get('/Editor').el.hide();
921 //print("set current tree");
922 //this.currentTree = this.toJS(false, false)[0];
923 //console.dump(this.currentTree);
924 //this.currentTree = this.currentTree || { items: [] };
925 //_this.renderView();
926 //console.dump(this.map);
927 //var RightPalete = imports.Builder.RightPalete.RightPalete;
930 var pm = this.get('/RightPalete.model');
933 this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
935 if (!this.get('/RightPalete').provider) {
936 print ("********* PALETE PROVIDER MISSING?!!");
938 this.get('/LeftTree').renderView();
940 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
944 this.get('/Window.view-notebook').el.set_current_page(
945 this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
949 public void updateSelected () {
952 var s = _this.view.el.get_selection();
959 if (!s.get_selected(out mod, out iter)) {
960 return; // nothing seleted..
964 this.el.get_value(iter, 2, out value);
965 var node = (JsRender.Node)(value.get_object());
967 this.el.set(iter, 0, node.nodeTitle(),
968 1, node.nodeTip(), -1
971 public string findDropNodeByPath (string treepath_str, string[] targets, int in_pref = -1) {
973 var path = treepath_str; // dupe it..
975 int pref = in_pref < 0 ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : in_pref;
979 //console.dump(this.treemap);
981 print("findDropNodeByPath : got path length %d / %s\n", path.length, path);
983 if (path.length == 0) {
984 // top drop. // just return empty..
985 return "|%d".printf((int)pref) ;
990 while (path.length > 0) {
991 //print("LOOKING FOR PATH: " + path);
992 var node_data = this.pathToNode(path);
994 if (node_data == null) {
995 print("node not found");
999 var xname = node_data.fqn();
1003 for (var i =0; i < targets.length; i++) {
1004 var tg = targets[i];
1005 if ((tg == xname) ) {
1009 // if target is "xxxx:name"
1010 if (tg.contains(xname +":")) {
1012 var ar = tg.split(":");
1018 if (match.length > 0) {
1019 if (last.length > 0) { // pref is after/before..
1020 // then it's after last
1024 return last + "|%d".printf((int)pref) + "|" + prop;
1028 return path + "|%d".printf( (int) Gtk.TreeViewDropPosition.INTO_OR_AFTER) + "|" + prop;
1031 var par = path.split(":");
1032 string [] ppar = {};
1033 for (var i = 0; i < par.length-1; i++) {
1037 path = string.joinv(":", ppar);
1045 public void moveNode (string target_data, Gdk.DragAction action)
1048 /// target_data = "path|pos");
1051 //print("MOVE NODE");
1052 // console.dump(target_data);
1053 Gtk.TreeIter old_iter;
1056 var s = _this.view.el.get_selection();
1057 s.get_selected(out mod , out old_iter);
1058 mod.get_path(old_iter);
1060 var node = this.pathToNode(mod.get_path(old_iter).to_string());
1061 //console.dump(node);
1063 print("moveNode: ERROR - node is null?");
1068 // needs to drop first, otherwise the target_data
1069 // treepath will be invalid.
1072 if ((action & Gdk.DragAction.MOVE) > 0) {
1073 print("REMOVING OLD NODE : " + target_data + "\n");
1075 this.dropNode(target_data, node, false);
1076 this.el.remove(ref old_iter);
1081 print("DROPPING NODE // copy: " + target_data + "\n");
1082 node = node.deepClone();
1083 this.dropNode(target_data, node, false);
1086 this.activePath= "";
1087 //this.updateNode(false,true);
1089 public void load (Gee.ArrayList<JsRender.Node> tr, Gtk.TreeIter? iter)
1092 //this.insert(citer,iter,0);
1093 for(var i =0 ; i < tr.size; i++) {
1095 this.el.insert(out citer,iter,-1); // why not append?
1097 this.el.append(out citer,null);
1100 this.el.set(citer, 0, tr.get(i).nodeTitle(),
1101 1, tr.get(i).nodeTip(), -1
1103 var o = new GLib.Value(typeof(Object));
1104 o.set_object((Object)tr.get(i));
1106 this.el.set_value(citer, 2, o);
1108 if (tr.get(i).items.size > 0) {
1109 this.load(tr.get(i).items, citer);
1116 public void deleteSelected () {
1118 print("DELETE SELECTED?");
1119 //_this.view.blockChanges = true;
1120 print("GET SELECTION?");
1122 var s = _this.view.el.get_selection();
1124 print("GET SELECTED?");
1129 if (!s.get_selected(out mod, out iter)) {
1130 return; // nothing seleted..
1135 this.activePath= "";
1136 print("GET vnode value?");
1139 this.el.get_value(iter, 2, out value);
1140 var data = (JsRender.Node)(value.get_object());
1141 print("removing node from Render\n");
1142 if (data.parent == null) {
1143 this.file.tree = null;
1147 print("removing node from Tree\n");
1149 this.el.remove(ref iter);
1159 this.activePath= ""; // again!?!?
1160 //this.changed(null,true);
1164 _this.view.blockChanges = false;
1166 public JsRender.Node pathToNode (string path) {
1170 _this.model.el.get_iter_from_string(out iter, path);
1173 _this.model.el.get_value(iter, 2, out value);
1175 return (JsRender.Node)value.dup_object();
1178 public void dropNode (string target_data_str, JsRender.Node node, bool show_templates) {
1179 // print("drop Node");
1180 // console.dump(node);
1181 // console.dump(target_data);
1184 // 0 = before , 1=after 2/3 onto
1187 var target_data= target_data_str.split("|");
1189 var parent_str = target_data[0].length > 0 ? target_data[0] : "";
1190 var pos = target_data.length > 1 ? int.parse(target_data[1]) : 2; // ontop..
1193 Gtk.TreePath tree_path = parent_str.length > 0 ? new Gtk.TreePath.from_string( parent_str ) : null;
1197 //print("add " + tp + "@" + target_data[1] );
1199 JsRender.Node parentNode = null;
1201 Gtk.TreeIter iter_after;
1202 Gtk.TreeIter iter_par ;
1205 if (target_data.length == 3 && target_data[2].length > 0) {
1206 node.props.set("* prop", target_data[2]);
1209 Gtk.TreePath expand_parent = null;
1211 // we only need to show the template if it's come from else where?
1212 if (show_templates) {
1214 if (this.template_select == null) {
1215 this.template_select = new DialogTemplateSelect();
1218 var new_node = this.template_select.show(
1219 (Gtk.Window) _this.el.get_toplevel (),
1223 if (new_node != null) {
1228 //print("pos is %d \n".printf(pos));
1230 Gtk.TreeIter n_iter;
1232 if ( parent_str.length < 1) {
1233 this.el.append(out n_iter, null); // drop at top level..
1235 this.file.tree = node;
1238 } else if (pos < 2) {
1239 //print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
1241 this.el.get_iter(out iter_after, tree_path );
1242 this.el.iter_parent(out iter_par, iter_after);
1243 expand_parent = this.el.get_path(iter_par);
1246 this.el.get_value( iter_par, 2, out value);
1247 parentNode = (JsRender.Node)value.dup_object();
1250 this.el.get_value( iter_after, 2, out value);
1251 var relNode = (JsRender.Node)value.dup_object();
1255 this.el.insert_after(out n_iter, iter_par , iter_after);
1256 var ix = parentNode.items.index_of(relNode);
1257 parentNode.items.insert(ix+1, node);
1260 this.el.insert_before(out n_iter, iter_par , iter_after);
1261 var ix = parentNode.items.index_of(relNode);
1262 parentNode.items.insert(ix, node);
1265 node.parent = parentNode;
1270 // print("appending to " + parent_str);
1271 this.el.get_iter(out iter_par, tree_path);
1272 this.el.append(out n_iter, iter_par );
1273 expand_parent = this.el.get_path(iter_par);
1276 this.el.get_value( iter_par, 2, out value);
1277 parentNode = (JsRender.Node)value.dup_object();
1278 node.parent = parentNode;
1279 parentNode.items.add(node);
1282 // reparent node in tree...
1285 // why only on no parent???
1287 //if (node.parent = null) {
1294 // work out what kind of packing to use.. -- should be in
1295 if (!node.has("pack") && parent_str.length > 1) {
1297 this.file.palete().fillPack(node,parentNode);
1304 this.el.set(n_iter, 0, node.nodeTitle(), 1, node.nodeTip(), -1 );
1305 var o = new GLib.Value(typeof(Object));
1306 o.set_object((Object)node);
1308 this.el.set_value(n_iter, 2, o);
1313 // load children - if it has any..
1315 if (node.items.size > 0) {
1316 this.load(node.items, n_iter);
1317 _this.view.el.expand_row(this.el.get_path(n_iter), true);
1318 } else if (expand_parent != null && !_this.view.el.is_row_expanded(expand_parent)) {
1319 _this.view.el.expand_row(expand_parent,true);
1322 //if (tp != null && (node.items.length() > 0 || pos > 1)) {
1323 // _this.view.el.expand_row(this.el.get_path(iter_par), true);
1325 // wee need to get the empty proptypes from somewhere..
1327 //var olditer = this.activeIter;
1328 this.activePath = this.el.get_path(n_iter).to_string();
1333 _this.view.el.set_cursor(this.el.get_path(n_iter), null, false);
1340 public class Xcls_TreeViewColumn4 : Object
1342 public Gtk.TreeViewColumn el;
1343 private Xcls_WindowLeftTree _this;
1349 public Xcls_TreeViewColumn4(Xcls_WindowLeftTree _owner )
1352 this.el = new Gtk.TreeViewColumn();
1356 // set gobject values
1357 this.el.title = "test";
1358 var child_0 = new Xcls_renderer( _this );
1360 this.el.pack_start ( child_0.el , true );
1364 this.el.add_attribute(_this.renderer.el , "markup", 0 ); }
1366 // user defined functions
1368 public class Xcls_renderer : Object
1370 public Gtk.CellRendererText el;
1371 private Xcls_WindowLeftTree _this;
1377 public Xcls_renderer(Xcls_WindowLeftTree _owner )
1380 _this.renderer = this;
1381 this.el = new Gtk.CellRendererText();
1385 // set gobject values
1388 // user defined functions
1390 public class Xcls_LeftTreeMenu : Object
1393 private Xcls_WindowLeftTree _this;
1399 public Xcls_LeftTreeMenu(Xcls_WindowLeftTree _owner )
1402 _this.LeftTreeMenu = this;
1403 this.el = new Gtk.Menu();
1407 // set gobject values
1408 var child_0 = new Xcls_MenuItem7( _this );
1410 this.el.add ( child_0.el );
1411 var child_1 = new Xcls_MenuItem8( _this );
1413 this.el.add ( child_1.el );
1414 var child_2 = new Xcls_MenuItem9( _this );
1416 this.el.add ( child_2.el );
1419 // user defined functions
1421 public class Xcls_MenuItem7 : Object
1423 public Gtk.MenuItem el;
1424 private Xcls_WindowLeftTree _this;
1430 public Xcls_MenuItem7(Xcls_WindowLeftTree _owner )
1433 this.el = new Gtk.MenuItem();
1437 // set gobject values
1438 this.el.label = "Delete Element";
1441 this.el.activate.connect( ( ) => {
1446 _this.model.deleteSelected();
1450 // user defined functions
1452 public class Xcls_MenuItem8 : Object
1454 public Gtk.MenuItem el;
1455 private Xcls_WindowLeftTree _this;
1461 public Xcls_MenuItem8(Xcls_WindowLeftTree _owner )
1464 this.el = new Gtk.MenuItem();
1468 // set gobject values
1469 this.el.label = "Save as Template";
1472 this.el.activate.connect( () => {
1474 DialogSaveTemplate.singleton().show(
1475 (Gtk.Window) _this.el.get_toplevel (),
1476 _this.model.file.palete(),
1477 _this.getActiveElement()
1484 // user defined functions
1486 public class Xcls_MenuItem9 : Object
1488 public Gtk.MenuItem el;
1489 private Xcls_WindowLeftTree _this;
1495 public Xcls_MenuItem9(Xcls_WindowLeftTree _owner )
1498 this.el = new Gtk.MenuItem();
1502 // set gobject values
1503 this.el.label = "Save as Module";
1506 this.el.activate.connect( () => {
1507 var node = _this.getActiveElement();
1508 var name = DialogSaveModule.singleton().show(
1509 (Gtk.Window) _this.el.get_toplevel (),
1510 _this.model.file.project,
1513 if (name.length < 1) {
1517 node.props.set("* xinclude", name);
1521 var s = _this.view.el.get_selection();
1523 print("GET SELECTED?");
1528 if (!s.get_selected(out mod, out iter)) {
1529 return; // nothing seleted..
1532 var n_cn = mod.iter_n_children(iter) -1;
1533 for (var i = n_cn; i > -1; i--) {
1534 mod.iter_nth_child(out citer, iter, i);
1537 print("removing node from Tree\n");
1539 _this.model.el.remove(ref citer);
1542 _this.node_selected(node);
1548 // user defined functions