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 "bool always_show_image" : true,
18 "bool hexpand" : true,
22 "* pack" : "set_image",
23 "utf8 icon_name" : "list-add",
32 " \t_this.main_window.windowstate.showAddObject(this.el);",
37 "string label" : "Add Child Element",
43 " this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);",
48 "Gtk.ShadowType shadow_type" : "Gtk.ShadowType.IN",
51 "# bool blockChanges" : false,
52 "# bool drag_in_motion" : "",
55 "# string dragData" : "",
56 "# string[] dropList" : "",
57 "$ enable_tree_lines" : true,
58 "$ headers_visible" : false,
59 "$ string lastEventSource" : "\"\"",
63 " var description = new Pango.FontDescription();",
64 " description.set_size(8000);",
65 " this.el.override_font(description);",
67 " var selection = this.el.get_selection();",
68 " selection.set_mode( Gtk.SelectionMode.SINGLE);",
71 " // is this really needed??",
73 " this.selection.signal['changed'].connect(function() {",
74 "\t _this.get('/LeftTree.view').listeners.cursor_changed.apply(",
75 "\t _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']",
79 " Gtk.drag_source_set (",
80 "\t this.el, /* widget will be drag-able */",
81 "\t Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */",
82 "\t BuilderApplication.targetList, /* lists of target to support */",
83 "\t Gdk.DragAction.COPY | Gdk.DragAction.MOVE | Gdk.DragAction.LINK /* what to do with data after dropped */",
87 " //Gtk.drag_source_add_text_targets(this.el); ",
91 " this.el, /* widget that will accept a drop */",
92 " Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,",
93 " BuilderApplication.targetList, /* lists of target to support */",
94 " Gdk.DragAction.COPY | Gdk.DragAction.MOVE | Gdk.DragAction.LINK /* what to do with data after dropped */",
97 " //Gtk.drag_dest_set_target_list(this.el, Builder.Application.targetList);",
98 " //Gtk.drag_dest_add_text_targets(this.el);",
103 "bool button_is_pressed" : false,
104 "bool expand" : true,
105 "bool key_is_pressed" : false,
106 "gboolean headers_visible" : true,
110 "# DialogTemplateSelect template_select" : "null",
111 "# string activePath" : "\"\"",
112 "$ columns" : "typeof(string),typeof(string),typeof(Object),typeof(Gdk.Pixbuf)",
115 " var s = this.get('/LeftTree.view').selection;",
116 " print (\"LIST ALL TYPES: \" + s.count_selected_rows() );",
118 " if (s.count_selected_rows() > 0) {",
119 " var iter = new Gtk.TreeIter(); ",
120 " s.get_selected(this.el, iter);",
122 " // set some properties of the tree for use by the dropped element.",
123 " var value = new GObject.Value('');",
124 " this.el.get_value(iter, 2, value);",
125 " var data = JSON.parse(value.value);",
128 " var xname = this.get('/LeftTree.model').file.guessName(data);",
129 " console.log('selected:' + xname);",
130 " if (xname.length) {",
131 " return [ xname ];",
133 " return []; // could not find it..",
138 " var _this = this;",
139 " function addall(li)",
141 " li.forEach(function(el) {",
142 " // this is specific to roo!!!?",
143 " if (!el) { // skip empty?",
146 " var fullpath = _this.file.guessName(el);",
147 " if (fullpath.length && ret.indexOf(fullpath) < 0) {",
148 " ret.push(fullpath);",
152 " if (el.items && el.items.length) {",
153 " addall(el.items);",
161 " addall([this.currentTree]);",
163 " // only if we have nothing, should we add '*top'",
164 " if (!ret.length) {",
165 " ret = [ '*top' ];",
167 " //console.log('all types in tree');",
168 " //console.dump(ret);",
177 "print(\"model initialized\");",
181 "* pack" : "set_model",
182 "currentTree" : false,
185 "xtype" : "TreeStore",
186 "| JsRender.Node pathToNode" : [
190 " Gtk.TreeIter iter;",
191 " _this.model.el.get_iter_from_string(out iter, path);",
193 " GLib.Value value;",
194 " _this.model.el.get_value(iter, 2, out value);",
196 " return (JsRender.Node)value.dup_object();",
200 "| string findDropNode" : [
201 " (string treepath_str, string[] targets) {",
203 " // this is used by the dragdrop code in the roo version AFAIR..",
205 " //var path = treepath_str.replace(/^builder-/, '');",
206 " // treemap is depreciated... - should really check if model has any entries..",
208 " if (this.el.iter_n_children(null) < 1) {",
209 " //print(\"NO KEYS\");",
210 " return \"|%d\".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);",
212 " //print(\"FIND treepath: \" + path);",
213 " //console.dump(this.treemap);",
215 " //if (!treepath_str.match(/^builder-/)) {",
216 " // return []; // nothing!",
218 " if (targets.length > 0 && targets[0] == \"*\") {",
219 " return treepath_str;",
221 " return this.findDropNodeByPath(treepath_str,targets, -1);",
225 "| string findDropNodeByPath" : [
226 " (string treepath_str, string[] targets, int in_pref = -1) {",
228 " var path = treepath_str; // dupe it..",
231 " // pref : 3 = ontop - 0 = after, 1 = before",
232 " int pref = in_pref < 0 ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : in_pref;",
236 " //console.dump(this.treemap);",
238 " print(\"findDropNodeByPath : got path length %d / %s\\n\", path.length, path);",
240 " if (path.length == 0) {",
241 " // top drop. // just return empty..",
242 " return \"|%d\".printf((int)pref) ;",
247 " while (path.length > 0) {",
249 " if (path.length == treepath_str.length && pref != Gtk.TreeViewDropPosition.INTO_OR_AFTER) {",
250 " if (path.last_index_of(\":\") < 0 ) {",
253 " path = path.substring(0, path.last_index_of(\":\"));",
254 " last = treepath_str;",
255 " print(\"DROP before or after : using %s\\n\",path);",
259 " //print(\"LOOKING FOR PATH: \" + path);",
260 " var node_data = this.pathToNode(path);",
262 " if (node_data == null) {",
263 " print(\"node not found\");",
267 " var xname = node_data.fqn();",
268 " var match = \"\";",
271 " for (var i =0; i < targets.length; i++) {",
272 " var tg = targets[i];",
273 " if ((tg == xname) ) {",
277 " // if target is \"xxxx:name\"",
278 " if (tg.contains(xname +\":\")) {",
280 " var ar = tg.split(\":\");",
286 " if (match.length > 0) {",
287 " if (last.length > 0) { // pref is after/before..",
288 " // then it's after last",
289 " //if (pref > 1) {",
292 " return last + \"|%d\".printf((int)pref) + \"|\" + prop;",
296 " // we need to add prop - as :store -> needs to bee added when dropping onto.",
297 " return path + \"|%d\".printf( (int) Gtk.TreeViewDropPosition.INTO_OR_AFTER) + \"|\" + prop;",
300 " last = \"\" + path;",
301 " var par = path.split(\":\");",
302 " string [] ppar = {};",
303 " for (var i = 0; i < par.length-1; i++) {",
307 " path = string.joinv(\":\", ppar);",
318 "| void deleteSelected" : [
321 " print(\"DELETE SELECTED?\");",
322 " //_this.view.blockChanges = true;",
323 " print(\"GET SELECTION?\");",
325 " var s = _this.view.el.get_selection();",
327 " print(\"GET SELECTED?\");",
328 " Gtk.TreeIter iter;",
329 " Gtk.TreeModel mod;",
332 " if (!s.get_selected(out mod, out iter)) {",
333 " return; // nothing seleted..",
338 " this.activePath= \"\"; ",
339 " print(\"GET vnode value?\");",
341 " GLib.Value value;",
342 " this.el.get_value(iter, 2, out value);",
343 " var data = (JsRender.Node)(value.get_object());",
344 " print(\"removing node from Render\\n\");",
345 " if (data.parent == null) {",
346 " _this.main_window.windowstate.file.tree = null;",
350 " print(\"removing node from Tree\\n\"); ",
351 " s.unselect_all();",
352 " this.el.remove(ref iter);",
362 " this.activePath= \"\"; // again!?!? ",
363 " //this.changed(null,true);",
367 " _this.view.blockChanges = false;",
371 "| void dropNode" : [
372 "(string target_data_str, JsRender.Node node, bool show_templates) {",
373 "// print(\"drop Node\");",
374 " // console.dump(node);",
375 " // console.dump(target_data);",
377 " \t\t//target_data_str",
378 " \t\t// {parent}|{pos}|{prop}",
381 " // 0 = before , 1=after 2/3 onto",
383 " \t\tGLib.debug(\"dropNode %s\", target_data_str);",
384 " var target_data= target_data_str.split(\"|\");",
386 " var parent_str = target_data[0].length > 0 ? target_data[0] : \"\";",
387 " var pos = target_data.length > 1 ? int.parse(target_data[1]) : 2; // ontop..",
390 " Gtk.TreePath tree_path = parent_str.length > 0 ? new Gtk.TreePath.from_string( parent_str ) : null;",
394 " //print(\"add \" + tp + \"@\" + target_data[1] );",
396 " JsRender.Node parentNode = null;",
398 " Gtk.TreeIter iter_after;",
399 " Gtk.TreeIter iter_par ;",
402 " if (target_data.length == 3 && target_data[2].length > 0) {",
403 " node.props.set(\"* prop\", target_data[2]);",
406 " Gtk.TreePath expand_parent = null;",
408 " // we only need to show the template if it's come from else where?",
409 " if (show_templates) {",
411 " var ts = _this.main_window.windowstate.template_select;",
413 " var new_node = ts.show(",
414 " _this.main_window, // (Gtk.Window) _this.el.get_toplevel (),",
415 " _this.main_window.windowstate.file.palete(),",
417 " _this.main_window.windowstate.project);",
419 " if (new_node == null) {",
420 " return; // do not add?",
425 " //print(\"pos is %d \\n\".printf(pos));",
427 " Gtk.TreeIter n_iter; ",
429 " if ( parent_str.length < 1) {",
430 " this.el.append(out n_iter, null); // drop at top level..",
431 " node.parent = null;",
432 " _this.main_window.windowstate.file.tree = node;",
435 " } else if (pos < 2) {",
436 " //print(target_data[1] > 0 ? 'insert_after' : 'insert_before');",
438 " this.el.get_iter(out iter_after, tree_path ); ",
439 " this.el.iter_parent(out iter_par, iter_after);",
440 " expand_parent = this.el.get_path(iter_par);",
442 " GLib.Value value;",
443 " this.el.get_value( iter_par, 2, out value);",
444 " parentNode = (JsRender.Node)value.dup_object();",
447 " this.el.get_value( iter_after, 2, out value);",
448 " var relNode = (JsRender.Node)value.dup_object();",
452 " this.el.insert_after(out n_iter, iter_par , iter_after);",
453 " var ix = parentNode.items.index_of(relNode);",
454 " parentNode.items.insert(ix+1, node);",
457 " this.el.insert_before(out n_iter, iter_par , iter_after);",
458 " var ix = parentNode.items.index_of(relNode);",
459 " parentNode.items.insert(ix, node);",
462 " node.parent = parentNode;",
467 " // print(\"appending to \" + parent_str);",
468 " this.el.get_iter(out iter_par, tree_path);",
469 " this.el.append(out n_iter, iter_par );",
470 " expand_parent = this.el.get_path(iter_par);",
472 " GLib.Value value;",
473 " this.el.get_value( iter_par, 2, out value);",
474 " parentNode = (JsRender.Node)value.dup_object();",
475 " node.parent = parentNode;",
476 " parentNode.items.add(node);",
479 " // reparent node in tree...",
482 " // why only on no parent???",
484 " //if (node.parent = null) {",
491 " // work out what kind of packing to use.. -- should be in ",
492 " if (!node.has(\"pack\") && parent_str.length > 1) {",
494 " _this.main_window.windowstate.file.palete().fillPack(node,parentNode);",
499 " // add the node...",
501 " this.el.set(n_iter, 0, node.nodeTitle(), 1, node.nodeTip(), -1 );",
502 " var o = GLib.Value(typeof(Object));",
503 " o.set_object((Object)node);",
505 " this.el.set_value(n_iter, 2, o);",
510 "// 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;",
541 "(Gee.ArrayList<JsRender.Node> tr, Gtk.TreeIter? iter) ",
543 " Gtk.TreeIter citer;",
544 " //this.insert(citer,iter,0);",
545 " var ic = Gtk.IconTheme.get_default();",
546 " var pixdef = ic.load_icon(\"emblem-new\", 16,0);",
548 " for(var i =0 ; i < tr.size; i++) {",
549 " if (iter != null) {",
550 " this.el.insert(out citer,iter,-1); // why not append?",
552 " this.el.append(out citer,null);",
555 " this.el.set(citer, 0, tr.get(i).nodeTitle(),",
556 " 1, tr.get(i).nodeTip(), -1",
558 " var o = GLib.Value(typeof(Object));",
559 " o.set_object((Object)tr.get(i));",
561 " this.el.set_value(citer, 2, o);",
563 " var clsname = tr.get(i).fqn();",
565 " var clsb = clsname.split(\".\");",
566 " var sub = clsb.length > 1 ? clsb[1].down() : \"\";",
568 " var pix = pixdef;",
569 " var fn = \"/usr/share/glade/pixmaps/hicolor/16x16/actions/widget-gtk-\" + sub + \".png\";",
570 " if (FileUtils.test (fn, FileTest.IS_REGULAR)) {",
571 "\t pix = new Gdk.Pixbuf.from_file (fn);",
575 " this.el.set_value(citer, 3, pix );",
581 " if (tr.get(i).items.size > 0) {",
582 " this.load(tr.get(i).items, citer);",
590 "| void loadFile" : [
591 "(JsRender.JsRender f) {",
592 " //console.dump(f);",
594 " _this.main_window.windowstate.leftTreeNodeSelected(null, \"\");",
596 " _this.main_window.windowstate.file = f;",
599 " if (f.tree == null) {",
601 "\t f.loadItems( );",
602 " } catch (Error e) {",
606 " // if it's still null?",
607 " if (f.tree == null) {",
611 " var o = new Gee.ArrayList<JsRender.Node>();",
613 " this.load(o,null);",
615 " _this.view.el.expand_all();",
617 " if (f.tree.items.size < 1) {",
620 " //this.get('/Window.leftvpaned').el.set_position(80);",
621 " // select first...",
622 " _this.view.el.set_cursor( ",
623 " new Gtk.TreePath.from_string(\"0\"), null, false);",
627 " //this.get('/Window.leftvpaned').el.set_position(200);",
636 "| void moveNode" : [
637 "(string target_data, Gdk.DragAction action) ",
640 " /// target_data = \"path|pos\");",
643 " //print(\"MOVE NODE\");",
644 " // console.dump(target_data);",
645 " Gtk.TreeIter old_iter;",
646 " Gtk.TreeModel mod;",
648 " var s = _this.view.el.get_selection();",
649 " s.get_selected(out mod , out old_iter);",
650 " mod.get_path(old_iter);",
652 " var node = this.pathToNode(mod.get_path(old_iter).to_string());",
653 " //console.dump(node);",
654 " if (node == null) {",
655 " print(\"moveNode: ERROR - node is null?\");",
660 " // needs to drop first, otherwise the target_data ",
661 " // treepath will be invalid.",
664 " if ((action & Gdk.DragAction.MOVE) > 0) {",
665 " print(\"REMOVING OLD NODE : \" + target_data + \"\\n\");",
667 " this.dropNode(target_data, node, false);",
668 " this.el.remove(ref old_iter);",
673 " print(\"DROPPING NODE // copy: \" + target_data + \"\\n\");",
674 " node = node.deepClone();",
675 " this.dropNode(target_data, node, false);",
678 " this.activePath= \"\";",
679 " //this.updateNode(false,true);",
683 "| void updateSelected" : [
687 " var s = _this.view.el.get_selection();",
689 " Gtk.TreeIter iter;",
690 " Gtk.TreeModel mod;",
694 " if (!s.get_selected(out mod, out iter)) {",
695 " return; // nothing seleted..",
698 " GLib.Value value;",
699 " this.el.get_value(iter, 2, out value);",
700 " var node = (JsRender.Node)(value.get_object());",
702 " this.el.set(iter, 0, node.nodeTitle(),",
703 " 1, node.nodeTip(), -1",
708 "| string treePathFromNode" : [
709 "(JsRender.Node node) {",
710 " // iterate through the tree and find the node",
713 " this.el.foreach((mod, pth, iter) => {",
714 " // get the node..",
717 " GLib.Value value;",
718 " _this.model.el.get_value(iter, 2, out value);",
722 " var n = (JsRender.Node)value;",
724 " print(\"compare %s to %s\\n\", n.fqn(), node.fqn());",
726 " ret = pth.to_string();",
740 " this.el.add_attribute(_this.renderer.el , \"markup\", 0 );",
741 " this.el.add_attribute(_this.iconrender.el , \"pixbuf\", 3 );",
744 "* pack" : "append_column",
748 "* pack" : "pack_start,true",
750 "xtype" : "CellRendererPixbuf"
754 "* pack" : "pack_start,true",
756 "xtype" : "CellRendererText"
759 "utf8 title" : "test",
760 "xtype" : "TreeViewColumn"
764 "button_press_event" : [
766 " //console.log(\"button press?\");",
767 " this.button_is_pressed = true;",
768 " print(\"BUTTON DOWN\\n\");",
770 " this.lastEventSource = \"tree\";",
771 " if (! _this.before_node_change() ) {",
778 " if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button != 3) {",
779 " //print(\"click\" + ev.type);",
782 " Gtk.TreePath res;",
783 " if (!_this.view.el.get_path_at_pos((int)ev.x,(int)ev.y, out res, null, null, null) ) {",
788 " _this.main_window.windowstate.leftTreeBeforeChange();",
792 " this.el.get_selection().select_path(res);",
794 " //if (!this.get('/LeftTreeMenu').el) { ",
795 " // this.get('/LeftTreeMenu').init(); ",
798 " _this.LeftTreeMenu.el.set_screen(Gdk.Screen.get_default());",
799 " _this.LeftTreeMenu.el.show_all();",
800 " _this.LeftTreeMenu.el.popup(null, null, null, 3, ev.time);",
801 " // print(\"click:\" + res.path.to_string());",
805 "button_release_event" : [
807 " this.button_is_pressed = false;",
813 " print(\"LEFT TREE Cursor Changed\\n\");",
814 "\tif (!this.button_is_pressed && !this.key_is_pressed) {",
815 "\t\t// then event was started by some other action",
816 "\t\t// which should manually trigger all the events..",
817 "\t\tprint(\"SKIPPING select - no button or key pressed\\n\");",
822 " if (this.blockChanges) { // probably not needed.. ",
823 "\t\tprint(\"SKIPPING select - blockchanges set..\\n\"); ",
826 " if (!_this.before_node_change( ) ) {",
827 "\t this.blockChanges = true;",
828 "\t this.el.get_selection().unselect_all();",
829 "\t this.blockChanges = false;",
833 " if (_this.main_window.windowstate.file == null) {",
834 " \t\tprint(\"SKIPPING select windowstate file is not set...\\n\"); ",
838 " //var render = this.get('/LeftTree').getRenderer(); ",
839 " print(\"LEFT TREE -> view -> selection changed called\\n\");",
842 " // -- it appears that the selection is not updated.",
844 " GLib.Timeout.add_full(GLib.Priority.DEFAULT,10 , () => {",
845 " print(\"LEFT TREE -> view -> selection changed TIMEOUT CALLED\\n\");",
847 " if (this.el.get_selection().count_selected_rows() < 1) {",
849 " print(\"selected rows < 1\\n\");",
850 " //??this.model.load( false);",
851 " _this.node_selected(null, this.lastEventSource);",
856 " //console.log('changed');",
857 " var s = this.el.get_selection();",
858 " Gtk.TreeIter iter;",
859 " Gtk.TreeModel mod;",
860 " s.get_selected(out mod, out iter);",
863 " // var val = \"\";",
864 " GLib.Value value;",
865 " _this.model.el.get_value(iter, 2, out value);",
866 " _this.model.activePath = mod.get_path(iter).to_string();",
868 " var node = (JsRender.Node)value.dup_object();",
869 " print (\"calling left_tree.node_selected\\n\");",
870 " _this.node_selected(node, this.lastEventSource);",
871 " while (Gtk.events_pending()) {",
872 " Gtk.main_iteration();",
874 " var cp = mod.get_path(iter);",
875 " Gtk.TreePath sp, ep;",
876 " this.el.get_visible_range(out sp, out ep);",
877 " // if sp is before cp then retuns 1.",
878 " // if cp is before ep then retuns 1.",
879 " if (cp.compare(sp) >= 0 && ep.compare(cp) >=1) {",
885 " this.el.scroll_to_cell(new Gtk.TreePath.from_string(_this.model.activePath), null, true, 0.1f,0.0f);",
889 " //_this.after_node_change(node);",
891 "// _this.model.file.changed(node, \"tree\");",
893 " //Seed.print( value.get_string());",
900 "\t//print('SOURCE: drag-begin');",
903 " //this.targetData = \"\";",
905 " // find what is selected in our tree...",
907 " var s = _this.view.el.get_selection();",
908 " if (s.count_selected_rows() < 1) {",
911 " Gtk.TreeIter iter;",
912 " Gtk.TreeModel mod;",
913 " s.get_selected(out mod, out iter);",
917 " // set some properties of the tree for use by the dropped element.",
918 " GLib.Value value;",
919 " _this.model.el.get_value(iter, 2, out value);",
920 " var tp = mod.get_path(iter).to_string();",
921 " var data = (JsRender.Node)(value.dup_object());",
922 " var xname = data.fqn();",
923 " print (\"XNAME IS \" + xname+ \"\\n\");",
924 " this.dragData = tp;",
925 " this.dropList = _this.main_window.windowstate.file.palete().getDropList(xname);",
927 " print (\"DROP LIST IS \" + string.joinv(\", \", this.dropList) + \"\\n\");",
930 " // make the drag icon a picture of the node that was selected",
933 " // by default returns the path..",
934 " var path = _this.model.el.get_path(iter);",
937 " var pix = this.el.create_row_drag_icon ( path);",
939 " Gtk.drag_set_icon_surface (ctx, pix) ;",
945 "( drag_context, data, info, time) => {",
948 " //print(\"drag-data-get\");",
949 " var s = this.el.get_selection();",
950 " if (s.count_selected_rows() < 1) {",
951 " data.set_text(\"\",0); ",
952 " print(\"return empty string - no selection..\");",
956 " Gtk.TreeIter iter;",
957 " Gtk.TreeModel mod;",
959 " s.get_selected(out mod, out iter);",
963 " GLib.Value value;",
964 " _this.model.el.get_value(iter, 2, out value);",
965 " var ndata = (JsRender.Node)(value.dup_object());",
969 " var tp = mod.get_path(iter).to_string();",
970 " // by default returns the path..",
972 " if ( info != Gdk.Atom.intern(\"STRING\",true) ) {",
973 " tp = ndata.toJsonString();",
976 " //data.set_text(tp,tp.length); ",
978 " data.set (data.get_target (), 8, (uchar[]) tp.to_utf8 ());",
981 " // print(\"return \" + tp);",
984 "drag_data_received" : [
985 " (ctx, x, y, sel, info, time) => {",
987 " // THIS CODE ONLY RELATES TO drag or drop of \"NEW\" elements or \"FROM another tree..\"",
990 " // print(\"Tree: drag-data-received\\n\");",
991 " var selection_text = (string)sel.get_data();",
992 " //print(\"selection_text= %s\\n\",selection_text);",
994 " var is_drag = this.drag_in_motion;",
998 "\t\tGLib.debug(\"Is Drag %s\\n\", is_drag ? \"Y\": \"N\");",
999 " var targetData = \"\";",
1001 " Gtk.TreePath path;",
1002 " Gtk.TreeViewDropPosition pos;",
1003 " var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);",
1005 " // if there are not items in the tree.. the we have to set isOver to true for anything..",
1006 " var isEmpty = false;",
1007 " if (_this.model.el.iter_n_children(null) < 1) {",
1008 " GLib.debug(\"got NO children?\\n\");",
1009 " isOver = true; //??? ",
1011 " pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;",
1015 " //console.log(\"LEFT-TREE: drag-motion\");",
1016 " var src = Gtk.drag_get_source_widget(ctx);",
1018 " // a drag from self - this should be handled by drop and motion.",
1019 " if (src == this.el) {",
1020 " GLib.debug(\"Source == this element should not happen.. ? \\n\");",
1023 " //print(\"drag_data_recieved from another element\");",
1028 " if (selection_text == null || selection_text.length < 1 || !isOver) {",
1029 " // nothing valid foudn to drop...",
1030 " GLib.debug(\"empty sel text or not over\");",
1032 " Gdk.drag_status(ctx, 0, time);",
1033 " this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);",
1036 " Gtk.drag_finish (ctx, false, false, time); // drop failed..",
1037 " // no drop action...",
1041 " var dropNode = new JsRender.Node(); ",
1043 " var dropNodeType = selection_text;",
1044 " var show_templates = true;",
1046 " if (dropNodeType[0] == '{') {",
1047 " var pa = new Json.Parser();",
1049 " pa.load_from_data(dropNodeType);",
1050 " } catch (Error e) {",
1051 " Gtk.drag_finish (ctx, false, false, time); // drop failed..",
1052 " // no drop action...",
1056 " dropNode.loadFromJson( pa.get_root().get_object(), 2);",
1057 " dropNodeType = dropNode.fqn();",
1058 " show_templates = false;",
1062 " \tif (selection_text.contains(\":\")) {",
1063 "\t \tvar bits = selection_text.split(\":\");",
1064 "\t dropNode.setFqn(bits[0]);",
1065 "\t dropNode.props.set(\"* prop\", bits[1]);",
1068 "\t dropNode.setFqn(selection_text);",
1073 " // dropList --- need to gather this ... ",
1074 " GLib.debug(\"get dropList for : %s\\n\",dropNodeType); ",
1075 " var dropList = _this.main_window.windowstate.file.palete().getDropList(dropNodeType);",
1077 " GLib.debug(\"dropList: %s\\n\", string.joinv(\" , \", dropList));",
1079 " // if drag action is link ... then we can drop it anywahere...",
1080 " if ((ctx.get_actions() & Gdk.DragAction.LINK) > 0) {",
1081 " // if path is null?? dragging into an empty tree?",
1082 " targetData = (path == null ? \"\" : path.to_string()) + \"|%d\".printf((int)pos);",
1086 " targetData = _this.model.findDropNodeByPath( isEmpty ? \"\" : path.to_string(), dropList, pos);",
1091 " GLib.debug(\"targetDAta: %s\", targetData );",
1093 " if (targetData.length < 1) {",
1095 " // invalid drop path..",
1096 " if (this.drag_in_motion) {",
1097 " Gdk.drag_status(ctx, 0, time);",
1098 " this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);",
1101 " Gtk.drag_finish (ctx, false, false, time); // drop failed..",
1102 " // no drop action...",
1108 " var td_ar = targetData.split(\"|\");",
1111 " if (this.drag_in_motion) { ",
1112 " Gdk.drag_status(ctx, Gdk.DragAction.COPY ,time);",
1114 " this.highlightDropPath( td_ar[0] , (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));",
1117 " // continue on to allow drop..",
1120 " // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..",
1122 " \t\t// {parent}|{pos}|{prop}",
1125 " _this.model.dropNode(targetData, dropNode, show_templates);",
1126 " GLib.debug(\"ADD new node!!!\\n\");",
1128 " ///Xcls_DialogTemplateSelect.singleton().show( _this.model.file.palete(), node);",
1130 " Gtk.drag_finish (ctx, false, false,time);",
1139 " ( ctx, x, y, time) => {",
1140 " //Seed.print(\"TARGET: drag-drop\");",
1143 " var src = Gtk.drag_get_source_widget(ctx);",
1145 " if (src != this.el) {",
1149 " this.drag_in_motion = false; ",
1150 " // request data that will be recieved by the recieve... ",
1151 " Gtk.drag_get_data",
1153 " this.el, // will receive 'drag-data-received' signal ",
1154 " ctx, // represents the current state of the DnD ",
1155 " Gdk.Atom.intern(\"application/json\",true), // the target type we want ",
1156 " time // time stamp ",
1160 " // No target offered by source => error",
1166 " // handle drop around self..",
1170 " //print(\"GETTING POS\");",
1171 " var targetData = \"\";",
1173 " Gtk.TreePath path;",
1174 " Gtk.TreeViewDropPosition pos;",
1175 " var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);",
1177 " // if there are not items in the tree.. the we have to set isOver to true for anything..",
1178 " var isEmpty = false;",
1179 " if (_this.model.el.iter_n_children(null) < 1) {",
1180 " print(\"got NO children?\\n\");",
1181 " isOver = true; //??? ",
1183 " pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;",
1188 " //var action = Gdk.DragAction.COPY;",
1189 " // unless we are copying!!! ctl button..",
1191 " var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?",
1192 " Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;",
1193 " // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;",
1196 " if (_this.model.el.iter_n_children(null) < 1) {",
1197 " // no children.. -- asume it's ok..",
1199 " targetData = \"|%d|\".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);",
1201 " // continue through to allow drop...",
1209 " //print(\"ISOVER? \" + isOver);",
1212 " Gtk.drag_finish (ctx, false, false, time); // drop failed..",
1213 " return true; // not over apoint!?! - no action on drop or motion..",
1216 " // drag node is parent of child..",
1217 " //console.log(\"SRC TREEPATH: \" + src.treepath);",
1218 " //console.log(\"TARGET TREEPATH: \" + data.path.to_string());",
1220 " // nned to check a few here..",
1221 " //Gtk.TreeViewDropPosition.INTO_OR_AFTER",
1222 " //Gtk.TreeViewDropPosition.INTO_OR_BEFORE",
1223 " //Gtk.TreeViewDropPosition.AFTER",
1224 " //Gtk.TreeViewDropPosition.BEFORE",
1226 " // locally dragged items to not really use the ",
1227 " var selection_text = this.dragData;",
1231 " if (selection_text == null || selection_text.length < 1) {",
1232 " //print(\"Error - drag selection text returned NULL\");",
1234 " Gtk.drag_finish (ctx, false, false, time); // drop failed..",
1235 " return true; /// -- fixme -- this is not really correct..",
1238 " // see if we are dragging into ourself?",
1239 " print (\"got selection text of \" + selection_text);",
1241 " var target_path = path.to_string();",
1242 " //print(\"target_path=\"+target_path);",
1245 " if (selection_text == target_path) {",
1246 " print(\"self drag ?? == we should perhaps allow copy onto self..\\n\");",
1248 " Gtk.drag_finish (ctx, false, false, time); // drop failed..",
1250 " return true; /// -- fixme -- this is not really correct..",
1255 " //print(\"DUMPING DATA\");",
1256 " //console.dump(data);",
1259 " //print(data.path.to_string() +' => '+ data.pos);",
1261 " // dropList is a list of xtypes that this node could be dropped on.",
1262 " // it is set up when we start to drag..",
1265 " targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);",
1267 " print(\"targetDAta: \" + targetData +\"\\n\");",
1269 " if (targetData.length < 1) {",
1270 " //print(\"Can not find drop node path\");",
1272 " Gtk.drag_finish (ctx, false, false, time); // drop failed..",
1278 " // continue on to allow drop..",
1280 " // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..",
1283 " var delete_selection_data = false;",
1285 " if (action == Gdk.DragAction.ASK) {",
1286 " /* Ask the user to move or copy, then set the ctx action. */",
1289 " if (action == Gdk.DragAction.MOVE) {",
1290 " delete_selection_data = true;",
1293 " // drag around.. - reorder..",
1294 " _this.model.moveNode(targetData, action);",
1300 " // we can send stuff to souce here...",
1303 "// do we always say failure, so we handle the reall drop?",
1304 " Gtk.drag_finish (ctx, false, false,time); //delete_selection_data, time);",
1316 " (drag_context) => {",
1317 "\t//Seed.print('LEFT-TREE: drag-end');",
1318 " this.dragData = \"\";",
1319 " this.dropList = null;",
1320 "// this.targetData = \"\";",
1321 " this.highlightDropPath(\"\",0);",
1326 " ( ctx, x, y, time) => {",
1327 " print(\"got drag motion\\n\");",
1328 " var src = Gtk.drag_get_source_widget(ctx);",
1329 " this.drag_x = x;",
1330 " this.drag_y = y; ",
1332 " if (src != this.el) {",
1336 " // the point of this is to detect where an item could be dropped..",
1337 " print(\"requesting drag data\\n\");",
1338 " this.drag_in_motion = true;",
1340 " // request data that will be recieved by the recieve... ",
1341 " Gtk.drag_get_data",
1343 " this.el, // will receive 'drag-data-received' signal ",
1344 " ctx, // represents the current state of the DnD ",
1345 " Gdk.Atom.intern(\"STRING\",true), // the target type we want ",
1346 " time // time stamp ",
1352 " print(\"action: %d\\n\", ctx.get_actions());",
1353 " //print(\"GETTING POS\");",
1354 " var targetData = \"\";",
1356 " Gtk.TreePath path;",
1357 " Gtk.TreeViewDropPosition pos;",
1358 " var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);",
1360 " // if there are not items in the tree.. the we have to set isOver to true for anything..",
1361 " var isEmpty = false;",
1362 " if (_this.model.el.iter_n_children(null) < 1) {",
1363 " print(\"got NO children?\\n\");",
1364 " isOver = true; //??? ",
1366 " pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;",
1370 " // ------------- a drag from self..",
1373 " //var action = Gdk.DragAction.COPY;",
1374 " // unless we are copying!!! ctl button..",
1376 " var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?",
1377 " Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;",
1378 " // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;",
1381 " if (_this.model.el.iter_n_children(null) < 1) {",
1382 " // no children.. -- asume it's ok..",
1384 " targetData = \"|%d|\".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);",
1386 " this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0); ",
1387 " Gdk.drag_status(ctx, action ,time);",
1390 " // continue through to allow drop...",
1398 " //print(\"ISOVER? \" + isOver);",
1401 " Gdk.drag_status(ctx, 0 ,time);",
1402 " this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0); ",
1407 " // drag node is parent of child..",
1408 " //console.log(\"SRC TREEPATH: \" + src.treepath);",
1409 " //console.log(\"TARGET TREEPATH: \" + data.path.to_string());",
1411 " // nned to check a few here..",
1412 " //Gtk.TreeViewDropPosition.INTO_OR_AFTER",
1413 " //Gtk.TreeViewDropPosition.INTO_OR_BEFORE",
1414 " //Gtk.TreeViewDropPosition.AFTER",
1415 " //Gtk.TreeViewDropPosition.BEFORE",
1417 " // locally dragged items to not really use the ",
1418 " var selection_text = this.dragData;",
1422 " if (selection_text == null || selection_text.length < 1) {",
1423 " //print(\"Error - drag selection text returned NULL\");",
1424 " Gdk.drag_status(ctx, 0 ,time);",
1425 " this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);",
1430 " // see if we are dragging into ourself?",
1431 " var target_path = path.to_string(); ",
1432 " print (\"Drag %s onto %s--%d\\n \", selection_text, target_path, pos);",
1434 " // pos : 3 = ontop - 0 = after, 1 = before",
1435 " //print(\"target_path=\"+target_path);",
1438 " if (selection_text == target_path) {",
1439 " print(\"self drag ?? == we should perhaps allow copy onto self..\\n\");",
1441 " Gdk.drag_status(ctx, 0 ,time);",
1442 " this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);",
1444 "// -- fixme -- this is not really correct..",
1449 " //print(\"DUMPING DATA\");",
1450 " //console.dump(data);",
1453 " //print(data.path.to_string() +' => '+ data.pos);",
1455 " // dropList is a list of xtypes that this node could be dropped on.",
1456 " // it is set up when we start to drag..",
1459 " targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);",
1461 " print(\"targetDAta: \" + targetData +\"\\n\");",
1463 " if (targetData.length < 1) {",
1464 " //print(\"Can not find drop node path\");",
1466 " Gdk.drag_status(ctx, 0, time);",
1467 " this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);",
1471 " var td_ar = targetData.split(\"|\");",
1475 " Gdk.drag_status(ctx, action ,time);",
1476 " this.highlightDropPath(td_ar[0], (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));",
1482 "key_press_event" : [
1484 " this.key_is_pressed = true;",
1488 "key_release_event" : [
1490 " this.key_is_pressed = false;",
1496 "tooltip_column" : 1,
1497 "xtype" : "TreeView",
1498 "| void highlightDropPath" : [
1499 " ( string treepath, Gtk.TreeViewDropPosition pos) {",
1501 " // highlighting for drag/drop",
1502 " if (treepath.length > 0) {",
1503 " this.el.set_drag_dest_row( new Gtk.TreePath.from_string( treepath ), pos);",
1505 " this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);",
1510 "| void selectNode" : [
1511 "(string treepath_str, string source) {",
1512 "\tthis.lastEventSource = source;",
1513 " //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));",
1514 " var tp = new Gtk.TreePath.from_string(treepath_str);",
1516 " this.el.set_cursor(tp, null, false); ",
1517 " this.el.scroll_to_cell(tp, null, false, 0,0);",
1521 "| void setCursor" : [
1522 "(string treepath, string sourceEvent) {",
1523 "\tthis.lastEventSource = sourceEvent;",
1524 "\t//this.blockChanges = true; << block changes prevents loading of 'node data' and firing of node_selected..",
1525 " this.el.set_cursor(new Gtk.TreePath.from_string(treepath), null, false); ",
1526 " // fire node_selected..",
1527 " //this.blockChanges = false;",
1528 "\tthis.lastEventSource = \"\";",
1536 "id" : "LeftTreeMenu",
1541 "label" : "Delete Element",
1546 " print(\"ACTIVATE?\");",
1549 " _this.model.deleteSelected();",
1553 "xtype" : "MenuItem"
1558 "label" : "Save as Template",
1563 " DialogSaveTemplate.singleton().show(",
1564 " (Gtk.Window) _this.el.get_toplevel (), ",
1565 " _this.main_window.windowstate.file.palete(), ",
1566 " _this.getActiveElement()",
1573 "xtype" : "MenuItem"
1578 "label" : "Save as Module",
1582 " var node = _this.getActiveElement();",
1583 " var name = DialogSaveModule.singleton().show(",
1584 " (Gtk.Window) _this.el.get_toplevel (), ",
1585 " _this.main_window.windowstate.project, ",
1588 " if (name.length < 1) {",
1592 " node.props.set(\"* xinclude\", name);",
1593 " node.items.clear();",
1596 " var s = _this.view.el.get_selection();",
1598 " print(\"GET SELECTED?\");",
1599 " Gtk.TreeIter iter;",
1600 " Gtk.TreeModel mod;",
1603 " if (!s.get_selected(out mod, out iter)) {",
1604 " return; // nothing seleted..",
1606 " Gtk.TreeIter citer;",
1607 " var n_cn = mod.iter_n_children(iter) -1;",
1608 " for (var i = n_cn; i > -1; i--) {",
1609 " mod.iter_nth_child(out citer, iter, i);",
1612 " print(\"removing node from Tree\\n\"); ",
1614 " _this.model.el.remove(ref citer);",
1616 " _this.changed();",
1617 " _this.node_selected(node, \"tree\");",
1623 "xtype" : "MenuItem"
1629 "xtype" : "ScrolledWindow"
1633 "| JsRender.JsRender getActiveFile" : [
1635 " return this.main_window.windowstate.file;",
1639 "| JsRender.Node? getActiveElement" : [
1640 " () { // return path to actie node.",
1642 " var path = this.getActivePath();",
1643 " if (path.length < 1) {",
1646 " return _this.model.pathToNode(path);",
1651 "| string getActivePath" : [
1654 " var view = this.view.el;",
1655 " if (view.get_selection().count_selected_rows() < 1) {",
1658 " Gtk.TreeIter iter;",
1659 " Gtk.TreeModel mod;",
1660 " view.get_selection().get_selected(out mod, out iter);",
1661 " return mod.get_path(iter).to_string();",
1668 "name" : "WindowLeftTree",
1670 "path" : "/home/alan/gitlive/roobuilder/src/Builder4/WindowLeftTree.bjs",