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;
80 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.cursor_changed.connect( ( ) => {
180 if (this.blockChanges) { // probably not needed..
183 if (!_this.before_node_change(null) ) {
184 this.blockChanges = true;
185 this.el.get_selection().unselect_all();
186 this.blockChanges = false;
189 if (_this.model.file == null) {
193 //var render = this.get('/LeftTree').getRenderer();
194 print("LEFT TREE -> view -> selection changed called\n");
197 // -- it appears that the selection is not updated.
199 GLib.Timeout.add_full(GLib.Priority.DEFAULT,10 , () => {
202 if (this.el.get_selection().count_selected_rows() < 1) {
204 print("selected rows < 1\n");
205 //??this.model.load( false);
206 _this.node_selected(null);
211 //console.log('changed');
212 var s = this.el.get_selection();
215 s.get_selected(out mod, out iter);
220 _this.model.el.get_value(iter, 2, out value);
221 _this.model.activePath = mod.get_path(iter).to_string();
223 var node = (JsRender.Node)value.dup_object();
224 _this.node_selected(node);
225 while (Gtk.events_pending()) {
226 Gtk.main_iteration();
228 var cp = mod.get_path(iter);
230 this.el.get_visible_range(out sp, out ep);
235 this.el.scroll_to_cell(new Gtk.TreePath.from_string(_this.model.activePath), null, true, 0.1f,0.0f);
239 //_this.after_node_change(node);
241 // _this.model.file.changed(node, "tree");
243 //Seed.print( value.get_string());
247 this.el.drag_begin.connect( ( ctx) => {
248 //print('SOURCE: drag-begin');
251 //this.targetData = "";
253 // find what is selected in our tree...
255 var s = _this.view.el.get_selection();
256 if (s.count_selected_rows() < 1) {
261 s.get_selected(out mod, out iter);
265 // set some properties of the tree for use by the dropped element.
267 _this.model.el.get_value(iter, 2, out value);
268 var tp = mod.get_path(iter).to_string();
269 var data = (JsRender.Node)(value.dup_object());
270 var xname = data.fqn();
271 print ("XNAME IS " + xname+ "\n");
273 this.dropList = _this.model.file.palete().getDropList(xname);
275 print ("DROP LIST IS " + string.joinv(", ", this.dropList) + "\n");
278 // make the drag icon a picture of the node that was selected
281 // by default returns the path..
282 var path = _this.model.el.get_path(iter);
285 var pix = this.el.create_row_drag_icon ( path);
287 Gtk.drag_set_icon_surface (ctx, pix) ;
291 this.el.drag_end.connect( (drag_context) => {
292 //Seed.print('LEFT-TREE: drag-end');
294 this.dropList = null;
295 // this.targetData = "";
296 this.highlightDropPath("",0);
299 this.el.drag_motion.connect( ( ctx, x, y, time) => {
300 print("got drag motion\n");
301 var src = Gtk.drag_get_source_widget(ctx);
305 if (src != this.el) {
309 // the point of this is to detect where an item could be dropped..
310 print("requesting drag data\n");
311 this.drag_in_motion = true;
313 // request data that will be recieved by the recieve...
316 this.el, // will receive 'drag-data-received' signal
317 ctx, // represents the current state of the DnD
318 Gdk.Atom.intern("STRING",true), // the target type we want
325 print("action: %d\n", ctx.get_actions());
326 //print("GETTING POS");
330 Gtk.TreeViewDropPosition pos;
331 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
333 // if there are not items in the tree.. the we have to set isOver to true for anything..
335 if (_this.model.el.iter_n_children(null) < 1) {
336 print("got NO children?\n");
339 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
343 // ------------- a drag from self..
346 //var action = Gdk.DragAction.COPY;
347 // unless we are copying!!! ctl button..
349 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
350 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
351 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
354 if (_this.model.el.iter_n_children(null) < 1) {
355 // no children.. -- asume it's ok..
357 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
359 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
360 Gdk.drag_status(ctx, action ,time);
363 // continue through to allow drop...
371 //print("ISOVER? " + isOver);
374 Gdk.drag_status(ctx, 0 ,time);
375 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
380 // drag node is parent of child..
381 //console.log("SRC TREEPATH: " + src.treepath);
382 //console.log("TARGET TREEPATH: " + data.path.to_string());
384 // nned to check a few here..
385 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
386 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
387 //Gtk.TreeViewDropPosition.AFTER
388 //Gtk.TreeViewDropPosition.BEFORE
390 // locally dragged items to not really use the
391 var selection_text = this.dragData;
395 if (selection_text == null || selection_text.length < 1) {
396 //print("Error - drag selection text returned NULL");
397 Gdk.drag_status(ctx, 0 ,time);
398 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
403 // see if we are dragging into ourself?
404 var target_path = path.to_string();
405 print ("Drag %s onto %s--%d\n ", selection_text, target_path, pos);
407 // pos : 3 = ontop - 0 = after, 1 = before
408 //print("target_path="+target_path);
411 if (selection_text == target_path) {
412 print("self drag ?? == we should perhaps allow copy onto self..\n");
414 Gdk.drag_status(ctx, 0 ,time);
415 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
417 // -- fixme -- this is not really correct..
422 //print("DUMPING DATA");
423 //console.dump(data);
426 //print(data.path.to_string() +' => '+ data.pos);
428 // dropList is a list of xtypes that this node could be dropped on.
429 // it is set up when we start to drag..
432 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
434 print("targetDAta: " + targetData +"\n");
436 if (targetData.length < 1) {
437 //print("Can not find drop node path");
439 Gdk.drag_status(ctx, 0, time);
440 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
444 var td_ar = targetData.split("|");
448 Gdk.drag_status(ctx, action ,time);
449 this.highlightDropPath(td_ar[0], (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
454 this.el.drag_data_get.connect( ( drag_context, data, info, time) => {
457 //print("drag-data-get");
458 var s = this.el.get_selection();
459 if (s.count_selected_rows() < 1) {
461 print("return empty string - no selection..");
468 s.get_selected(out mod, out iter);
473 _this.model.el.get_value(iter, 2, out value);
474 var ndata = (JsRender.Node)(value.dup_object());
475 var xname = ndata.fqn();
478 var tp = mod.get_path(iter).to_string();
479 // by default returns the path..
481 if ( info != Gdk.Atom.intern("STRING",true) ) {
482 tp = ndata.toJsonString();
485 //data.set_text(tp,tp.length);
487 data.set (data.get_target (), 8, (uchar[]) tp.to_utf8 ());
490 // print("return " + tp);
492 this.el.drag_data_received.connect( (ctx, x, y, sel, info, time) => {
494 // THIS CODE ONLY RELATES TO drag or drop of "NEW" elements or "FROM another tree.."
497 // print("Tree: drag-data-received\n");
498 var selection_text = (string)sel.get_data();
499 //print("selection_text= %s\n",selection_text);
501 var is_drag = this.drag_in_motion;
505 print("Is Drag %s\n", is_drag ? "Y": "N");
509 Gtk.TreeViewDropPosition pos;
510 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
512 // if there are not items in the tree.. the we have to set isOver to true for anything..
514 if (_this.model.el.iter_n_children(null) < 1) {
515 print("got NO children?\n");
518 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
522 //console.log("LEFT-TREE: drag-motion");
523 var src = Gtk.drag_get_source_widget(ctx);
525 // a drag from self - this should be handled by drop and motion.
526 if (src == this.el) {
527 print("Source == this element should not happen.. ? \n");
530 //print("drag_data_recieved from another element");
535 if (selection_text == null || selection_text.length < 1 || !isOver) {
536 // nothing valid foudn to drop...
537 print("empty sel text or not over");
539 Gdk.drag_status(ctx, 0, time);
540 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
543 Gtk.drag_finish (ctx, false, false, time); // drop failed..
548 var dropNode = new JsRender.Node();
550 var dropNodeType = selection_text;
551 var show_templates = true;
553 if (dropNodeType[0] == '{') {
554 var pa = new Json.Parser();
555 pa.load_from_data(dropNodeType);
557 dropNode.loadFromJson( pa.get_root().get_object(), 2);
558 dropNodeType = dropNode.fqn();
559 show_templates = false;
564 dropNode.setFqn(selection_text);
568 // dropList --- need to gather this ...
569 print("get dropList for : %s\n",dropNodeType);
570 var dropList = _this.model.file.palete().getDropList(dropNodeType);
572 print("dropList: %s\n", string.joinv(" , ", dropList));
574 // if drag action is link ... then we can drop it anywahere...
575 if ((ctx.get_actions() & Gdk.DragAction.LINK) > 0) {
576 // if path is null?? dragging into an empty tree?
577 targetData = (path == null ? "" : path.to_string()) + "|%d".printf((int)pos);
581 targetData = _this.model.findDropNodeByPath( isEmpty ? "" : path.to_string(), dropList, pos);
586 print("targetDAta: " + targetData +"\n");
588 if (targetData.length < 1) {
590 // invalid drop path..
591 if (this.drag_in_motion) {
592 Gdk.drag_status(ctx, 0, time);
593 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
596 Gtk.drag_finish (ctx, false, false, time); // drop failed..
602 var td_ar = targetData.split("|");
605 if (this.drag_in_motion) {
606 Gdk.drag_status(ctx, Gdk.DragAction.COPY ,time);
608 this.highlightDropPath( td_ar[0] , (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
611 // continue on to allow drop..
614 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
617 _this.model.dropNode(targetData, dropNode, show_templates);
618 print("ADD new node!!!\n");
620 ///Xcls_DialogTemplateSelect.singleton().show( _this.model.file.palete(), node);
622 Gtk.drag_finish (ctx, false, false,time);
629 this.el.drag_drop.connect( ( ctx, x, y, time) => {
630 //Seed.print("TARGET: drag-drop");
633 var src = Gtk.drag_get_source_widget(ctx);
635 if (src != this.el) {
639 this.drag_in_motion = false;
640 // request data that will be recieved by the recieve...
643 this.el, // will receive 'drag-data-received' signal
644 ctx, // represents the current state of the DnD
645 Gdk.Atom.intern("application/json",true), // the target type we want
650 // No target offered by source => error
656 // handle drop around self..
660 //print("GETTING POS");
664 Gtk.TreeViewDropPosition pos;
665 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
667 // if there are not items in the tree.. the we have to set isOver to true for anything..
669 if (_this.model.el.iter_n_children(null) < 1) {
670 print("got NO children?\n");
673 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
678 //var action = Gdk.DragAction.COPY;
679 // unless we are copying!!! ctl button..
681 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
682 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
683 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
686 if (_this.model.el.iter_n_children(null) < 1) {
687 // no children.. -- asume it's ok..
689 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
691 // continue through to allow drop...
699 //print("ISOVER? " + isOver);
702 Gtk.drag_finish (ctx, false, false, time); // drop failed..
703 return true; // not over apoint!?! - no action on drop or motion..
706 // drag node is parent of child..
707 //console.log("SRC TREEPATH: " + src.treepath);
708 //console.log("TARGET TREEPATH: " + data.path.to_string());
710 // nned to check a few here..
711 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
712 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
713 //Gtk.TreeViewDropPosition.AFTER
714 //Gtk.TreeViewDropPosition.BEFORE
716 // locally dragged items to not really use the
717 var selection_text = this.dragData;
721 if (selection_text == null || selection_text.length < 1) {
722 //print("Error - drag selection text returned NULL");
724 Gtk.drag_finish (ctx, false, false, time); // drop failed..
725 return true; /// -- fixme -- this is not really correct..
728 // see if we are dragging into ourself?
729 print ("got selection text of " + selection_text);
731 var target_path = path.to_string();
732 //print("target_path="+target_path);
735 if (selection_text == target_path) {
736 print("self drag ?? == we should perhaps allow copy onto self..\n");
738 Gtk.drag_finish (ctx, false, false, time); // drop failed..
740 return true; /// -- fixme -- this is not really correct..
745 //print("DUMPING DATA");
746 //console.dump(data);
749 //print(data.path.to_string() +' => '+ data.pos);
751 // dropList is a list of xtypes that this node could be dropped on.
752 // it is set up when we start to drag..
755 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
757 print("targetDAta: " + targetData +"\n");
759 if (targetData.length < 1) {
760 //print("Can not find drop node path");
762 Gtk.drag_finish (ctx, false, false, time); // drop failed..
766 var td_ar = targetData.split("|");
770 // continue on to allow drop..
772 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
775 var delete_selection_data = false;
777 if (action == Gdk.DragAction.ASK) {
778 /* Ask the user to move or copy, then set the ctx action. */
781 if (action == Gdk.DragAction.MOVE) {
782 delete_selection_data = true;
785 // drag around.. - reorder..
786 _this.model.moveNode(targetData, action);
792 // we can send stuff to souce here...
795 // do we always say failure, so we handle the reall drop?
796 Gtk.drag_finish (ctx, false, false,time); //delete_selection_data, time);
808 // user defined functions
809 public void highlightDropPath ( string treepath, Gtk.TreeViewDropPosition pos) {
811 // highlighting for drag/drop
812 if (treepath.length > 0) {
813 this.el.set_drag_dest_row( new Gtk.TreePath.from_string( treepath ), pos);
815 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
819 public void selectNode (string treepath_str) {
820 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
821 var tp = new Gtk.TreePath.from_string(treepath_str);
823 this.el.set_cursor(tp, null, false);
824 this.el.scroll_to_cell(tp, null, false, 0,0);
827 public class Xcls_model : Object
829 public Gtk.TreeStore el;
830 private Xcls_WindowLeftTree _this;
834 public DialogTemplateSelect template_select;
835 public JsRender.JsRender? file;
836 public string activePath;
837 public Project.Project? project;
840 public Xcls_model(Xcls_WindowLeftTree _owner )
844 this.el = new Gtk.TreeStore( 3, typeof(string),typeof(string),typeof(Object) );
847 this.template_select = null;
849 this.activePath = "";
852 // set gobject values
856 print("model initialized");
859 // user defined functions
860 public string findDropNode (string treepath_str, string[] targets) {
862 // this is used by the dragdrop code in the roo version AFAIR..
864 //var path = treepath_str.replace(/^builder-/, '');
865 // treemap is depreciated... - should really check if model has any entries..
867 if (this.el.iter_n_children(null) < 1) {
869 return "|%d".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
871 //print("FIND treepath: " + path);
872 //console.dump(this.treemap);
874 //if (!treepath_str.match(/^builder-/)) {
875 // return []; // nothing!
877 if (targets.length > 0 && targets[0] == "*") {
880 return this.findDropNodeByPath(treepath_str,targets, -1);
882 public void loadFile (JsRender.JsRender f) {
889 // console.log('missing file');
893 // load the file if not loaded..
894 if (f.tree == null) {
897 // if it's still null?
898 if (f.tree == null) {
902 /// this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name);
904 //if (f.items.length && typeof(f.items[0]) == 'string') {
906 //this.get('/RightEditor').el.show();
907 //this.get('/RightEditor.view').load( f.items[0]);
911 //print(JSON.stringify(f.items, null,4));
912 //console.dump(f.items);
913 var o = new Gee.ArrayList<JsRender.Node>();
917 _this.view.el.expand_all();
919 if (f.tree.items.size < 1) {
922 //this.get('/Window.leftvpaned').el.set_position(80);
924 _this.view.el.set_cursor(
925 new Gtk.TreePath.from_string("0"), null, false);
929 //this.get('/Window.leftvpaned').el.set_position(200);
935 //print("hide right editior");
936 //this.get('/RightEditor').el.hide();
937 //this.get('/Editor').el.hide();
938 //print("set current tree");
939 //this.currentTree = this.toJS(false, false)[0];
940 //console.dump(this.currentTree);
941 //this.currentTree = this.currentTree || { items: [] };
942 //_this.renderView();
943 //console.dump(this.map);
944 //var RightPalete = imports.Builder.RightPalete.RightPalete;
947 var pm = this.get('/RightPalete.model');
950 this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
952 if (!this.get('/RightPalete').provider) {
953 print ("********* PALETE PROVIDER MISSING?!!");
955 this.get('/LeftTree').renderView();
957 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
961 this.get('/Window.view-notebook').el.set_current_page(
962 this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
966 public void updateSelected () {
969 var s = _this.view.el.get_selection();
976 if (!s.get_selected(out mod, out iter)) {
977 return; // nothing seleted..
981 this.el.get_value(iter, 2, out value);
982 var node = (JsRender.Node)(value.get_object());
984 this.el.set(iter, 0, node.nodeTitle(),
985 1, node.nodeTip(), -1
988 public string findDropNodeByPath (string treepath_str, string[] targets, int in_pref = -1) {
990 var path = treepath_str; // dupe it..
993 // pref : 3 = ontop - 0 = after, 1 = before
994 int pref = in_pref < 0 ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : in_pref;
998 //console.dump(this.treemap);
1000 print("findDropNodeByPath : got path length %d / %s\n", path.length, path);
1002 if (path.length == 0) {
1003 // top drop. // just return empty..
1004 return "|%d".printf((int)pref) ;
1009 while (path.length > 0) {
1011 if (path.length == treepath_str.length && pref != Gtk.TreeViewDropPosition.INTO_OR_AFTER) {
1012 if (path.last_index_of(":") < 0 ) {
1015 path = path.substring(0, path.last_index_of(":"));
1016 last = treepath_str;
1017 print("DROP before or after : using %s\n",path);
1021 //print("LOOKING FOR PATH: " + path);
1022 var node_data = this.pathToNode(path);
1024 if (node_data == null) {
1025 print("node not found");
1029 var xname = node_data.fqn();
1033 for (var i =0; i < targets.length; i++) {
1034 var tg = targets[i];
1035 if ((tg == xname) ) {
1039 // if target is "xxxx:name"
1040 if (tg.contains(xname +":")) {
1042 var ar = tg.split(":");
1048 if (match.length > 0) {
1049 if (last.length > 0) { // pref is after/before..
1050 // then it's after last
1054 return last + "|%d".printf((int)pref) + "|" + prop;
1058 // we need to add prop - as :store -> needs to bee added when dropping onto.
1059 return path + "|%d".printf( (int) Gtk.TreeViewDropPosition.INTO_OR_AFTER) + "|" + prop;
1063 var par = path.split(":");
1064 string [] ppar = {};
1065 for (var i = 0; i < par.length-1; i++) {
1069 path = string.joinv(":", ppar);
1078 public void moveNode (string target_data, Gdk.DragAction action)
1081 /// target_data = "path|pos");
1084 //print("MOVE NODE");
1085 // console.dump(target_data);
1086 Gtk.TreeIter old_iter;
1089 var s = _this.view.el.get_selection();
1090 s.get_selected(out mod , out old_iter);
1091 mod.get_path(old_iter);
1093 var node = this.pathToNode(mod.get_path(old_iter).to_string());
1094 //console.dump(node);
1096 print("moveNode: ERROR - node is null?");
1101 // needs to drop first, otherwise the target_data
1102 // treepath will be invalid.
1105 if ((action & Gdk.DragAction.MOVE) > 0) {
1106 print("REMOVING OLD NODE : " + target_data + "\n");
1108 this.dropNode(target_data, node, false);
1109 this.el.remove(ref old_iter);
1114 print("DROPPING NODE // copy: " + target_data + "\n");
1115 node = node.deepClone();
1116 this.dropNode(target_data, node, false);
1119 this.activePath= "";
1120 //this.updateNode(false,true);
1122 public void load (Gee.ArrayList<JsRender.Node> tr, Gtk.TreeIter? iter)
1125 //this.insert(citer,iter,0);
1126 for(var i =0 ; i < tr.size; i++) {
1128 this.el.insert(out citer,iter,-1); // why not append?
1130 this.el.append(out citer,null);
1133 this.el.set(citer, 0, tr.get(i).nodeTitle(),
1134 1, tr.get(i).nodeTip(), -1
1136 var o = new GLib.Value(typeof(Object));
1137 o.set_object((Object)tr.get(i));
1139 this.el.set_value(citer, 2, o);
1141 if (tr.get(i).items.size > 0) {
1142 this.load(tr.get(i).items, citer);
1149 public void deleteSelected () {
1151 print("DELETE SELECTED?");
1152 //_this.view.blockChanges = true;
1153 print("GET SELECTION?");
1155 var s = _this.view.el.get_selection();
1157 print("GET SELECTED?");
1162 if (!s.get_selected(out mod, out iter)) {
1163 return; // nothing seleted..
1168 this.activePath= "";
1169 print("GET vnode value?");
1172 this.el.get_value(iter, 2, out value);
1173 var data = (JsRender.Node)(value.get_object());
1174 print("removing node from Render\n");
1175 if (data.parent == null) {
1176 this.file.tree = null;
1180 print("removing node from Tree\n");
1182 this.el.remove(ref iter);
1192 this.activePath= ""; // again!?!?
1193 //this.changed(null,true);
1197 _this.view.blockChanges = false;
1199 public JsRender.Node pathToNode (string path) {
1203 _this.model.el.get_iter_from_string(out iter, path);
1206 _this.model.el.get_value(iter, 2, out value);
1208 return (JsRender.Node)value.dup_object();
1211 public void dropNode (string target_data_str, JsRender.Node node, bool show_templates) {
1212 // print("drop Node");
1213 // console.dump(node);
1214 // console.dump(target_data);
1217 // 0 = before , 1=after 2/3 onto
1220 var target_data= target_data_str.split("|");
1222 var parent_str = target_data[0].length > 0 ? target_data[0] : "";
1223 var pos = target_data.length > 1 ? int.parse(target_data[1]) : 2; // ontop..
1226 Gtk.TreePath tree_path = parent_str.length > 0 ? new Gtk.TreePath.from_string( parent_str ) : null;
1230 //print("add " + tp + "@" + target_data[1] );
1232 JsRender.Node parentNode = null;
1234 Gtk.TreeIter iter_after;
1235 Gtk.TreeIter iter_par ;
1238 if (target_data.length == 3 && target_data[2].length > 0) {
1239 node.props.set("* prop", target_data[2]);
1242 Gtk.TreePath expand_parent = null;
1244 // we only need to show the template if it's come from else where?
1245 if (show_templates) {
1247 var ts = _this.main_window.windowstate.template_select;
1249 var new_node = ts.show(
1250 _this.main_window, // (Gtk.Window) _this.el.get_toplevel (),
1255 if (new_node == null) {
1256 return; // do not add?
1261 //print("pos is %d \n".printf(pos));
1263 Gtk.TreeIter n_iter;
1265 if ( parent_str.length < 1) {
1266 this.el.append(out n_iter, null); // drop at top level..
1268 this.file.tree = node;
1271 } else if (pos < 2) {
1272 //print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
1274 this.el.get_iter(out iter_after, tree_path );
1275 this.el.iter_parent(out iter_par, iter_after);
1276 expand_parent = this.el.get_path(iter_par);
1279 this.el.get_value( iter_par, 2, out value);
1280 parentNode = (JsRender.Node)value.dup_object();
1283 this.el.get_value( iter_after, 2, out value);
1284 var relNode = (JsRender.Node)value.dup_object();
1288 this.el.insert_after(out n_iter, iter_par , iter_after);
1289 var ix = parentNode.items.index_of(relNode);
1290 parentNode.items.insert(ix+1, node);
1293 this.el.insert_before(out n_iter, iter_par , iter_after);
1294 var ix = parentNode.items.index_of(relNode);
1295 parentNode.items.insert(ix, node);
1298 node.parent = parentNode;
1303 // print("appending to " + parent_str);
1304 this.el.get_iter(out iter_par, tree_path);
1305 this.el.append(out n_iter, iter_par );
1306 expand_parent = this.el.get_path(iter_par);
1309 this.el.get_value( iter_par, 2, out value);
1310 parentNode = (JsRender.Node)value.dup_object();
1311 node.parent = parentNode;
1312 parentNode.items.add(node);
1315 // reparent node in tree...
1318 // why only on no parent???
1320 //if (node.parent = null) {
1327 // work out what kind of packing to use.. -- should be in
1328 if (!node.has("pack") && parent_str.length > 1) {
1330 this.file.palete().fillPack(node,parentNode);
1337 this.el.set(n_iter, 0, node.nodeTitle(), 1, node.nodeTip(), -1 );
1338 var o = new GLib.Value(typeof(Object));
1339 o.set_object((Object)node);
1341 this.el.set_value(n_iter, 2, o);
1346 // load children - if it has any..
1348 if (node.items.size > 0) {
1349 this.load(node.items, n_iter);
1350 _this.view.el.expand_row(this.el.get_path(n_iter), true);
1351 } else if (expand_parent != null && !_this.view.el.is_row_expanded(expand_parent)) {
1352 _this.view.el.expand_row(expand_parent,true);
1355 //if (tp != null && (node.items.length() > 0 || pos > 1)) {
1356 // _this.view.el.expand_row(this.el.get_path(iter_par), true);
1358 // wee need to get the empty proptypes from somewhere..
1360 //var olditer = this.activeIter;
1361 this.activePath = this.el.get_path(n_iter).to_string();
1366 _this.view.el.set_cursor(this.el.get_path(n_iter), null, false);
1373 public class Xcls_TreeViewColumn4 : Object
1375 public Gtk.TreeViewColumn el;
1376 private Xcls_WindowLeftTree _this;
1382 public Xcls_TreeViewColumn4(Xcls_WindowLeftTree _owner )
1385 this.el = new Gtk.TreeViewColumn();
1389 // set gobject values
1390 this.el.title = "test";
1391 var child_0 = new Xcls_renderer( _this );
1393 this.el.pack_start ( child_0.el , true );
1397 this.el.add_attribute(_this.renderer.el , "markup", 0 );
1400 // user defined functions
1402 public class Xcls_renderer : Object
1404 public Gtk.CellRendererText el;
1405 private Xcls_WindowLeftTree _this;
1411 public Xcls_renderer(Xcls_WindowLeftTree _owner )
1414 _this.renderer = this;
1415 this.el = new Gtk.CellRendererText();
1419 // set gobject values
1422 // user defined functions
1424 public class Xcls_LeftTreeMenu : Object
1427 private Xcls_WindowLeftTree _this;
1433 public Xcls_LeftTreeMenu(Xcls_WindowLeftTree _owner )
1436 _this.LeftTreeMenu = this;
1437 this.el = new Gtk.Menu();
1441 // set gobject values
1442 var child_0 = new Xcls_MenuItem7( _this );
1444 this.el.add ( child_0.el );
1445 var child_1 = new Xcls_MenuItem8( _this );
1447 this.el.add ( child_1.el );
1448 var child_2 = new Xcls_MenuItem9( _this );
1450 this.el.add ( child_2.el );
1453 // user defined functions
1455 public class Xcls_MenuItem7 : Object
1457 public Gtk.MenuItem el;
1458 private Xcls_WindowLeftTree _this;
1464 public Xcls_MenuItem7(Xcls_WindowLeftTree _owner )
1467 this.el = new Gtk.MenuItem();
1471 // set gobject values
1472 this.el.label = "Delete Element";
1475 this.el.activate.connect( ( ) => {
1480 _this.model.deleteSelected();
1484 // user defined functions
1486 public class Xcls_MenuItem8 : Object
1488 public Gtk.MenuItem el;
1489 private Xcls_WindowLeftTree _this;
1495 public Xcls_MenuItem8(Xcls_WindowLeftTree _owner )
1498 this.el = new Gtk.MenuItem();
1502 // set gobject values
1503 this.el.label = "Save as Template";
1506 this.el.activate.connect( () => {
1508 DialogSaveTemplate.singleton().show(
1509 (Gtk.Window) _this.el.get_toplevel (),
1510 _this.model.file.palete(),
1511 _this.getActiveElement()
1518 // user defined functions
1520 public class Xcls_MenuItem9 : Object
1522 public Gtk.MenuItem el;
1523 private Xcls_WindowLeftTree _this;
1529 public Xcls_MenuItem9(Xcls_WindowLeftTree _owner )
1532 this.el = new Gtk.MenuItem();
1536 // set gobject values
1537 this.el.label = "Save as Module";
1540 this.el.activate.connect( () => {
1541 var node = _this.getActiveElement();
1542 var name = DialogSaveModule.singleton().show(
1543 (Gtk.Window) _this.el.get_toplevel (),
1544 _this.model.file.project,
1547 if (name.length < 1) {
1551 node.props.set("* xinclude", name);
1555 var s = _this.view.el.get_selection();
1557 print("GET SELECTED?");
1562 if (!s.get_selected(out mod, out iter)) {
1563 return; // nothing seleted..
1566 var n_cn = mod.iter_n_children(iter) -1;
1567 for (var i = n_cn; i > -1; i--) {
1568 mod.iter_nth_child(out citer, iter, i);
1571 print("removing node from Tree\n");
1573 _this.model.el.remove(ref citer);
1576 _this.node_selected(node);
1582 // user defined functions