1 static Xcls_WindowLeftTree _WindowLeftTree;
3 public class Xcls_WindowLeftTree : Object
5 public Gtk.ScrolledWindow el;
6 private Xcls_WindowLeftTree _this;
8 public static Xcls_WindowLeftTree singleton()
10 if (_WindowLeftTree == null) {
11 _WindowLeftTree= new Xcls_WindowLeftTree();
13 return _WindowLeftTree;
15 public Xcls_view view;
16 public Xcls_model model;
17 public Xcls_renderer renderer;
18 public Xcls_LeftTreeMenu LeftTreeMenu;
21 public signal bool before_node_change (JsRender.Node? node);
22 public signal void changed ();
23 public signal void node_selected (JsRender.Node? node);
24 public Xcls_MainWindow main_window;
27 public Xcls_WindowLeftTree()
30 this.el = new Gtk.ScrolledWindow( null, null );
33 this.main_window = null;
36 this.el.shadow_type = Gtk.ShadowType.IN;
37 var child_0 = new Xcls_view( _this );
39 this.el.add ( child_0.el );
40 var child_1 = new Xcls_LeftTreeMenu( _this );
45 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
48 // user defined functions
49 public JsRender.Node? getActiveElement () { // return path to actie node.
51 var path = this.getActivePath();
52 if (path.length < 1) {
55 return _this.model.pathToNode(path);
58 public JsRender.JsRender getActiveFile () {
59 return this.model.file;
61 public string getActivePath () {
62 var model = this.model;
63 var view = this.view.el;
64 if (view.get_selection().count_selected_rows() < 1) {
69 view.get_selection().get_selected(out mod, out iter);
70 return mod.get_path(iter).to_string();
72 public class Xcls_view : Object
74 public Gtk.TreeView el;
75 private Xcls_WindowLeftTree _this;
79 public string dragData;
81 public string[] dropList;
83 public bool drag_in_motion;
84 public bool blockChanges;
87 public Xcls_view(Xcls_WindowLeftTree _owner )
91 this.el = new Gtk.TreeView();
94 this.blockChanges = false;
97 this.el.tooltip_column = 1;
98 this.el.enable_tree_lines = true;
99 this.el.headers_visible = false;
100 var child_0 = new Xcls_model( _this );
102 this.el.set_model ( child_0.el );
103 var child_1 = new Xcls_TreeViewColumn4( _this );
105 this.el.append_column ( child_1.el );
110 var description = new Pango.FontDescription();
111 description.set_size(8000);
112 this.el.modify_font(description);
114 var selection = this.el.get_selection();
115 selection.set_mode( Gtk.SelectionMode.SINGLE);
118 // is this really needed??
120 this.selection.signal['changed'].connect(function() {
121 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
122 _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
126 Gtk.drag_source_set (
127 this.el, /* widget will be drag-able */
128 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
129 BuilderApplication.targetList, /* lists of target to support */
130 Gdk.DragAction.COPY | Gdk.DragAction.MOVE | Gdk.DragAction.LINK /* what to do with data after dropped */
134 //Gtk.drag_source_add_text_targets(this.el);
138 this.el, /* widget that will accept a drop */
139 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
140 BuilderApplication.targetList, /* lists of target to support */
141 Gdk.DragAction.COPY | Gdk.DragAction.MOVE | Gdk.DragAction.LINK /* what to do with data after dropped */
144 //Gtk.drag_dest_set_target_list(this.el, Builder.Application.targetList);
145 //Gtk.drag_dest_add_text_targets(this.el);
149 this.el.button_press_event.connect( ( ev) => {
150 //console.log("button press?");
151 if (! _this.before_node_change(null) ) {
156 if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button != 3) {
157 //print("click" + ev.type);
161 if (!_this.view.el.get_path_at_pos((int)ev.x,(int)ev.y, out res, null, null, null) ) {
165 this.el.get_selection().select_path(res);
167 //if (!this.get('/LeftTreeMenu').el) {
168 // this.get('/LeftTreeMenu').init();
171 _this.LeftTreeMenu.el.set_screen(Gdk.Screen.get_default());
172 _this.LeftTreeMenu.el.show_all();
173 _this.LeftTreeMenu.el.popup(null, null, null, 3, ev.time);
174 // print("click:" + res.path.to_string());
177 this.el.drag_begin.connect( ( ctx) => {
178 //print('SOURCE: drag-begin');
181 //this.targetData = "";
183 // find what is selected in our tree...
185 var s = _this.view.el.get_selection();
186 if (s.count_selected_rows() < 1) {
191 s.get_selected(out mod, out iter);
195 // set some properties of the tree for use by the dropped element.
197 _this.model.el.get_value(iter, 2, out value);
198 var tp = mod.get_path(iter).to_string();
199 var data = (JsRender.Node)(value.dup_object());
200 var xname = data.fqn();
201 print ("XNAME IS " + xname+ "\n");
203 this.dropList = _this.model.file.palete().getDropList(xname);
205 print ("DROP LIST IS " + string.joinv(", ", this.dropList) + "\n");
208 // make the drag icon a picture of the node that was selected
211 // by default returns the path..
212 var path = _this.model.el.get_path(iter);
215 var pix = this.el.create_row_drag_icon ( path);
217 Gtk.drag_set_icon_surface (ctx, pix) ;
221 this.el.cursor_changed.connect( ( ) => {
224 if (this.blockChanges) { // probably not needed..
227 if (!_this.before_node_change(null) ) {
228 this.blockChanges = true;
229 this.el.get_selection().unselect_all();
230 this.blockChanges = false;
233 if (_this.model.file == null) {
237 //var render = this.get('/LeftTree').getRenderer();
238 print("LEFT TREE -> view -> selection changed called\n");
241 // -- it appears that the selection is not updated.
243 GLib.Timeout.add_full(GLib.Priority.DEFAULT,10 , () => {
246 if (this.el.get_selection().count_selected_rows() < 1) {
248 print("selected rows < 1\n");
249 //??this.model.load( false);
250 _this.node_selected(null);
255 //console.log('changed');
256 var s = this.el.get_selection();
259 s.get_selected(out mod, out iter);
264 _this.model.el.get_value(iter, 2, out value);
265 _this.model.activePath = mod.get_path(iter).to_string();
267 var node = (JsRender.Node)value.dup_object();
268 _this.node_selected(node);
270 this.el.scroll_to_cell(_this.model.activePath, false, 0.5f,0.0f);
274 //_this.after_node_change(node);
276 // _this.model.file.changed(node, "tree");
278 //Seed.print( value.get_string());
282 this.el.drag_end.connect( (drag_context) => {
283 //Seed.print('LEFT-TREE: drag-end');
285 this.dropList = null;
286 // this.targetData = "";
287 this.highlightDropPath("",0);
290 this.el.drag_motion.connect( ( ctx, x, y, time) => {
291 print("got drag motion\n");
292 var src = Gtk.drag_get_source_widget(ctx);
296 if (src != this.el) {
300 // the point of this is to detect where an item could be dropped..
301 print("requesting drag data\n");
302 this.drag_in_motion = true;
304 // request data that will be recieved by the recieve...
307 this.el, // will receive 'drag-data-received' signal
308 ctx, // represents the current state of the DnD
309 Gdk.Atom.intern("STRING",true), // the target type we want
316 print("action: %d\n", ctx.get_actions());
317 //print("GETTING POS");
321 Gtk.TreeViewDropPosition pos;
322 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
324 // if there are not items in the tree.. the we have to set isOver to true for anything..
326 if (_this.model.el.iter_n_children(null) < 1) {
327 print("got NO children?\n");
330 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
334 // ------------- a drag from self..
337 //var action = Gdk.DragAction.COPY;
338 // unless we are copying!!! ctl button..
340 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
341 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
342 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
345 if (_this.model.el.iter_n_children(null) < 1) {
346 // no children.. -- asume it's ok..
348 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
350 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
351 Gdk.drag_status(ctx, action ,time);
354 // continue through to allow drop...
362 //print("ISOVER? " + isOver);
365 Gdk.drag_status(ctx, 0 ,time);
366 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
371 // drag node is parent of child..
372 //console.log("SRC TREEPATH: " + src.treepath);
373 //console.log("TARGET TREEPATH: " + data.path.to_string());
375 // nned to check a few here..
376 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
377 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
378 //Gtk.TreeViewDropPosition.AFTER
379 //Gtk.TreeViewDropPosition.BEFORE
381 // locally dragged items to not really use the
382 var selection_text = this.dragData;
386 if (selection_text == null || selection_text.length < 1) {
387 //print("Error - drag selection text returned NULL");
388 Gdk.drag_status(ctx, 0 ,time);
389 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
394 // see if we are dragging into ourself?
395 var target_path = path.to_string();
396 print ("Drag %s onto %s--%d\n ", selection_text, target_path, pos);
398 // pos : 3 = ontop - 0 = after, 1 = before
399 //print("target_path="+target_path);
402 if (selection_text == target_path) {
403 print("self drag ?? == we should perhaps allow copy onto self..\n");
405 Gdk.drag_status(ctx, 0 ,time);
406 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
408 // -- fixme -- this is not really correct..
413 //print("DUMPING DATA");
414 //console.dump(data);
417 //print(data.path.to_string() +' => '+ data.pos);
419 // dropList is a list of xtypes that this node could be dropped on.
420 // it is set up when we start to drag..
423 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
425 print("targetDAta: " + targetData +"\n");
427 if (targetData.length < 1) {
428 //print("Can not find drop node path");
430 Gdk.drag_status(ctx, 0, time);
431 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
435 var td_ar = targetData.split("|");
439 Gdk.drag_status(ctx, action ,time);
440 this.highlightDropPath(td_ar[0], (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
445 this.el.drag_data_get.connect( ( drag_context, data, info, time) => {
448 //print("drag-data-get");
449 var s = this.el.get_selection();
450 if (s.count_selected_rows() < 1) {
452 print("return empty string - no selection..");
459 s.get_selected(out mod, out iter);
464 _this.model.el.get_value(iter, 2, out value);
465 var ndata = (JsRender.Node)(value.dup_object());
466 var xname = ndata.fqn();
469 var tp = mod.get_path(iter).to_string();
470 // by default returns the path..
472 if ( info != Gdk.Atom.intern("STRING",true) ) {
473 tp = ndata.toJsonString();
476 //data.set_text(tp,tp.length);
478 data.set (data.get_target (), 8, (uchar[]) tp.to_utf8 ());
481 // print("return " + tp);
483 this.el.drag_data_received.connect( (ctx, x, y, sel, info, time) => {
485 // THIS CODE ONLY RELATES TO drag or drop of "NEW" elements or "FROM another tree.."
488 // print("Tree: drag-data-received\n");
489 var selection_text = (string)sel.get_data();
490 //print("selection_text= %s\n",selection_text);
492 var is_drag = this.drag_in_motion;
496 print("Is Drag %s\n", is_drag ? "Y": "N");
500 Gtk.TreeViewDropPosition pos;
501 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
503 // if there are not items in the tree.. the we have to set isOver to true for anything..
505 if (_this.model.el.iter_n_children(null) < 1) {
506 print("got NO children?\n");
509 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
513 //console.log("LEFT-TREE: drag-motion");
514 var src = Gtk.drag_get_source_widget(ctx);
516 // a drag from self - this should be handled by drop and motion.
517 if (src == this.el) {
518 print("Source == this element should not happen.. ? \n");
521 //print("drag_data_recieved from another element");
526 if (selection_text == null || selection_text.length < 1 || !isOver) {
527 // nothing valid foudn to drop...
528 print("empty sel text or not over");
530 Gdk.drag_status(ctx, 0, time);
531 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
534 Gtk.drag_finish (ctx, false, false, time); // drop failed..
539 var dropNode = new JsRender.Node();
541 var dropNodeType = selection_text;
542 var show_templates = true;
544 if (dropNodeType[0] == '{') {
545 var pa = new Json.Parser();
546 pa.load_from_data(dropNodeType);
548 dropNode.loadFromJson( pa.get_root().get_object(), 2);
549 dropNodeType = dropNode.fqn();
550 show_templates = false;
555 dropNode.setFqn(selection_text);
559 // dropList --- need to gather this ...
560 print("get dropList for : %s\n",dropNodeType);
561 var dropList = _this.model.file.palete().getDropList(dropNodeType);
563 print("dropList: %s\n", string.joinv(" , ", dropList));
565 // if drag action is link ... then we can drop it anywahere...
566 if ((ctx.get_actions() & Gdk.DragAction.LINK) > 0) {
567 // if path is null?? dragging into an empty tree?
568 targetData = (path == null ? "" : path.to_string()) + "|%d".printf((int)pos);
572 targetData = _this.model.findDropNodeByPath( isEmpty ? "" : path.to_string(), dropList, pos);
577 print("targetDAta: " + targetData +"\n");
579 if (targetData.length < 1) {
581 // invalid drop path..
582 if (this.drag_in_motion) {
583 Gdk.drag_status(ctx, 0, time);
584 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
587 Gtk.drag_finish (ctx, false, false, time); // drop failed..
593 var td_ar = targetData.split("|");
596 if (this.drag_in_motion) {
597 Gdk.drag_status(ctx, Gdk.DragAction.COPY ,time);
599 this.highlightDropPath( td_ar[0] , (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
602 // continue on to allow drop..
605 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
608 _this.model.dropNode(targetData, dropNode, show_templates);
609 print("ADD new node!!!\n");
611 ///Xcls_DialogTemplateSelect.singleton().show( _this.model.file.palete(), node);
613 Gtk.drag_finish (ctx, false, false,time);
620 this.el.drag_drop.connect( ( ctx, x, y, time) => {
621 //Seed.print("TARGET: drag-drop");
624 var src = Gtk.drag_get_source_widget(ctx);
626 if (src != this.el) {
630 this.drag_in_motion = false;
631 // request data that will be recieved by the recieve...
634 this.el, // will receive 'drag-data-received' signal
635 ctx, // represents the current state of the DnD
636 Gdk.Atom.intern("application/json",true), // the target type we want
641 // No target offered by source => error
647 // handle drop around self..
651 //print("GETTING POS");
655 Gtk.TreeViewDropPosition pos;
656 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
658 // if there are not items in the tree.. the we have to set isOver to true for anything..
660 if (_this.model.el.iter_n_children(null) < 1) {
661 print("got NO children?\n");
664 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
669 //var action = Gdk.DragAction.COPY;
670 // unless we are copying!!! ctl button..
672 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
673 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
674 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
677 if (_this.model.el.iter_n_children(null) < 1) {
678 // no children.. -- asume it's ok..
680 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
682 // continue through to allow drop...
690 //print("ISOVER? " + isOver);
693 Gtk.drag_finish (ctx, false, false, time); // drop failed..
694 return true; // not over apoint!?! - no action on drop or motion..
697 // drag node is parent of child..
698 //console.log("SRC TREEPATH: " + src.treepath);
699 //console.log("TARGET TREEPATH: " + data.path.to_string());
701 // nned to check a few here..
702 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
703 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
704 //Gtk.TreeViewDropPosition.AFTER
705 //Gtk.TreeViewDropPosition.BEFORE
707 // locally dragged items to not really use the
708 var selection_text = this.dragData;
712 if (selection_text == null || selection_text.length < 1) {
713 //print("Error - drag selection text returned NULL");
715 Gtk.drag_finish (ctx, false, false, time); // drop failed..
716 return true; /// -- fixme -- this is not really correct..
719 // see if we are dragging into ourself?
720 print ("got selection text of " + selection_text);
722 var target_path = path.to_string();
723 //print("target_path="+target_path);
726 if (selection_text == target_path) {
727 print("self drag ?? == we should perhaps allow copy onto self..\n");
729 Gtk.drag_finish (ctx, false, false, time); // drop failed..
731 return true; /// -- fixme -- this is not really correct..
736 //print("DUMPING DATA");
737 //console.dump(data);
740 //print(data.path.to_string() +' => '+ data.pos);
742 // dropList is a list of xtypes that this node could be dropped on.
743 // it is set up when we start to drag..
746 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
748 print("targetDAta: " + targetData +"\n");
750 if (targetData.length < 1) {
751 //print("Can not find drop node path");
753 Gtk.drag_finish (ctx, false, false, time); // drop failed..
757 var td_ar = targetData.split("|");
761 // continue on to allow drop..
763 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
766 var delete_selection_data = false;
768 if (action == Gdk.DragAction.ASK) {
769 /* Ask the user to move or copy, then set the ctx action. */
772 if (action == Gdk.DragAction.MOVE) {
773 delete_selection_data = true;
776 // drag around.. - reorder..
777 _this.model.moveNode(targetData, action);
783 // we can send stuff to souce here...
786 // do we always say failure, so we handle the reall drop?
787 Gtk.drag_finish (ctx, false, false,time); //delete_selection_data, time);
799 // user defined functions
800 public void highlightDropPath ( string treepath, Gtk.TreeViewDropPosition pos) {
802 // highlighting for drag/drop
803 if (treepath.length > 0) {
804 this.el.set_drag_dest_row( new Gtk.TreePath.from_string( treepath ), pos);
806 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
810 public void selectNode (string treepath_str) {
811 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
812 var tp = new Gtk.TreePath.from_string(treepath_str);
814 this.el.set_cursor(tp, null, false);
815 this.el.scroll_to_cell(tp, null, false, 0,0);
818 public class Xcls_model : Object
820 public Gtk.TreeStore el;
821 private Xcls_WindowLeftTree _this;
825 public DialogTemplateSelect template_select;
826 public JsRender.JsRender? file;
827 public string activePath;
828 public Project.Project? project;
831 public Xcls_model(Xcls_WindowLeftTree _owner )
835 this.el = new Gtk.TreeStore( 3, typeof(string),typeof(string),typeof(Object) );
838 this.template_select = null;
840 this.activePath = "";
843 // set gobject values
847 print("model initialized");
850 // user defined functions
851 public string findDropNode (string treepath_str, string[] targets) {
853 // this is used by the dragdrop code in the roo version AFAIR..
855 //var path = treepath_str.replace(/^builder-/, '');
856 // treemap is depreciated... - should really check if model has any entries..
858 if (this.el.iter_n_children(null) < 1) {
860 return "|%d".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
862 //print("FIND treepath: " + path);
863 //console.dump(this.treemap);
865 //if (!treepath_str.match(/^builder-/)) {
866 // return []; // nothing!
868 if (targets.length > 0 && targets[0] == "*") {
871 return this.findDropNodeByPath(treepath_str,targets, -1);
873 public void loadFile (JsRender.JsRender f) {
880 // console.log('missing file');
884 // load the file if not loaded..
885 if (f.tree == null) {
888 // if it's still null?
889 if (f.tree == null) {
893 /// this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name);
895 //if (f.items.length && typeof(f.items[0]) == 'string') {
897 //this.get('/RightEditor').el.show();
898 //this.get('/RightEditor.view').load( f.items[0]);
902 //print(JSON.stringify(f.items, null,4));
903 //console.dump(f.items);
904 var o = new Gee.ArrayList<JsRender.Node>();
908 _this.view.el.expand_all();
910 if (f.tree.items.size < 1) {
913 //this.get('/Window.leftvpaned').el.set_position(80);
915 _this.view.el.set_cursor(
916 new Gtk.TreePath.from_string("0"), null, false);
920 //this.get('/Window.leftvpaned').el.set_position(200);
926 //print("hide right editior");
927 //this.get('/RightEditor').el.hide();
928 //this.get('/Editor').el.hide();
929 //print("set current tree");
930 //this.currentTree = this.toJS(false, false)[0];
931 //console.dump(this.currentTree);
932 //this.currentTree = this.currentTree || { items: [] };
933 //_this.renderView();
934 //console.dump(this.map);
935 //var RightPalete = imports.Builder.RightPalete.RightPalete;
938 var pm = this.get('/RightPalete.model');
941 this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
943 if (!this.get('/RightPalete').provider) {
944 print ("********* PALETE PROVIDER MISSING?!!");
946 this.get('/LeftTree').renderView();
948 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
952 this.get('/Window.view-notebook').el.set_current_page(
953 this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
957 public void updateSelected () {
960 var s = _this.view.el.get_selection();
967 if (!s.get_selected(out mod, out iter)) {
968 return; // nothing seleted..
972 this.el.get_value(iter, 2, out value);
973 var node = (JsRender.Node)(value.get_object());
975 this.el.set(iter, 0, node.nodeTitle(),
976 1, node.nodeTip(), -1
979 public string findDropNodeByPath (string treepath_str, string[] targets, int in_pref = -1) {
981 var path = treepath_str; // dupe it..
984 // pref : 3 = ontop - 0 = after, 1 = before
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) {
1002 if (path.length == treepath_str.length && pref != Gtk.TreeViewDropPosition.INTO_OR_AFTER) {
1003 if (path.last_index_of(":") < 0 ) {
1006 path = path.substring(0, path.last_index_of(":"));
1007 last = treepath_str;
1008 print("DROP before or after : using %s\n",path);
1012 //print("LOOKING FOR PATH: " + path);
1013 var node_data = this.pathToNode(path);
1015 if (node_data == null) {
1016 print("node not found");
1020 var xname = node_data.fqn();
1024 for (var i =0; i < targets.length; i++) {
1025 var tg = targets[i];
1026 if ((tg == xname) ) {
1030 // if target is "xxxx:name"
1031 if (tg.contains(xname +":")) {
1033 var ar = tg.split(":");
1039 if (match.length > 0) {
1040 if (last.length > 0) { // pref is after/before..
1041 // then it's after last
1045 return last + "|%d".printf((int)pref) + "|" + prop;
1049 // we need to add prop - as :store -> needs to bee added when dropping onto.
1050 return path + "|%d".printf( (int) Gtk.TreeViewDropPosition.INTO_OR_AFTER) + "|" + prop;
1054 var par = path.split(":");
1055 string [] ppar = {};
1056 for (var i = 0; i < par.length-1; i++) {
1060 path = string.joinv(":", ppar);
1069 public void moveNode (string target_data, Gdk.DragAction action)
1072 /// target_data = "path|pos");
1075 //print("MOVE NODE");
1076 // console.dump(target_data);
1077 Gtk.TreeIter old_iter;
1080 var s = _this.view.el.get_selection();
1081 s.get_selected(out mod , out old_iter);
1082 mod.get_path(old_iter);
1084 var node = this.pathToNode(mod.get_path(old_iter).to_string());
1085 //console.dump(node);
1087 print("moveNode: ERROR - node is null?");
1092 // needs to drop first, otherwise the target_data
1093 // treepath will be invalid.
1096 if ((action & Gdk.DragAction.MOVE) > 0) {
1097 print("REMOVING OLD NODE : " + target_data + "\n");
1099 this.dropNode(target_data, node, false);
1100 this.el.remove(ref old_iter);
1105 print("DROPPING NODE // copy: " + target_data + "\n");
1106 node = node.deepClone();
1107 this.dropNode(target_data, node, false);
1110 this.activePath= "";
1111 //this.updateNode(false,true);
1113 public void load (Gee.ArrayList<JsRender.Node> tr, Gtk.TreeIter? iter)
1116 //this.insert(citer,iter,0);
1117 for(var i =0 ; i < tr.size; i++) {
1119 this.el.insert(out citer,iter,-1); // why not append?
1121 this.el.append(out citer,null);
1124 this.el.set(citer, 0, tr.get(i).nodeTitle(),
1125 1, tr.get(i).nodeTip(), -1
1127 var o = new GLib.Value(typeof(Object));
1128 o.set_object((Object)tr.get(i));
1130 this.el.set_value(citer, 2, o);
1132 if (tr.get(i).items.size > 0) {
1133 this.load(tr.get(i).items, citer);
1140 public void deleteSelected () {
1142 print("DELETE SELECTED?");
1143 //_this.view.blockChanges = true;
1144 print("GET SELECTION?");
1146 var s = _this.view.el.get_selection();
1148 print("GET SELECTED?");
1153 if (!s.get_selected(out mod, out iter)) {
1154 return; // nothing seleted..
1159 this.activePath= "";
1160 print("GET vnode value?");
1163 this.el.get_value(iter, 2, out value);
1164 var data = (JsRender.Node)(value.get_object());
1165 print("removing node from Render\n");
1166 if (data.parent == null) {
1167 this.file.tree = null;
1171 print("removing node from Tree\n");
1173 this.el.remove(ref iter);
1183 this.activePath= ""; // again!?!?
1184 //this.changed(null,true);
1188 _this.view.blockChanges = false;
1190 public JsRender.Node pathToNode (string path) {
1194 _this.model.el.get_iter_from_string(out iter, path);
1197 _this.model.el.get_value(iter, 2, out value);
1199 return (JsRender.Node)value.dup_object();
1202 public void dropNode (string target_data_str, JsRender.Node node, bool show_templates) {
1203 // print("drop Node");
1204 // console.dump(node);
1205 // console.dump(target_data);
1208 // 0 = before , 1=after 2/3 onto
1211 var target_data= target_data_str.split("|");
1213 var parent_str = target_data[0].length > 0 ? target_data[0] : "";
1214 var pos = target_data.length > 1 ? int.parse(target_data[1]) : 2; // ontop..
1217 Gtk.TreePath tree_path = parent_str.length > 0 ? new Gtk.TreePath.from_string( parent_str ) : null;
1221 //print("add " + tp + "@" + target_data[1] );
1223 JsRender.Node parentNode = null;
1225 Gtk.TreeIter iter_after;
1226 Gtk.TreeIter iter_par ;
1229 if (target_data.length == 3 && target_data[2].length > 0) {
1230 node.props.set("* prop", target_data[2]);
1233 Gtk.TreePath expand_parent = null;
1235 // we only need to show the template if it's come from else where?
1236 if (show_templates) {
1238 if (this.template_select == null) {
1239 this.template_select = new DialogTemplateSelect();
1242 var new_node = this.template_select.show(
1243 (Gtk.Window) _this.el.get_toplevel (),
1247 if (new_node == null) {
1248 return; // do not add?
1253 //print("pos is %d \n".printf(pos));
1255 Gtk.TreeIter n_iter;
1257 if ( parent_str.length < 1) {
1258 this.el.append(out n_iter, null); // drop at top level..
1260 this.file.tree = node;
1263 } else if (pos < 2) {
1264 //print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
1266 this.el.get_iter(out iter_after, tree_path );
1267 this.el.iter_parent(out iter_par, iter_after);
1268 expand_parent = this.el.get_path(iter_par);
1271 this.el.get_value( iter_par, 2, out value);
1272 parentNode = (JsRender.Node)value.dup_object();
1275 this.el.get_value( iter_after, 2, out value);
1276 var relNode = (JsRender.Node)value.dup_object();
1280 this.el.insert_after(out n_iter, iter_par , iter_after);
1281 var ix = parentNode.items.index_of(relNode);
1282 parentNode.items.insert(ix+1, node);
1285 this.el.insert_before(out n_iter, iter_par , iter_after);
1286 var ix = parentNode.items.index_of(relNode);
1287 parentNode.items.insert(ix, node);
1290 node.parent = parentNode;
1295 // print("appending to " + parent_str);
1296 this.el.get_iter(out iter_par, tree_path);
1297 this.el.append(out n_iter, iter_par );
1298 expand_parent = this.el.get_path(iter_par);
1301 this.el.get_value( iter_par, 2, out value);
1302 parentNode = (JsRender.Node)value.dup_object();
1303 node.parent = parentNode;
1304 parentNode.items.add(node);
1307 // reparent node in tree...
1310 // why only on no parent???
1312 //if (node.parent = null) {
1319 // work out what kind of packing to use.. -- should be in
1320 if (!node.has("pack") && parent_str.length > 1) {
1322 this.file.palete().fillPack(node,parentNode);
1329 this.el.set(n_iter, 0, node.nodeTitle(), 1, node.nodeTip(), -1 );
1330 var o = new GLib.Value(typeof(Object));
1331 o.set_object((Object)node);
1333 this.el.set_value(n_iter, 2, o);
1338 // load children - if it has any..
1340 if (node.items.size > 0) {
1341 this.load(node.items, n_iter);
1342 _this.view.el.expand_row(this.el.get_path(n_iter), true);
1343 } else if (expand_parent != null && !_this.view.el.is_row_expanded(expand_parent)) {
1344 _this.view.el.expand_row(expand_parent,true);
1347 //if (tp != null && (node.items.length() > 0 || pos > 1)) {
1348 // _this.view.el.expand_row(this.el.get_path(iter_par), true);
1350 // wee need to get the empty proptypes from somewhere..
1352 //var olditer = this.activeIter;
1353 this.activePath = this.el.get_path(n_iter).to_string();
1358 _this.view.el.set_cursor(this.el.get_path(n_iter), null, false);
1365 public class Xcls_TreeViewColumn4 : Object
1367 public Gtk.TreeViewColumn el;
1368 private Xcls_WindowLeftTree _this;
1374 public Xcls_TreeViewColumn4(Xcls_WindowLeftTree _owner )
1377 this.el = new Gtk.TreeViewColumn();
1381 // set gobject values
1382 this.el.title = "test";
1383 var child_0 = new Xcls_renderer( _this );
1385 this.el.pack_start ( child_0.el , true );
1389 this.el.add_attribute(_this.renderer.el , "markup", 0 );
1392 // user defined functions
1394 public class Xcls_renderer : Object
1396 public Gtk.CellRendererText el;
1397 private Xcls_WindowLeftTree _this;
1403 public Xcls_renderer(Xcls_WindowLeftTree _owner )
1406 _this.renderer = this;
1407 this.el = new Gtk.CellRendererText();
1411 // set gobject values
1414 // user defined functions
1416 public class Xcls_LeftTreeMenu : Object
1419 private Xcls_WindowLeftTree _this;
1425 public Xcls_LeftTreeMenu(Xcls_WindowLeftTree _owner )
1428 _this.LeftTreeMenu = this;
1429 this.el = new Gtk.Menu();
1433 // set gobject values
1434 var child_0 = new Xcls_MenuItem7( _this );
1436 this.el.add ( child_0.el );
1437 var child_1 = new Xcls_MenuItem8( _this );
1439 this.el.add ( child_1.el );
1440 var child_2 = new Xcls_MenuItem9( _this );
1442 this.el.add ( child_2.el );
1445 // user defined functions
1447 public class Xcls_MenuItem7 : Object
1449 public Gtk.MenuItem el;
1450 private Xcls_WindowLeftTree _this;
1456 public Xcls_MenuItem7(Xcls_WindowLeftTree _owner )
1459 this.el = new Gtk.MenuItem();
1463 // set gobject values
1464 this.el.label = "Delete Element";
1467 this.el.activate.connect( ( ) => {
1472 _this.model.deleteSelected();
1476 // user defined functions
1478 public class Xcls_MenuItem8 : Object
1480 public Gtk.MenuItem el;
1481 private Xcls_WindowLeftTree _this;
1487 public Xcls_MenuItem8(Xcls_WindowLeftTree _owner )
1490 this.el = new Gtk.MenuItem();
1494 // set gobject values
1495 this.el.label = "Save as Template";
1498 this.el.activate.connect( () => {
1500 DialogSaveTemplate.singleton().show(
1501 (Gtk.Window) _this.el.get_toplevel (),
1502 _this.model.file.palete(),
1503 _this.getActiveElement()
1510 // user defined functions
1512 public class Xcls_MenuItem9 : Object
1514 public Gtk.MenuItem el;
1515 private Xcls_WindowLeftTree _this;
1521 public Xcls_MenuItem9(Xcls_WindowLeftTree _owner )
1524 this.el = new Gtk.MenuItem();
1528 // set gobject values
1529 this.el.label = "Save as Module";
1532 this.el.activate.connect( () => {
1533 var node = _this.getActiveElement();
1534 var name = DialogSaveModule.singleton().show(
1535 (Gtk.Window) _this.el.get_toplevel (),
1536 _this.model.file.project,
1539 if (name.length < 1) {
1543 node.props.set("* xinclude", name);
1547 var s = _this.view.el.get_selection();
1549 print("GET SELECTED?");
1554 if (!s.get_selected(out mod, out iter)) {
1555 return; // nothing seleted..
1558 var n_cn = mod.iter_n_children(iter) -1;
1559 for (var i = n_cn; i > -1; i--) {
1560 mod.iter_nth_child(out citer, iter, i);
1563 print("removing node from Tree\n");
1565 _this.model.el.remove(ref citer);
1568 _this.node_selected(node);
1574 // user defined functions