1 static Xcls_WindowLeftTree _WindowLeftTree;
3 public class Xcls_WindowLeftTree : Object
5 public Gtk.ScrolledWindow el;
6 private Xcls_WindowLeftTree _this;
8 public static Xcls_WindowLeftTree singleton()
10 if (_WindowLeftTree == null) {
11 _WindowLeftTree= new Xcls_WindowLeftTree();
13 return _WindowLeftTree;
15 public Xcls_view view;
16 public Xcls_model model;
17 public Xcls_renderer renderer;
18 public Xcls_LeftTreeMenu LeftTreeMenu;
21 public signal bool before_node_change (JsRender.Node? node);
22 public signal void changed ();
23 public signal void node_selected (JsRender.Node? node);
24 public Xcls_MainWindow main_window;
27 public Xcls_WindowLeftTree()
30 this.el = new Gtk.ScrolledWindow( null, null );
33 this.main_window = null;
36 this.el.shadow_type = Gtk.ShadowType.IN;
37 var child_0 = new Xcls_view( _this );
39 this.el.add ( child_0.el );
40 var child_1 = new Xcls_LeftTreeMenu( _this );
45 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC); }
47 // user defined functions
48 public JsRender.Node? getActiveElement () { // return path to actie node.
50 var path = this.getActivePath();
51 if (path.length < 1) {
54 return _this.model.pathToNode(path);
57 public JsRender.JsRender getActiveFile () {
58 return this.model.file;
60 public string getActivePath () {
61 var model = this.model;
62 var view = this.view.el;
63 if (view.get_selection().count_selected_rows() < 1) {
68 view.get_selection().get_selected(out mod, out iter);
69 return mod.get_path(iter).to_string();
71 public class Xcls_view : Object
73 public Gtk.TreeView el;
74 private Xcls_WindowLeftTree _this;
78 public string dragData;
80 public string[] dropList;
82 public bool drag_in_motion;
83 public bool blockChanges;
86 public Xcls_view(Xcls_WindowLeftTree _owner )
90 this.el = new Gtk.TreeView();
93 this.blockChanges = false;
96 this.el.tooltip_column = 1;
97 this.el.enable_tree_lines = true;
98 this.el.headers_visible = false;
99 var child_0 = new Xcls_model( _this );
101 this.el.set_model ( child_0.el );
102 var child_1 = new Xcls_TreeViewColumn4( _this );
104 this.el.append_column ( child_1.el );
109 var description = new Pango.FontDescription();
110 description.set_size(8000);
111 this.el.modify_font(description);
113 var selection = this.el.get_selection();
114 selection.set_mode( Gtk.SelectionMode.SINGLE);
117 // is this really needed??
119 this.selection.signal['changed'].connect(function() {
120 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
121 _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
125 Gtk.drag_source_set (
126 this.el, /* widget will be drag-able */
127 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
128 Builder4.Application.targetList, /* lists of target to support */
129 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
133 //Gtk.drag_source_add_text_targets(this.el);
137 this.el, /* widget that will accept a drop */
138 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
139 Builder4.Application.targetList, /* lists of target to support */
140 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
143 //Gtk.drag_dest_set_target_list(this.el, Builder.Application.targetList);
144 //Gtk.drag_dest_add_text_targets(this.el);
147 this.el.button_press_event.connect( ( ev) => {
148 //console.log("button press?");
149 if (! _this.before_node_change(null) ) {
154 if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button != 3) {
155 //print("click" + ev.type);
159 if (!_this.view.el.get_path_at_pos((int)ev.x,(int)ev.y, out res, null, null, null) ) {
163 this.el.get_selection().select_path(res);
165 //if (!this.get('/LeftTreeMenu').el) {
166 // this.get('/LeftTreeMenu').init();
169 _this.LeftTreeMenu.el.set_screen(Gdk.Screen.get_default());
170 _this.LeftTreeMenu.el.show_all();
171 _this.LeftTreeMenu.el.popup(null, null, null, 3, ev.time);
172 // print("click:" + res.path.to_string());
175 this.el.drag_begin.connect( ( ctx) => {
176 //print('SOURCE: drag-begin');
179 //this.targetData = "";
181 // find what is selected in our tree...
183 var s = _this.view.el.get_selection();
184 if (s.count_selected_rows() < 1) {
189 s.get_selected(out mod, out iter);
193 // set some properties of the tree for use by the dropped element.
195 _this.model.el.get_value(iter, 2, out value);
196 var tp = mod.get_path(iter).to_string();
197 var data = (JsRender.Node)(value.dup_object());
198 var xname = data.fqn();
199 print ("XNAME IS " + xname+ "\n");
201 this.dropList = _this.model.file.palete().getDropList(xname);
203 print ("DROP LIST IS " + string.joinv(", ", this.dropList) + "\n");
206 // make the drag icon a picture of the node that was selected
209 // by default returns the path..
210 var path = _this.model.el.get_path(iter);
213 var pix = this.el.create_row_drag_icon ( path);
215 Gtk.drag_set_icon_surface (ctx, pix) ;
219 this.el.cursor_changed.connect( ( ) => {
222 if (this.blockChanges) { // probably not needed..
225 if (!_this.before_node_change(null) ) {
226 this.blockChanges = true;
227 this.el.get_selection().unselect_all();
228 this.blockChanges = false;
231 if (_this.model.file == null) {
235 //var render = this.get('/LeftTree').getRenderer();
236 print("LEFT TREE -> view -> selection changed called\n");
239 // -- it appears that the selection is not updated.
241 GLib.Timeout.add_full(GLib.Priority.DEFAULT,10 , () => {
244 if (this.el.get_selection().count_selected_rows() < 1) {
246 print("selected rows < 1\n");
247 //??this.model.load( false);
248 _this.node_selected(null);
253 //console.log('changed');
254 var s = this.el.get_selection();
257 s.get_selected(out mod, out iter);
262 _this.model.el.get_value(iter, 2, out value);
263 _this.model.activePath = mod.get_path(iter).to_string();
265 var node = (JsRender.Node)value.dup_object();
266 _this.node_selected(node);
269 //_this.after_node_change(node);
271 // _this.model.file.changed(node, "tree");
273 //Seed.print( value.get_string());
277 this.el.drag_end.connect( (drag_context) => {
278 //Seed.print('LEFT-TREE: drag-end');
280 this.dropList = null;
281 // this.targetData = "";
282 this.highlightDropPath("",0);
285 this.el.drag_motion.connect( ( ctx, x, y, time) => {
286 print("got drag motion\n");
287 var src = Gtk.drag_get_source_widget(ctx);
291 if (src != this.el) {
295 // the point of this is to detect where an item could be dropped..
296 print("requesting drag data\n");
297 this.drag_in_motion = true;
299 // request data that will be recieved by the recieve...
302 this.el, // will receive 'drag-data-received' signal
303 ctx, // represents the current state of the DnD
304 Gdk.Atom.intern("STRING",true), // the target type we want
312 //print("GETTING POS");
316 Gtk.TreeViewDropPosition pos;
317 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
319 // if there are not items in the tree.. the we have to set isOver to true for anything..
321 if (_this.model.el.iter_n_children(null) < 1) {
322 print("got NO children?\n");
325 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
329 // ------------- a drag from self..
332 //var action = Gdk.DragAction.COPY;
333 // unless we are copying!!! ctl button..
335 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
336 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
337 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
340 if (_this.model.el.iter_n_children(null) < 1) {
341 // no children.. -- asume it's ok..
343 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
345 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
346 Gdk.drag_status(ctx, action ,time);
349 // continue through to allow drop...
357 //print("ISOVER? " + isOver);
360 Gdk.drag_status(ctx, 0 ,time);
361 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
366 // drag node is parent of child..
367 //console.log("SRC TREEPATH: " + src.treepath);
368 //console.log("TARGET TREEPATH: " + data.path.to_string());
370 // nned to check a few here..
371 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
372 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
373 //Gtk.TreeViewDropPosition.AFTER
374 //Gtk.TreeViewDropPosition.BEFORE
376 // locally dragged items to not really use the
377 var selection_text = this.dragData;
381 if (selection_text == null || selection_text.length < 1) {
382 //print("Error - drag selection text returned NULL");
383 Gdk.drag_status(ctx, 0 ,time);
384 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
389 // see if we are dragging into ourself?
390 print ("got selection text of " + selection_text);
392 var target_path = path.to_string();
393 //print("target_path="+target_path);
396 if (selection_text == target_path) {
397 print("self drag ?? == we should perhaps allow copy onto self..\n");
399 Gdk.drag_status(ctx, 0 ,time);
400 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
402 // -- fixme -- this is not really correct..
407 //print("DUMPING DATA");
408 //console.dump(data);
411 //print(data.path.to_string() +' => '+ data.pos);
413 // dropList is a list of xtypes that this node could be dropped on.
414 // it is set up when we start to drag..
417 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
419 print("targetDAta: " + targetData +"\n");
421 if (targetData.length < 1) {
422 //print("Can not find drop node path");
424 Gdk.drag_status(ctx, 0, time);
425 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
429 var td_ar = targetData.split("|");
433 Gdk.drag_status(ctx, action ,time);
434 this.highlightDropPath(td_ar[0], (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
439 this.el.drag_data_get.connect( ( drag_context, data, info, time) => {
442 //print("drag-data-get");
443 var s = this.el.get_selection();
444 if (s.count_selected_rows() < 1) {
446 print("return empty string - no selection..");
453 s.get_selected(out mod, out iter);
458 _this.model.el.get_value(iter, 2, out value);
459 var ndata = (JsRender.Node)(value.dup_object());
460 var xname = ndata.fqn();
463 var tp = mod.get_path(iter).to_string();
464 // by default returns the path..
466 if ( info != Gdk.Atom.intern("STRING",true) ) {
467 tp = ndata.toJsonString();
470 //data.set_text(tp,tp.length);
472 data.set (data.get_target (), 8, (uchar[]) tp.to_utf8 ());
475 // print("return " + tp);
477 this.el.drag_data_received.connect( (ctx, x, y, sel, info, time) => {
478 // print("Tree: drag-data-received\n");
479 var selection_text = (string)sel.get_data();
480 //print("selection_text= %s\n",selection_text);
482 var is_drag = this.drag_in_motion;
486 print("Is Drag %s\n", is_drag ? "Y": "N");
490 Gtk.TreeViewDropPosition pos;
491 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
493 // if there are not items in the tree.. the we have to set isOver to true for anything..
495 if (_this.model.el.iter_n_children(null) < 1) {
496 print("got NO children?\n");
499 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
503 //console.log("LEFT-TREE: drag-motion");
504 var src = Gtk.drag_get_source_widget(ctx);
506 // a drag from self - this should be handled by drop and motion.
507 if (src == this.el) {
508 print("Source == this element should not happen.. ? \n");
511 //print("drag_data_recieved from another element");
516 if (selection_text == null || selection_text.length < 1 || !isOver) {
517 // nothing valid foudn to drop...
518 print("empty sel text or not over");
520 Gdk.drag_status(ctx, 0, time);
521 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
524 Gtk.drag_finish (ctx, false, false, time); // drop failed..
529 var dropNode = new JsRender.Node();
531 var dropNodeType = selection_text;
532 var show_templates = true;
534 if (dropNodeType[0] == '{') {
535 var pa = new Json.Parser();
536 pa.load_from_data(dropNodeType);
538 dropNode.loadFromJson( pa.get_root().get_object(), 2);
539 dropNodeType = dropNode.fqn();
540 show_templates = false;
545 dropNode.setFqn(selection_text);
549 // dropList --- need to gather this ...
550 print("get dropList for : %s\n",dropNodeType);
551 var dropList = _this.model.file.palete().getDropList(dropNodeType);
553 print("dropList: %s\n", string.joinv(" , ", dropList));
555 targetData = _this.model.findDropNodeByPath( isEmpty ? "" : path.to_string(), dropList, pos);
557 print("targetDAta: " + targetData +"\n");
559 if (targetData.length < 1) {
561 // invalid drop path..
562 if (this.drag_in_motion) {
563 Gdk.drag_status(ctx, 0, time);
564 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
567 Gtk.drag_finish (ctx, false, false, time); // drop failed..
573 var td_ar = targetData.split("|");
576 if (this.drag_in_motion) {
577 Gdk.drag_status(ctx, Gdk.DragAction.COPY ,time);
579 this.highlightDropPath( td_ar[0] , (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
582 // continue on to allow drop..
585 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
588 _this.model.dropNode(targetData, dropNode, show_templates);
589 print("ADD new node!!!\n");
591 ///Xcls_DialogTemplateSelect.singleton().show( _this.model.file.palete(), node);
593 Gtk.drag_finish (ctx, false, false,time);
600 this.el.drag_drop.connect( ( ctx, x, y, time) => {
601 //Seed.print("TARGET: drag-drop");
604 var src = Gtk.drag_get_source_widget(ctx);
606 if (src != this.el) {
610 this.drag_in_motion = false;
611 // request data that will be recieved by the recieve...
614 this.el, // will receive 'drag-data-received' signal
615 ctx, // represents the current state of the DnD
616 Gdk.Atom.intern("application/json",true), // the target type we want
621 // No target offered by source => error
627 // handle drop around self..
631 //print("GETTING POS");
635 Gtk.TreeViewDropPosition pos;
636 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
638 // if there are not items in the tree.. the we have to set isOver to true for anything..
640 if (_this.model.el.iter_n_children(null) < 1) {
641 print("got NO children?\n");
644 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
649 //var action = Gdk.DragAction.COPY;
650 // unless we are copying!!! ctl button..
652 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
653 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
654 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
657 if (_this.model.el.iter_n_children(null) < 1) {
658 // no children.. -- asume it's ok..
660 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
662 // continue through to allow drop...
670 //print("ISOVER? " + isOver);
673 Gtk.drag_finish (ctx, false, false, time); // drop failed..
674 return true; // not over apoint!?! - no action on drop or motion..
677 // drag node is parent of child..
678 //console.log("SRC TREEPATH: " + src.treepath);
679 //console.log("TARGET TREEPATH: " + data.path.to_string());
681 // nned to check a few here..
682 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
683 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
684 //Gtk.TreeViewDropPosition.AFTER
685 //Gtk.TreeViewDropPosition.BEFORE
687 // locally dragged items to not really use the
688 var selection_text = this.dragData;
692 if (selection_text == null || selection_text.length < 1) {
693 //print("Error - drag selection text returned NULL");
695 Gtk.drag_finish (ctx, false, false, time); // drop failed..
696 return true; /// -- fixme -- this is not really correct..
699 // see if we are dragging into ourself?
700 print ("got selection text of " + selection_text);
702 var target_path = path.to_string();
703 //print("target_path="+target_path);
706 if (selection_text == target_path) {
707 print("self drag ?? == we should perhaps allow copy onto self..\n");
709 Gtk.drag_finish (ctx, false, false, time); // drop failed..
711 return true; /// -- fixme -- this is not really correct..
716 //print("DUMPING DATA");
717 //console.dump(data);
720 //print(data.path.to_string() +' => '+ data.pos);
722 // dropList is a list of xtypes that this node could be dropped on.
723 // it is set up when we start to drag..
726 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
728 print("targetDAta: " + targetData +"\n");
730 if (targetData.length < 1) {
731 //print("Can not find drop node path");
733 Gtk.drag_finish (ctx, false, false, time); // drop failed..
737 var td_ar = targetData.split("|");
741 // continue on to allow drop..
743 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
746 var delete_selection_data = false;
748 if (ctx.get_actions() == Gdk.DragAction.ASK) {
749 /* Ask the user to move or copy, then set the ctx action. */
752 if (ctx.get_actions() == Gdk.DragAction.MOVE) {
753 delete_selection_data = true;
757 // drag around.. - reorder..
758 _this.model.moveNode(targetData, ctx.get_actions());
764 // we can send stuff to souce here...
767 // do we always say failure, so we handle the reall drop?
768 Gtk.drag_finish (ctx, false, false,time); //delete_selection_data, time);
780 // user defined functions
781 public void highlightDropPath ( string treepath, Gtk.TreeViewDropPosition pos) {
783 // highlighting for drag/drop
784 if (treepath.length > 0) {
785 this.el.set_drag_dest_row( new Gtk.TreePath.from_string( treepath ), pos);
787 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
791 public void selectNode (string treepath_str) {
792 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
793 var tp = new Gtk.TreePath.from_string(treepath_str);
795 this.el.set_cursor(tp, null, false);
796 this.el.scroll_to_cell(tp, null, false, 0,0);
799 public class Xcls_model : Object
801 public Gtk.TreeStore el;
802 private Xcls_WindowLeftTree _this;
806 public DialogTemplateSelect template_select;
807 public JsRender.JsRender? file;
808 public string activePath;
809 public Project.Project? project;
812 public Xcls_model(Xcls_WindowLeftTree _owner )
816 this.el = new Gtk.TreeStore( 3, typeof(string),typeof(string),typeof(Object) );
819 this.template_select = null;
821 this.activePath = "";
824 // set gobject values
828 print("model initialized"); }
830 // user defined functions
831 public string findDropNode (string treepath_str, string[] targets) {
833 // this is used by the dragdrop code in the roo version AFAIR..
835 //var path = treepath_str.replace(/^builder-/, '');
836 // treemap is depreciated... - should really check if model has any entries..
838 if (this.el.iter_n_children(null) < 1) {
840 return "|%d".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
842 //print("FIND treepath: " + path);
843 //console.dump(this.treemap);
845 //if (!treepath_str.match(/^builder-/)) {
846 // return []; // nothing!
848 if (targets.length > 0 && targets[0] == "*") {
851 return this.findDropNodeByPath(treepath_str,targets, -1);
853 public void loadFile (JsRender.JsRender f) {
860 // console.log('missing file');
864 // load the file if not loaded..
865 if (f.tree == null) {
868 // if it's still null?
869 if (f.tree == null) {
873 /// this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name);
875 //if (f.items.length && typeof(f.items[0]) == 'string') {
877 //this.get('/RightEditor').el.show();
878 //this.get('/RightEditor.view').load( f.items[0]);
882 //print(JSON.stringify(f.items, null,4));
883 //console.dump(f.items);
884 var o = new Gee.ArrayList<JsRender.Node>();
888 _this.view.el.expand_all();
890 if (f.tree.items.size < 1) {
893 //this.get('/Window.leftvpaned').el.set_position(80);
895 _this.view.el.set_cursor(
896 new Gtk.TreePath.from_string("0"), null, false);
900 //this.get('/Window.leftvpaned').el.set_position(200);
906 //print("hide right editior");
907 //this.get('/RightEditor').el.hide();
908 //this.get('/Editor').el.hide();
909 //print("set current tree");
910 //this.currentTree = this.toJS(false, false)[0];
911 //console.dump(this.currentTree);
912 //this.currentTree = this.currentTree || { items: [] };
913 //_this.renderView();
914 //console.dump(this.map);
915 //var RightPalete = imports.Builder.RightPalete.RightPalete;
918 var pm = this.get('/RightPalete.model');
921 this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
923 if (!this.get('/RightPalete').provider) {
924 print ("********* PALETE PROVIDER MISSING?!!");
926 this.get('/LeftTree').renderView();
928 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
932 this.get('/Window.view-notebook').el.set_current_page(
933 this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
937 public void updateSelected () {
940 var s = _this.view.el.get_selection();
947 if (!s.get_selected(out mod, out iter)) {
948 return; // nothing seleted..
952 this.el.get_value(iter, 2, out value);
953 var node = (JsRender.Node)(value.get_object());
955 this.el.set(iter, 0, node.nodeTitle(),
956 1, node.nodeTip(), -1
959 public string findDropNodeByPath (string treepath_str, string[] targets, int in_pref = -1) {
961 var path = treepath_str; // dupe it..
963 int pref = in_pref < 0 ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : in_pref;
967 //console.dump(this.treemap);
969 print("findDropNodeByPath : got path length %d / %s\n", path.length, path);
971 if (path.length == 0) {
972 // top drop. // just return empty..
973 return "|%d".printf((int)pref) ;
978 while (path.length > 0) {
979 //print("LOOKING FOR PATH: " + path);
980 var node_data = this.pathToNode(path);
982 if (node_data == null) {
983 print("node not found");
987 var xname = node_data.fqn();
991 for (var i =0; i < targets.length; i++) {
993 if ((tg == xname) ) {
997 // if target is "xxxx:name"
998 if (tg.contains(xname +":")) {
1000 var ar = tg.split(":");
1006 if (match.length > 0) {
1007 if (last.length > 0) { // pref is after/before..
1008 // then it's after last
1012 return last + "|%d".printf((int)pref) + "|" + prop;
1016 return path + "|%d".printf( (int) Gtk.TreeViewDropPosition.INTO_OR_AFTER) + "|" + prop;
1019 var par = path.split(":");
1020 string [] ppar = {};
1021 for (var i = 0; i < par.length-1; i++) {
1025 path = string.joinv(":", ppar);
1033 public void moveNode (string target_data, Gdk.DragAction action)
1036 /// target_data = "path|pos");
1039 //print("MOVE NODE");
1040 // console.dump(target_data);
1041 Gtk.TreeIter old_iter;
1044 var s = _this.view.el.get_selection();
1045 s.get_selected(out mod , out old_iter);
1046 mod.get_path(old_iter);
1048 var node = this.pathToNode(mod.get_path(old_iter).to_string());
1049 //console.dump(node);
1051 print("moveNode: ERROR - node is null?");
1056 // needs to drop first, otherwise the target_data
1057 // treepath will be invalid.
1060 if ((action & Gdk.DragAction.MOVE) > 0) {
1061 print("REMOVING OLD NODE : " + target_data + "\n");
1063 this.dropNode(target_data, node, false);
1064 this.el.remove(ref old_iter);
1069 print("DROPPING NODE // copy: " + target_data + "\n");
1070 node = node.deepClone();
1071 this.dropNode(target_data, node, false);
1074 this.activePath= "";
1075 //this.updateNode(false,true);
1077 public void load (Gee.ArrayList<JsRender.Node> tr, Gtk.TreeIter? iter)
1080 //this.insert(citer,iter,0);
1081 for(var i =0 ; i < tr.size; i++) {
1083 this.el.insert(out citer,iter,-1); // why not append?
1085 this.el.append(out citer,null);
1088 this.el.set(citer, 0, tr.get(i).nodeTitle(),
1089 1, tr.get(i).nodeTip(), -1
1091 var o = new GLib.Value(typeof(Object));
1092 o.set_object((Object)tr.get(i));
1094 this.el.set_value(citer, 2, o);
1096 if (tr.get(i).items.size > 0) {
1097 this.load(tr.get(i).items, citer);
1104 public void deleteSelected () {
1106 print("DELETE SELECTED?");
1107 //_this.view.blockChanges = true;
1108 print("GET SELECTION?");
1110 var s = _this.view.el.get_selection();
1112 print("GET SELECTED?");
1117 if (!s.get_selected(out mod, out iter)) {
1118 return; // nothing seleted..
1123 this.activePath= "";
1124 print("GET vnode value?");
1127 this.el.get_value(iter, 2, out value);
1128 var data = (JsRender.Node)(value.get_object());
1129 print("removing node from Render\n");
1130 if (data.parent == null) {
1131 this.file.tree = null;
1135 print("removing node from Tree\n");
1137 this.el.remove(ref iter);
1147 this.activePath= ""; // again!?!?
1148 //this.changed(null,true);
1152 _this.view.blockChanges = false;
1154 public JsRender.Node pathToNode (string path) {
1158 _this.model.el.get_iter_from_string(out iter, path);
1161 _this.model.el.get_value(iter, 2, out value);
1163 return (JsRender.Node)value.dup_object();
1166 public void dropNode (string target_data_str, JsRender.Node node, bool show_templates) {
1167 // print("drop Node");
1168 // console.dump(node);
1169 // console.dump(target_data);
1172 // 0 = before , 1=after 2/3 onto
1175 var target_data= target_data_str.split("|");
1177 var parent_str = target_data[0].length > 0 ? target_data[0] : "";
1178 var pos = target_data.length > 1 ? int.parse(target_data[1]) : 2; // ontop..
1181 Gtk.TreePath tree_path = parent_str.length > 0 ? new Gtk.TreePath.from_string( parent_str ) : null;
1185 //print("add " + tp + "@" + target_data[1] );
1187 JsRender.Node parentNode = null;
1189 Gtk.TreeIter iter_after;
1190 Gtk.TreeIter iter_par ;
1193 if (target_data.length == 3 && target_data[2].length > 0) {
1194 node.props.set("* prop", target_data[2]);
1197 Gtk.TreePath expand_parent = null;
1199 // we only need to show the template if it's come from else where?
1200 if (show_templates) {
1202 if (this.template_select == null) {
1203 this.template_select = new DialogTemplateSelect();
1206 var new_node = this.template_select.show(
1207 (Gtk.Window) _this.el.get_toplevel (),
1211 if (new_node != null) {
1216 //print("pos is %d \n".printf(pos));
1218 Gtk.TreeIter n_iter;
1220 if ( parent_str.length < 1) {
1221 this.el.append(out n_iter, null); // drop at top level..
1223 this.file.tree = node;
1226 } else if (pos < 2) {
1227 //print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
1229 this.el.get_iter(out iter_after, tree_path );
1230 this.el.iter_parent(out iter_par, iter_after);
1231 expand_parent = this.el.get_path(iter_par);
1234 this.el.get_value( iter_par, 2, out value);
1235 parentNode = (JsRender.Node)value.dup_object();
1238 this.el.get_value( iter_after, 2, out value);
1239 var relNode = (JsRender.Node)value.dup_object();
1243 this.el.insert_after(out n_iter, iter_par , iter_after);
1244 var ix = parentNode.items.index_of(relNode);
1245 parentNode.items.insert(ix+1, node);
1248 this.el.insert_before(out n_iter, iter_par , iter_after);
1249 var ix = parentNode.items.index_of(relNode);
1250 parentNode.items.insert(ix, node);
1253 node.parent = parentNode;
1258 // print("appending to " + parent_str);
1259 this.el.get_iter(out iter_par, tree_path);
1260 this.el.append(out n_iter, iter_par );
1261 expand_parent = this.el.get_path(iter_par);
1264 this.el.get_value( iter_par, 2, out value);
1265 parentNode = (JsRender.Node)value.dup_object();
1266 node.parent = parentNode;
1267 parentNode.items.add(node);
1270 // reparent node in tree...
1273 // why only on no parent???
1275 //if (node.parent = null) {
1282 // work out what kind of packing to use.. -- should be in
1283 if (!node.has("pack") && parent_str.length > 1) {
1285 this.file.palete().fillPack(node,parentNode);
1292 this.el.set(n_iter, 0, node.nodeTitle(), 1, node.nodeTip(), -1 );
1293 var o = new GLib.Value(typeof(Object));
1294 o.set_object((Object)node);
1296 this.el.set_value(n_iter, 2, o);
1301 // load children - if it has any..
1303 if (node.items.size > 0) {
1304 this.load(node.items, n_iter);
1305 _this.view.el.expand_row(this.el.get_path(n_iter), true);
1306 } else if (expand_parent != null && !_this.view.el.is_row_expanded(expand_parent)) {
1307 _this.view.el.expand_row(expand_parent,true);
1310 //if (tp != null && (node.items.length() > 0 || pos > 1)) {
1311 // _this.view.el.expand_row(this.el.get_path(iter_par), true);
1313 // wee need to get the empty proptypes from somewhere..
1315 //var olditer = this.activeIter;
1316 this.activePath = this.el.get_path(n_iter).to_string();
1321 _this.view.el.set_cursor(this.el.get_path(n_iter), null, false);
1328 public class Xcls_TreeViewColumn4 : Object
1330 public Gtk.TreeViewColumn el;
1331 private Xcls_WindowLeftTree _this;
1337 public Xcls_TreeViewColumn4(Xcls_WindowLeftTree _owner )
1340 this.el = new Gtk.TreeViewColumn();
1344 // set gobject values
1345 this.el.title = "test";
1346 var child_0 = new Xcls_renderer( _this );
1348 this.el.pack_start ( child_0.el , true );
1352 this.el.add_attribute(_this.renderer.el , "markup", 0 ); }
1354 // user defined functions
1356 public class Xcls_renderer : Object
1358 public Gtk.CellRendererText el;
1359 private Xcls_WindowLeftTree _this;
1365 public Xcls_renderer(Xcls_WindowLeftTree _owner )
1368 _this.renderer = this;
1369 this.el = new Gtk.CellRendererText();
1373 // set gobject values
1376 // user defined functions
1378 public class Xcls_LeftTreeMenu : Object
1381 private Xcls_WindowLeftTree _this;
1387 public Xcls_LeftTreeMenu(Xcls_WindowLeftTree _owner )
1390 _this.LeftTreeMenu = this;
1391 this.el = new Gtk.Menu();
1395 // set gobject values
1396 var child_0 = new Xcls_MenuItem7( _this );
1398 this.el.add ( child_0.el );
1399 var child_1 = new Xcls_MenuItem8( _this );
1401 this.el.add ( child_1.el );
1402 var child_2 = new Xcls_MenuItem9( _this );
1404 this.el.add ( child_2.el );
1407 // user defined functions
1409 public class Xcls_MenuItem7 : Object
1411 public Gtk.MenuItem el;
1412 private Xcls_WindowLeftTree _this;
1418 public Xcls_MenuItem7(Xcls_WindowLeftTree _owner )
1421 this.el = new Gtk.MenuItem();
1425 // set gobject values
1426 this.el.label = "Delete Element";
1429 this.el.activate.connect( ( ) => {
1434 _this.model.deleteSelected();
1438 // user defined functions
1440 public class Xcls_MenuItem8 : Object
1442 public Gtk.MenuItem el;
1443 private Xcls_WindowLeftTree _this;
1449 public Xcls_MenuItem8(Xcls_WindowLeftTree _owner )
1452 this.el = new Gtk.MenuItem();
1456 // set gobject values
1457 this.el.label = "Save as Template";
1460 this.el.activate.connect( () => {
1462 DialogSaveTemplate.singleton().show(
1463 (Gtk.Window) _this.el.get_toplevel (),
1464 _this.model.file.palete(),
1465 _this.getActiveElement()
1472 // user defined functions
1474 public class Xcls_MenuItem9 : Object
1476 public Gtk.MenuItem el;
1477 private Xcls_WindowLeftTree _this;
1483 public Xcls_MenuItem9(Xcls_WindowLeftTree _owner )
1486 this.el = new Gtk.MenuItem();
1490 // set gobject values
1491 this.el.label = "Save as Module";
1494 this.el.activate.connect( () => {
1495 var node = _this.getActiveElement();
1496 var name = DialogSaveModule.singleton().show(
1497 (Gtk.Window) _this.el.get_toplevel (),
1498 _this.model.file.project,
1501 if (name.length < 1) {
1505 node.props.set("* xinclude", name);
1509 var s = _this.view.el.get_selection();
1511 print("GET SELECTED?");
1516 if (!s.get_selected(out mod, out iter)) {
1517 return; // nothing seleted..
1520 var n_cn = mod.iter_n_children(iter) -1;
1521 for (var i = n_cn; i > -1; i--) {
1522 mod.iter_nth_child(out citer, iter, i);
1525 print("removing node from Tree\n");
1527 _this.model.el.remove(ref citer);
1530 _this.node_selected(node);
1536 // user defined functions