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();",
543 " Gdk.Pixbuf pix = null,addi = null;",
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() : \"\";",
553 " var fn = \"/usr/share/glade/pixmaps/hicolor/16x16/actions/widget-gtk-\" + sub + \".png\";",
555 "\t\taddi = ic.load_icon(\"list-add\", 16,0);",
556 "\t\tif (FileUtils.test (fn, FileTest.IS_REGULAR)) {",
558 "\t\t \tpix = new Gdk.Pixbuf.from_file (fn);",
561 "\t\t \tpix = ic.load_icon(\"emblem-new\", 16,0);",
563 " \t} catch (GLib.Error e) {}",
565 " var fqn = node.fqn();",
566 " var cn = _this.main_window.windowstate.project.palete.getChildList(fqn);",
570 " \t\t0, node.nodeTitle(),",
571 " 1, node.nodeTip(), ",
574 " this.el.set_value(iter, 2,o);",
575 " this.el.set_value(iter, 3,pix); ",
576 " \tthis.el.set_value(iter, 4, cn.length > 0 ? addi : null); ",
582 "(Gee.ArrayList<JsRender.Node> tr, Gtk.TreeIter? iter) ",
586 " Gtk.TreeIter citer;",
587 " //this.insert(citer,iter,0);",
590 " for(var i =0 ; i < tr.size; i++) {",
591 " if (iter != null) {",
592 " this.el.insert(out citer,iter,-1); // why not append?",
594 " this.el.append(out citer,null);",
596 " this.iterSetValues(citer, tr.get(i));",
600 " if (tr.get(i).items.size > 0) {",
601 " this.load(tr.get(i).items, citer);",
609 "| void loadFile" : [
610 "(JsRender.JsRender f) {",
611 " //console.dump(f);",
613 " _this.main_window.windowstate.leftTreeNodeSelected(null, \"\");",
615 " _this.main_window.windowstate.file = f;",
618 " if (f.tree == null) {",
620 "\t f.loadItems( );",
621 " } catch (Error e) {",
625 " // if it's still null?",
626 " if (f.tree == null) {",
627 "\t\t_this.main_window.windowstate.showAddObject(_this.view.el);",
632 " var o = new Gee.ArrayList<JsRender.Node>();",
634 " this.load(o,null);",
636 " _this.view.el.expand_all();",
638 " if (f.tree.items.size < 1) {",
641 " //this.get('/Window.leftvpaned').el.set_position(80);",
642 " // select first...",
643 " _this.view.el.set_cursor( ",
644 " new Gtk.TreePath.from_string(\"0\"), null, false);",
648 " //this.get('/Window.leftvpaned').el.set_position(200);",
652 " while (Gtk.events_pending()) {",
653 " Gtk.main_iteration();",
656 " _this.maincol.el.set_max_width(_this.viewwin.el.get_allocated_width() - 32);",
666 "| void moveNode" : [
667 "(string target_data, Gdk.DragAction action) ",
670 " /// target_data = \"path|pos\");",
673 " //print(\"MOVE NODE\");",
674 " // console.dump(target_data);",
675 " Gtk.TreeIter old_iter;",
676 " Gtk.TreeModel mod;",
678 " var s = _this.view.el.get_selection();",
679 " s.get_selected(out mod , out old_iter);",
680 " mod.get_path(old_iter);",
682 " var node = this.pathToNode(mod.get_path(old_iter).to_string());",
683 " //console.dump(node);",
684 " if (node == null) {",
685 " GLib.debug(\"moveNode: ERROR - node is null?\");",
690 " // needs to drop first, otherwise the target_data ",
691 " // treepath will be invalid.",
694 " if ((action & Gdk.DragAction.MOVE) > 0) {",
695 " GLib.debug(\"REMOVING OLD NODE : \" + target_data + \"\\n\");",
697 " this.dropNode(target_data, node, false);",
698 " this.el.remove(ref old_iter);",
703 " GLib.debug(\"DROPPING NODE // copy: \" + target_data + \"\\n\");",
704 " node = node.deepClone();",
705 " this.dropNode(target_data, node, false);",
708 " this.activePath= \"\";",
709 " //this.updateNode(false,true);",
713 "| void updateSelected" : [
717 " var s = _this.view.el.get_selection();",
719 " Gtk.TreeIter iter;",
720 " Gtk.TreeModel mod;",
724 " if (!s.get_selected(out mod, out iter)) {",
725 " return; // nothing seleted..",
728 " GLib.Value value;",
729 " this.el.get_value(iter, 2, out value);",
730 " var node = (JsRender.Node)(value.get_object());",
732 " this.el.set(iter, 0, node.nodeTitle(),",
733 " 1, node.nodeTip(), -1",
740 "$ Gtk.TreeViewColumnSizing sizing" : "Gtk.TreeViewColumnSizing.FIXED",
743 " this.el.add_attribute(_this.renderer.el , \"markup\", 0 );",
744 " this.el.add_attribute(_this.iconrender.el , \"pixbuf\", 3 );",
747 "* pack" : "append_column",
748 "bool expand" : true,
749 "bool resizable" : true,
754 "* pack" : "pack_start,false",
757 "xtype" : "CellRendererPixbuf"
761 "* pack" : "pack_start,true",
763 "xtype" : "CellRendererText"
766 "utf8 title" : "Node",
767 "xtype" : "TreeViewColumn"
770 "$ Gtk.TreeViewColumnSizing sizing" : "Gtk.TreeViewColumnSizing.FIXED",
773 " this.el.add_attribute(_this.addiconrender.el , \"pixbuf\", 4 );",
776 "* pack" : "append_column",
777 "bool expand" : false,
778 "int max_width" : 24,
782 "* pack" : "pack_start,true",
783 "id" : "addiconrender",
785 "xtype" : "CellRendererPixbuf"
788 "utf8 title" : "Add",
789 "xtype" : "TreeViewColumn"
793 "button_press_event" : [
795 " //console.log(\"button press?\");",
796 " this.button_is_pressed = true;",
797 " print(\"BUTTON DOWN\\n\");",
799 " this.lastEventSource = \"tree\";",
800 " if (! _this.before_node_change() ) {",
805 "\tif (ev.type != Gdk.EventType.BUTTON_PRESS) {",
808 " if (_this.model.el.iter_n_children(null) < 1) {",
809 "\t _this.main_window.windowstate.showAddObject(_this.view.el);",
814 " Gtk.TreePath res;",
815 " Gtk.TreeViewColumn col;",
816 " if (!_this.view.el.get_path_at_pos((int)ev.x,(int)ev.y, out res, out col, null, null) ) {",
820 " if (col.title == \"Add\") {",
821 " \t\tGLib.Value value;",
822 " \t\tGtk.TreeIter iter;",
824 "\t\t_this.model.el.get_iter (out iter, res);",
825 " _this.model.el.get_value(iter, 2, out value);\t\t",
826 " // why dup_ - gets and and inc's ref count (which in theory should be freed at the end.?",
828 " var node = (JsRender.Node)value.dup_object();",
829 " var fqn = node.fqn();",
830 " \tvar cn = _this.main_window.windowstate.project.palete.getChildList(fqn);",
831 " \t\tif (cn.length < 1) {",
832 " \t\t\treturn true;",
835 " _this.main_window.windowstate.leftTreeBeforeChange();",
836 " this.el.get_selection().select_path(res);",
837 " \t_this.main_window.windowstate.showAddObject(this.el);",
841 "\tif ( ev.button != 3) {",
842 " //print(\"click\" + ev.type);",
845 " _this.main_window.windowstate.leftTreeBeforeChange();",
849 " this.el.get_selection().select_path(res);",
853 " //if (!this.get('/LeftTreeMenu').el) { ",
854 " // this.get('/LeftTreeMenu').init(); ",
857 " _this.LeftTreeMenu.el.set_screen(Gdk.Screen.get_default());",
858 " _this.LeftTreeMenu.el.show_all();",
859 " _this.LeftTreeMenu.el.popup(null, null, null, 3, ev.time);",
860 " // print(\"click:\" + res.path.to_string());",
864 "button_release_event" : [
866 " this.button_is_pressed = false;",
872 " print(\"LEFT TREE Cursor Changed\\n\");",
873 "\t//if (!this.button_is_pressed && !this.key_is_pressed) {",
874 "\t\t// then event was started by some other action",
875 "\t\t// which should manually trigger all the events..",
876 "\t//\tprint(\"SKIPPING select - no button or key pressed\\n\");",
881 " if (this.blockChanges) { // probably not needed.. ",
882 "\t\tprint(\"SKIPPING select - blockchanges set..\\n\"); ",
885 " if (!_this.before_node_change( ) ) {",
886 "\t this.blockChanges = true;",
887 "\t this.el.get_selection().unselect_all();",
888 "\t this.blockChanges = false;",
892 " if (_this.main_window.windowstate.file == null) {",
893 " \t\tprint(\"SKIPPING select windowstate file is not set...\\n\"); ",
897 " //var render = this.get('/LeftTree').getRenderer(); ",
898 " print(\"LEFT TREE -> view -> selection changed called\\n\");",
901 " // -- it appears that the selection is not updated.",
903 " GLib.Timeout.add_full(GLib.Priority.DEFAULT,10 , () => {",
904 " print(\"LEFT TREE -> view -> selection changed TIMEOUT CALLED\\n\");",
906 " if (this.el.get_selection().count_selected_rows() < 1) {",
908 " print(\"selected rows < 1\\n\");",
909 " //??this.model.load( false);",
910 " _this.node_selected(null, this.lastEventSource);",
915 " //console.log('changed');",
916 " var s = this.el.get_selection();",
917 " Gtk.TreeIter iter;",
918 " Gtk.TreeModel mod;",
919 " s.get_selected(out mod, out iter);",
922 " // var val = \"\";",
923 " GLib.Value value;",
924 " _this.model.el.get_value(iter, 2, out value);",
925 " _this.model.activePath = mod.get_path(iter).to_string();",
929 " var node = (JsRender.Node)value.dup_object();",
930 " print (\"calling left_tree.node_selected\\n\");",
931 " _this.node_selected(node, this.lastEventSource);",
932 " while (Gtk.events_pending()) {",
933 " Gtk.main_iteration();",
935 " var cp = mod.get_path(iter);",
936 " Gtk.TreePath sp, ep;",
937 " this.el.get_visible_range(out sp, out ep);",
938 " // if sp is before cp then retuns 1.",
939 " // if cp is before ep then retuns 1.",
940 " if (cp.compare(sp) >= 0 && ep.compare(cp) >=1) {",
946 " this.el.scroll_to_cell(new Gtk.TreePath.from_string(_this.model.activePath), null, true, 0.1f,0.0f);",
950 " //_this.after_node_change(node);",
952 "// _this.model.file.changed(node, \"tree\");",
954 " //Seed.print( value.get_string());",
961 "\t//print('SOURCE: drag-begin');",
964 " //this.targetData = \"\";",
966 " // find what is selected in our tree...",
968 " var s = _this.view.el.get_selection();",
969 " if (s.count_selected_rows() < 1) {",
972 " Gtk.TreeIter iter;",
973 " Gtk.TreeModel mod;",
974 " s.get_selected(out mod, out iter);",
978 " // set some properties of the tree for use by the dropped element.",
979 " GLib.Value value;",
980 " _this.model.el.get_value(iter, 2, out value);",
981 " var tp = mod.get_path(iter).to_string();",
982 " var data = (JsRender.Node)(value.dup_object());",
983 " var xname = data.fqn();",
984 " print (\"XNAME IS \" + xname+ \"\\n\");",
985 " this.dragData = tp;",
986 " this.dropList = _this.main_window.windowstate.file.palete().getDropList(xname);",
988 " print (\"DROP LIST IS \" + string.joinv(\", \", this.dropList) + \"\\n\");",
991 " // make the drag icon a picture of the node that was selected",
994 " // by default returns the path..",
995 " var path = _this.model.el.get_path(iter);",
998 " var pix = this.el.create_row_drag_icon ( path);",
1000 " Gtk.drag_set_icon_surface (ctx, pix) ;",
1006 "( drag_context, data, info, time) => {",
1009 "\t//print(\"drag-data-get\");",
1010 "\tvar s = this.el.get_selection();",
1011 "\tif (s.count_selected_rows() < 1) {",
1012 "\t\tdata.set_text(\"\",0); ",
1013 "\t\t print(\"return empty string - no selection..\");",
1017 "\tGtk.TreeIter iter;",
1018 "\tGtk.TreeModel mod;",
1020 "\ts.get_selected(out mod, out iter);",
1024 "\tGLib.Value value;",
1025 "\t_this.model.el.get_value(iter, 2, out value);",
1026 "\tvar ndata = (JsRender.Node)(value.dup_object());",
1030 "\tvar tp = mod.get_path(iter).to_string();",
1031 "\t// by default returns the path..",
1033 "\tif ( info != Gdk.Atom.intern(\"STRING\",true) ) {",
1034 "\t\ttp = ndata.toJsonString();",
1037 "\t//data.set_text(tp,tp.length); ",
1039 "\tdata.set (data.get_target (), 8, (uchar[]) tp.to_utf8 ());",
1042 "\t// print(\"return \" + tp);",
1045 "drag_data_received" : [
1046 "\t(ctx, x, y, sel, info, time) => {",
1048 "\t// THIS CODE ONLY RELATES TO drag or drop of \"NEW\" elements or \"FROM another tree..\"",
1051 "\t// print(\"Tree: drag-data-received\\n\");",
1052 "\tvar selection_text = (string)sel.get_data();",
1053 "\t//print(\"selection_text= %s\\n\",selection_text);",
1055 "\tvar is_drag = this.drag_in_motion;",
1059 "\tGLib.debug(\"Is Drag %s\\n\", is_drag ? \"Y\": \"N\");",
1060 "\tvar targetData = \"\";",
1062 "\tGtk.TreePath path;",
1063 "\tGtk.TreeViewDropPosition pos;",
1064 "\tvar isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);",
1066 "\t// if there are not items in the tree.. the we have to set isOver to true for anything..",
1067 "\tvar isEmpty = false;",
1068 "\tif (_this.model.el.iter_n_children(null) < 1) {",
1069 "\t\tGLib.debug(\"got NO children?\\n\");",
1070 "\t\tisOver = true; //??? ",
1071 "\t\tisEmpty = true;",
1072 "\t\tpos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;",
1076 "\t//console.log(\"LEFT-TREE: drag-motion\");",
1077 "\tvar src = Gtk.drag_get_source_widget(ctx);",
1079 "\t// a drag from self - this should be handled by drop and motion.",
1080 "\tif (src == this.el) {",
1081 "\t\tGLib.debug(\"Source == this element should not happen.. ? \\n\");",
1084 "\t//print(\"drag_data_recieved from another element\");",
1089 "\tif (selection_text == null || selection_text.length < 1 || !isOver) {",
1090 "\t\t// nothing valid foudn to drop...",
1091 "\t\t GLib.debug(\"empty sel text or not over\");",
1092 "\t\tif (is_drag) {",
1093 "\t\t Gdk.drag_status(ctx, 0, time);",
1094 "\t\t this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);",
1097 "\t\tGtk.drag_finish (ctx, false, false, time); // drop failed..",
1098 "\t\t// no drop action...",
1102 "\tvar dropNode = new JsRender.Node(); ",
1104 "\tvar dropNodeType = selection_text;",
1105 "\tvar show_templates = true;",
1107 "\tif (dropNodeType[0] == '{') {",
1108 "\t\tvar pa = new Json.Parser();",
1110 "\t\t pa.load_from_data(dropNodeType);",
1111 "\t\t} catch (Error e) {",
1112 "\t\t Gtk.drag_finish (ctx, false, false, time); // drop failed..",
1113 "\t\t // no drop action...",
1117 "\t\tdropNode.loadFromJson( pa.get_root().get_object(), 2);",
1118 "\t\tdropNodeType = dropNode.fqn();",
1119 "\t\tshow_templates = false;",
1123 "\t\t// drop with property.",
1124 "\t\tif (selection_text.contains(\":\")) {",
1125 "\t\t\tvar bits = selection_text.split(\":\");",
1126 "\t\t dropNode.setFqn(bits[0]);",
1127 "\t\t dropNode.set_prop(new JsRender.NodeProp.special(\"prop\", bits[1]));",
1132 "\t\t dropNode.setFqn(selection_text);",
1137 "\t// dropList --- need to gather this ... ",
1138 "\tGLib.debug(\"get dropList for : %s\\n\",dropNodeType); ",
1139 "\tvar dropList = _this.main_window.windowstate.file.palete().getDropList(dropNodeType);",
1141 "\tGLib.debug(\"dropList: %s\\n\", string.joinv(\" , \", dropList));",
1143 "\t// if drag action is link ... then we can drop it anywahere...",
1144 "\t if ((ctx.get_actions() & Gdk.DragAction.LINK) > 0) {",
1145 "\t\t // if path is null?? dragging into an empty tree?",
1146 "\t\t targetData = (path == null ? \"\" : path.to_string()) + \"|%d\".printf((int)pos);",
1150 "\t\ttargetData = _this.model.findDropNodeByPath( isEmpty ? \"\" : path.to_string(), dropList, pos);",
1155 "\tGLib.debug(\"targetDAta: %s\", targetData );",
1157 "\tif (targetData.length < 1) {",
1159 "\t\t// invalid drop path..",
1160 "\t\tif (this.drag_in_motion) {",
1161 "\t\t Gdk.drag_status(ctx, 0, time);",
1162 "\t\t this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);",
1165 "\t\tGtk.drag_finish (ctx, false, false, time); // drop failed..",
1166 "\t\t// no drop action...",
1172 "\t var td_ar = targetData.split(\"|\");",
1175 "\tif (this.drag_in_motion) { ",
1176 "\t\tGdk.drag_status(ctx, Gdk.DragAction.COPY ,time);",
1178 "\t\tthis.highlightDropPath( td_ar[0] , (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));",
1181 "\t// continue on to allow drop..",
1184 "\t// at this point, drag is not in motion... -- as checked above... - so it's a real drop event..",
1186 "\t// {parent}|{pos}|{prop}",
1189 " _this.model.dropNode(targetData, dropNode, show_templates);",
1191 "\tGLib.debug(\"ADD new node!!!\\n\");",
1193 "\t///Xcls_DialogTemplateSelect.singleton().show( _this.model.file.palete(), node);",
1195 "\tGtk.drag_finish (ctx, false, false,time);",
1204 " ( ctx, x, y, time) => {",
1205 " //Seed.print(\"TARGET: drag-drop\");",
1208 " var src = Gtk.drag_get_source_widget(ctx);",
1210 " if (src != this.el) {",
1214 " this.drag_in_motion = false; ",
1215 " // request data that will be recieved by the recieve... ",
1216 " Gtk.drag_get_data",
1218 " this.el, // will receive 'drag-data-received' signal ",
1219 " ctx, // represents the current state of the DnD ",
1220 " Gdk.Atom.intern(\"application/json\",true), // the target type we want ",
1221 " time // time stamp ",
1225 " // No target offered by source => error",
1231 " // handle drop around self..",
1235 " //print(\"GETTING POS\");",
1236 " var targetData = \"\";",
1238 " Gtk.TreePath path;",
1239 " Gtk.TreeViewDropPosition pos;",
1240 " var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);",
1242 " // if there are not items in the tree.. the we have to set isOver to true for anything..",
1243 " var isEmpty = false;",
1244 " if (_this.model.el.iter_n_children(null) < 1) {",
1245 " print(\"got NO children?\\n\");",
1246 " isOver = true; //??? ",
1248 " pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;",
1253 " //var action = Gdk.DragAction.COPY;",
1254 " // unless we are copying!!! ctl button..",
1256 " var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?",
1257 " Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;",
1258 " // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;",
1261 " if (_this.model.el.iter_n_children(null) < 1) {",
1262 " // no children.. -- asume it's ok..",
1264 " targetData = \"|%d|\".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);",
1266 " // continue through to allow drop...",
1274 " //print(\"ISOVER? \" + isOver);",
1277 " Gtk.drag_finish (ctx, false, false, time); // drop failed..",
1278 " return true; // not over apoint!?! - no action on drop or motion..",
1281 " // drag node is parent of child..",
1282 " //console.log(\"SRC TREEPATH: \" + src.treepath);",
1283 " //console.log(\"TARGET TREEPATH: \" + data.path.to_string());",
1285 " // nned to check a few here..",
1286 " //Gtk.TreeViewDropPosition.INTO_OR_AFTER",
1287 " //Gtk.TreeViewDropPosition.INTO_OR_BEFORE",
1288 " //Gtk.TreeViewDropPosition.AFTER",
1289 " //Gtk.TreeViewDropPosition.BEFORE",
1291 " // locally dragged items to not really use the ",
1292 " var selection_text = this.dragData;",
1296 " if (selection_text == null || selection_text.length < 1) {",
1297 " //print(\"Error - drag selection text returned NULL\");",
1299 " Gtk.drag_finish (ctx, false, false, time); // drop failed..",
1300 " return true; /// -- fixme -- this is not really correct..",
1303 " // see if we are dragging into ourself?",
1304 " print (\"got selection text of \" + selection_text);",
1306 " var target_path = path.to_string();",
1307 " //print(\"target_path=\"+target_path);",
1310 " if (selection_text == target_path) {",
1311 " print(\"self drag ?? == we should perhaps allow copy onto self..\\n\");",
1313 " Gtk.drag_finish (ctx, false, false, time); // drop failed..",
1315 " return true; /// -- fixme -- this is not really correct..",
1320 " //print(\"DUMPING DATA\");",
1321 " //console.dump(data);",
1324 " //print(data.path.to_string() +' => '+ data.pos);",
1326 " // dropList is a list of xtypes that this node could be dropped on.",
1327 " // it is set up when we start to drag..",
1330 " targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);",
1332 " print(\"targetDAta: \" + targetData +\"\\n\");",
1334 " if (targetData.length < 1) {",
1335 " //print(\"Can not find drop node path\");",
1337 " Gtk.drag_finish (ctx, false, false, time); // drop failed..",
1343 " // continue on to allow drop..",
1345 " // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..",
1348 " var delete_selection_data = false;",
1350 " if (action == Gdk.DragAction.ASK) {",
1351 " /* Ask the user to move or copy, then set the ctx action. */",
1354 " if (action == Gdk.DragAction.MOVE) {",
1355 " delete_selection_data = true;",
1358 " // drag around.. - reorder..",
1359 " _this.model.moveNode(targetData, action);",
1365 " // we can send stuff to souce here...",
1368 "// do we always say failure, so we handle the reall drop?",
1369 " Gtk.drag_finish (ctx, false, false,time); //delete_selection_data, time);",
1381 " (drag_context) => {",
1382 "\t//Seed.print('LEFT-TREE: drag-end');",
1383 " this.dragData = \"\";",
1384 " this.dropList = null;",
1385 "// this.targetData = \"\";",
1386 " this.highlightDropPath(\"\",0);",
1391 " ( ctx, x, y, time) => {",
1392 " print(\"got drag motion\\n\");",
1393 " var src = Gtk.drag_get_source_widget(ctx);",
1394 " this.drag_x = x;",
1395 " this.drag_y = y; ",
1397 " if (src != this.el) {",
1401 " // the point of this is to detect where an item could be dropped..",
1402 " print(\"requesting drag data\\n\");",
1403 " this.drag_in_motion = true;",
1405 " // request data that will be recieved by the recieve... ",
1406 " Gtk.drag_get_data",
1408 " this.el, // will receive 'drag-data-received' signal ",
1409 " ctx, // represents the current state of the DnD ",
1410 " Gdk.Atom.intern(\"STRING\",true), // the target type we want ",
1411 " time // time stamp ",
1417 " print(\"action: %d\\n\", ctx.get_actions());",
1418 " //print(\"GETTING POS\");",
1419 " var targetData = \"\";",
1421 " Gtk.TreePath path;",
1422 " Gtk.TreeViewDropPosition pos;",
1423 " var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);",
1425 " // if there are not items in the tree.. the we have to set isOver to true for anything..",
1426 " var isEmpty = false;",
1427 " if (_this.model.el.iter_n_children(null) < 1) {",
1428 " print(\"got NO children?\\n\");",
1429 " isOver = true; //??? ",
1431 " pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;",
1435 " // ------------- a drag from self..",
1438 " //var action = Gdk.DragAction.COPY;",
1439 " // unless we are copying!!! ctl button..",
1441 " var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?",
1442 " Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;",
1443 " // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;",
1446 " if (_this.model.el.iter_n_children(null) < 1) {",
1447 " // no children.. -- asume it's ok..",
1449 " targetData = \"|%d|\".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);",
1451 " this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0); ",
1452 " Gdk.drag_status(ctx, action ,time);",
1455 " // continue through to allow drop...",
1463 " //print(\"ISOVER? \" + isOver);",
1466 " Gdk.drag_status(ctx, 0 ,time);",
1467 " this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0); ",
1472 " // drag node is parent of child..",
1473 " //console.log(\"SRC TREEPATH: \" + src.treepath);",
1474 " //console.log(\"TARGET TREEPATH: \" + data.path.to_string());",
1476 " // nned to check a few here..",
1477 " //Gtk.TreeViewDropPosition.INTO_OR_AFTER",
1478 " //Gtk.TreeViewDropPosition.INTO_OR_BEFORE",
1479 " //Gtk.TreeViewDropPosition.AFTER",
1480 " //Gtk.TreeViewDropPosition.BEFORE",
1482 " // locally dragged items to not really use the ",
1483 " var selection_text = this.dragData;",
1487 " if (selection_text == null || selection_text.length < 1) {",
1488 " //print(\"Error - drag selection text returned NULL\");",
1489 " Gdk.drag_status(ctx, 0 ,time);",
1490 " this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);",
1495 " // see if we are dragging into ourself?",
1496 " var target_path = path.to_string(); ",
1497 " print (\"Drag %s onto %s--%d\\n \", selection_text, target_path, pos);",
1499 " // pos : 3 = ontop - 0 = after, 1 = before",
1500 " //print(\"target_path=\"+target_path);",
1503 " if (selection_text == target_path) {",
1504 " print(\"self drag ?? == we should perhaps allow copy onto self..\\n\");",
1506 " Gdk.drag_status(ctx, 0 ,time);",
1507 " this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);",
1509 "// -- fixme -- this is not really correct..",
1514 " //print(\"DUMPING DATA\");",
1515 " //console.dump(data);",
1518 " //print(data.path.to_string() +' => '+ data.pos);",
1520 " // dropList is a list of xtypes that this node could be dropped on.",
1521 " // it is set up when we start to drag..",
1524 " targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);",
1526 " print(\"targetDAta: \" + targetData +\"\\n\");",
1528 " if (targetData.length < 1) {",
1529 " //print(\"Can not find drop node path\");",
1531 " Gdk.drag_status(ctx, 0, time);",
1532 " this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);",
1536 " var td_ar = targetData.split(\"|\");",
1540 " Gdk.drag_status(ctx, action ,time);",
1541 " this.highlightDropPath(td_ar[0], (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));",
1547 "key_press_event" : [
1549 " this.key_is_pressed = true;",
1553 "key_release_event" : [
1555 " this.key_is_pressed = false;",
1561 "tooltip_column" : 1,
1562 "xtype" : "TreeView",
1563 "| void highlightDropPath" : [
1564 " ( string treepath, Gtk.TreeViewDropPosition pos) {",
1566 " // highlighting for drag/drop",
1567 " if (treepath.length > 0) {",
1568 " this.el.set_drag_dest_row( new Gtk.TreePath.from_string( treepath ), pos);",
1570 " this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);",
1575 "| void selectNode" : [
1576 "(string treepath_str, string source) {",
1577 "\tthis.lastEventSource = source;",
1578 " //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));",
1579 " var tp = new Gtk.TreePath.from_string(treepath_str);",
1581 " this.el.set_cursor(tp, null, false); ",
1582 " this.el.scroll_to_cell(tp, null, false, 0,0);",
1586 "| void setCursor" : [
1587 "(string treepath, string sourceEvent) {",
1588 "\tthis.lastEventSource = sourceEvent;",
1589 "\t//this.blockChanges = true; << block changes prevents loading of 'node data' and firing of node_selected..",
1590 " this.el.set_cursor(new Gtk.TreePath.from_string(treepath), null, false); ",
1591 " // fire node_selected..",
1592 " //this.blockChanges = false;",
1593 "\tthis.lastEventSource = \"\";",
1601 "id" : "LeftTreeMenu",
1606 "label" : "Delete Element",
1611 " print(\"ACTIVATE?\");",
1614 " _this.model.deleteSelected();",
1618 "xtype" : "MenuItem"
1623 "label" : "Save as Template",
1628 " DialogSaveTemplate.singleton().show(",
1629 " (Gtk.Window) _this.el.get_toplevel (), ",
1630 " _this.main_window.windowstate.file.palete(), ",
1631 " _this.getActiveElement()",
1638 "xtype" : "MenuItem"
1643 "label" : "Save as Module",
1647 " var node = _this.getActiveElement();",
1648 " var name = DialogSaveModule.singleton().show(",
1649 " (Gtk.Window) _this.el.get_toplevel (), ",
1650 " _this.main_window.windowstate.project, ",
1653 " if (name.length < 1) {",
1657 " node.set_prop( new JsRender.NodeProp.special(\"xinclude\", name));",
1658 " node.items.clear();",
1661 " var s = _this.view.el.get_selection();",
1663 " print(\"GET SELECTED?\");",
1664 " Gtk.TreeIter iter;",
1665 " Gtk.TreeModel mod;",
1668 " if (!s.get_selected(out mod, out iter)) {",
1669 " return; // nothing seleted..",
1671 " Gtk.TreeIter citer;",
1672 " var n_cn = mod.iter_n_children(iter) -1;",
1673 " for (var i = n_cn; i > -1; i--) {",
1674 " mod.iter_nth_child(out citer, iter, i);",
1677 " print(\"removing node from Tree\\n\"); ",
1679 " _this.model.el.remove(ref citer);",
1681 " _this.changed();",
1682 " _this.node_selected(node, \"tree\");",
1688 "xtype" : "MenuItem"
1696 "(allocation) => {",
1699 "\t//GLib.debug(\"Got allocation width of scrolled view %d\", allocation.width );",
1700 "\t_this.maincol.el.set_max_width(allocation.width - 32);",
1705 "xtype" : "ScrolledWindow"
1709 "| JsRender.JsRender getActiveFile" : [
1711 " return this.main_window.windowstate.file;",
1715 "| JsRender.Node? getActiveElement" : [
1716 " () { // return path to actie node.",
1718 " var path = this.getActivePath();",
1719 " if (path.length < 1) {",
1722 " return _this.model.pathToNode(path);",
1727 "| string getActivePath" : [
1730 " var view = this.view.el;",
1731 " if (view.get_selection().count_selected_rows() < 1) {",
1734 " Gtk.TreeIter iter;",
1735 " Gtk.TreeModel mod;",
1736 " view.get_selection().get_selected(out mod, out iter);",
1737 " return mod.get_path(iter).to_string();",
1744 "name" : "WindowLeftTree",
1746 "path" : "/home/alan/gitlive/roobuilder/src/Builder4/WindowLeftTree.bjs",