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);
231 // if sp is before cp then retuns 1.
232 // if cp is before ep then retuns 1.
233 if (cp.compare(sp) >= 0 && ep.compare(cp) >=1) {
239 this.el.scroll_to_cell(new Gtk.TreePath.from_string(_this.model.activePath), null, true, 0.1f,0.0f);
243 //_this.after_node_change(node);
245 // _this.model.file.changed(node, "tree");
247 //Seed.print( value.get_string());
251 this.el.drag_begin.connect( ( ctx) => {
252 //print('SOURCE: drag-begin');
255 //this.targetData = "";
257 // find what is selected in our tree...
259 var s = _this.view.el.get_selection();
260 if (s.count_selected_rows() < 1) {
265 s.get_selected(out mod, out iter);
269 // set some properties of the tree for use by the dropped element.
271 _this.model.el.get_value(iter, 2, out value);
272 var tp = mod.get_path(iter).to_string();
273 var data = (JsRender.Node)(value.dup_object());
274 var xname = data.fqn();
275 print ("XNAME IS " + xname+ "\n");
277 this.dropList = _this.model.file.palete().getDropList(xname);
279 print ("DROP LIST IS " + string.joinv(", ", this.dropList) + "\n");
282 // make the drag icon a picture of the node that was selected
285 // by default returns the path..
286 var path = _this.model.el.get_path(iter);
289 var pix = this.el.create_row_drag_icon ( path);
291 Gtk.drag_set_icon_surface (ctx, pix) ;
295 this.el.drag_end.connect( (drag_context) => {
296 //Seed.print('LEFT-TREE: drag-end');
298 this.dropList = null;
299 // this.targetData = "";
300 this.highlightDropPath("",0);
303 this.el.drag_motion.connect( ( ctx, x, y, time) => {
304 print("got drag motion\n");
305 var src = Gtk.drag_get_source_widget(ctx);
309 if (src != this.el) {
313 // the point of this is to detect where an item could be dropped..
314 print("requesting drag data\n");
315 this.drag_in_motion = true;
317 // request data that will be recieved by the recieve...
320 this.el, // will receive 'drag-data-received' signal
321 ctx, // represents the current state of the DnD
322 Gdk.Atom.intern("STRING",true), // the target type we want
329 print("action: %d\n", ctx.get_actions());
330 //print("GETTING POS");
334 Gtk.TreeViewDropPosition pos;
335 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
337 // if there are not items in the tree.. the we have to set isOver to true for anything..
339 if (_this.model.el.iter_n_children(null) < 1) {
340 print("got NO children?\n");
343 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
347 // ------------- a drag from self..
350 //var action = Gdk.DragAction.COPY;
351 // unless we are copying!!! ctl button..
353 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
354 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
355 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
358 if (_this.model.el.iter_n_children(null) < 1) {
359 // no children.. -- asume it's ok..
361 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
363 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
364 Gdk.drag_status(ctx, action ,time);
367 // continue through to allow drop...
375 //print("ISOVER? " + isOver);
378 Gdk.drag_status(ctx, 0 ,time);
379 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
384 // drag node is parent of child..
385 //console.log("SRC TREEPATH: " + src.treepath);
386 //console.log("TARGET TREEPATH: " + data.path.to_string());
388 // nned to check a few here..
389 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
390 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
391 //Gtk.TreeViewDropPosition.AFTER
392 //Gtk.TreeViewDropPosition.BEFORE
394 // locally dragged items to not really use the
395 var selection_text = this.dragData;
399 if (selection_text == null || selection_text.length < 1) {
400 //print("Error - drag selection text returned NULL");
401 Gdk.drag_status(ctx, 0 ,time);
402 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
407 // see if we are dragging into ourself?
408 var target_path = path.to_string();
409 print ("Drag %s onto %s--%d\n ", selection_text, target_path, pos);
411 // pos : 3 = ontop - 0 = after, 1 = before
412 //print("target_path="+target_path);
415 if (selection_text == target_path) {
416 print("self drag ?? == we should perhaps allow copy onto self..\n");
418 Gdk.drag_status(ctx, 0 ,time);
419 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
421 // -- fixme -- this is not really correct..
426 //print("DUMPING DATA");
427 //console.dump(data);
430 //print(data.path.to_string() +' => '+ data.pos);
432 // dropList is a list of xtypes that this node could be dropped on.
433 // it is set up when we start to drag..
436 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
438 print("targetDAta: " + targetData +"\n");
440 if (targetData.length < 1) {
441 //print("Can not find drop node path");
443 Gdk.drag_status(ctx, 0, time);
444 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
448 var td_ar = targetData.split("|");
452 Gdk.drag_status(ctx, action ,time);
453 this.highlightDropPath(td_ar[0], (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
458 this.el.drag_data_get.connect( ( drag_context, data, info, time) => {
461 //print("drag-data-get");
462 var s = this.el.get_selection();
463 if (s.count_selected_rows() < 1) {
465 print("return empty string - no selection..");
472 s.get_selected(out mod, out iter);
477 _this.model.el.get_value(iter, 2, out value);
478 var ndata = (JsRender.Node)(value.dup_object());
479 var xname = ndata.fqn();
482 var tp = mod.get_path(iter).to_string();
483 // by default returns the path..
485 if ( info != Gdk.Atom.intern("STRING",true) ) {
486 tp = ndata.toJsonString();
489 //data.set_text(tp,tp.length);
491 data.set (data.get_target (), 8, (uchar[]) tp.to_utf8 ());
494 // print("return " + tp);
496 this.el.drag_data_received.connect( (ctx, x, y, sel, info, time) => {
498 // THIS CODE ONLY RELATES TO drag or drop of "NEW" elements or "FROM another tree.."
501 // print("Tree: drag-data-received\n");
502 var selection_text = (string)sel.get_data();
503 //print("selection_text= %s\n",selection_text);
505 var is_drag = this.drag_in_motion;
509 print("Is Drag %s\n", is_drag ? "Y": "N");
513 Gtk.TreeViewDropPosition pos;
514 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
516 // if there are not items in the tree.. the we have to set isOver to true for anything..
518 if (_this.model.el.iter_n_children(null) < 1) {
519 print("got NO children?\n");
522 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
526 //console.log("LEFT-TREE: drag-motion");
527 var src = Gtk.drag_get_source_widget(ctx);
529 // a drag from self - this should be handled by drop and motion.
530 if (src == this.el) {
531 print("Source == this element should not happen.. ? \n");
534 //print("drag_data_recieved from another element");
539 if (selection_text == null || selection_text.length < 1 || !isOver) {
540 // nothing valid foudn to drop...
541 print("empty sel text or not over");
543 Gdk.drag_status(ctx, 0, time);
544 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
547 Gtk.drag_finish (ctx, false, false, time); // drop failed..
552 var dropNode = new JsRender.Node();
554 var dropNodeType = selection_text;
555 var show_templates = true;
557 if (dropNodeType[0] == '{') {
558 var pa = new Json.Parser();
559 pa.load_from_data(dropNodeType);
561 dropNode.loadFromJson( pa.get_root().get_object(), 2);
562 dropNodeType = dropNode.fqn();
563 show_templates = false;
568 dropNode.setFqn(selection_text);
572 // dropList --- need to gather this ...
573 print("get dropList for : %s\n",dropNodeType);
574 var dropList = _this.model.file.palete().getDropList(dropNodeType);
576 print("dropList: %s\n", string.joinv(" , ", dropList));
578 // if drag action is link ... then we can drop it anywahere...
579 if ((ctx.get_actions() & Gdk.DragAction.LINK) > 0) {
580 // if path is null?? dragging into an empty tree?
581 targetData = (path == null ? "" : path.to_string()) + "|%d".printf((int)pos);
585 targetData = _this.model.findDropNodeByPath( isEmpty ? "" : path.to_string(), dropList, pos);
590 print("targetDAta: " + targetData +"\n");
592 if (targetData.length < 1) {
594 // invalid drop path..
595 if (this.drag_in_motion) {
596 Gdk.drag_status(ctx, 0, time);
597 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
600 Gtk.drag_finish (ctx, false, false, time); // drop failed..
606 var td_ar = targetData.split("|");
609 if (this.drag_in_motion) {
610 Gdk.drag_status(ctx, Gdk.DragAction.COPY ,time);
612 this.highlightDropPath( td_ar[0] , (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
615 // continue on to allow drop..
618 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
621 _this.model.dropNode(targetData, dropNode, show_templates);
622 print("ADD new node!!!\n");
624 ///Xcls_DialogTemplateSelect.singleton().show( _this.model.file.palete(), node);
626 Gtk.drag_finish (ctx, false, false,time);
633 this.el.drag_drop.connect( ( ctx, x, y, time) => {
634 //Seed.print("TARGET: drag-drop");
637 var src = Gtk.drag_get_source_widget(ctx);
639 if (src != this.el) {
643 this.drag_in_motion = false;
644 // request data that will be recieved by the recieve...
647 this.el, // will receive 'drag-data-received' signal
648 ctx, // represents the current state of the DnD
649 Gdk.Atom.intern("application/json",true), // the target type we want
654 // No target offered by source => error
660 // handle drop around self..
664 //print("GETTING POS");
668 Gtk.TreeViewDropPosition pos;
669 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
671 // if there are not items in the tree.. the we have to set isOver to true for anything..
673 if (_this.model.el.iter_n_children(null) < 1) {
674 print("got NO children?\n");
677 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
682 //var action = Gdk.DragAction.COPY;
683 // unless we are copying!!! ctl button..
685 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
686 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
687 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
690 if (_this.model.el.iter_n_children(null) < 1) {
691 // no children.. -- asume it's ok..
693 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
695 // continue through to allow drop...
703 //print("ISOVER? " + isOver);
706 Gtk.drag_finish (ctx, false, false, time); // drop failed..
707 return true; // not over apoint!?! - no action on drop or motion..
710 // drag node is parent of child..
711 //console.log("SRC TREEPATH: " + src.treepath);
712 //console.log("TARGET TREEPATH: " + data.path.to_string());
714 // nned to check a few here..
715 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
716 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
717 //Gtk.TreeViewDropPosition.AFTER
718 //Gtk.TreeViewDropPosition.BEFORE
720 // locally dragged items to not really use the
721 var selection_text = this.dragData;
725 if (selection_text == null || selection_text.length < 1) {
726 //print("Error - drag selection text returned NULL");
728 Gtk.drag_finish (ctx, false, false, time); // drop failed..
729 return true; /// -- fixme -- this is not really correct..
732 // see if we are dragging into ourself?
733 print ("got selection text of " + selection_text);
735 var target_path = path.to_string();
736 //print("target_path="+target_path);
739 if (selection_text == target_path) {
740 print("self drag ?? == we should perhaps allow copy onto self..\n");
742 Gtk.drag_finish (ctx, false, false, time); // drop failed..
744 return true; /// -- fixme -- this is not really correct..
749 //print("DUMPING DATA");
750 //console.dump(data);
753 //print(data.path.to_string() +' => '+ data.pos);
755 // dropList is a list of xtypes that this node could be dropped on.
756 // it is set up when we start to drag..
759 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
761 print("targetDAta: " + targetData +"\n");
763 if (targetData.length < 1) {
764 //print("Can not find drop node path");
766 Gtk.drag_finish (ctx, false, false, time); // drop failed..
770 var td_ar = targetData.split("|");
774 // continue on to allow drop..
776 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
779 var delete_selection_data = false;
781 if (action == Gdk.DragAction.ASK) {
782 /* Ask the user to move or copy, then set the ctx action. */
785 if (action == Gdk.DragAction.MOVE) {
786 delete_selection_data = true;
789 // drag around.. - reorder..
790 _this.model.moveNode(targetData, action);
796 // we can send stuff to souce here...
799 // do we always say failure, so we handle the reall drop?
800 Gtk.drag_finish (ctx, false, false,time); //delete_selection_data, time);
812 // user defined functions
813 public void highlightDropPath ( string treepath, Gtk.TreeViewDropPosition pos) {
815 // highlighting for drag/drop
816 if (treepath.length > 0) {
817 this.el.set_drag_dest_row( new Gtk.TreePath.from_string( treepath ), pos);
819 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
823 public void selectNode (string treepath_str) {
824 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
825 var tp = new Gtk.TreePath.from_string(treepath_str);
827 this.el.set_cursor(tp, null, false);
828 this.el.scroll_to_cell(tp, null, false, 0,0);
831 public class Xcls_model : Object
833 public Gtk.TreeStore el;
834 private Xcls_WindowLeftTree _this;
838 public DialogTemplateSelect template_select;
839 public JsRender.JsRender? file;
840 public string activePath;
841 public Project.Project? project;
844 public Xcls_model(Xcls_WindowLeftTree _owner )
848 this.el = new Gtk.TreeStore( 3, typeof(string),typeof(string),typeof(Object) );
851 this.template_select = null;
853 this.activePath = "";
856 // set gobject values
860 print("model initialized");
863 // user defined functions
864 public string findDropNode (string treepath_str, string[] targets) {
866 // this is used by the dragdrop code in the roo version AFAIR..
868 //var path = treepath_str.replace(/^builder-/, '');
869 // treemap is depreciated... - should really check if model has any entries..
871 if (this.el.iter_n_children(null) < 1) {
873 return "|%d".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
875 //print("FIND treepath: " + path);
876 //console.dump(this.treemap);
878 //if (!treepath_str.match(/^builder-/)) {
879 // return []; // nothing!
881 if (targets.length > 0 && targets[0] == "*") {
884 return this.findDropNodeByPath(treepath_str,targets, -1);
886 public void loadFile (JsRender.JsRender f) {
893 // console.log('missing file');
897 // load the file if not loaded..
898 if (f.tree == null) {
901 // if it's still null?
902 if (f.tree == null) {
906 /// this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name);
908 //if (f.items.length && typeof(f.items[0]) == 'string') {
910 //this.get('/RightEditor').el.show();
911 //this.get('/RightEditor.view').load( f.items[0]);
915 //print(JSON.stringify(f.items, null,4));
916 //console.dump(f.items);
917 var o = new Gee.ArrayList<JsRender.Node>();
921 _this.view.el.expand_all();
923 if (f.tree.items.size < 1) {
926 //this.get('/Window.leftvpaned').el.set_position(80);
928 _this.view.el.set_cursor(
929 new Gtk.TreePath.from_string("0"), null, false);
933 //this.get('/Window.leftvpaned').el.set_position(200);
939 //print("hide right editior");
940 //this.get('/RightEditor').el.hide();
941 //this.get('/Editor').el.hide();
942 //print("set current tree");
943 //this.currentTree = this.toJS(false, false)[0];
944 //console.dump(this.currentTree);
945 //this.currentTree = this.currentTree || { items: [] };
946 //_this.renderView();
947 //console.dump(this.map);
948 //var RightPalete = imports.Builder.RightPalete.RightPalete;
951 var pm = this.get('/RightPalete.model');
954 this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
956 if (!this.get('/RightPalete').provider) {
957 print ("********* PALETE PROVIDER MISSING?!!");
959 this.get('/LeftTree').renderView();
961 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
965 this.get('/Window.view-notebook').el.set_current_page(
966 this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
970 public void updateSelected () {
973 var s = _this.view.el.get_selection();
980 if (!s.get_selected(out mod, out iter)) {
981 return; // nothing seleted..
985 this.el.get_value(iter, 2, out value);
986 var node = (JsRender.Node)(value.get_object());
988 this.el.set(iter, 0, node.nodeTitle(),
989 1, node.nodeTip(), -1
992 public string findDropNodeByPath (string treepath_str, string[] targets, int in_pref = -1) {
994 var path = treepath_str; // dupe it..
997 // pref : 3 = ontop - 0 = after, 1 = before
998 int pref = in_pref < 0 ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : in_pref;
1002 //console.dump(this.treemap);
1004 print("findDropNodeByPath : got path length %d / %s\n", path.length, path);
1006 if (path.length == 0) {
1007 // top drop. // just return empty..
1008 return "|%d".printf((int)pref) ;
1013 while (path.length > 0) {
1015 if (path.length == treepath_str.length && pref != Gtk.TreeViewDropPosition.INTO_OR_AFTER) {
1016 if (path.last_index_of(":") < 0 ) {
1019 path = path.substring(0, path.last_index_of(":"));
1020 last = treepath_str;
1021 print("DROP before or after : using %s\n",path);
1025 //print("LOOKING FOR PATH: " + path);
1026 var node_data = this.pathToNode(path);
1028 if (node_data == null) {
1029 print("node not found");
1033 var xname = node_data.fqn();
1037 for (var i =0; i < targets.length; i++) {
1038 var tg = targets[i];
1039 if ((tg == xname) ) {
1043 // if target is "xxxx:name"
1044 if (tg.contains(xname +":")) {
1046 var ar = tg.split(":");
1052 if (match.length > 0) {
1053 if (last.length > 0) { // pref is after/before..
1054 // then it's after last
1058 return last + "|%d".printf((int)pref) + "|" + prop;
1062 // we need to add prop - as :store -> needs to bee added when dropping onto.
1063 return path + "|%d".printf( (int) Gtk.TreeViewDropPosition.INTO_OR_AFTER) + "|" + prop;
1067 var par = path.split(":");
1068 string [] ppar = {};
1069 for (var i = 0; i < par.length-1; i++) {
1073 path = string.joinv(":", ppar);
1082 public void moveNode (string target_data, Gdk.DragAction action)
1085 /// target_data = "path|pos");
1088 //print("MOVE NODE");
1089 // console.dump(target_data);
1090 Gtk.TreeIter old_iter;
1093 var s = _this.view.el.get_selection();
1094 s.get_selected(out mod , out old_iter);
1095 mod.get_path(old_iter);
1097 var node = this.pathToNode(mod.get_path(old_iter).to_string());
1098 //console.dump(node);
1100 print("moveNode: ERROR - node is null?");
1105 // needs to drop first, otherwise the target_data
1106 // treepath will be invalid.
1109 if ((action & Gdk.DragAction.MOVE) > 0) {
1110 print("REMOVING OLD NODE : " + target_data + "\n");
1112 this.dropNode(target_data, node, false);
1113 this.el.remove(ref old_iter);
1118 print("DROPPING NODE // copy: " + target_data + "\n");
1119 node = node.deepClone();
1120 this.dropNode(target_data, node, false);
1123 this.activePath= "";
1124 //this.updateNode(false,true);
1126 public void load (Gee.ArrayList<JsRender.Node> tr, Gtk.TreeIter? iter)
1129 //this.insert(citer,iter,0);
1130 for(var i =0 ; i < tr.size; i++) {
1132 this.el.insert(out citer,iter,-1); // why not append?
1134 this.el.append(out citer,null);
1137 this.el.set(citer, 0, tr.get(i).nodeTitle(),
1138 1, tr.get(i).nodeTip(), -1
1140 var o = new GLib.Value(typeof(Object));
1141 o.set_object((Object)tr.get(i));
1143 this.el.set_value(citer, 2, o);
1145 if (tr.get(i).items.size > 0) {
1146 this.load(tr.get(i).items, citer);
1153 public void deleteSelected () {
1155 print("DELETE SELECTED?");
1156 //_this.view.blockChanges = true;
1157 print("GET SELECTION?");
1159 var s = _this.view.el.get_selection();
1161 print("GET SELECTED?");
1166 if (!s.get_selected(out mod, out iter)) {
1167 return; // nothing seleted..
1172 this.activePath= "";
1173 print("GET vnode value?");
1176 this.el.get_value(iter, 2, out value);
1177 var data = (JsRender.Node)(value.get_object());
1178 print("removing node from Render\n");
1179 if (data.parent == null) {
1180 this.file.tree = null;
1184 print("removing node from Tree\n");
1186 this.el.remove(ref iter);
1196 this.activePath= ""; // again!?!?
1197 //this.changed(null,true);
1201 _this.view.blockChanges = false;
1203 public JsRender.Node pathToNode (string path) {
1207 _this.model.el.get_iter_from_string(out iter, path);
1210 _this.model.el.get_value(iter, 2, out value);
1212 return (JsRender.Node)value.dup_object();
1215 public void dropNode (string target_data_str, JsRender.Node node, bool show_templates) {
1216 // print("drop Node");
1217 // console.dump(node);
1218 // console.dump(target_data);
1221 // 0 = before , 1=after 2/3 onto
1224 var target_data= target_data_str.split("|");
1226 var parent_str = target_data[0].length > 0 ? target_data[0] : "";
1227 var pos = target_data.length > 1 ? int.parse(target_data[1]) : 2; // ontop..
1230 Gtk.TreePath tree_path = parent_str.length > 0 ? new Gtk.TreePath.from_string( parent_str ) : null;
1234 //print("add " + tp + "@" + target_data[1] );
1236 JsRender.Node parentNode = null;
1238 Gtk.TreeIter iter_after;
1239 Gtk.TreeIter iter_par ;
1242 if (target_data.length == 3 && target_data[2].length > 0) {
1243 node.props.set("* prop", target_data[2]);
1246 Gtk.TreePath expand_parent = null;
1248 // we only need to show the template if it's come from else where?
1249 if (show_templates) {
1251 var ts = _this.main_window.windowstate.template_select;
1253 var new_node = ts.show(
1254 _this.main_window, // (Gtk.Window) _this.el.get_toplevel (),
1259 if (new_node == null) {
1260 return; // do not add?
1265 //print("pos is %d \n".printf(pos));
1267 Gtk.TreeIter n_iter;
1269 if ( parent_str.length < 1) {
1270 this.el.append(out n_iter, null); // drop at top level..
1272 this.file.tree = node;
1275 } else if (pos < 2) {
1276 //print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
1278 this.el.get_iter(out iter_after, tree_path );
1279 this.el.iter_parent(out iter_par, iter_after);
1280 expand_parent = this.el.get_path(iter_par);
1283 this.el.get_value( iter_par, 2, out value);
1284 parentNode = (JsRender.Node)value.dup_object();
1287 this.el.get_value( iter_after, 2, out value);
1288 var relNode = (JsRender.Node)value.dup_object();
1292 this.el.insert_after(out n_iter, iter_par , iter_after);
1293 var ix = parentNode.items.index_of(relNode);
1294 parentNode.items.insert(ix+1, node);
1297 this.el.insert_before(out n_iter, iter_par , iter_after);
1298 var ix = parentNode.items.index_of(relNode);
1299 parentNode.items.insert(ix, node);
1302 node.parent = parentNode;
1307 // print("appending to " + parent_str);
1308 this.el.get_iter(out iter_par, tree_path);
1309 this.el.append(out n_iter, iter_par );
1310 expand_parent = this.el.get_path(iter_par);
1313 this.el.get_value( iter_par, 2, out value);
1314 parentNode = (JsRender.Node)value.dup_object();
1315 node.parent = parentNode;
1316 parentNode.items.add(node);
1319 // reparent node in tree...
1322 // why only on no parent???
1324 //if (node.parent = null) {
1331 // work out what kind of packing to use.. -- should be in
1332 if (!node.has("pack") && parent_str.length > 1) {
1334 this.file.palete().fillPack(node,parentNode);
1341 this.el.set(n_iter, 0, node.nodeTitle(), 1, node.nodeTip(), -1 );
1342 var o = new GLib.Value(typeof(Object));
1343 o.set_object((Object)node);
1345 this.el.set_value(n_iter, 2, o);
1350 // load children - if it has any..
1352 if (node.items.size > 0) {
1353 this.load(node.items, n_iter);
1354 _this.view.el.expand_row(this.el.get_path(n_iter), true);
1355 } else if (expand_parent != null && !_this.view.el.is_row_expanded(expand_parent)) {
1356 _this.view.el.expand_row(expand_parent,true);
1359 //if (tp != null && (node.items.length() > 0 || pos > 1)) {
1360 // _this.view.el.expand_row(this.el.get_path(iter_par), true);
1362 // wee need to get the empty proptypes from somewhere..
1364 //var olditer = this.activeIter;
1365 this.activePath = this.el.get_path(n_iter).to_string();
1370 _this.view.el.set_cursor(this.el.get_path(n_iter), null, false);
1377 public class Xcls_TreeViewColumn4 : Object
1379 public Gtk.TreeViewColumn el;
1380 private Xcls_WindowLeftTree _this;
1386 public Xcls_TreeViewColumn4(Xcls_WindowLeftTree _owner )
1389 this.el = new Gtk.TreeViewColumn();
1393 // set gobject values
1394 this.el.title = "test";
1395 var child_0 = new Xcls_renderer( _this );
1397 this.el.pack_start ( child_0.el , true );
1401 this.el.add_attribute(_this.renderer.el , "markup", 0 );
1404 // user defined functions
1406 public class Xcls_renderer : Object
1408 public Gtk.CellRendererText el;
1409 private Xcls_WindowLeftTree _this;
1415 public Xcls_renderer(Xcls_WindowLeftTree _owner )
1418 _this.renderer = this;
1419 this.el = new Gtk.CellRendererText();
1423 // set gobject values
1426 // user defined functions
1428 public class Xcls_LeftTreeMenu : Object
1431 private Xcls_WindowLeftTree _this;
1437 public Xcls_LeftTreeMenu(Xcls_WindowLeftTree _owner )
1440 _this.LeftTreeMenu = this;
1441 this.el = new Gtk.Menu();
1445 // set gobject values
1446 var child_0 = new Xcls_MenuItem7( _this );
1448 this.el.add ( child_0.el );
1449 var child_1 = new Xcls_MenuItem8( _this );
1451 this.el.add ( child_1.el );
1452 var child_2 = new Xcls_MenuItem9( _this );
1454 this.el.add ( child_2.el );
1457 // user defined functions
1459 public class Xcls_MenuItem7 : Object
1461 public Gtk.MenuItem el;
1462 private Xcls_WindowLeftTree _this;
1468 public Xcls_MenuItem7(Xcls_WindowLeftTree _owner )
1471 this.el = new Gtk.MenuItem();
1475 // set gobject values
1476 this.el.label = "Delete Element";
1479 this.el.activate.connect( ( ) => {
1484 _this.model.deleteSelected();
1488 // user defined functions
1490 public class Xcls_MenuItem8 : Object
1492 public Gtk.MenuItem el;
1493 private Xcls_WindowLeftTree _this;
1499 public Xcls_MenuItem8(Xcls_WindowLeftTree _owner )
1502 this.el = new Gtk.MenuItem();
1506 // set gobject values
1507 this.el.label = "Save as Template";
1510 this.el.activate.connect( () => {
1512 DialogSaveTemplate.singleton().show(
1513 (Gtk.Window) _this.el.get_toplevel (),
1514 _this.model.file.palete(),
1515 _this.getActiveElement()
1522 // user defined functions
1524 public class Xcls_MenuItem9 : Object
1526 public Gtk.MenuItem el;
1527 private Xcls_WindowLeftTree _this;
1533 public Xcls_MenuItem9(Xcls_WindowLeftTree _owner )
1536 this.el = new Gtk.MenuItem();
1540 // set gobject values
1541 this.el.label = "Save as Module";
1544 this.el.activate.connect( () => {
1545 var node = _this.getActiveElement();
1546 var name = DialogSaveModule.singleton().show(
1547 (Gtk.Window) _this.el.get_toplevel (),
1548 _this.model.file.project,
1551 if (name.length < 1) {
1555 node.props.set("* xinclude", name);
1559 var s = _this.view.el.get_selection();
1561 print("GET SELECTED?");
1566 if (!s.get_selected(out mod, out iter)) {
1567 return; // nothing seleted..
1570 var n_cn = mod.iter_n_children(iter) -1;
1571 for (var i = n_cn; i > -1; i--) {
1572 mod.iter_nth_child(out citer, iter, i);
1575 print("removing node from Tree\n");
1577 _this.model.el.remove(ref citer);
1580 _this.node_selected(node);
1586 // user defined functions