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;
79 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.cursor_changed.connect( ( ) => {
178 if (this.blockChanges) { // probably not needed..
181 if (!_this.before_node_change(null) ) {
182 this.blockChanges = true;
183 this.el.get_selection().unselect_all();
184 this.blockChanges = false;
187 if (_this.model.file == null) {
191 //var render = this.get('/LeftTree').getRenderer();
192 print("LEFT TREE -> view -> selection changed called\n");
195 // -- it appears that the selection is not updated.
197 GLib.Timeout.add_full(GLib.Priority.DEFAULT,10 , () => {
200 if (this.el.get_selection().count_selected_rows() < 1) {
202 print("selected rows < 1\n");
203 //??this.model.load( false);
204 _this.node_selected(null);
209 //console.log('changed');
210 var s = this.el.get_selection();
213 s.get_selected(out mod, out iter);
218 _this.model.el.get_value(iter, 2, out value);
219 _this.model.activePath = mod.get_path(iter).to_string();
221 var node = (JsRender.Node)value.dup_object();
222 _this.node_selected(node);
225 //_this.after_node_change(node);
227 // _this.model.file.changed(node, "tree");
229 //Seed.print( value.get_string());
233 this.el.drag_begin.connect( ( ctx) => {
234 //print('SOURCE: drag-begin');
237 //this.targetData = "";
239 // find what is selected in our tree...
241 var s = _this.view.el.get_selection();
242 if (s.count_selected_rows() < 1) {
247 s.get_selected(out mod, out iter);
251 // set some properties of the tree for use by the dropped element.
253 _this.model.el.get_value(iter, 2, out value);
254 var tp = mod.get_path(iter).to_string();
255 var data = (JsRender.Node)(value.dup_object());
256 var xname = data.fqn();
257 print ("XNAME IS " + xname+ "\n");
259 //this.dropList = _this.model.file.palete().getDropList(xname);
261 print ("DROP LIST IS " + string.joinv(", ", this.dropList) + "\n");
264 // make the drag icon a picture of the node that was selected
267 // by default returns the path..
270 var pix = this.el.create_row_drag_icon ( path);
272 Gtk.drag_set_icon_surface (ctx, pix) ;
276 this.el.drag_end.connect( (drag_context) => {
277 //Seed.print('LEFT-TREE: drag-end');
279 this.dropList = null;
280 // this.targetData = "";
281 this.highlightDropPath("",0);
284 this.el.drag_motion.connect( ( ctx, x, y, time) => {
286 // the point of this is to detect where an item could be dropped..
287 print("got drag motion");
288 this.drag_in_motion = true;
292 // request data that will be recieved by the recieve...
295 this.el, // will receive 'drag-data-received' signal
296 ctx, // represents the current state of the DnD
297 Gdk.Atom.intern("STRING",true), // the target type we want
303 this.el.drag_data_get.connect( ( drag_context, data, info, time) => {
306 //print("drag-data-get");
307 var s = this.el.get_selection();
308 if (s.count_selected_rows() < 1) {
310 print("return empty string - no selection..");
317 s.get_selected(out mod, out iter);
322 _this.model.el.get_value(iter, 2, out value);
323 var ndata = (JsRender.Node)(value.dup_object());
324 var xname = ndata.fqn();
327 var tp = mod.get_path(iter).to_string();
328 // by default returns the path..
330 if ( info != Gdk.Atom.intern("STRING",true) ) {
331 tp = node.toJsonString();
334 data.set_text(tp,tp.length);
339 // print("return " + tp);
341 this.el.drag_data_received.connect( (ctx, x, y, sel, info, time) => {
342 //print("Tree: drag-data-received");
345 var is_drag = info == Gdk.Atom.intern("STRING",true),
348 //print("GETTING POS");
352 Gtk.TreeViewDropPosition pos;
353 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
355 // if there are not items in the tree.. the we have to set isOver to true for anything..
357 if (_this.model.el.iter_n_children(null) < 1) {
358 print("got NO children?\n");
361 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
365 //console.log("LEFT-TREE: drag-motion");
366 var src = Gtk.drag_get_source_widget(ctx);
368 // a drag from elsewhere...- prevent drop..
369 if (src != this.el) {
370 //print("drag_data_recieved from another element");
373 var selection_text = sel.get_text();
376 if (selection_text == null || selection_text.length < 1 || !isOver) {
377 // nothing valid foudn to drop...
379 Gdk.drag_status(ctx, 0, time);
380 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
383 Gtk.drag_finish (ctx, false, false, time); // drop failed..
388 JsRender.Node dropNode = new JsRender.Node();
390 var dropNodeType = selection_text;
391 var show_templates = true;
393 if (!is_drag && dropNodeType[0] == '{') {
394 var pa = new Json.Parser();
395 pa.load_from_data(dropNodeType);
396 dropNode = new JsRender.Node();
397 dropNode.loadFromJson( pa.get_root(), 2);
398 dropNodeType = dropNode.fqn();
399 show_templates = false;
402 dropNode.setFqn(selection_text);
406 // dropList --- need to gather this ...
407 //print("get dropList for : %s\n",selection_text);
408 var dropList = _this.model.file.palete().getDropList(dropNodeType);
410 print("dropList: %s\n", string.joinv(" , ", dropList));
412 targetData = _this.model.findDropNodeByPath( isEmpty ? "" : path.to_string(), dropList, pos);
414 print("targetDAta: " + targetData +"\n");
416 if (targetData.length < 1) {
418 // invalid drop path..
419 if (this.drag_in_motion) {
420 Gdk.drag_status(ctx, 0, time);
421 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
424 Gtk.drag_finish (ctx, false, false, time); // drop failed..
430 var td_ar = targetData.split("|");
433 if (this.drag_in_motion) {
434 Gdk.drag_status(ctx, Gdk.DragAction.COPY ,time);
436 this.highlightDropPath( td_ar[0] , (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
439 // continue on to allow drop..
442 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
445 _this.model.dropNode(targetData, dropNode, show_templates);
446 print("ADD new node!!!\n");
448 ///Xcls_DialogTemplateSelect.singleton().show( _this.model.file.palete(), node);
450 Gtk.drag_finish (ctx, false, false,time);
460 // ------------- a drag from self..
463 //var action = Gdk.DragAction.COPY;
464 // unless we are copying!!! ctl button..
465 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ? Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
468 if (_this.model.el.iter_n_children(null) < 1) {
469 // no children.. -- asume it's ok..
471 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
472 if (this.drag_in_motion) {
473 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
474 Gdk.drag_status(ctx, action ,time);
477 // continue through to allow drop...
485 //print("ISOVER? " + isOver);
487 if (this.drag_in_motion) {
488 Gdk.drag_status(ctx, 0 ,time);
489 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
492 Gtk.drag_finish (ctx, false, false, time); // drop failed..
493 return; // not over apoint!?! - no action on drop or motion..
496 // drag node is parent of child..
497 //console.log("SRC TREEPATH: " + src.treepath);
498 //console.log("TARGET TREEPATH: " + data.path.to_string());
500 // nned to check a few here..
501 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
502 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
503 //Gtk.TreeViewDropPosition.AFTER
504 //Gtk.TreeViewDropPosition.BEFORE
506 // locally dragged items to not really use the
507 var selection_text = this.dragData;
511 if (selection_text == null || selection_text.length < 1) {
512 //print("Error - drag selection text returned NULL");
513 if (this.drag_in_motion) {
514 Gdk.drag_status(ctx, 0 ,time);
515 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
518 Gtk.drag_finish (ctx, false, false, time); // drop failed..
519 return; /// -- fixme -- this is not really correct..
522 // see if we are dragging into ourself?
523 print ("got selection text of " + selection_text);
525 var target_path = path.to_string();
526 //print("target_path="+target_path);
529 if (selection_text == target_path) {
530 print("self drag ?? == we should perhaps allow copy onto self..\n");
531 if (this.drag_in_motion) {
532 Gdk.drag_status(ctx, 0 ,time);
533 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
536 Gtk.drag_finish (ctx, false, false, time); // drop failed..
538 return; /// -- fixme -- this is not really correct..
543 //print("DUMPING DATA");
544 //console.dump(data);
547 //print(data.path.to_string() +' => '+ data.pos);
549 // dropList is a list of xtypes that this node could be dropped on.
550 // it is set up when we start to drag..
553 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
555 print("targetDAta: " + targetData +"\n");
557 if (targetData.length < 1) {
558 //print("Can not find drop node path");
559 if (this.drag_in_motion) {
560 Gdk.drag_status(ctx, 0, time);
561 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
564 Gtk.drag_finish (ctx, false, false, time); // drop failed..
568 var td_ar = targetData.split("|");
571 if (this.drag_in_motion) {
572 Gdk.drag_status(ctx, action ,time);
573 this.highlightDropPath(td_ar[0], (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
576 // continue on to allow drop..
579 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
582 var delete_selection_data = false;
584 if (ctx.get_actions() == Gdk.DragAction.ASK) {
585 /* Ask the user to move or copy, then set the ctx action. */
588 if (ctx.get_actions() == Gdk.DragAction.MOVE) {
589 delete_selection_data = true;
593 // drag around.. - reorder..
594 _this.model.moveNode(targetData, ctx.get_actions());
600 // we can send stuff to souce here...
603 // do we always say failure, so we handle the reall drop?
604 Gtk.drag_finish (ctx, false, false,time); //delete_selection_data, time);
607 this.el.drag_drop.connect( ( ctx, x, y, time) => {
608 //Seed.print("TARGET: drag-drop");
611 var src = Gtk.drag_get_source_widget(ctx);
613 if (src != this.el) {
617 this.drag_in_motion = false;
618 // request data that will be recieved by the recieve...
621 this.el, // will receive 'drag-data-received' signal
622 ctx, // represents the current state of the DnD
623 Gdk.Atom.intern("application/json",true), // the target type we want
628 // No target offered by source => error
634 // handle drop around self..
636 var is_drag = info == Gdk.Atom.intern("STRING",true),
639 //print("GETTING POS");
643 Gtk.TreeViewDropPosition pos;
644 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
646 // if there are not items in the tree.. the we have to set isOver to true for anything..
648 if (_this.model.el.iter_n_children(null) < 1) {
649 print("got NO children?\n");
652 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
657 //var action = Gdk.DragAction.COPY;
658 // unless we are copying!!! ctl button..
659 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ? Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
662 if (_this.model.el.iter_n_children(null) < 1) {
663 // no children.. -- asume it's ok..
665 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
667 // continue through to allow drop...
675 //print("ISOVER? " + isOver);
678 Gtk.drag_finish (ctx, false, false, time); // drop failed..
679 return true; // not over apoint!?! - no action on drop or motion..
682 // drag node is parent of child..
683 //console.log("SRC TREEPATH: " + src.treepath);
684 //console.log("TARGET TREEPATH: " + data.path.to_string());
686 // nned to check a few here..
687 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
688 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
689 //Gtk.TreeViewDropPosition.AFTER
690 //Gtk.TreeViewDropPosition.BEFORE
692 // locally dragged items to not really use the
693 var selection_text = this.dragData;
697 if (selection_text == null || selection_text.length < 1) {
698 //print("Error - drag selection text returned NULL");
700 Gtk.drag_finish (ctx, false, false, time); // drop failed..
701 return true; /// -- fixme -- this is not really correct..
704 // see if we are dragging into ourself?
705 print ("got selection text of " + selection_text);
707 var target_path = path.to_string();
708 //print("target_path="+target_path);
711 if (selection_text == target_path) {
712 print("self drag ?? == we should perhaps allow copy onto self..\n");
713 if (this.drag_in_motion) {
714 Gdk.drag_status(ctx, 0 ,time);
715 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
718 Gtk.drag_finish (ctx, false, false, time); // drop failed..
720 return; /// -- fixme -- this is not really correct..
725 //print("DUMPING DATA");
726 //console.dump(data);
729 //print(data.path.to_string() +' => '+ data.pos);
731 // dropList is a list of xtypes that this node could be dropped on.
732 // it is set up when we start to drag..
735 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
737 print("targetDAta: " + targetData +"\n");
739 if (targetData.length < 1) {
740 //print("Can not find drop node path");
741 if (this.drag_in_motion) {
742 Gdk.drag_status(ctx, 0, time);
743 this.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
746 Gtk.drag_finish (ctx, false, false, time); // drop failed..
750 var td_ar = targetData.split("|");
753 if (this.drag_in_motion) {
754 Gdk.drag_status(ctx, action ,time);
755 this.highlightDropPath(td_ar[0], (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));
758 // continue on to allow drop..
761 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
764 var delete_selection_data = false;
766 if (ctx.get_actions() == Gdk.DragAction.ASK) {
767 /* Ask the user to move or copy, then set the ctx action. */
770 if (ctx.get_actions() == Gdk.DragAction.MOVE) {
771 delete_selection_data = true;
775 // drag around.. - reorder..
776 _this.model.moveNode(targetData, ctx.get_actions());
782 // we can send stuff to souce here...
785 // do we always say failure, so we handle the reall drop?
786 Gtk.drag_finish (ctx, false, false,time); //delete_selection_data, time);
798 // user defined functions
799 public void highlightDropPath ( string treepath, Gtk.TreeViewDropPosition pos) {
801 // highlighting for drag/drop
802 if (treepath.length > 0) {
803 this.el.set_drag_dest_row( new Gtk.TreePath.from_string( treepath ), pos);
805 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
809 public void selectNode (string treepath_str) {
810 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
811 var tp = new Gtk.TreePath.from_string(treepath_str);
813 this.el.set_cursor(tp, null, false);
814 this.el.scroll_to_cell(tp, null, false, 0,0);
817 public class Xcls_model : Object
819 public Gtk.TreeStore el;
820 private Xcls_WindowLeftTree _this;
824 public DialogTemplateSelect template_select;
825 public JsRender.JsRender? file;
826 public string activePath;
827 public Project.Project? project;
830 public Xcls_model(Xcls_WindowLeftTree _owner )
834 this.el = new Gtk.TreeStore( 3, typeof(string),typeof(string),typeof(Object) );
837 this.template_select = null;
839 this.activePath = "";
842 // set gobject values
846 print("model initialized"); }
848 // user defined functions
849 public string findDropNode (string treepath_str, string[] targets) {
851 // this is used by the dragdrop code in the roo version AFAIR..
853 //var path = treepath_str.replace(/^builder-/, '');
854 // treemap is depreciated... - should really check if model has any entries..
856 if (this.el.iter_n_children(null) < 1) {
858 return "|%d".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
860 //print("FIND treepath: " + path);
861 //console.dump(this.treemap);
863 //if (!treepath_str.match(/^builder-/)) {
864 // return []; // nothing!
866 if (targets.length > 0 && targets[0] == "*") {
869 return this.findDropNodeByPath(treepath_str,targets, -1);
871 public void loadFile (JsRender.JsRender f) {
878 // console.log('missing file');
882 // load the file if not loaded..
883 if (f.tree == null) {
886 // if it's still null?
887 if (f.tree == null) {
891 /// this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name);
893 //if (f.items.length && typeof(f.items[0]) == 'string') {
895 //this.get('/RightEditor').el.show();
896 //this.get('/RightEditor.view').load( f.items[0]);
900 //print(JSON.stringify(f.items, null,4));
901 //console.dump(f.items);
902 var o = new Gee.ArrayList<JsRender.Node>();
906 _this.view.el.expand_all();
908 if (f.tree.items.size < 1) {
911 //this.get('/Window.leftvpaned').el.set_position(80);
913 _this.view.el.set_cursor(
914 new Gtk.TreePath.from_string("0"), null, false);
918 //this.get('/Window.leftvpaned').el.set_position(200);
924 //print("hide right editior");
925 //this.get('/RightEditor').el.hide();
926 //this.get('/Editor').el.hide();
927 //print("set current tree");
928 //this.currentTree = this.toJS(false, false)[0];
929 //console.dump(this.currentTree);
930 //this.currentTree = this.currentTree || { items: [] };
931 //_this.renderView();
932 //console.dump(this.map);
933 //var RightPalete = imports.Builder.RightPalete.RightPalete;
936 var pm = this.get('/RightPalete.model');
939 this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
941 if (!this.get('/RightPalete').provider) {
942 print ("********* PALETE PROVIDER MISSING?!!");
944 this.get('/LeftTree').renderView();
946 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
950 this.get('/Window.view-notebook').el.set_current_page(
951 this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
955 public void updateSelected () {
958 var s = _this.view.el.get_selection();
965 if (!s.get_selected(out mod, out iter)) {
966 return; // nothing seleted..
970 this.el.get_value(iter, 2, out value);
971 var node = (JsRender.Node)(value.get_object());
973 this.el.set(iter, 0, node.nodeTitle(),
974 1, node.nodeTip(), -1
977 public string findDropNodeByPath (string treepath_str, string[] targets, int in_pref = -1) {
979 var path = treepath_str; // dupe it..
981 int pref = in_pref < 0 ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : in_pref;
985 //console.dump(this.treemap);
987 print("findDropNodeByPath : got path length %d / %s\n", path.length, path);
989 if (path.length == 0) {
990 // top drop. // just return empty..
991 return "|%d".printf((int)pref) ;
996 while (path.length > 0) {
997 //print("LOOKING FOR PATH: " + path);
998 var node_data = this.pathToNode(path);
1000 if (node_data == null) {
1001 print("node not found");
1005 var xname = node_data.fqn();
1009 for (var i =0; i < targets.length; i++) {
1010 var tg = targets[i];
1011 if ((tg == xname) ) {
1015 // if target is "xxxx:name"
1016 if (tg.contains(xname +":")) {
1018 var ar = tg.split(":");
1024 if (match.length > 0) {
1025 if (last.length > 0) { // pref is after/before..
1026 // then it's after last
1030 return last + "|%d".printf((int)pref) + "|" + prop;
1034 return path + "|%d".printf( (int) Gtk.TreeViewDropPosition.INTO_OR_AFTER) + "|" + prop;
1037 var par = path.split(":");
1038 string [] ppar = {};
1039 for (var i = 0; i < par.length-1; i++) {
1043 path = string.joinv(":", ppar);
1051 public void moveNode (string target_data, Gdk.DragAction action)
1054 /// target_data = "path|pos");
1057 //print("MOVE NODE");
1058 // console.dump(target_data);
1059 Gtk.TreeIter old_iter;
1062 var s = _this.view.el.get_selection();
1063 s.get_selected(out mod , out old_iter);
1064 mod.get_path(old_iter);
1066 var node = this.pathToNode(mod.get_path(old_iter).to_string());
1067 //console.dump(node);
1069 print("moveNode: ERROR - node is null?");
1074 // needs to drop first, otherwise the target_data
1075 // treepath will be invalid.
1078 if ((action & Gdk.DragAction.MOVE) > 0) {
1079 print("REMOVING OLD NODE : " + target_data + "\n");
1081 this.dropNode(target_data, node, false);
1082 this.el.remove(ref old_iter);
1087 print("DROPPING NODE // copy: " + target_data + "\n");
1088 node = node.deepClone();
1089 this.dropNode(target_data, node, false);
1092 this.activePath= "";
1093 //this.updateNode(false,true);
1095 public void load (Gee.ArrayList<JsRender.Node> tr, Gtk.TreeIter? iter)
1098 //this.insert(citer,iter,0);
1099 for(var i =0 ; i < tr.size; i++) {
1101 this.el.insert(out citer,iter,-1); // why not append?
1103 this.el.append(out citer,null);
1106 this.el.set(citer, 0, tr.get(i).nodeTitle(),
1107 1, tr.get(i).nodeTip(), -1
1109 var o = new GLib.Value(typeof(Object));
1110 o.set_object((Object)tr.get(i));
1112 this.el.set_value(citer, 2, o);
1114 if (tr.get(i).items.size > 0) {
1115 this.load(tr.get(i).items, citer);
1122 public void deleteSelected () {
1124 print("DELETE SELECTED?");
1125 //_this.view.blockChanges = true;
1126 print("GET SELECTION?");
1128 var s = _this.view.el.get_selection();
1130 print("GET SELECTED?");
1135 if (!s.get_selected(out mod, out iter)) {
1136 return; // nothing seleted..
1141 this.activePath= "";
1142 print("GET vnode value?");
1145 this.el.get_value(iter, 2, out value);
1146 var data = (JsRender.Node)(value.get_object());
1147 print("removing node from Render\n");
1148 if (data.parent == null) {
1149 this.file.tree = null;
1153 print("removing node from Tree\n");
1155 this.el.remove(ref iter);
1165 this.activePath= ""; // again!?!?
1166 //this.changed(null,true);
1170 _this.view.blockChanges = false;
1172 public JsRender.Node pathToNode (string path) {
1176 _this.model.el.get_iter_from_string(out iter, path);
1179 _this.model.el.get_value(iter, 2, out value);
1181 return (JsRender.Node)value.dup_object();
1184 public void dropNode (string target_data_str, JsRender.Node node, bool show_templates) {
1185 // print("drop Node");
1186 // console.dump(node);
1187 // console.dump(target_data);
1190 // 0 = before , 1=after 2/3 onto
1193 var target_data= target_data_str.split("|");
1195 var parent_str = target_data[0].length > 0 ? target_data[0] : "";
1196 var pos = target_data.length > 1 ? int.parse(target_data[1]) : 2; // ontop..
1199 Gtk.TreePath tree_path = parent_str.length > 0 ? new Gtk.TreePath.from_string( parent_str ) : null;
1203 //print("add " + tp + "@" + target_data[1] );
1205 JsRender.Node parentNode = null;
1207 Gtk.TreeIter iter_after;
1208 Gtk.TreeIter iter_par ;
1211 if (target_data.length == 3 && target_data[2].length > 0) {
1212 node.props.set("* prop", target_data[2]);
1215 Gtk.TreePath expand_parent = null;
1217 // we only need to show the template if it's come from else where?
1218 if (show_templates) {
1220 if (this.template_select == null) {
1221 this.template_select = new DialogTemplateSelect();
1224 var new_node = this.template_select.show(
1225 (Gtk.Window) _this.el.get_toplevel (),
1229 if (new_node != null) {
1234 //print("pos is %d \n".printf(pos));
1236 Gtk.TreeIter n_iter;
1238 if ( parent_str.length < 1) {
1239 this.el.append(out n_iter, null); // drop at top level..
1241 this.file.tree = node;
1244 } else if (pos < 2) {
1245 //print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
1247 this.el.get_iter(out iter_after, tree_path );
1248 this.el.iter_parent(out iter_par, iter_after);
1249 expand_parent = this.el.get_path(iter_par);
1252 this.el.get_value( iter_par, 2, out value);
1253 parentNode = (JsRender.Node)value.dup_object();
1256 this.el.get_value( iter_after, 2, out value);
1257 var relNode = (JsRender.Node)value.dup_object();
1261 this.el.insert_after(out n_iter, iter_par , iter_after);
1262 var ix = parentNode.items.index_of(relNode);
1263 parentNode.items.insert(ix+1, node);
1266 this.el.insert_before(out n_iter, iter_par , iter_after);
1267 var ix = parentNode.items.index_of(relNode);
1268 parentNode.items.insert(ix, node);
1271 node.parent = parentNode;
1276 // print("appending to " + parent_str);
1277 this.el.get_iter(out iter_par, tree_path);
1278 this.el.append(out n_iter, iter_par );
1279 expand_parent = this.el.get_path(iter_par);
1282 this.el.get_value( iter_par, 2, out value);
1283 parentNode = (JsRender.Node)value.dup_object();
1284 node.parent = parentNode;
1285 parentNode.items.add(node);
1288 // reparent node in tree...
1291 // why only on no parent???
1293 //if (node.parent = null) {
1300 // work out what kind of packing to use.. -- should be in
1301 if (!node.has("pack") && parent_str.length > 1) {
1303 this.file.palete().fillPack(node,parentNode);
1310 this.el.set(n_iter, 0, node.nodeTitle(), 1, node.nodeTip(), -1 );
1311 var o = new GLib.Value(typeof(Object));
1312 o.set_object((Object)node);
1314 this.el.set_value(n_iter, 2, o);
1319 // load children - if it has any..
1321 if (node.items.size > 0) {
1322 this.load(node.items, n_iter);
1323 _this.view.el.expand_row(this.el.get_path(n_iter), true);
1324 } else if (expand_parent != null && !_this.view.el.is_row_expanded(expand_parent)) {
1325 _this.view.el.expand_row(expand_parent,true);
1328 //if (tp != null && (node.items.length() > 0 || pos > 1)) {
1329 // _this.view.el.expand_row(this.el.get_path(iter_par), true);
1331 // wee need to get the empty proptypes from somewhere..
1333 //var olditer = this.activeIter;
1334 this.activePath = this.el.get_path(n_iter).to_string();
1339 _this.view.el.set_cursor(this.el.get_path(n_iter), null, false);
1346 public class Xcls_TreeViewColumn4 : Object
1348 public Gtk.TreeViewColumn el;
1349 private Xcls_WindowLeftTree _this;
1355 public Xcls_TreeViewColumn4(Xcls_WindowLeftTree _owner )
1358 this.el = new Gtk.TreeViewColumn();
1362 // set gobject values
1363 this.el.title = "test";
1364 var child_0 = new Xcls_renderer( _this );
1366 this.el.pack_start ( child_0.el , true );
1370 this.el.add_attribute(_this.renderer.el , "markup", 0 ); }
1372 // user defined functions
1374 public class Xcls_renderer : Object
1376 public Gtk.CellRendererText el;
1377 private Xcls_WindowLeftTree _this;
1383 public Xcls_renderer(Xcls_WindowLeftTree _owner )
1386 _this.renderer = this;
1387 this.el = new Gtk.CellRendererText();
1391 // set gobject values
1394 // user defined functions
1396 public class Xcls_LeftTreeMenu : Object
1399 private Xcls_WindowLeftTree _this;
1405 public Xcls_LeftTreeMenu(Xcls_WindowLeftTree _owner )
1408 _this.LeftTreeMenu = this;
1409 this.el = new Gtk.Menu();
1413 // set gobject values
1414 var child_0 = new Xcls_MenuItem7( _this );
1416 this.el.add ( child_0.el );
1417 var child_1 = new Xcls_MenuItem8( _this );
1419 this.el.add ( child_1.el );
1420 var child_2 = new Xcls_MenuItem9( _this );
1422 this.el.add ( child_2.el );
1425 // user defined functions
1427 public class Xcls_MenuItem7 : Object
1429 public Gtk.MenuItem el;
1430 private Xcls_WindowLeftTree _this;
1436 public Xcls_MenuItem7(Xcls_WindowLeftTree _owner )
1439 this.el = new Gtk.MenuItem();
1443 // set gobject values
1444 this.el.label = "Delete Element";
1447 this.el.activate.connect( ( ) => {
1452 _this.model.deleteSelected();
1456 // user defined functions
1458 public class Xcls_MenuItem8 : Object
1460 public Gtk.MenuItem el;
1461 private Xcls_WindowLeftTree _this;
1467 public Xcls_MenuItem8(Xcls_WindowLeftTree _owner )
1470 this.el = new Gtk.MenuItem();
1474 // set gobject values
1475 this.el.label = "Save as Template";
1478 this.el.activate.connect( () => {
1480 DialogSaveTemplate.singleton().show(
1481 (Gtk.Window) _this.el.get_toplevel (),
1482 _this.model.file.palete(),
1483 _this.getActiveElement()
1490 // user defined functions
1492 public class Xcls_MenuItem9 : Object
1494 public Gtk.MenuItem el;
1495 private Xcls_WindowLeftTree _this;
1501 public Xcls_MenuItem9(Xcls_WindowLeftTree _owner )
1504 this.el = new Gtk.MenuItem();
1508 // set gobject values
1509 this.el.label = "Save as Module";
1512 this.el.activate.connect( () => {
1513 var node = _this.getActiveElement();
1514 var name = DialogSaveModule.singleton().show(
1515 (Gtk.Window) _this.el.get_toplevel (),
1516 _this.model.file.project,
1519 if (name.length < 1) {
1523 node.props.set("* xinclude", name);
1527 var s = _this.view.el.get_selection();
1529 print("GET SELECTED?");
1534 if (!s.get_selected(out mod, out iter)) {
1535 return; // nothing seleted..
1538 var n_cn = mod.iter_n_children(iter) -1;
1539 for (var i = n_cn; i > -1; i--) {
1540 mod.iter_nth_child(out citer, iter, i);
1543 print("removing node from Tree\n");
1545 _this.model.el.remove(ref citer);
1548 _this.node_selected(node);
1554 // user defined functions