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;
80 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.drag_begin.connect( ( ctx) => {
176 //print('SOURCE: drag-begin');
179 //this.targetData = "";
181 // find what is selected in our tree...
183 var s = _this.view.el.get_selection();
184 if (s.count_selected_rows() < 1) {
189 s.get_selected(out mod, out iter);
193 // set some properties of the tree for use by the dropped element.
195 _this.model.el.get_value(iter, 2, out value);
196 var tp = mod.get_path(iter).to_string();
197 var data = (JsRender.Node)(value.dup_object());
198 var xname = data.fqn();
199 print ("XNAME IS " + xname+ "\n");
201 this.dropList = _this.model.file.palete().getDropList(xname);
203 print ("DROP LIST IS " + string.joinv(", ", this.dropList) + "\n");
206 // make the drag icon a picture of the node that was selected
209 // by default returns the path..
210 var path = _this.model.el.get_path(iter);
213 var pix = this.el.create_row_drag_icon ( path);
215 Gtk.drag_set_icon_surface (ctx, pix) ;
219 this.el.cursor_changed.connect( ( ) => {
222 if (this.blockChanges) { // probably not needed..
225 if (!_this.before_node_change(null) ) {
226 this.blockChanges = true;
227 this.el.get_selection().unselect_all();
228 this.blockChanges = false;
231 if (_this.model.file == null) {
235 //var render = this.get('/LeftTree').getRenderer();
236 print("LEFT TREE -> view -> selection changed called\n");
239 // -- it appears that the selection is not updated.
241 GLib.Timeout.add_full(GLib.Priority.DEFAULT,10 , () => {
244 if (this.el.get_selection().count_selected_rows() < 1) {
246 print("selected rows < 1\n");
247 //??this.model.load( false);
248 _this.node_selected(null);
253 //console.log('changed');
254 var s = this.el.get_selection();
257 s.get_selected(out mod, out iter);
262 _this.model.el.get_value(iter, 2, out value);
263 _this.model.activePath = mod.get_path(iter).to_string();
265 var node = (JsRender.Node)value.dup_object();
266 _this.node_selected(node);
269 //_this.after_node_change(node);
271 // _this.model.file.changed(node, "tree");
273 //Seed.print( value.get_string());
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("action: %d\n", ctx.get_actions());
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 var target_path = path.to_string();
391 print ("Drag %s onto %s--%d\n ", selection_text, target_path, pos);
393 // pos : 3 = ontop - 0 = after, 1 = before
394 //print("target_path="+target_path);
397 if (selection_text == target_path) {
398 print("self drag ?? == we should perhaps allow copy onto self..\n");
400 Gdk.drag_status(ctx, 0 ,time);
401 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
403 // -- fixme -- this is not really correct..
408 //print("DUMPING DATA");
409 //console.dump(data);
412 //print(data.path.to_string() +' => '+ data.pos);
414 // dropList is a list of xtypes that this node could be dropped on.
415 // it is set up when we start to drag..
418 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
420 print("targetDAta: " + targetData +"\n");
422 if (targetData.length < 1) {
423 //print("Can not find drop node path");
425 Gdk.drag_status(ctx, 0, time);
426 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
430 var td_ar = targetData.split("|");
434 Gdk.drag_status(ctx, action ,time);
435 this.highlightDropPath(td_ar[0], (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
440 this.el.drag_data_get.connect( ( drag_context, data, info, time) => {
443 //print("drag-data-get");
444 var s = this.el.get_selection();
445 if (s.count_selected_rows() < 1) {
447 print("return empty string - no selection..");
454 s.get_selected(out mod, out iter);
459 _this.model.el.get_value(iter, 2, out value);
460 var ndata = (JsRender.Node)(value.dup_object());
461 var xname = ndata.fqn();
464 var tp = mod.get_path(iter).to_string();
465 // by default returns the path..
467 if ( info != Gdk.Atom.intern("STRING",true) ) {
468 tp = ndata.toJsonString();
471 //data.set_text(tp,tp.length);
473 data.set (data.get_target (), 8, (uchar[]) tp.to_utf8 ());
476 // print("return " + tp);
478 this.el.drag_data_received.connect( (ctx, x, y, sel, info, time) => {
480 // THIS CODE ONLY RELATES TO drag or drop of "NEW" elements or "FROM another tree.."
483 // print("Tree: drag-data-received\n");
484 var selection_text = (string)sel.get_data();
485 //print("selection_text= %s\n",selection_text);
487 var is_drag = this.drag_in_motion;
491 print("Is Drag %s\n", is_drag ? "Y": "N");
495 Gtk.TreeViewDropPosition pos;
496 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
498 // if there are not items in the tree.. the we have to set isOver to true for anything..
500 if (_this.model.el.iter_n_children(null) < 1) {
501 print("got NO children?\n");
504 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
508 //console.log("LEFT-TREE: drag-motion");
509 var src = Gtk.drag_get_source_widget(ctx);
511 // a drag from self - this should be handled by drop and motion.
512 if (src == this.el) {
513 print("Source == this element should not happen.. ? \n");
516 //print("drag_data_recieved from another element");
521 if (selection_text == null || selection_text.length < 1 || !isOver) {
522 // nothing valid foudn to drop...
523 print("empty sel text or not over");
525 Gdk.drag_status(ctx, 0, time);
526 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
529 Gtk.drag_finish (ctx, false, false, time); // drop failed..
534 var dropNode = new JsRender.Node();
536 var dropNodeType = selection_text;
537 var show_templates = true;
539 if (dropNodeType[0] == '{') {
540 var pa = new Json.Parser();
541 pa.load_from_data(dropNodeType);
543 dropNode.loadFromJson( pa.get_root().get_object(), 2);
544 dropNodeType = dropNode.fqn();
545 show_templates = false;
550 dropNode.setFqn(selection_text);
554 // dropList --- need to gather this ...
555 print("get dropList for : %s\n",dropNodeType);
556 var dropList = _this.model.file.palete().getDropList(dropNodeType);
558 print("dropList: %s\n", string.joinv(" , ", dropList));
560 // if drag action is link ... then we can drop it anywahere...
561 if ((ctx.get_actions() & Gdk.DragAction.LINK) > 0) {
562 targetData = path.to_string() + "";
566 targetData = _this.model.findDropNodeByPath( isEmpty ? "" : path.to_string(), dropList, pos);
571 print("targetDAta: " + targetData +"\n");
573 if (targetData.length < 1) {
575 // invalid drop path..
576 if (this.drag_in_motion) {
577 Gdk.drag_status(ctx, 0, time);
578 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
581 Gtk.drag_finish (ctx, false, false, time); // drop failed..
587 var td_ar = targetData.split("|");
590 if (this.drag_in_motion) {
591 Gdk.drag_status(ctx, Gdk.DragAction.COPY ,time);
593 this.highlightDropPath( td_ar[0] , (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
596 // continue on to allow drop..
599 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
602 _this.model.dropNode(targetData, dropNode, show_templates);
603 print("ADD new node!!!\n");
605 ///Xcls_DialogTemplateSelect.singleton().show( _this.model.file.palete(), node);
607 Gtk.drag_finish (ctx, false, false,time);
614 this.el.drag_drop.connect( ( ctx, x, y, time) => {
615 //Seed.print("TARGET: drag-drop");
618 var src = Gtk.drag_get_source_widget(ctx);
620 if (src != this.el) {
624 this.drag_in_motion = false;
625 // request data that will be recieved by the recieve...
628 this.el, // will receive 'drag-data-received' signal
629 ctx, // represents the current state of the DnD
630 Gdk.Atom.intern("application/json",true), // the target type we want
635 // No target offered by source => error
641 // handle drop around self..
645 //print("GETTING POS");
649 Gtk.TreeViewDropPosition pos;
650 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
652 // if there are not items in the tree.. the we have to set isOver to true for anything..
654 if (_this.model.el.iter_n_children(null) < 1) {
655 print("got NO children?\n");
658 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
663 //var action = Gdk.DragAction.COPY;
664 // unless we are copying!!! ctl button..
666 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
667 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
668 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
671 if (_this.model.el.iter_n_children(null) < 1) {
672 // no children.. -- asume it's ok..
674 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
676 // continue through to allow drop...
684 //print("ISOVER? " + isOver);
687 Gtk.drag_finish (ctx, false, false, time); // drop failed..
688 return true; // not over apoint!?! - no action on drop or motion..
691 // drag node is parent of child..
692 //console.log("SRC TREEPATH: " + src.treepath);
693 //console.log("TARGET TREEPATH: " + data.path.to_string());
695 // nned to check a few here..
696 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
697 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
698 //Gtk.TreeViewDropPosition.AFTER
699 //Gtk.TreeViewDropPosition.BEFORE
701 // locally dragged items to not really use the
702 var selection_text = this.dragData;
706 if (selection_text == null || selection_text.length < 1) {
707 //print("Error - drag selection text returned NULL");
709 Gtk.drag_finish (ctx, false, false, time); // drop failed..
710 return true; /// -- fixme -- this is not really correct..
713 // see if we are dragging into ourself?
714 print ("got selection text of " + selection_text);
716 var target_path = path.to_string();
717 //print("target_path="+target_path);
720 if (selection_text == target_path) {
721 print("self drag ?? == we should perhaps allow copy onto self..\n");
723 Gtk.drag_finish (ctx, false, false, time); // drop failed..
725 return true; /// -- fixme -- this is not really correct..
730 //print("DUMPING DATA");
731 //console.dump(data);
734 //print(data.path.to_string() +' => '+ data.pos);
736 // dropList is a list of xtypes that this node could be dropped on.
737 // it is set up when we start to drag..
740 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
742 print("targetDAta: " + targetData +"\n");
744 if (targetData.length < 1) {
745 //print("Can not find drop node path");
747 Gtk.drag_finish (ctx, false, false, time); // drop failed..
751 var td_ar = targetData.split("|");
755 // continue on to allow drop..
757 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
760 var delete_selection_data = false;
762 if (action == Gdk.DragAction.ASK) {
763 /* Ask the user to move or copy, then set the ctx action. */
766 if (action == Gdk.DragAction.MOVE) {
767 delete_selection_data = true;
770 // drag around.. - reorder..
771 _this.model.moveNode(targetData, action);
777 // we can send stuff to souce here...
780 // do we always say failure, so we handle the reall drop?
781 Gtk.drag_finish (ctx, false, false,time); //delete_selection_data, time);
793 // user defined functions
794 public void highlightDropPath ( string treepath, Gtk.TreeViewDropPosition pos) {
796 // highlighting for drag/drop
797 if (treepath.length > 0) {
798 this.el.set_drag_dest_row( new Gtk.TreePath.from_string( treepath ), pos);
800 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
804 public void selectNode (string treepath_str) {
805 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
806 var tp = new Gtk.TreePath.from_string(treepath_str);
808 this.el.set_cursor(tp, null, false);
809 this.el.scroll_to_cell(tp, null, false, 0,0);
812 public class Xcls_model : Object
814 public Gtk.TreeStore el;
815 private Xcls_WindowLeftTree _this;
819 public DialogTemplateSelect template_select;
820 public JsRender.JsRender? file;
821 public string activePath;
822 public Project.Project? project;
825 public Xcls_model(Xcls_WindowLeftTree _owner )
829 this.el = new Gtk.TreeStore( 3, typeof(string),typeof(string),typeof(Object) );
832 this.template_select = null;
834 this.activePath = "";
837 // set gobject values
841 print("model initialized"); }
843 // user defined functions
844 public string findDropNode (string treepath_str, string[] targets) {
846 // this is used by the dragdrop code in the roo version AFAIR..
848 //var path = treepath_str.replace(/^builder-/, '');
849 // treemap is depreciated... - should really check if model has any entries..
851 if (this.el.iter_n_children(null) < 1) {
853 return "|%d".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
855 //print("FIND treepath: " + path);
856 //console.dump(this.treemap);
858 //if (!treepath_str.match(/^builder-/)) {
859 // return []; // nothing!
861 if (targets.length > 0 && targets[0] == "*") {
864 return this.findDropNodeByPath(treepath_str,targets, -1);
866 public void loadFile (JsRender.JsRender f) {
873 // console.log('missing file');
877 // load the file if not loaded..
878 if (f.tree == null) {
881 // if it's still null?
882 if (f.tree == null) {
886 /// this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name);
888 //if (f.items.length && typeof(f.items[0]) == 'string') {
890 //this.get('/RightEditor').el.show();
891 //this.get('/RightEditor.view').load( f.items[0]);
895 //print(JSON.stringify(f.items, null,4));
896 //console.dump(f.items);
897 var o = new Gee.ArrayList<JsRender.Node>();
901 _this.view.el.expand_all();
903 if (f.tree.items.size < 1) {
906 //this.get('/Window.leftvpaned').el.set_position(80);
908 _this.view.el.set_cursor(
909 new Gtk.TreePath.from_string("0"), null, false);
913 //this.get('/Window.leftvpaned').el.set_position(200);
919 //print("hide right editior");
920 //this.get('/RightEditor').el.hide();
921 //this.get('/Editor').el.hide();
922 //print("set current tree");
923 //this.currentTree = this.toJS(false, false)[0];
924 //console.dump(this.currentTree);
925 //this.currentTree = this.currentTree || { items: [] };
926 //_this.renderView();
927 //console.dump(this.map);
928 //var RightPalete = imports.Builder.RightPalete.RightPalete;
931 var pm = this.get('/RightPalete.model');
934 this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
936 if (!this.get('/RightPalete').provider) {
937 print ("********* PALETE PROVIDER MISSING?!!");
939 this.get('/LeftTree').renderView();
941 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
945 this.get('/Window.view-notebook').el.set_current_page(
946 this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
950 public void updateSelected () {
953 var s = _this.view.el.get_selection();
960 if (!s.get_selected(out mod, out iter)) {
961 return; // nothing seleted..
965 this.el.get_value(iter, 2, out value);
966 var node = (JsRender.Node)(value.get_object());
968 this.el.set(iter, 0, node.nodeTitle(),
969 1, node.nodeTip(), -1
972 public string findDropNodeByPath (string treepath_str, string[] targets, int in_pref = -1) {
974 var path = treepath_str; // dupe it..
976 int pref = in_pref < 0 ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : in_pref;
980 //console.dump(this.treemap);
982 print("findDropNodeByPath : got path length %d / %s\n", path.length, path);
984 if (path.length == 0) {
985 // top drop. // just return empty..
986 return "|%d".printf((int)pref) ;
991 while (path.length > 0) {
992 //print("LOOKING FOR PATH: " + path);
993 var node_data = this.pathToNode(path);
995 if (node_data == null) {
996 print("node not found");
1000 var xname = node_data.fqn();
1004 for (var i =0; i < targets.length; i++) {
1005 var tg = targets[i];
1006 if ((tg == xname) ) {
1010 // if target is "xxxx:name"
1011 if (tg.contains(xname +":")) {
1013 var ar = tg.split(":");
1019 if (match.length > 0) {
1020 if (last.length > 0) { // pref is after/before..
1021 // then it's after last
1025 return last + "|%d".printf((int)pref) + "|" + prop;
1029 return path + "|%d".printf( (int) Gtk.TreeViewDropPosition.INTO_OR_AFTER) + "|" + prop;
1032 var par = path.split(":");
1033 string [] ppar = {};
1034 for (var i = 0; i < par.length-1; i++) {
1038 path = string.joinv(":", ppar);
1046 public void moveNode (string target_data, Gdk.DragAction action)
1049 /// target_data = "path|pos");
1052 //print("MOVE NODE");
1053 // console.dump(target_data);
1054 Gtk.TreeIter old_iter;
1057 var s = _this.view.el.get_selection();
1058 s.get_selected(out mod , out old_iter);
1059 mod.get_path(old_iter);
1061 var node = this.pathToNode(mod.get_path(old_iter).to_string());
1062 //console.dump(node);
1064 print("moveNode: ERROR - node is null?");
1069 // needs to drop first, otherwise the target_data
1070 // treepath will be invalid.
1073 if ((action & Gdk.DragAction.MOVE) > 0) {
1074 print("REMOVING OLD NODE : " + target_data + "\n");
1076 this.dropNode(target_data, node, false);
1077 this.el.remove(ref old_iter);
1082 print("DROPPING NODE // copy: " + target_data + "\n");
1083 node = node.deepClone();
1084 this.dropNode(target_data, node, false);
1087 this.activePath= "";
1088 //this.updateNode(false,true);
1090 public void load (Gee.ArrayList<JsRender.Node> tr, Gtk.TreeIter? iter)
1093 //this.insert(citer,iter,0);
1094 for(var i =0 ; i < tr.size; i++) {
1096 this.el.insert(out citer,iter,-1); // why not append?
1098 this.el.append(out citer,null);
1101 this.el.set(citer, 0, tr.get(i).nodeTitle(),
1102 1, tr.get(i).nodeTip(), -1
1104 var o = new GLib.Value(typeof(Object));
1105 o.set_object((Object)tr.get(i));
1107 this.el.set_value(citer, 2, o);
1109 if (tr.get(i).items.size > 0) {
1110 this.load(tr.get(i).items, citer);
1117 public void deleteSelected () {
1119 print("DELETE SELECTED?");
1120 //_this.view.blockChanges = true;
1121 print("GET SELECTION?");
1123 var s = _this.view.el.get_selection();
1125 print("GET SELECTED?");
1130 if (!s.get_selected(out mod, out iter)) {
1131 return; // nothing seleted..
1136 this.activePath= "";
1137 print("GET vnode value?");
1140 this.el.get_value(iter, 2, out value);
1141 var data = (JsRender.Node)(value.get_object());
1142 print("removing node from Render\n");
1143 if (data.parent == null) {
1144 this.file.tree = null;
1148 print("removing node from Tree\n");
1150 this.el.remove(ref iter);
1160 this.activePath= ""; // again!?!?
1161 //this.changed(null,true);
1165 _this.view.blockChanges = false;
1167 public JsRender.Node pathToNode (string path) {
1171 _this.model.el.get_iter_from_string(out iter, path);
1174 _this.model.el.get_value(iter, 2, out value);
1176 return (JsRender.Node)value.dup_object();
1179 public void dropNode (string target_data_str, JsRender.Node node, bool show_templates) {
1180 // print("drop Node");
1181 // console.dump(node);
1182 // console.dump(target_data);
1185 // 0 = before , 1=after 2/3 onto
1188 var target_data= target_data_str.split("|");
1190 var parent_str = target_data[0].length > 0 ? target_data[0] : "";
1191 var pos = target_data.length > 1 ? int.parse(target_data[1]) : 2; // ontop..
1194 Gtk.TreePath tree_path = parent_str.length > 0 ? new Gtk.TreePath.from_string( parent_str ) : null;
1198 //print("add " + tp + "@" + target_data[1] );
1200 JsRender.Node parentNode = null;
1202 Gtk.TreeIter iter_after;
1203 Gtk.TreeIter iter_par ;
1206 if (target_data.length == 3 && target_data[2].length > 0) {
1207 node.props.set("* prop", target_data[2]);
1210 Gtk.TreePath expand_parent = null;
1212 // we only need to show the template if it's come from else where?
1213 if (show_templates) {
1215 if (this.template_select == null) {
1216 this.template_select = new DialogTemplateSelect();
1219 var new_node = this.template_select.show(
1220 (Gtk.Window) _this.el.get_toplevel (),
1224 if (new_node != null) {
1229 //print("pos is %d \n".printf(pos));
1231 Gtk.TreeIter n_iter;
1233 if ( parent_str.length < 1) {
1234 this.el.append(out n_iter, null); // drop at top level..
1236 this.file.tree = node;
1239 } else if (pos < 2) {
1240 //print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
1242 this.el.get_iter(out iter_after, tree_path );
1243 this.el.iter_parent(out iter_par, iter_after);
1244 expand_parent = this.el.get_path(iter_par);
1247 this.el.get_value( iter_par, 2, out value);
1248 parentNode = (JsRender.Node)value.dup_object();
1251 this.el.get_value( iter_after, 2, out value);
1252 var relNode = (JsRender.Node)value.dup_object();
1256 this.el.insert_after(out n_iter, iter_par , iter_after);
1257 var ix = parentNode.items.index_of(relNode);
1258 parentNode.items.insert(ix+1, node);
1261 this.el.insert_before(out n_iter, iter_par , iter_after);
1262 var ix = parentNode.items.index_of(relNode);
1263 parentNode.items.insert(ix, node);
1266 node.parent = parentNode;
1271 // print("appending to " + parent_str);
1272 this.el.get_iter(out iter_par, tree_path);
1273 this.el.append(out n_iter, iter_par );
1274 expand_parent = this.el.get_path(iter_par);
1277 this.el.get_value( iter_par, 2, out value);
1278 parentNode = (JsRender.Node)value.dup_object();
1279 node.parent = parentNode;
1280 parentNode.items.add(node);
1283 // reparent node in tree...
1286 // why only on no parent???
1288 //if (node.parent = null) {
1295 // work out what kind of packing to use.. -- should be in
1296 if (!node.has("pack") && parent_str.length > 1) {
1298 this.file.palete().fillPack(node,parentNode);
1305 this.el.set(n_iter, 0, node.nodeTitle(), 1, node.nodeTip(), -1 );
1306 var o = new GLib.Value(typeof(Object));
1307 o.set_object((Object)node);
1309 this.el.set_value(n_iter, 2, o);
1314 // load children - if it has any..
1316 if (node.items.size > 0) {
1317 this.load(node.items, n_iter);
1318 _this.view.el.expand_row(this.el.get_path(n_iter), true);
1319 } else if (expand_parent != null && !_this.view.el.is_row_expanded(expand_parent)) {
1320 _this.view.el.expand_row(expand_parent,true);
1323 //if (tp != null && (node.items.length() > 0 || pos > 1)) {
1324 // _this.view.el.expand_row(this.el.get_path(iter_par), true);
1326 // wee need to get the empty proptypes from somewhere..
1328 //var olditer = this.activeIter;
1329 this.activePath = this.el.get_path(n_iter).to_string();
1334 _this.view.el.set_cursor(this.el.get_path(n_iter), null, false);
1341 public class Xcls_TreeViewColumn4 : Object
1343 public Gtk.TreeViewColumn el;
1344 private Xcls_WindowLeftTree _this;
1350 public Xcls_TreeViewColumn4(Xcls_WindowLeftTree _owner )
1353 this.el = new Gtk.TreeViewColumn();
1357 // set gobject values
1358 this.el.title = "test";
1359 var child_0 = new Xcls_renderer( _this );
1361 this.el.pack_start ( child_0.el , true );
1365 this.el.add_attribute(_this.renderer.el , "markup", 0 ); }
1367 // user defined functions
1369 public class Xcls_renderer : Object
1371 public Gtk.CellRendererText el;
1372 private Xcls_WindowLeftTree _this;
1378 public Xcls_renderer(Xcls_WindowLeftTree _owner )
1381 _this.renderer = this;
1382 this.el = new Gtk.CellRendererText();
1386 // set gobject values
1389 // user defined functions
1391 public class Xcls_LeftTreeMenu : Object
1394 private Xcls_WindowLeftTree _this;
1400 public Xcls_LeftTreeMenu(Xcls_WindowLeftTree _owner )
1403 _this.LeftTreeMenu = this;
1404 this.el = new Gtk.Menu();
1408 // set gobject values
1409 var child_0 = new Xcls_MenuItem7( _this );
1411 this.el.add ( child_0.el );
1412 var child_1 = new Xcls_MenuItem8( _this );
1414 this.el.add ( child_1.el );
1415 var child_2 = new Xcls_MenuItem9( _this );
1417 this.el.add ( child_2.el );
1420 // user defined functions
1422 public class Xcls_MenuItem7 : Object
1424 public Gtk.MenuItem el;
1425 private Xcls_WindowLeftTree _this;
1431 public Xcls_MenuItem7(Xcls_WindowLeftTree _owner )
1434 this.el = new Gtk.MenuItem();
1438 // set gobject values
1439 this.el.label = "Delete Element";
1442 this.el.activate.connect( ( ) => {
1447 _this.model.deleteSelected();
1451 // user defined functions
1453 public class Xcls_MenuItem8 : Object
1455 public Gtk.MenuItem el;
1456 private Xcls_WindowLeftTree _this;
1462 public Xcls_MenuItem8(Xcls_WindowLeftTree _owner )
1465 this.el = new Gtk.MenuItem();
1469 // set gobject values
1470 this.el.label = "Save as Template";
1473 this.el.activate.connect( () => {
1475 DialogSaveTemplate.singleton().show(
1476 (Gtk.Window) _this.el.get_toplevel (),
1477 _this.model.file.palete(),
1478 _this.getActiveElement()
1485 // user defined functions
1487 public class Xcls_MenuItem9 : Object
1489 public Gtk.MenuItem el;
1490 private Xcls_WindowLeftTree _this;
1496 public Xcls_MenuItem9(Xcls_WindowLeftTree _owner )
1499 this.el = new Gtk.MenuItem();
1503 // set gobject values
1504 this.el.label = "Save as Module";
1507 this.el.activate.connect( () => {
1508 var node = _this.getActiveElement();
1509 var name = DialogSaveModule.singleton().show(
1510 (Gtk.Window) _this.el.get_toplevel (),
1511 _this.model.file.project,
1514 if (name.length < 1) {
1518 node.props.set("* xinclude", name);
1522 var s = _this.view.el.get_selection();
1524 print("GET SELECTED?");
1529 if (!s.get_selected(out mod, out iter)) {
1530 return; // nothing seleted..
1533 var n_cn = mod.iter_n_children(iter) -1;
1534 for (var i = n_cn; i > -1; i--) {
1535 mod.iter_nth_child(out citer, iter, i);
1538 print("removing node from Tree\n");
1540 _this.model.el.remove(ref citer);
1543 _this.node_selected(node);
1549 // user defined functions