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)",
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 " for(var i =0 ; i < tr.size; i++) {",
546 " if (iter != null) {",
547 " this.el.insert(out citer,iter,-1); // why not append?",
549 " this.el.append(out citer,null);",
552 " this.el.set(citer, 0, tr.get(i).nodeTitle(),",
553 " 1, tr.get(i).nodeTip(), -1",
555 " var o = GLib.Value(typeof(Object));",
556 " o.set_object((Object)tr.get(i));",
558 " this.el.set_value(citer, 2, o);",
560 " if (tr.get(i).items.size > 0) {",
561 " this.load(tr.get(i).items, citer);",
569 "| void loadFile" : [
570 "(JsRender.JsRender f) {",
571 " //console.dump(f);",
573 " _this.main_window.windowstate.leftTreeNodeSelected(null, \"\");",
575 " _this.main_window.windowstate.file = f;",
578 " if (f.tree == null) {",
580 "\t f.loadItems( );",
581 " } catch (Error e) {",
585 " // if it's still null?",
586 " if (f.tree == null) {",
590 " var o = new Gee.ArrayList<JsRender.Node>();",
592 " this.load(o,null);",
594 " _this.view.el.expand_all();",
596 " if (f.tree.items.size < 1) {",
599 " //this.get('/Window.leftvpaned').el.set_position(80);",
600 " // select first...",
601 " _this.view.el.set_cursor( ",
602 " new Gtk.TreePath.from_string(\"0\"), null, false);",
606 " //this.get('/Window.leftvpaned').el.set_position(200);",
615 "| void moveNode" : [
616 "(string target_data, Gdk.DragAction action) ",
619 " /// target_data = \"path|pos\");",
622 " //print(\"MOVE NODE\");",
623 " // console.dump(target_data);",
624 " Gtk.TreeIter old_iter;",
625 " Gtk.TreeModel mod;",
627 " var s = _this.view.el.get_selection();",
628 " s.get_selected(out mod , out old_iter);",
629 " mod.get_path(old_iter);",
631 " var node = this.pathToNode(mod.get_path(old_iter).to_string());",
632 " //console.dump(node);",
633 " if (node == null) {",
634 " print(\"moveNode: ERROR - node is null?\");",
639 " // needs to drop first, otherwise the target_data ",
640 " // treepath will be invalid.",
643 " if ((action & Gdk.DragAction.MOVE) > 0) {",
644 " print(\"REMOVING OLD NODE : \" + target_data + \"\\n\");",
646 " this.dropNode(target_data, node, false);",
647 " this.el.remove(ref old_iter);",
652 " print(\"DROPPING NODE // copy: \" + target_data + \"\\n\");",
653 " node = node.deepClone();",
654 " this.dropNode(target_data, node, false);",
657 " this.activePath= \"\";",
658 " //this.updateNode(false,true);",
662 "| void updateSelected" : [
666 " var s = _this.view.el.get_selection();",
668 " Gtk.TreeIter iter;",
669 " Gtk.TreeModel mod;",
673 " if (!s.get_selected(out mod, out iter)) {",
674 " return; // nothing seleted..",
677 " GLib.Value value;",
678 " this.el.get_value(iter, 2, out value);",
679 " var node = (JsRender.Node)(value.get_object());",
681 " this.el.set(iter, 0, node.nodeTitle(),",
682 " 1, node.nodeTip(), -1",
687 "| string treePathFromNode" : [
688 "(JsRender.Node node) {",
689 " // iterate through the tree and find the node",
692 " this.el.foreach((mod, pth, iter) => {",
693 " // get the node..",
696 " GLib.Value value;",
697 " _this.model.el.get_value(iter, 2, out value);",
701 " var n = (JsRender.Node)value;",
703 " print(\"compare %s to %s\\n\", n.fqn(), node.fqn());",
705 " ret = pth.to_string();",
719 " this.el.add_attribute(_this.renderer.el , \"markup\", 0 );",
722 "* pack" : "append_column",
726 "* pack" : "pack_start,true",
728 "xtype" : "CellRendererText"
731 "utf8 title" : "test",
732 "xtype" : "TreeViewColumn"
736 "button_press_event" : [
738 " //console.log(\"button press?\");",
739 " this.button_is_pressed = true;",
740 " print(\"BUTTON DOWN\\n\");",
742 " this.lastEventSource = \"tree\";",
743 " if (! _this.before_node_change() ) {",
750 " if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button != 3) {",
751 " //print(\"click\" + ev.type);",
754 " Gtk.TreePath res;",
755 " if (!_this.view.el.get_path_at_pos((int)ev.x,(int)ev.y, out res, null, null, null) ) {",
759 " this.el.get_selection().select_path(res);",
761 " //if (!this.get('/LeftTreeMenu').el) { ",
762 " // this.get('/LeftTreeMenu').init(); ",
765 " _this.LeftTreeMenu.el.set_screen(Gdk.Screen.get_default());",
766 " _this.LeftTreeMenu.el.show_all();",
767 " _this.LeftTreeMenu.el.popup(null, null, null, 3, ev.time);",
768 " // print(\"click:\" + res.path.to_string());",
772 "button_release_event" : [
774 " this.button_is_pressed = false;",
780 " print(\"LEFT TREE Cursor Changed\\n\");",
781 "\tif (!this.button_is_pressed && !this.key_is_pressed) {",
782 "\t\t// then event was started by some other action",
783 "\t\t// which should manually trigger all the events..",
784 "\t\tprint(\"SKIPPING select - no button or key pressed\\n\");",
789 " if (this.blockChanges) { // probably not needed.. ",
790 "\t\tprint(\"SKIPPING select - blockchanges set..\\n\"); ",
793 " if (!_this.before_node_change( ) ) {",
794 "\t this.blockChanges = true;",
795 "\t this.el.get_selection().unselect_all();",
796 "\t this.blockChanges = false;",
800 " if (_this.main_window.windowstate.file == null) {",
801 " \t\tprint(\"SKIPPING select windowstate file is not set...\\n\"); ",
805 " //var render = this.get('/LeftTree').getRenderer(); ",
806 " print(\"LEFT TREE -> view -> selection changed called\\n\");",
809 " // -- it appears that the selection is not updated.",
811 " GLib.Timeout.add_full(GLib.Priority.DEFAULT,10 , () => {",
812 " print(\"LEFT TREE -> view -> selection changed TIMEOUT CALLED\\n\");",
814 " if (this.el.get_selection().count_selected_rows() < 1) {",
816 " print(\"selected rows < 1\\n\");",
817 " //??this.model.load( false);",
818 " _this.node_selected(null, this.lastEventSource);",
823 " //console.log('changed');",
824 " var s = this.el.get_selection();",
825 " Gtk.TreeIter iter;",
826 " Gtk.TreeModel mod;",
827 " s.get_selected(out mod, out iter);",
830 " // var val = \"\";",
831 " GLib.Value value;",
832 " _this.model.el.get_value(iter, 2, out value);",
833 " _this.model.activePath = mod.get_path(iter).to_string();",
835 " var node = (JsRender.Node)value.dup_object();",
836 " print (\"calling left_tree.node_selected\\n\");",
837 " _this.node_selected(node, this.lastEventSource);",
838 " while (Gtk.events_pending()) {",
839 " Gtk.main_iteration();",
841 " var cp = mod.get_path(iter);",
842 " Gtk.TreePath sp, ep;",
843 " this.el.get_visible_range(out sp, out ep);",
844 " // if sp is before cp then retuns 1.",
845 " // if cp is before ep then retuns 1.",
846 " if (cp.compare(sp) >= 0 && ep.compare(cp) >=1) {",
852 " this.el.scroll_to_cell(new Gtk.TreePath.from_string(_this.model.activePath), null, true, 0.1f,0.0f);",
856 " //_this.after_node_change(node);",
858 "// _this.model.file.changed(node, \"tree\");",
860 " //Seed.print( value.get_string());",
867 "\t//print('SOURCE: drag-begin');",
870 " //this.targetData = \"\";",
872 " // find what is selected in our tree...",
874 " var s = _this.view.el.get_selection();",
875 " if (s.count_selected_rows() < 1) {",
878 " Gtk.TreeIter iter;",
879 " Gtk.TreeModel mod;",
880 " s.get_selected(out mod, out iter);",
884 " // set some properties of the tree for use by the dropped element.",
885 " GLib.Value value;",
886 " _this.model.el.get_value(iter, 2, out value);",
887 " var tp = mod.get_path(iter).to_string();",
888 " var data = (JsRender.Node)(value.dup_object());",
889 " var xname = data.fqn();",
890 " print (\"XNAME IS \" + xname+ \"\\n\");",
891 " this.dragData = tp;",
892 " this.dropList = _this.main_window.windowstate.file.palete().getDropList(xname);",
894 " print (\"DROP LIST IS \" + string.joinv(\", \", this.dropList) + \"\\n\");",
897 " // make the drag icon a picture of the node that was selected",
900 " // by default returns the path..",
901 " var path = _this.model.el.get_path(iter);",
904 " var pix = this.el.create_row_drag_icon ( path);",
906 " Gtk.drag_set_icon_surface (ctx, pix) ;",
912 "( drag_context, data, info, time) => {",
915 " //print(\"drag-data-get\");",
916 " var s = this.el.get_selection();",
917 " if (s.count_selected_rows() < 1) {",
918 " data.set_text(\"\",0); ",
919 " print(\"return empty string - no selection..\");",
923 " Gtk.TreeIter iter;",
924 " Gtk.TreeModel mod;",
926 " s.get_selected(out mod, out iter);",
930 " GLib.Value value;",
931 " _this.model.el.get_value(iter, 2, out value);",
932 " var ndata = (JsRender.Node)(value.dup_object());",
936 " var tp = mod.get_path(iter).to_string();",
937 " // by default returns the path..",
939 " if ( info != Gdk.Atom.intern(\"STRING\",true) ) {",
940 " tp = ndata.toJsonString();",
943 " //data.set_text(tp,tp.length); ",
945 " data.set (data.get_target (), 8, (uchar[]) tp.to_utf8 ());",
948 " // print(\"return \" + tp);",
951 "drag_data_received" : [
952 " (ctx, x, y, sel, info, time) => {",
954 " // THIS CODE ONLY RELATES TO drag or drop of \"NEW\" elements or \"FROM another tree..\"",
957 " // print(\"Tree: drag-data-received\\n\");",
958 " var selection_text = (string)sel.get_data();",
959 " //print(\"selection_text= %s\\n\",selection_text);",
961 " var is_drag = this.drag_in_motion;",
965 "\t\tGLib.debug(\"Is Drag %s\\n\", is_drag ? \"Y\": \"N\");",
966 " var targetData = \"\";",
968 " Gtk.TreePath path;",
969 " Gtk.TreeViewDropPosition pos;",
970 " var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);",
972 " // if there are not items in the tree.. the we have to set isOver to true for anything..",
973 " var isEmpty = false;",
974 " if (_this.model.el.iter_n_children(null) < 1) {",
975 " GLib.debug(\"got NO children?\\n\");",
976 " isOver = true; //??? ",
978 " pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;",
982 " //console.log(\"LEFT-TREE: drag-motion\");",
983 " var src = Gtk.drag_get_source_widget(ctx);",
985 " // a drag from self - this should be handled by drop and motion.",
986 " if (src == this.el) {",
987 " GLib.debug(\"Source == this element should not happen.. ? \\n\");",
990 " //print(\"drag_data_recieved from another element\");",
995 " if (selection_text == null || selection_text.length < 1 || !isOver) {",
996 " // nothing valid foudn to drop...",
997 " GLib.debug(\"empty sel text or not over\");",
999 " Gdk.drag_status(ctx, 0, time);",
1000 " this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);",
1003 " Gtk.drag_finish (ctx, false, false, time); // drop failed..",
1004 " // no drop action...",
1008 " var dropNode = new JsRender.Node(); ",
1010 " var dropNodeType = selection_text;",
1011 " var show_templates = true;",
1013 " if (dropNodeType[0] == '{') {",
1014 " var pa = new Json.Parser();",
1016 " pa.load_from_data(dropNodeType);",
1017 " } catch (Error e) {",
1018 " Gtk.drag_finish (ctx, false, false, time); // drop failed..",
1019 " // no drop action...",
1023 " dropNode.loadFromJson( pa.get_root().get_object(), 2);",
1024 " dropNodeType = dropNode.fqn();",
1025 " show_templates = false;",
1029 " \tif (selection_text.contains(\":\")) {",
1030 "\t \tvar bits = selection_text.split(\":\");",
1031 "\t dropNode.setFqn(bits[0]);",
1032 "\t dropNode.props.set(\"* prop\", bits[1]);",
1035 "\t dropNode.setFqn(selection_text);",
1040 " // dropList --- need to gather this ... ",
1041 " GLib.debug(\"get dropList for : %s\\n\",dropNodeType); ",
1042 " var dropList = _this.main_window.windowstate.file.palete().getDropList(dropNodeType);",
1044 " GLib.debug(\"dropList: %s\\n\", string.joinv(\" , \", dropList));",
1046 " // if drag action is link ... then we can drop it anywahere...",
1047 " if ((ctx.get_actions() & Gdk.DragAction.LINK) > 0) {",
1048 " // if path is null?? dragging into an empty tree?",
1049 " targetData = (path == null ? \"\" : path.to_string()) + \"|%d\".printf((int)pos);",
1053 " targetData = _this.model.findDropNodeByPath( isEmpty ? \"\" : path.to_string(), dropList, pos);",
1058 " GLib.debug(\"targetDAta: %s\", targetData );",
1060 " if (targetData.length < 1) {",
1062 " // invalid drop path..",
1063 " if (this.drag_in_motion) {",
1064 " Gdk.drag_status(ctx, 0, time);",
1065 " this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);",
1068 " Gtk.drag_finish (ctx, false, false, time); // drop failed..",
1069 " // no drop action...",
1075 " var td_ar = targetData.split(\"|\");",
1078 " if (this.drag_in_motion) { ",
1079 " Gdk.drag_status(ctx, Gdk.DragAction.COPY ,time);",
1081 " this.highlightDropPath( td_ar[0] , (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));",
1084 " // continue on to allow drop..",
1087 " // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..",
1089 " \t\t// {parent}|{pos}|{prop}",
1092 " _this.model.dropNode(targetData, dropNode, show_templates);",
1093 " GLib.debug(\"ADD new node!!!\\n\");",
1095 " ///Xcls_DialogTemplateSelect.singleton().show( _this.model.file.palete(), node);",
1097 " Gtk.drag_finish (ctx, false, false,time);",
1106 " ( ctx, x, y, time) => {",
1107 " //Seed.print(\"TARGET: drag-drop\");",
1110 " var src = Gtk.drag_get_source_widget(ctx);",
1112 " if (src != this.el) {",
1116 " this.drag_in_motion = false; ",
1117 " // request data that will be recieved by the recieve... ",
1118 " Gtk.drag_get_data",
1120 " this.el, // will receive 'drag-data-received' signal ",
1121 " ctx, // represents the current state of the DnD ",
1122 " Gdk.Atom.intern(\"application/json\",true), // the target type we want ",
1123 " time // time stamp ",
1127 " // No target offered by source => error",
1133 " // handle drop around self..",
1137 " //print(\"GETTING POS\");",
1138 " var targetData = \"\";",
1140 " Gtk.TreePath path;",
1141 " Gtk.TreeViewDropPosition pos;",
1142 " var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);",
1144 " // if there are not items in the tree.. the we have to set isOver to true for anything..",
1145 " var isEmpty = false;",
1146 " if (_this.model.el.iter_n_children(null) < 1) {",
1147 " print(\"got NO children?\\n\");",
1148 " isOver = true; //??? ",
1150 " pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;",
1155 " //var action = Gdk.DragAction.COPY;",
1156 " // unless we are copying!!! ctl button..",
1158 " var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?",
1159 " Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;",
1160 " // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;",
1163 " if (_this.model.el.iter_n_children(null) < 1) {",
1164 " // no children.. -- asume it's ok..",
1166 " targetData = \"|%d|\".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);",
1168 " // continue through to allow drop...",
1176 " //print(\"ISOVER? \" + isOver);",
1179 " Gtk.drag_finish (ctx, false, false, time); // drop failed..",
1180 " return true; // not over apoint!?! - no action on drop or motion..",
1183 " // drag node is parent of child..",
1184 " //console.log(\"SRC TREEPATH: \" + src.treepath);",
1185 " //console.log(\"TARGET TREEPATH: \" + data.path.to_string());",
1187 " // nned to check a few here..",
1188 " //Gtk.TreeViewDropPosition.INTO_OR_AFTER",
1189 " //Gtk.TreeViewDropPosition.INTO_OR_BEFORE",
1190 " //Gtk.TreeViewDropPosition.AFTER",
1191 " //Gtk.TreeViewDropPosition.BEFORE",
1193 " // locally dragged items to not really use the ",
1194 " var selection_text = this.dragData;",
1198 " if (selection_text == null || selection_text.length < 1) {",
1199 " //print(\"Error - drag selection text returned NULL\");",
1201 " Gtk.drag_finish (ctx, false, false, time); // drop failed..",
1202 " return true; /// -- fixme -- this is not really correct..",
1205 " // see if we are dragging into ourself?",
1206 " print (\"got selection text of \" + selection_text);",
1208 " var target_path = path.to_string();",
1209 " //print(\"target_path=\"+target_path);",
1212 " if (selection_text == target_path) {",
1213 " print(\"self drag ?? == we should perhaps allow copy onto self..\\n\");",
1215 " Gtk.drag_finish (ctx, false, false, time); // drop failed..",
1217 " return true; /// -- fixme -- this is not really correct..",
1222 " //print(\"DUMPING DATA\");",
1223 " //console.dump(data);",
1226 " //print(data.path.to_string() +' => '+ data.pos);",
1228 " // dropList is a list of xtypes that this node could be dropped on.",
1229 " // it is set up when we start to drag..",
1232 " targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);",
1234 " print(\"targetDAta: \" + targetData +\"\\n\");",
1236 " if (targetData.length < 1) {",
1237 " //print(\"Can not find drop node path\");",
1239 " Gtk.drag_finish (ctx, false, false, time); // drop failed..",
1245 " // continue on to allow drop..",
1247 " // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..",
1250 " var delete_selection_data = false;",
1252 " if (action == Gdk.DragAction.ASK) {",
1253 " /* Ask the user to move or copy, then set the ctx action. */",
1256 " if (action == Gdk.DragAction.MOVE) {",
1257 " delete_selection_data = true;",
1260 " // drag around.. - reorder..",
1261 " _this.model.moveNode(targetData, action);",
1267 " // we can send stuff to souce here...",
1270 "// do we always say failure, so we handle the reall drop?",
1271 " Gtk.drag_finish (ctx, false, false,time); //delete_selection_data, time);",
1283 " (drag_context) => {",
1284 "\t//Seed.print('LEFT-TREE: drag-end');",
1285 " this.dragData = \"\";",
1286 " this.dropList = null;",
1287 "// this.targetData = \"\";",
1288 " this.highlightDropPath(\"\",0);",
1293 " ( ctx, x, y, time) => {",
1294 " print(\"got drag motion\\n\");",
1295 " var src = Gtk.drag_get_source_widget(ctx);",
1296 " this.drag_x = x;",
1297 " this.drag_y = y; ",
1299 " if (src != this.el) {",
1303 " // the point of this is to detect where an item could be dropped..",
1304 " print(\"requesting drag data\\n\");",
1305 " this.drag_in_motion = true;",
1307 " // request data that will be recieved by the recieve... ",
1308 " Gtk.drag_get_data",
1310 " this.el, // will receive 'drag-data-received' signal ",
1311 " ctx, // represents the current state of the DnD ",
1312 " Gdk.Atom.intern(\"STRING\",true), // the target type we want ",
1313 " time // time stamp ",
1319 " print(\"action: %d\\n\", ctx.get_actions());",
1320 " //print(\"GETTING POS\");",
1321 " var targetData = \"\";",
1323 " Gtk.TreePath path;",
1324 " Gtk.TreeViewDropPosition pos;",
1325 " var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);",
1327 " // if there are not items in the tree.. the we have to set isOver to true for anything..",
1328 " var isEmpty = false;",
1329 " if (_this.model.el.iter_n_children(null) < 1) {",
1330 " print(\"got NO children?\\n\");",
1331 " isOver = true; //??? ",
1333 " pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;",
1337 " // ------------- a drag from self..",
1340 " //var action = Gdk.DragAction.COPY;",
1341 " // unless we are copying!!! ctl button..",
1343 " var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?",
1344 " Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;",
1345 " // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;",
1348 " if (_this.model.el.iter_n_children(null) < 1) {",
1349 " // no children.. -- asume it's ok..",
1351 " targetData = \"|%d|\".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);",
1353 " this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0); ",
1354 " Gdk.drag_status(ctx, action ,time);",
1357 " // continue through to allow drop...",
1365 " //print(\"ISOVER? \" + isOver);",
1368 " Gdk.drag_status(ctx, 0 ,time);",
1369 " this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0); ",
1374 " // drag node is parent of child..",
1375 " //console.log(\"SRC TREEPATH: \" + src.treepath);",
1376 " //console.log(\"TARGET TREEPATH: \" + data.path.to_string());",
1378 " // nned to check a few here..",
1379 " //Gtk.TreeViewDropPosition.INTO_OR_AFTER",
1380 " //Gtk.TreeViewDropPosition.INTO_OR_BEFORE",
1381 " //Gtk.TreeViewDropPosition.AFTER",
1382 " //Gtk.TreeViewDropPosition.BEFORE",
1384 " // locally dragged items to not really use the ",
1385 " var selection_text = this.dragData;",
1389 " if (selection_text == null || selection_text.length < 1) {",
1390 " //print(\"Error - drag selection text returned NULL\");",
1391 " Gdk.drag_status(ctx, 0 ,time);",
1392 " this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);",
1397 " // see if we are dragging into ourself?",
1398 " var target_path = path.to_string(); ",
1399 " print (\"Drag %s onto %s--%d\\n \", selection_text, target_path, pos);",
1401 " // pos : 3 = ontop - 0 = after, 1 = before",
1402 " //print(\"target_path=\"+target_path);",
1405 " if (selection_text == target_path) {",
1406 " print(\"self drag ?? == we should perhaps allow copy onto self..\\n\");",
1408 " Gdk.drag_status(ctx, 0 ,time);",
1409 " this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);",
1411 "// -- fixme -- this is not really correct..",
1416 " //print(\"DUMPING DATA\");",
1417 " //console.dump(data);",
1420 " //print(data.path.to_string() +' => '+ data.pos);",
1422 " // dropList is a list of xtypes that this node could be dropped on.",
1423 " // it is set up when we start to drag..",
1426 " targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);",
1428 " print(\"targetDAta: \" + targetData +\"\\n\");",
1430 " if (targetData.length < 1) {",
1431 " //print(\"Can not find drop node path\");",
1433 " Gdk.drag_status(ctx, 0, time);",
1434 " this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);",
1438 " var td_ar = targetData.split(\"|\");",
1442 " Gdk.drag_status(ctx, action ,time);",
1443 " this.highlightDropPath(td_ar[0], (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));",
1449 "key_press_event" : [
1451 " this.key_is_pressed = true;",
1455 "key_release_event" : [
1457 " this.key_is_pressed = false;",
1463 "tooltip_column" : 1,
1464 "xtype" : "TreeView",
1465 "| void highlightDropPath" : [
1466 " ( string treepath, Gtk.TreeViewDropPosition pos) {",
1468 " // highlighting for drag/drop",
1469 " if (treepath.length > 0) {",
1470 " this.el.set_drag_dest_row( new Gtk.TreePath.from_string( treepath ), pos);",
1472 " this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);",
1477 "| void selectNode" : [
1478 "(string treepath_str, string source) {",
1479 "\tthis.lastEventSource = source;",
1480 " //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));",
1481 " var tp = new Gtk.TreePath.from_string(treepath_str);",
1483 " this.el.set_cursor(tp, null, false); ",
1484 " this.el.scroll_to_cell(tp, null, false, 0,0);",
1488 "| void setCursor" : [
1489 "(string treepath, string sourceEvent) {",
1490 "\tthis.lastEventSource = sourceEvent;",
1491 "\t//this.blockChanges = true; << block changes prevents loading of 'node data' and firing of node_selected..",
1492 " this.el.set_cursor(new Gtk.TreePath.from_string(treepath), null, false); ",
1493 " // fire node_selected..",
1494 " //this.blockChanges = false;",
1495 "\tthis.lastEventSource = \"\";",
1503 "id" : "LeftTreeMenu",
1508 "label" : "Delete Element",
1513 " print(\"ACTIVATE?\");",
1516 " _this.model.deleteSelected();",
1520 "xtype" : "MenuItem"
1525 "label" : "Save as Template",
1530 " DialogSaveTemplate.singleton().show(",
1531 " (Gtk.Window) _this.el.get_toplevel (), ",
1532 " _this.main_window.windowstate.file.palete(), ",
1533 " _this.getActiveElement()",
1540 "xtype" : "MenuItem"
1545 "label" : "Save as Module",
1549 " var node = _this.getActiveElement();",
1550 " var name = DialogSaveModule.singleton().show(",
1551 " (Gtk.Window) _this.el.get_toplevel (), ",
1552 " _this.main_window.windowstate.project, ",
1555 " if (name.length < 1) {",
1559 " node.props.set(\"* xinclude\", name);",
1560 " node.items.clear();",
1563 " var s = _this.view.el.get_selection();",
1565 " print(\"GET SELECTED?\");",
1566 " Gtk.TreeIter iter;",
1567 " Gtk.TreeModel mod;",
1570 " if (!s.get_selected(out mod, out iter)) {",
1571 " return; // nothing seleted..",
1573 " Gtk.TreeIter citer;",
1574 " var n_cn = mod.iter_n_children(iter) -1;",
1575 " for (var i = n_cn; i > -1; i--) {",
1576 " mod.iter_nth_child(out citer, iter, i);",
1579 " print(\"removing node from Tree\\n\"); ",
1581 " _this.model.el.remove(ref citer);",
1583 " _this.changed();",
1584 " _this.node_selected(node, \"tree\");",
1590 "xtype" : "MenuItem"
1596 "xtype" : "ScrolledWindow"
1600 "| JsRender.JsRender getActiveFile" : [
1602 " return this.main_window.windowstate.file;",
1606 "| JsRender.Node? getActiveElement" : [
1607 " () { // return path to actie node.",
1609 " var path = this.getActivePath();",
1610 " if (path.length < 1) {",
1613 " return _this.model.pathToNode(path);",
1618 "| string getActivePath" : [
1621 " var view = this.view.el;",
1622 " if (view.get_selection().count_selected_rows() < 1) {",
1625 " Gtk.TreeIter iter;",
1626 " Gtk.TreeModel mod;",
1627 " view.get_selection().get_selected(out mod, out iter);",
1628 " return mod.get_path(iter).to_string();",
1635 "name" : "WindowLeftTree",
1637 "path" : "/home/alan/gitlive/roobuilder/src/Builder4/WindowLeftTree.bjs",