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);
560 print("dropList: %s\n", string.joinv(" , ", dropList));
563 Gdk.ModifierType dmask;
565 ctx.get_dest_window().get_device_position(ctx.get_device(), out dx, out dy, out dmask);
568 print("button mask?: %d\n", dmask);
569 // if drag action is shift ... then we can drop it anywahere...
570 if ((dmask & Gdk.ModifierType.SHIFT_MASK) > 0) {
571 targetData = "%s|%d|".printf( path.to_string(), pos);
575 targetData = _this.model.findDropNodeByPath( isEmpty ? "" : path.to_string(), dropList, pos);
580 print("targetDAta: " + targetData +"\n");
582 if (targetData.length < 1) {
584 // invalid drop path..
585 if (this.drag_in_motion) {
586 Gdk.drag_status(ctx, 0, time);
587 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
590 Gtk.drag_finish (ctx, false, false, time); // drop failed..
596 var td_ar = targetData.split("|");
599 if (this.drag_in_motion) {
600 Gdk.drag_status(ctx, Gdk.DragAction.COPY ,time);
602 this.highlightDropPath( td_ar[0] , (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
605 // continue on to allow drop..
608 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
611 _this.model.dropNode(targetData, dropNode, show_templates);
612 print("ADD new node!!!\n");
614 ///Xcls_DialogTemplateSelect.singleton().show( _this.model.file.palete(), node);
616 Gtk.drag_finish (ctx, false, false,time);
623 this.el.drag_drop.connect( ( ctx, x, y, time) => {
624 //Seed.print("TARGET: drag-drop");
627 var src = Gtk.drag_get_source_widget(ctx);
629 if (src != this.el) {
633 this.drag_in_motion = false;
634 // request data that will be recieved by the recieve...
637 this.el, // will receive 'drag-data-received' signal
638 ctx, // represents the current state of the DnD
639 Gdk.Atom.intern("application/json",true), // the target type we want
644 // No target offered by source => error
650 // handle drop around self..
654 //print("GETTING POS");
658 Gtk.TreeViewDropPosition pos;
659 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
661 // if there are not items in the tree.. the we have to set isOver to true for anything..
663 if (_this.model.el.iter_n_children(null) < 1) {
664 print("got NO children?\n");
667 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
672 //var action = Gdk.DragAction.COPY;
673 // unless we are copying!!! ctl button..
675 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
676 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
677 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
680 if (_this.model.el.iter_n_children(null) < 1) {
681 // no children.. -- asume it's ok..
683 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
685 // continue through to allow drop...
693 //print("ISOVER? " + isOver);
696 Gtk.drag_finish (ctx, false, false, time); // drop failed..
697 return true; // not over apoint!?! - no action on drop or motion..
700 // drag node is parent of child..
701 //console.log("SRC TREEPATH: " + src.treepath);
702 //console.log("TARGET TREEPATH: " + data.path.to_string());
704 // nned to check a few here..
705 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
706 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
707 //Gtk.TreeViewDropPosition.AFTER
708 //Gtk.TreeViewDropPosition.BEFORE
710 // locally dragged items to not really use the
711 var selection_text = this.dragData;
715 if (selection_text == null || selection_text.length < 1) {
716 //print("Error - drag selection text returned NULL");
718 Gtk.drag_finish (ctx, false, false, time); // drop failed..
719 return true; /// -- fixme -- this is not really correct..
722 // see if we are dragging into ourself?
723 print ("got selection text of " + selection_text);
725 var target_path = path.to_string();
726 //print("target_path="+target_path);
729 if (selection_text == target_path) {
730 print("self drag ?? == we should perhaps allow copy onto self..\n");
732 Gtk.drag_finish (ctx, false, false, time); // drop failed..
734 return true; /// -- fixme -- this is not really correct..
739 //print("DUMPING DATA");
740 //console.dump(data);
743 //print(data.path.to_string() +' => '+ data.pos);
745 // dropList is a list of xtypes that this node could be dropped on.
746 // it is set up when we start to drag..
749 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
751 print("targetDAta: " + targetData +"\n");
753 if (targetData.length < 1) {
754 //print("Can not find drop node path");
756 Gtk.drag_finish (ctx, false, false, time); // drop failed..
760 var td_ar = targetData.split("|");
764 // continue on to allow drop..
766 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
769 var delete_selection_data = false;
771 if (action == Gdk.DragAction.ASK) {
772 /* Ask the user to move or copy, then set the ctx action. */
775 if (action == Gdk.DragAction.MOVE) {
776 delete_selection_data = true;
779 // drag around.. - reorder..
780 _this.model.moveNode(targetData, action);
786 // we can send stuff to souce here...
789 // do we always say failure, so we handle the reall drop?
790 Gtk.drag_finish (ctx, false, false,time); //delete_selection_data, time);
802 // user defined functions
803 public void highlightDropPath ( string treepath, Gtk.TreeViewDropPosition pos) {
805 // highlighting for drag/drop
806 if (treepath.length > 0) {
807 this.el.set_drag_dest_row( new Gtk.TreePath.from_string( treepath ), pos);
809 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
813 public void selectNode (string treepath_str) {
814 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
815 var tp = new Gtk.TreePath.from_string(treepath_str);
817 this.el.set_cursor(tp, null, false);
818 this.el.scroll_to_cell(tp, null, false, 0,0);
821 public class Xcls_model : Object
823 public Gtk.TreeStore el;
824 private Xcls_WindowLeftTree _this;
828 public DialogTemplateSelect template_select;
829 public JsRender.JsRender? file;
830 public string activePath;
831 public Project.Project? project;
834 public Xcls_model(Xcls_WindowLeftTree _owner )
838 this.el = new Gtk.TreeStore( 3, typeof(string),typeof(string),typeof(Object) );
841 this.template_select = null;
843 this.activePath = "";
846 // set gobject values
850 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..
985 int pref = in_pref < 0 ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : in_pref;
989 //console.dump(this.treemap);
991 print("findDropNodeByPath : got path length %d / %s\n", path.length, path);
993 if (path.length == 0) {
994 // top drop. // just return empty..
995 return "|%d".printf((int)pref) ;
1000 while (path.length > 0) {
1001 //print("LOOKING FOR PATH: " + path);
1002 var node_data = this.pathToNode(path);
1004 if (node_data == null) {
1005 print("node not found");
1009 var xname = node_data.fqn();
1013 for (var i =0; i < targets.length; i++) {
1014 var tg = targets[i];
1015 if ((tg == xname) ) {
1019 // if target is "xxxx:name"
1020 if (tg.contains(xname +":")) {
1022 var ar = tg.split(":");
1028 if (match.length > 0) {
1029 if (last.length > 0) { // pref is after/before..
1030 // then it's after last
1034 return last + "|%d".printf((int)pref) + "|" + prop;
1038 return path + "|%d".printf( (int) Gtk.TreeViewDropPosition.INTO_OR_AFTER) + "|" + prop;
1041 var par = path.split(":");
1042 string [] ppar = {};
1043 for (var i = 0; i < par.length-1; i++) {
1047 path = string.joinv(":", ppar);
1055 public void moveNode (string target_data, Gdk.DragAction action)
1058 /// target_data = "path|pos");
1061 //print("MOVE NODE");
1062 // console.dump(target_data);
1063 Gtk.TreeIter old_iter;
1066 var s = _this.view.el.get_selection();
1067 s.get_selected(out mod , out old_iter);
1068 mod.get_path(old_iter);
1070 var node = this.pathToNode(mod.get_path(old_iter).to_string());
1071 //console.dump(node);
1073 print("moveNode: ERROR - node is null?");
1078 // needs to drop first, otherwise the target_data
1079 // treepath will be invalid.
1082 if ((action & Gdk.DragAction.MOVE) > 0) {
1083 print("REMOVING OLD NODE : " + target_data + "\n");
1085 this.dropNode(target_data, node, false);
1086 this.el.remove(ref old_iter);
1091 print("DROPPING NODE // copy: " + target_data + "\n");
1092 node = node.deepClone();
1093 this.dropNode(target_data, node, false);
1096 this.activePath= "";
1097 //this.updateNode(false,true);
1099 public void load (Gee.ArrayList<JsRender.Node> tr, Gtk.TreeIter? iter)
1102 //this.insert(citer,iter,0);
1103 for(var i =0 ; i < tr.size; i++) {
1105 this.el.insert(out citer,iter,-1); // why not append?
1107 this.el.append(out citer,null);
1110 this.el.set(citer, 0, tr.get(i).nodeTitle(),
1111 1, tr.get(i).nodeTip(), -1
1113 var o = new GLib.Value(typeof(Object));
1114 o.set_object((Object)tr.get(i));
1116 this.el.set_value(citer, 2, o);
1118 if (tr.get(i).items.size > 0) {
1119 this.load(tr.get(i).items, citer);
1126 public void deleteSelected () {
1128 print("DELETE SELECTED?");
1129 //_this.view.blockChanges = true;
1130 print("GET SELECTION?");
1132 var s = _this.view.el.get_selection();
1134 print("GET SELECTED?");
1139 if (!s.get_selected(out mod, out iter)) {
1140 return; // nothing seleted..
1145 this.activePath= "";
1146 print("GET vnode value?");
1149 this.el.get_value(iter, 2, out value);
1150 var data = (JsRender.Node)(value.get_object());
1151 print("removing node from Render\n");
1152 if (data.parent == null) {
1153 this.file.tree = null;
1157 print("removing node from Tree\n");
1159 this.el.remove(ref iter);
1169 this.activePath= ""; // again!?!?
1170 //this.changed(null,true);
1174 _this.view.blockChanges = false;
1176 public JsRender.Node pathToNode (string path) {
1180 _this.model.el.get_iter_from_string(out iter, path);
1183 _this.model.el.get_value(iter, 2, out value);
1185 return (JsRender.Node)value.dup_object();
1188 public void dropNode (string target_data_str, JsRender.Node node, bool show_templates) {
1189 // print("drop Node");
1190 // console.dump(node);
1191 // console.dump(target_data);
1194 // 0 = before , 1=after 2/3 onto
1197 var target_data= target_data_str.split("|");
1199 var parent_str = target_data[0].length > 0 ? target_data[0] : "";
1200 var pos = target_data.length > 1 ? int.parse(target_data[1]) : 2; // ontop..
1203 Gtk.TreePath tree_path = parent_str.length > 0 ? new Gtk.TreePath.from_string( parent_str ) : null;
1207 //print("add " + tp + "@" + target_data[1] );
1209 JsRender.Node parentNode = null;
1211 Gtk.TreeIter iter_after;
1212 Gtk.TreeIter iter_par ;
1215 if (target_data.length == 3 && target_data[2].length > 0) {
1216 node.props.set("* prop", target_data[2]);
1219 Gtk.TreePath expand_parent = null;
1221 // we only need to show the template if it's come from else where?
1222 if (show_templates) {
1224 if (this.template_select == null) {
1225 this.template_select = new DialogTemplateSelect();
1228 var new_node = this.template_select.show(
1229 (Gtk.Window) _this.el.get_toplevel (),
1233 if (new_node != null) {
1238 //print("pos is %d \n".printf(pos));
1240 Gtk.TreeIter n_iter;
1242 if ( parent_str.length < 1) {
1243 this.el.append(out n_iter, null); // drop at top level..
1245 this.file.tree = node;
1248 } else if (pos < 2) {
1249 //print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
1251 this.el.get_iter(out iter_after, tree_path );
1252 this.el.iter_parent(out iter_par, iter_after);
1253 expand_parent = this.el.get_path(iter_par);
1256 this.el.get_value( iter_par, 2, out value);
1257 parentNode = (JsRender.Node)value.dup_object();
1260 this.el.get_value( iter_after, 2, out value);
1261 var relNode = (JsRender.Node)value.dup_object();
1265 this.el.insert_after(out n_iter, iter_par , iter_after);
1266 var ix = parentNode.items.index_of(relNode);
1267 parentNode.items.insert(ix+1, node);
1270 this.el.insert_before(out n_iter, iter_par , iter_after);
1271 var ix = parentNode.items.index_of(relNode);
1272 parentNode.items.insert(ix, node);
1275 node.parent = parentNode;
1280 // print("appending to " + parent_str);
1281 this.el.get_iter(out iter_par, tree_path);
1282 this.el.append(out n_iter, iter_par );
1283 expand_parent = this.el.get_path(iter_par);
1286 this.el.get_value( iter_par, 2, out value);
1287 parentNode = (JsRender.Node)value.dup_object();
1288 node.parent = parentNode;
1289 parentNode.items.add(node);
1292 // reparent node in tree...
1295 // why only on no parent???
1297 //if (node.parent = null) {
1304 // work out what kind of packing to use.. -- should be in
1305 if (!node.has("pack") && parent_str.length > 1) {
1307 this.file.palete().fillPack(node,parentNode);
1314 this.el.set(n_iter, 0, node.nodeTitle(), 1, node.nodeTip(), -1 );
1315 var o = new GLib.Value(typeof(Object));
1316 o.set_object((Object)node);
1318 this.el.set_value(n_iter, 2, o);
1323 // load children - if it has any..
1325 if (node.items.size > 0) {
1326 this.load(node.items, n_iter);
1327 _this.view.el.expand_row(this.el.get_path(n_iter), true);
1328 } else if (expand_parent != null && !_this.view.el.is_row_expanded(expand_parent)) {
1329 _this.view.el.expand_row(expand_parent,true);
1332 //if (tp != null && (node.items.length() > 0 || pos > 1)) {
1333 // _this.view.el.expand_row(this.el.get_path(iter_par), true);
1335 // wee need to get the empty proptypes from somewhere..
1337 //var olditer = this.activeIter;
1338 this.activePath = this.el.get_path(n_iter).to_string();
1343 _this.view.el.set_cursor(this.el.get_path(n_iter), null, false);
1350 public class Xcls_TreeViewColumn4 : Object
1352 public Gtk.TreeViewColumn el;
1353 private Xcls_WindowLeftTree _this;
1359 public Xcls_TreeViewColumn4(Xcls_WindowLeftTree _owner )
1362 this.el = new Gtk.TreeViewColumn();
1366 // set gobject values
1367 this.el.title = "test";
1368 var child_0 = new Xcls_renderer( _this );
1370 this.el.pack_start ( child_0.el , true );
1374 this.el.add_attribute(_this.renderer.el , "markup", 0 ); }
1376 // user defined functions
1378 public class Xcls_renderer : Object
1380 public Gtk.CellRendererText el;
1381 private Xcls_WindowLeftTree _this;
1387 public Xcls_renderer(Xcls_WindowLeftTree _owner )
1390 _this.renderer = this;
1391 this.el = new Gtk.CellRendererText();
1395 // set gobject values
1398 // user defined functions
1400 public class Xcls_LeftTreeMenu : Object
1403 private Xcls_WindowLeftTree _this;
1409 public Xcls_LeftTreeMenu(Xcls_WindowLeftTree _owner )
1412 _this.LeftTreeMenu = this;
1413 this.el = new Gtk.Menu();
1417 // set gobject values
1418 var child_0 = new Xcls_MenuItem7( _this );
1420 this.el.add ( child_0.el );
1421 var child_1 = new Xcls_MenuItem8( _this );
1423 this.el.add ( child_1.el );
1424 var child_2 = new Xcls_MenuItem9( _this );
1426 this.el.add ( child_2.el );
1429 // user defined functions
1431 public class Xcls_MenuItem7 : Object
1433 public Gtk.MenuItem el;
1434 private Xcls_WindowLeftTree _this;
1440 public Xcls_MenuItem7(Xcls_WindowLeftTree _owner )
1443 this.el = new Gtk.MenuItem();
1447 // set gobject values
1448 this.el.label = "Delete Element";
1451 this.el.activate.connect( ( ) => {
1456 _this.model.deleteSelected();
1460 // user defined functions
1462 public class Xcls_MenuItem8 : Object
1464 public Gtk.MenuItem el;
1465 private Xcls_WindowLeftTree _this;
1471 public Xcls_MenuItem8(Xcls_WindowLeftTree _owner )
1474 this.el = new Gtk.MenuItem();
1478 // set gobject values
1479 this.el.label = "Save as Template";
1482 this.el.activate.connect( () => {
1484 DialogSaveTemplate.singleton().show(
1485 (Gtk.Window) _this.el.get_toplevel (),
1486 _this.model.file.palete(),
1487 _this.getActiveElement()
1494 // user defined functions
1496 public class Xcls_MenuItem9 : Object
1498 public Gtk.MenuItem el;
1499 private Xcls_WindowLeftTree _this;
1505 public Xcls_MenuItem9(Xcls_WindowLeftTree _owner )
1508 this.el = new Gtk.MenuItem();
1512 // set gobject values
1513 this.el.label = "Save as Module";
1516 this.el.activate.connect( () => {
1517 var node = _this.getActiveElement();
1518 var name = DialogSaveModule.singleton().show(
1519 (Gtk.Window) _this.el.get_toplevel (),
1520 _this.model.file.project,
1523 if (name.length < 1) {
1527 node.props.set("* xinclude", name);
1531 var s = _this.view.el.get_selection();
1533 print("GET SELECTED?");
1538 if (!s.get_selected(out mod, out iter)) {
1539 return; // nothing seleted..
1542 var n_cn = mod.iter_n_children(iter) -1;
1543 for (var i = n_cn; i > -1; i--) {
1544 mod.iter_nth_child(out citer, iter, i);
1547 print("removing node from Tree\n");
1549 _this.model.el.remove(ref citer);
1552 _this.node_selected(node);
1558 // user defined functions