2 "build_module" : "builder",
5 "# Xcls_MainWindow main_window" : "null",
8 "@ bool before_node_change" : "()",
9 "@ void changed" : "()",
10 "@ void node_selected" : "(JsRender.Node? node, string source)",
11 "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
12 "id" : "WindowLeftTree",
17 " this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);",
22 "Gtk.ShadowType shadow_type" : "Gtk.ShadowType.IN",
26 "# bool blockChanges" : false,
27 "# bool drag_in_motion" : "",
30 "# string dragData" : "",
31 "# string[] dropList" : "",
32 "$ enable_tree_lines" : true,
33 "$ string lastEventSource" : "\"\"",
37 " var description = new Pango.FontDescription();",
38 " description.set_size(8000);",
39 " this.el.override_font(description);",
41 " var selection = this.el.get_selection();",
42 " selection.set_mode( Gtk.SelectionMode.SINGLE);",
45 " // is this really needed??",
47 " this.selection.signal['changed'].connect(function() {",
48 "\t _this.get('/LeftTree.view').listeners.cursor_changed.apply(",
49 "\t _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']",
53 " Gtk.drag_source_set (",
54 "\t this.el, /* widget will be drag-able */",
55 "\t Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */",
56 "\t BuilderApplication.targetList, /* lists of target to support */",
57 "\t Gdk.DragAction.COPY | Gdk.DragAction.MOVE | Gdk.DragAction.LINK /* what to do with data after dropped */",
61 " //Gtk.drag_source_add_text_targets(this.el); ",
65 " this.el, /* widget that will accept a drop */",
66 " Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,",
67 " BuilderApplication.targetList, /* lists of target to support */",
68 " Gdk.DragAction.COPY | Gdk.DragAction.MOVE | Gdk.DragAction.LINK /* what to do with data after dropped */",
71 " //Gtk.drag_dest_set_target_list(this.el, Builder.Application.targetList);",
72 " //Gtk.drag_dest_add_text_targets(this.el);",
81 "Boolean id" : "view",
82 "bool button_is_pressed" : false,
84 "bool headers_visible" : false,
85 "bool key_is_pressed" : false,
88 "# DialogTemplateSelect template_select" : "null",
89 "# string activePath" : "\"\"",
94 "typeof(Gdk.Pixbuf),",
99 " var s = this.get('/LeftTree.view').selection;",
100 " print (\"LIST ALL TYPES: \" + s.count_selected_rows() );",
102 " if (s.count_selected_rows() > 0) {",
103 " var iter = new Gtk.TreeIter(); ",
104 " s.get_selected(this.el, iter);",
106 " // set some properties of the tree for use by the dropped element.",
107 " var value = new GObject.Value('');",
108 " this.el.get_value(iter, 2, value);",
109 " var data = JSON.parse(value.value);",
112 " var xname = this.get('/LeftTree.model').file.guessName(data);",
113 " console.log('selected:' + xname);",
114 " if (xname.length) {",
115 " return [ xname ];",
117 " return []; // could not find it..",
122 " var _this = this;",
123 " function addall(li)",
125 " li.forEach(function(el) {",
126 " // this is specific to roo!!!?",
127 " if (!el) { // skip empty?",
130 " var fullpath = _this.file.guessName(el);",
131 " if (fullpath.length && ret.indexOf(fullpath) < 0) {",
132 " ret.push(fullpath);",
136 " if (el.items && el.items.length) {",
137 " addall(el.items);",
145 " addall([this.currentTree]);",
147 " // only if we have nothing, should we add '*top'",
148 " if (!ret.length) {",
149 " ret = [ '*top' ];",
151 " //console.log('all types in tree');",
152 " //console.dump(ret);",
161 "print(\"model initialized\");",
165 "* pack" : "set_model",
166 "currentTree" : false,
169 "xtype" : "TreeStore",
170 "| JsRender.Node pathToNode" : [
174 " Gtk.TreeIter iter;",
175 " _this.model.el.get_iter_from_string(out iter, path);",
177 " GLib.Value value;",
178 " _this.model.el.get_value(iter, 2, out value);",
180 " return (JsRender.Node)value.dup_object();",
184 "| string findDropNode" : [
185 " (string treepath_str, string[] targets) {",
187 " // this is used by the dragdrop code in the roo version AFAIR..",
189 " //var path = treepath_str.replace(/^builder-/, '');",
190 " // treemap is depreciated... - should really check if model has any entries..",
192 " if (this.el.iter_n_children(null) < 1) {",
193 " //print(\"NO KEYS\");",
194 " return \"|%d\".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);",
196 " //print(\"FIND treepath: \" + path);",
197 " //console.dump(this.treemap);",
199 " //if (!treepath_str.match(/^builder-/)) {",
200 " // return []; // nothing!",
202 " if (targets.length > 0 && targets[0] == \"*\") {",
203 " return treepath_str;",
205 " return this.findDropNodeByPath(treepath_str,targets, -1);",
209 "| string findDropNodeByPath" : [
210 " (string treepath_str, string[] targets, int in_pref = -1) {",
212 " var path = treepath_str; // dupe it..",
215 " // pref : 3 = ontop - 0 = after, 1 = before",
216 " int pref = in_pref < 0 ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : in_pref;",
220 " //console.dump(this.treemap);",
222 " print(\"findDropNodeByPath : got path length %d / %s\\n\", path.length, path);",
224 " if (path.length == 0) {",
225 " // top drop. // just return empty..",
226 " return \"|%d\".printf((int)pref) ;",
231 " while (path.length > 0) {",
233 " if (path.length == treepath_str.length && pref != Gtk.TreeViewDropPosition.INTO_OR_AFTER) {",
234 " if (path.last_index_of(\":\") < 0 ) {",
237 " path = path.substring(0, path.last_index_of(\":\"));",
238 " last = treepath_str;",
239 " print(\"DROP before or after : using %s\\n\",path);",
243 " //print(\"LOOKING FOR PATH: \" + path);",
244 " var node_data = this.pathToNode(path);",
246 " if (node_data == null) {",
247 " print(\"node not found\");",
251 " var xname = node_data.fqn();",
252 " var match = \"\";",
255 " for (var i =0; i < targets.length; i++) {",
256 " var tg = targets[i];",
257 " if ((tg == xname) ) {",
261 " // if target is \"xxxx:name\"",
262 " if (tg.contains(xname +\":\")) {",
264 " var ar = tg.split(\":\");",
270 " if (match.length > 0) {",
271 " if (last.length > 0) { // pref is after/before..",
272 " // then it's after last",
273 " //if (pref > 1) {",
276 " return last + \"|%d\".printf((int)pref) + \"|\" + prop;",
280 " // we need to add prop - as :store -> needs to bee added when dropping onto.",
281 " return path + \"|%d\".printf( (int) Gtk.TreeViewDropPosition.INTO_OR_AFTER) + \"|\" + prop;",
284 " last = \"\" + path;",
285 " var par = path.split(\":\");",
286 " string [] ppar = {};",
287 " for (var i = 0; i < par.length-1; i++) {",
291 " path = string.joinv(\":\", ppar);",
302 "| string treePathFromNode" : [
303 "(JsRender.Node node) {",
304 " // iterate through the tree and find the node",
307 " this.el.foreach((mod, pth, iter) => {",
308 " // get the node..",
311 " GLib.Value value;",
312 " _this.model.el.get_value(iter, 2, out value);",
316 " var n = (JsRender.Node)value;",
318 " print(\"compare %s to %s\\n\", n.fqn(), node.fqn());",
320 " ret = pth.to_string();",
330 "| void deleteSelected" : [
333 " print(\"DELETE SELECTED?\");",
334 " //_this.view.blockChanges = true;",
335 " print(\"GET SELECTION?\");",
337 " var s = _this.view.el.get_selection();",
339 " print(\"GET SELECTED?\");",
340 " Gtk.TreeIter iter;",
341 " Gtk.TreeModel mod;",
344 " if (!s.get_selected(out mod, out iter)) {",
345 " return; // nothing seleted..",
350 " this.activePath= \"\"; ",
351 " print(\"GET vnode value?\");",
353 " GLib.Value value;",
354 " this.el.get_value(iter, 2, out value);",
355 " var data = (JsRender.Node)(value.get_object());",
356 " print(\"removing node from Render\\n\");",
357 " if (data.parent == null) {",
358 " _this.main_window.windowstate.file.tree = null;",
362 " print(\"removing node from Tree\\n\"); ",
363 " s.unselect_all();",
364 " this.el.remove(ref iter);",
374 " this.activePath= \"\"; // again!?!? ",
375 " //this.changed(null,true);",
379 " _this.view.blockChanges = false;",
383 "| void dropNode" : [
384 "(string target_data_str, JsRender.Node node, bool show_templates) {",
385 "// print(\"drop Node\");",
386 " // console.dump(node);",
387 " // console.dump(target_data);",
389 " \t\t//target_data_str",
390 " \t\t// {parent}|{pos}|{prop}",
393 " // 0 = before , 1=after 2/3 onto",
395 " \t\tGLib.debug(\"dropNode %s\", target_data_str);",
397 " var target_data= target_data_str.split(\"|\");",
399 " var parent_str = target_data[0].length > 0 ? target_data[0] : \"\";",
400 " var pos = target_data.length > 1 ? int.parse(target_data[1]) : 2; // ontop..",
403 " Gtk.TreePath tree_path = parent_str.length > 0 ? new Gtk.TreePath.from_string( parent_str ) : null;",
407 " //print(\"add \" + tp + \"@\" + target_data[1] );",
409 " JsRender.Node parentNode = null;",
411 " Gtk.TreeIter iter_after;",
412 " Gtk.TreeIter iter_par ;",
414 " \t// this appears to be done in drag_ddata_recieved as well.",
415 " if (target_data.length == 3 && target_data[2].length > 0) {",
416 "\t node.set_prop(new JsRender.NodeProp.special(\"prop\", target_data[2]));",
420 " Gtk.TreePath expand_parent = null;",
422 " // we only need to show the template if it's come from else where?",
423 " if (show_templates) {",
425 " var ts = _this.main_window.windowstate.template_select;",
427 " var new_node = ts.show(",
428 " _this.main_window, // (Gtk.Window) _this.el.get_toplevel (),",
429 " _this.main_window.windowstate.file.palete(),",
431 " _this.main_window.windowstate.project);",
433 " if (new_node == null) {",
434 " return; // do not add?",
439 " //print(\"pos is %d \\n\".printf(pos));",
441 " Gtk.TreeIter n_iter; ",
443 " if ( parent_str.length < 1) {",
444 " this.el.append(out n_iter, null); // drop at top level..",
445 " node.parent = null;",
446 " _this.main_window.windowstate.file.tree = node;",
449 " } else if (pos < 2) {",
450 " //print(target_data[1] > 0 ? 'insert_after' : 'insert_before');",
452 " this.el.get_iter(out iter_after, tree_path ); ",
453 " this.el.iter_parent(out iter_par, iter_after);",
454 " expand_parent = this.el.get_path(iter_par);",
457 " // not sure why all the 'dup_object()' stuff? did it crash before?",
458 " GLib.Value value;",
459 " this.el.get_value( iter_par, 2, out value);",
460 " parentNode = (JsRender.Node)value.dup_object();",
463 " this.el.get_value( iter_after, 2, out value);",
464 " var relNode = (JsRender.Node)value.dup_object();",
468 " this.el.insert_after(out n_iter, iter_par , iter_after);",
469 " var ix = parentNode.items.index_of(relNode);",
470 " parentNode.items.insert(ix+1, node);",
473 " this.el.insert_before(out n_iter, iter_par , iter_after);",
474 " var ix = parentNode.items.index_of(relNode);",
475 " parentNode.items.insert(ix, node);",
478 " node.parent = parentNode;",
483 " // print(\"appending to \" + parent_str);",
484 " this.el.get_iter(out iter_par, tree_path);",
485 " this.el.append(out n_iter, iter_par );",
486 " expand_parent = this.el.get_path(iter_par);",
488 " GLib.Value value;",
489 " this.el.get_value( iter_par, 2, out value);",
490 " parentNode = (JsRender.Node)value.dup_object();",
491 " node.parent = parentNode;",
492 " parentNode.items.add(node);",
498 " // work out what kind of packing to use.. -- should be in ",
501 " //_this.main_window.windowstate.file.palete().fillPack(node,parentNode);",
502 " _this.main_window.windowstate.file.palete().on_child_added(parentNode,node);",
505 " this.iterSetValues(n_iter, node);",
506 " // add the node...",
510 "\t\t// load children - if it has any..",
512 " if (node.items.size > 0) {",
513 " this.load(node.items, n_iter);",
514 " _this.view.el.expand_row(this.el.get_path(n_iter), true);",
515 " } else if (expand_parent != null && !_this.view.el.is_row_expanded(expand_parent)) {",
516 " _this.view.el.expand_row(expand_parent,true);",
519 " //if (tp != null && (node.items.length() > 0 || pos > 1)) {",
520 " // _this.view.el.expand_row(this.el.get_path(iter_par), true);",
522 " // wee need to get the empty proptypes from somewhere..",
524 " //var olditer = this.activeIter;",
525 " this.activePath = this.el.get_path(n_iter).to_string();",
528 " // pretend button was pressed, so that we can trigger select node...",
529 " _this.view.button_is_pressed = true;",
530 " _this.view.lastEventSource = \"\";",
531 " _this.view.el.set_cursor(this.el.get_path(n_iter), null, false);",
532 " _this.view.button_is_pressed = false;",
540 "| void iterSetValues" : [
541 "(Gtk.TreeIter iter, JsRender.Node node) {",
542 "\tvar ic = Gtk.IconTheme.get_default();",
545 " var o = GLib.Value(typeof(Object));",
546 " o.set_object((Object)node);",
547 " var clsname = node.fqn();",
549 " var clsb = clsname.split(\".\");",
550 " var sub = clsb.length > 1 ? clsb[1].down() : \"\";",
552 " var addi = ic.load_icon(\"list-add\", 16,0);",
553 " var fn = \"/usr/share/glade/pixmaps/hicolor/16x16/actions/widget-gtk-\" + sub + \".png\";",
554 " if (FileUtils.test (fn, FileTest.IS_REGULAR)) {",
555 " pix = new Gdk.Pixbuf.from_file (fn);",
557 " \tpix = ic.load_icon(\"emblem-new\", 16,0);",
560 " var fqn = node.fqn();",
561 " var cn = _this.main_window.windowstate.project.palete.getChildList(fqn);",
565 " \t\t0, node.nodeTitle(),",
566 " 1, node.nodeTip(), ",
569 " this.el.set_value(iter, 2,o);",
570 " this.el.set_value(iter, 3,pix); ",
571 " \tthis.el.set_value(iter, 4, cn.length > 0 ? addi : null); ",
577 "(Gee.ArrayList<JsRender.Node> tr, Gtk.TreeIter? iter) ",
581 " Gtk.TreeIter citer;",
582 " //this.insert(citer,iter,0);",
585 " for(var i =0 ; i < tr.size; i++) {",
586 " if (iter != null) {",
587 " this.el.insert(out citer,iter,-1); // why not append?",
589 " this.el.append(out citer,null);",
591 " this.iterSetValues(citer, tr.get(i));",
595 " if (tr.get(i).items.size > 0) {",
596 " this.load(tr.get(i).items, citer);",
604 "| void loadFile" : [
605 "(JsRender.JsRender f) {",
606 " //console.dump(f);",
608 " _this.main_window.windowstate.leftTreeNodeSelected(null, \"\");",
610 " _this.main_window.windowstate.file = f;",
613 " if (f.tree == null) {",
615 "\t f.loadItems( );",
616 " } catch (Error e) {",
620 " // if it's still null?",
621 " if (f.tree == null) {",
622 "\t\t_this.main_window.windowstate.showAddObject(_this.view.el);",
627 " var o = new Gee.ArrayList<JsRender.Node>();",
629 " this.load(o,null);",
631 " _this.view.el.expand_all();",
633 " if (f.tree.items.size < 1) {",
636 " //this.get('/Window.leftvpaned').el.set_position(80);",
637 " // select first...",
638 " _this.view.el.set_cursor( ",
639 " new Gtk.TreePath.from_string(\"0\"), null, false);",
643 " //this.get('/Window.leftvpaned').el.set_position(200);",
647 " while (Gtk.events_pending()) {",
648 " Gtk.main_iteration();",
651 " _this.maincol.el.set_max_width(_this.viewwin.el.get_allocated_width() - 32);",
661 "| void moveNode" : [
662 "(string target_data, Gdk.DragAction action) ",
665 " /// target_data = \"path|pos\");",
668 " //print(\"MOVE NODE\");",
669 " // console.dump(target_data);",
670 " Gtk.TreeIter old_iter;",
671 " Gtk.TreeModel mod;",
673 " var s = _this.view.el.get_selection();",
674 " s.get_selected(out mod , out old_iter);",
675 " mod.get_path(old_iter);",
677 " var node = this.pathToNode(mod.get_path(old_iter).to_string());",
678 " //console.dump(node);",
679 " if (node == null) {",
680 " GLib.debug(\"moveNode: ERROR - node is null?\");",
685 " // needs to drop first, otherwise the target_data ",
686 " // treepath will be invalid.",
689 " if ((action & Gdk.DragAction.MOVE) > 0) {",
690 " GLib.debug(\"REMOVING OLD NODE : \" + target_data + \"\\n\");",
692 " this.dropNode(target_data, node, false);",
693 " this.el.remove(ref old_iter);",
698 " GLib.debug(\"DROPPING NODE // copy: \" + target_data + \"\\n\");",
699 " node = node.deepClone();",
700 " this.dropNode(target_data, node, false);",
703 " this.activePath= \"\";",
704 " //this.updateNode(false,true);",
708 "| void updateSelected" : [
712 " var s = _this.view.el.get_selection();",
714 " Gtk.TreeIter iter;",
715 " Gtk.TreeModel mod;",
719 " if (!s.get_selected(out mod, out iter)) {",
720 " return; // nothing seleted..",
723 " GLib.Value value;",
724 " this.el.get_value(iter, 2, out value);",
725 " var node = (JsRender.Node)(value.get_object());",
727 " this.el.set(iter, 0, node.nodeTitle(),",
728 " 1, node.nodeTip(), -1",
735 "$ Gtk.TreeViewColumnSizing sizing" : "Gtk.TreeViewColumnSizing.FIXED",
738 " this.el.add_attribute(_this.renderer.el , \"markup\", 0 );",
739 " this.el.add_attribute(_this.iconrender.el , \"pixbuf\", 3 );",
742 "* pack" : "append_column",
743 "bool expand" : true,
744 "bool resizable" : true,
749 "* pack" : "pack_start,false",
752 "xtype" : "CellRendererPixbuf"
756 "* pack" : "pack_start,true",
758 "xtype" : "CellRendererText"
761 "utf8 title" : "Node",
762 "xtype" : "TreeViewColumn"
765 "$ Gtk.TreeViewColumnSizing sizing" : "Gtk.TreeViewColumnSizing.FIXED",
768 " this.el.add_attribute(_this.addiconrender.el , \"pixbuf\", 4 );",
771 "* pack" : "append_column",
772 "bool expand" : false,
773 "int max_width" : 24,
777 "* pack" : "pack_start,true",
778 "id" : "addiconrender",
780 "xtype" : "CellRendererPixbuf"
783 "utf8 title" : "Add",
784 "xtype" : "TreeViewColumn"
788 "button_press_event" : [
790 " //console.log(\"button press?\");",
791 " this.button_is_pressed = true;",
792 " print(\"BUTTON DOWN\\n\");",
794 " this.lastEventSource = \"tree\";",
795 " if (! _this.before_node_change() ) {",
800 "\tif (ev.type != Gdk.EventType.BUTTON_PRESS) {",
803 " if (_this.model.el.iter_n_children(null) < 1) {",
804 "\t _this.main_window.windowstate.showAddObject(_this.view.el);",
809 " Gtk.TreePath res;",
810 " Gtk.TreeViewColumn col;",
811 " if (!_this.view.el.get_path_at_pos((int)ev.x,(int)ev.y, out res, out col, null, null) ) {",
815 " if (col.title == \"Add\") {",
816 " \t\tGLib.Value value;",
817 " \t\tGtk.TreeIter iter;",
819 "\t\t_this.model.el.get_iter (out iter, res);",
820 " _this.model.el.get_value(iter, 2, out value);\t\t",
821 " // why dup_ - gets and and inc's ref count (which in theory should be freed at the end.?",
823 " var node = (JsRender.Node)value.dup_object();",
824 " var fqn = node.fqn();",
825 " \tvar cn = _this.main_window.windowstate.project.palete.getChildList(fqn);",
826 " \t\tif (cn.length < 1) {",
827 " \t\t\treturn true;",
830 " _this.main_window.windowstate.leftTreeBeforeChange();",
831 " this.el.get_selection().select_path(res);",
832 " \t_this.main_window.windowstate.showAddObject(this.el);",
836 "\tif ( ev.button != 3) {",
837 " //print(\"click\" + ev.type);",
840 " _this.main_window.windowstate.leftTreeBeforeChange();",
844 " this.el.get_selection().select_path(res);",
848 " //if (!this.get('/LeftTreeMenu').el) { ",
849 " // this.get('/LeftTreeMenu').init(); ",
852 " _this.LeftTreeMenu.el.set_screen(Gdk.Screen.get_default());",
853 " _this.LeftTreeMenu.el.show_all();",
854 " _this.LeftTreeMenu.el.popup(null, null, null, 3, ev.time);",
855 " // print(\"click:\" + res.path.to_string());",
859 "button_release_event" : [
861 " this.button_is_pressed = false;",
867 " print(\"LEFT TREE Cursor Changed\\n\");",
868 "\tif (!this.button_is_pressed && !this.key_is_pressed) {",
869 "\t\t// then event was started by some other action",
870 "\t\t// which should manually trigger all the events..",
871 "\t\tprint(\"SKIPPING select - no button or key pressed\\n\");",
876 " if (this.blockChanges) { // probably not needed.. ",
877 "\t\tprint(\"SKIPPING select - blockchanges set..\\n\"); ",
880 " if (!_this.before_node_change( ) ) {",
881 "\t this.blockChanges = true;",
882 "\t this.el.get_selection().unselect_all();",
883 "\t this.blockChanges = false;",
887 " if (_this.main_window.windowstate.file == null) {",
888 " \t\tprint(\"SKIPPING select windowstate file is not set...\\n\"); ",
892 " //var render = this.get('/LeftTree').getRenderer(); ",
893 " print(\"LEFT TREE -> view -> selection changed called\\n\");",
896 " // -- it appears that the selection is not updated.",
898 " GLib.Timeout.add_full(GLib.Priority.DEFAULT,10 , () => {",
899 " print(\"LEFT TREE -> view -> selection changed TIMEOUT CALLED\\n\");",
901 " if (this.el.get_selection().count_selected_rows() < 1) {",
903 " print(\"selected rows < 1\\n\");",
904 " //??this.model.load( false);",
905 " _this.node_selected(null, this.lastEventSource);",
910 " //console.log('changed');",
911 " var s = this.el.get_selection();",
912 " Gtk.TreeIter iter;",
913 " Gtk.TreeModel mod;",
914 " s.get_selected(out mod, out iter);",
917 " // var val = \"\";",
918 " GLib.Value value;",
919 " _this.model.el.get_value(iter, 2, out value);",
920 " _this.model.activePath = mod.get_path(iter).to_string();",
924 " var node = (JsRender.Node)value.dup_object();",
925 " print (\"calling left_tree.node_selected\\n\");",
926 " _this.node_selected(node, this.lastEventSource);",
927 " while (Gtk.events_pending()) {",
928 " Gtk.main_iteration();",
930 " var cp = mod.get_path(iter);",
931 " Gtk.TreePath sp, ep;",
932 " this.el.get_visible_range(out sp, out ep);",
933 " // if sp is before cp then retuns 1.",
934 " // if cp is before ep then retuns 1.",
935 " if (cp.compare(sp) >= 0 && ep.compare(cp) >=1) {",
941 " this.el.scroll_to_cell(new Gtk.TreePath.from_string(_this.model.activePath), null, true, 0.1f,0.0f);",
945 " //_this.after_node_change(node);",
947 "// _this.model.file.changed(node, \"tree\");",
949 " //Seed.print( value.get_string());",
956 "\t//print('SOURCE: drag-begin');",
959 " //this.targetData = \"\";",
961 " // find what is selected in our tree...",
963 " var s = _this.view.el.get_selection();",
964 " if (s.count_selected_rows() < 1) {",
967 " Gtk.TreeIter iter;",
968 " Gtk.TreeModel mod;",
969 " s.get_selected(out mod, out iter);",
973 " // set some properties of the tree for use by the dropped element.",
974 " GLib.Value value;",
975 " _this.model.el.get_value(iter, 2, out value);",
976 " var tp = mod.get_path(iter).to_string();",
977 " var data = (JsRender.Node)(value.dup_object());",
978 " var xname = data.fqn();",
979 " print (\"XNAME IS \" + xname+ \"\\n\");",
980 " this.dragData = tp;",
981 " this.dropList = _this.main_window.windowstate.file.palete().getDropList(xname);",
983 " print (\"DROP LIST IS \" + string.joinv(\", \", this.dropList) + \"\\n\");",
986 " // make the drag icon a picture of the node that was selected",
989 " // by default returns the path..",
990 " var path = _this.model.el.get_path(iter);",
993 " var pix = this.el.create_row_drag_icon ( path);",
995 " Gtk.drag_set_icon_surface (ctx, pix) ;",
1001 "( drag_context, data, info, time) => {",
1004 "\t//print(\"drag-data-get\");",
1005 "\tvar s = this.el.get_selection();",
1006 "\tif (s.count_selected_rows() < 1) {",
1007 "\t\tdata.set_text(\"\",0); ",
1008 "\t\t print(\"return empty string - no selection..\");",
1012 "\tGtk.TreeIter iter;",
1013 "\tGtk.TreeModel mod;",
1015 "\ts.get_selected(out mod, out iter);",
1019 "\tGLib.Value value;",
1020 "\t_this.model.el.get_value(iter, 2, out value);",
1021 "\tvar ndata = (JsRender.Node)(value.dup_object());",
1025 "\tvar tp = mod.get_path(iter).to_string();",
1026 "\t// by default returns the path..",
1028 "\tif ( info != Gdk.Atom.intern(\"STRING\",true) ) {",
1029 "\t\ttp = ndata.toJsonString();",
1032 "\t//data.set_text(tp,tp.length); ",
1034 "\tdata.set (data.get_target (), 8, (uchar[]) tp.to_utf8 ());",
1037 "\t// print(\"return \" + tp);",
1040 "drag_data_received" : [
1041 "\t(ctx, x, y, sel, info, time) => {",
1043 "\t// THIS CODE ONLY RELATES TO drag or drop of \"NEW\" elements or \"FROM another tree..\"",
1046 "\t// print(\"Tree: drag-data-received\\n\");",
1047 "\tvar selection_text = (string)sel.get_data();",
1048 "\t//print(\"selection_text= %s\\n\",selection_text);",
1050 "\tvar is_drag = this.drag_in_motion;",
1054 "\tGLib.debug(\"Is Drag %s\\n\", is_drag ? \"Y\": \"N\");",
1055 "\tvar targetData = \"\";",
1057 "\tGtk.TreePath path;",
1058 "\tGtk.TreeViewDropPosition pos;",
1059 "\tvar isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);",
1061 "\t// if there are not items in the tree.. the we have to set isOver to true for anything..",
1062 "\tvar isEmpty = false;",
1063 "\tif (_this.model.el.iter_n_children(null) < 1) {",
1064 "\t\tGLib.debug(\"got NO children?\\n\");",
1065 "\t\tisOver = true; //??? ",
1066 "\t\tisEmpty = true;",
1067 "\t\tpos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;",
1071 "\t//console.log(\"LEFT-TREE: drag-motion\");",
1072 "\tvar src = Gtk.drag_get_source_widget(ctx);",
1074 "\t// a drag from self - this should be handled by drop and motion.",
1075 "\tif (src == this.el) {",
1076 "\t\tGLib.debug(\"Source == this element should not happen.. ? \\n\");",
1079 "\t//print(\"drag_data_recieved from another element\");",
1084 "\tif (selection_text == null || selection_text.length < 1 || !isOver) {",
1085 "\t\t// nothing valid foudn to drop...",
1086 "\t\t GLib.debug(\"empty sel text or not over\");",
1087 "\t\tif (is_drag) {",
1088 "\t\t Gdk.drag_status(ctx, 0, time);",
1089 "\t\t this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);",
1092 "\t\tGtk.drag_finish (ctx, false, false, time); // drop failed..",
1093 "\t\t// no drop action...",
1097 "\tvar dropNode = new JsRender.Node(); ",
1099 "\tvar dropNodeType = selection_text;",
1100 "\tvar show_templates = true;",
1102 "\tif (dropNodeType[0] == '{') {",
1103 "\t\tvar pa = new Json.Parser();",
1105 "\t\t pa.load_from_data(dropNodeType);",
1106 "\t\t} catch (Error e) {",
1107 "\t\t Gtk.drag_finish (ctx, false, false, time); // drop failed..",
1108 "\t\t // no drop action...",
1112 "\t\tdropNode.loadFromJson( pa.get_root().get_object(), 2);",
1113 "\t\tdropNodeType = dropNode.fqn();",
1114 "\t\tshow_templates = false;",
1118 "\t\t// drop with property.",
1119 "\t\tif (selection_text.contains(\":\")) {",
1120 "\t\t\tvar bits = selection_text.split(\":\");",
1121 "\t\t dropNode.setFqn(bits[0]);",
1122 "\t\t dropNode.set_prop(new JsRender.NodeProp.special(\"prop\", bits[1]));",
1127 "\t\t dropNode.setFqn(selection_text);",
1132 "\t// dropList --- need to gather this ... ",
1133 "\tGLib.debug(\"get dropList for : %s\\n\",dropNodeType); ",
1134 "\tvar dropList = _this.main_window.windowstate.file.palete().getDropList(dropNodeType);",
1136 "\tGLib.debug(\"dropList: %s\\n\", string.joinv(\" , \", dropList));",
1138 "\t// if drag action is link ... then we can drop it anywahere...",
1139 "\t if ((ctx.get_actions() & Gdk.DragAction.LINK) > 0) {",
1140 "\t\t // if path is null?? dragging into an empty tree?",
1141 "\t\t targetData = (path == null ? \"\" : path.to_string()) + \"|%d\".printf((int)pos);",
1145 "\t\ttargetData = _this.model.findDropNodeByPath( isEmpty ? \"\" : path.to_string(), dropList, pos);",
1150 "\tGLib.debug(\"targetDAta: %s\", targetData );",
1152 "\tif (targetData.length < 1) {",
1154 "\t\t// invalid drop path..",
1155 "\t\tif (this.drag_in_motion) {",
1156 "\t\t Gdk.drag_status(ctx, 0, time);",
1157 "\t\t this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);",
1160 "\t\tGtk.drag_finish (ctx, false, false, time); // drop failed..",
1161 "\t\t// no drop action...",
1167 "\t var td_ar = targetData.split(\"|\");",
1170 "\tif (this.drag_in_motion) { ",
1171 "\t\tGdk.drag_status(ctx, Gdk.DragAction.COPY ,time);",
1173 "\t\tthis.highlightDropPath( td_ar[0] , (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));",
1176 "\t// continue on to allow drop..",
1179 "\t// at this point, drag is not in motion... -- as checked above... - so it's a real drop event..",
1181 "\t// {parent}|{pos}|{prop}",
1184 " _this.model.dropNode(targetData, dropNode, show_templates);",
1186 "\tGLib.debug(\"ADD new node!!!\\n\");",
1188 "\t///Xcls_DialogTemplateSelect.singleton().show( _this.model.file.palete(), node);",
1190 "\tGtk.drag_finish (ctx, false, false,time);",
1199 " ( ctx, x, y, time) => {",
1200 " //Seed.print(\"TARGET: drag-drop\");",
1203 " var src = Gtk.drag_get_source_widget(ctx);",
1205 " if (src != this.el) {",
1209 " this.drag_in_motion = false; ",
1210 " // request data that will be recieved by the recieve... ",
1211 " Gtk.drag_get_data",
1213 " this.el, // will receive 'drag-data-received' signal ",
1214 " ctx, // represents the current state of the DnD ",
1215 " Gdk.Atom.intern(\"application/json\",true), // the target type we want ",
1216 " time // time stamp ",
1220 " // No target offered by source => error",
1226 " // handle drop around self..",
1230 " //print(\"GETTING POS\");",
1231 " var targetData = \"\";",
1233 " Gtk.TreePath path;",
1234 " Gtk.TreeViewDropPosition pos;",
1235 " var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);",
1237 " // if there are not items in the tree.. the we have to set isOver to true for anything..",
1238 " var isEmpty = false;",
1239 " if (_this.model.el.iter_n_children(null) < 1) {",
1240 " print(\"got NO children?\\n\");",
1241 " isOver = true; //??? ",
1243 " pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;",
1248 " //var action = Gdk.DragAction.COPY;",
1249 " // unless we are copying!!! ctl button..",
1251 " var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?",
1252 " Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;",
1253 " // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;",
1256 " if (_this.model.el.iter_n_children(null) < 1) {",
1257 " // no children.. -- asume it's ok..",
1259 " targetData = \"|%d|\".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);",
1261 " // continue through to allow drop...",
1269 " //print(\"ISOVER? \" + isOver);",
1272 " Gtk.drag_finish (ctx, false, false, time); // drop failed..",
1273 " return true; // not over apoint!?! - no action on drop or motion..",
1276 " // drag node is parent of child..",
1277 " //console.log(\"SRC TREEPATH: \" + src.treepath);",
1278 " //console.log(\"TARGET TREEPATH: \" + data.path.to_string());",
1280 " // nned to check a few here..",
1281 " //Gtk.TreeViewDropPosition.INTO_OR_AFTER",
1282 " //Gtk.TreeViewDropPosition.INTO_OR_BEFORE",
1283 " //Gtk.TreeViewDropPosition.AFTER",
1284 " //Gtk.TreeViewDropPosition.BEFORE",
1286 " // locally dragged items to not really use the ",
1287 " var selection_text = this.dragData;",
1291 " if (selection_text == null || selection_text.length < 1) {",
1292 " //print(\"Error - drag selection text returned NULL\");",
1294 " Gtk.drag_finish (ctx, false, false, time); // drop failed..",
1295 " return true; /// -- fixme -- this is not really correct..",
1298 " // see if we are dragging into ourself?",
1299 " print (\"got selection text of \" + selection_text);",
1301 " var target_path = path.to_string();",
1302 " //print(\"target_path=\"+target_path);",
1305 " if (selection_text == target_path) {",
1306 " print(\"self drag ?? == we should perhaps allow copy onto self..\\n\");",
1308 " Gtk.drag_finish (ctx, false, false, time); // drop failed..",
1310 " return true; /// -- fixme -- this is not really correct..",
1315 " //print(\"DUMPING DATA\");",
1316 " //console.dump(data);",
1319 " //print(data.path.to_string() +' => '+ data.pos);",
1321 " // dropList is a list of xtypes that this node could be dropped on.",
1322 " // it is set up when we start to drag..",
1325 " targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);",
1327 " print(\"targetDAta: \" + targetData +\"\\n\");",
1329 " if (targetData.length < 1) {",
1330 " //print(\"Can not find drop node path\");",
1332 " Gtk.drag_finish (ctx, false, false, time); // drop failed..",
1338 " // continue on to allow drop..",
1340 " // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..",
1343 " var delete_selection_data = false;",
1345 " if (action == Gdk.DragAction.ASK) {",
1346 " /* Ask the user to move or copy, then set the ctx action. */",
1349 " if (action == Gdk.DragAction.MOVE) {",
1350 " delete_selection_data = true;",
1353 " // drag around.. - reorder..",
1354 " _this.model.moveNode(targetData, action);",
1360 " // we can send stuff to souce here...",
1363 "// do we always say failure, so we handle the reall drop?",
1364 " Gtk.drag_finish (ctx, false, false,time); //delete_selection_data, time);",
1376 " (drag_context) => {",
1377 "\t//Seed.print('LEFT-TREE: drag-end');",
1378 " this.dragData = \"\";",
1379 " this.dropList = null;",
1380 "// this.targetData = \"\";",
1381 " this.highlightDropPath(\"\",0);",
1386 " ( ctx, x, y, time) => {",
1387 " print(\"got drag motion\\n\");",
1388 " var src = Gtk.drag_get_source_widget(ctx);",
1389 " this.drag_x = x;",
1390 " this.drag_y = y; ",
1392 " if (src != this.el) {",
1396 " // the point of this is to detect where an item could be dropped..",
1397 " print(\"requesting drag data\\n\");",
1398 " this.drag_in_motion = true;",
1400 " // request data that will be recieved by the recieve... ",
1401 " Gtk.drag_get_data",
1403 " this.el, // will receive 'drag-data-received' signal ",
1404 " ctx, // represents the current state of the DnD ",
1405 " Gdk.Atom.intern(\"STRING\",true), // the target type we want ",
1406 " time // time stamp ",
1412 " print(\"action: %d\\n\", ctx.get_actions());",
1413 " //print(\"GETTING POS\");",
1414 " var targetData = \"\";",
1416 " Gtk.TreePath path;",
1417 " Gtk.TreeViewDropPosition pos;",
1418 " var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);",
1420 " // if there are not items in the tree.. the we have to set isOver to true for anything..",
1421 " var isEmpty = false;",
1422 " if (_this.model.el.iter_n_children(null) < 1) {",
1423 " print(\"got NO children?\\n\");",
1424 " isOver = true; //??? ",
1426 " pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;",
1430 " // ------------- a drag from self..",
1433 " //var action = Gdk.DragAction.COPY;",
1434 " // unless we are copying!!! ctl button..",
1436 " var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?",
1437 " Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;",
1438 " // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;",
1441 " if (_this.model.el.iter_n_children(null) < 1) {",
1442 " // no children.. -- asume it's ok..",
1444 " targetData = \"|%d|\".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);",
1446 " this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0); ",
1447 " Gdk.drag_status(ctx, action ,time);",
1450 " // continue through to allow drop...",
1458 " //print(\"ISOVER? \" + isOver);",
1461 " Gdk.drag_status(ctx, 0 ,time);",
1462 " this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0); ",
1467 " // drag node is parent of child..",
1468 " //console.log(\"SRC TREEPATH: \" + src.treepath);",
1469 " //console.log(\"TARGET TREEPATH: \" + data.path.to_string());",
1471 " // nned to check a few here..",
1472 " //Gtk.TreeViewDropPosition.INTO_OR_AFTER",
1473 " //Gtk.TreeViewDropPosition.INTO_OR_BEFORE",
1474 " //Gtk.TreeViewDropPosition.AFTER",
1475 " //Gtk.TreeViewDropPosition.BEFORE",
1477 " // locally dragged items to not really use the ",
1478 " var selection_text = this.dragData;",
1482 " if (selection_text == null || selection_text.length < 1) {",
1483 " //print(\"Error - drag selection text returned NULL\");",
1484 " Gdk.drag_status(ctx, 0 ,time);",
1485 " this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);",
1490 " // see if we are dragging into ourself?",
1491 " var target_path = path.to_string(); ",
1492 " print (\"Drag %s onto %s--%d\\n \", selection_text, target_path, pos);",
1494 " // pos : 3 = ontop - 0 = after, 1 = before",
1495 " //print(\"target_path=\"+target_path);",
1498 " if (selection_text == target_path) {",
1499 " print(\"self drag ?? == we should perhaps allow copy onto self..\\n\");",
1501 " Gdk.drag_status(ctx, 0 ,time);",
1502 " this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);",
1504 "// -- fixme -- this is not really correct..",
1509 " //print(\"DUMPING DATA\");",
1510 " //console.dump(data);",
1513 " //print(data.path.to_string() +' => '+ data.pos);",
1515 " // dropList is a list of xtypes that this node could be dropped on.",
1516 " // it is set up when we start to drag..",
1519 " targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);",
1521 " print(\"targetDAta: \" + targetData +\"\\n\");",
1523 " if (targetData.length < 1) {",
1524 " //print(\"Can not find drop node path\");",
1526 " Gdk.drag_status(ctx, 0, time);",
1527 " this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);",
1531 " var td_ar = targetData.split(\"|\");",
1535 " Gdk.drag_status(ctx, action ,time);",
1536 " this.highlightDropPath(td_ar[0], (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));",
1542 "key_press_event" : [
1544 " this.key_is_pressed = true;",
1548 "key_release_event" : [
1550 " this.key_is_pressed = false;",
1556 "tooltip_column" : 1,
1557 "xtype" : "TreeView",
1558 "| void highlightDropPath" : [
1559 " ( string treepath, Gtk.TreeViewDropPosition pos) {",
1561 " // highlighting for drag/drop",
1562 " if (treepath.length > 0) {",
1563 " this.el.set_drag_dest_row( new Gtk.TreePath.from_string( treepath ), pos);",
1565 " this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);",
1570 "| void selectNode" : [
1571 "(string treepath_str, string source) {",
1572 "\tthis.lastEventSource = source;",
1573 " //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));",
1574 " var tp = new Gtk.TreePath.from_string(treepath_str);",
1576 " this.el.set_cursor(tp, null, false); ",
1577 " this.el.scroll_to_cell(tp, null, false, 0,0);",
1581 "| void setCursor" : [
1582 "(string treepath, string sourceEvent) {",
1583 "\tthis.lastEventSource = sourceEvent;",
1584 "\t//this.blockChanges = true; << block changes prevents loading of 'node data' and firing of node_selected..",
1585 " this.el.set_cursor(new Gtk.TreePath.from_string(treepath), null, false); ",
1586 " // fire node_selected..",
1587 " //this.blockChanges = false;",
1588 "\tthis.lastEventSource = \"\";",
1596 "id" : "LeftTreeMenu",
1601 "label" : "Delete Element",
1606 " print(\"ACTIVATE?\");",
1609 " _this.model.deleteSelected();",
1613 "xtype" : "MenuItem"
1618 "label" : "Save as Template",
1623 " DialogSaveTemplate.singleton().show(",
1624 " (Gtk.Window) _this.el.get_toplevel (), ",
1625 " _this.main_window.windowstate.file.palete(), ",
1626 " _this.getActiveElement()",
1633 "xtype" : "MenuItem"
1638 "label" : "Save as Module",
1642 " var node = _this.getActiveElement();",
1643 " var name = DialogSaveModule.singleton().show(",
1644 " (Gtk.Window) _this.el.get_toplevel (), ",
1645 " _this.main_window.windowstate.project, ",
1648 " if (name.length < 1) {",
1652 " node.set_prop( new JsRender.NodeProp.special(\"xinclude\", name));",
1653 " node.items.clear();",
1656 " var s = _this.view.el.get_selection();",
1658 " print(\"GET SELECTED?\");",
1659 " Gtk.TreeIter iter;",
1660 " Gtk.TreeModel mod;",
1663 " if (!s.get_selected(out mod, out iter)) {",
1664 " return; // nothing seleted..",
1666 " Gtk.TreeIter citer;",
1667 " var n_cn = mod.iter_n_children(iter) -1;",
1668 " for (var i = n_cn; i > -1; i--) {",
1669 " mod.iter_nth_child(out citer, iter, i);",
1672 " print(\"removing node from Tree\\n\"); ",
1674 " _this.model.el.remove(ref citer);",
1676 " _this.changed();",
1677 " _this.node_selected(node, \"tree\");",
1683 "xtype" : "MenuItem"
1691 "(allocation) => {",
1694 "\t//GLib.debug(\"Got allocation width of scrolled view %d\", allocation.width );",
1695 "\t_this.maincol.el.set_max_width(allocation.width - 32);",
1700 "xtype" : "ScrolledWindow"
1704 "| JsRender.JsRender getActiveFile" : [
1706 " return this.main_window.windowstate.file;",
1710 "| JsRender.Node? getActiveElement" : [
1711 " () { // return path to actie node.",
1713 " var path = this.getActivePath();",
1714 " if (path.length < 1) {",
1717 " return _this.model.pathToNode(path);",
1722 "| string getActivePath" : [
1725 " var view = this.view.el;",
1726 " if (view.get_selection().count_selected_rows() < 1) {",
1729 " Gtk.TreeIter iter;",
1730 " Gtk.TreeModel mod;",
1731 " view.get_selection().get_selected(out mod, out iter);",
1732 " return mod.get_path(iter).to_string();",
1739 "name" : "WindowLeftTree",
1741 "path" : "/home/alan/gitlive/roobuilder/src/Builder4/WindowLeftTree.bjs",