2 "build_module" : "builder",
5 "# Xcls_MainWindow main_window" : "null",
8 "@ bool before_node_change" : "()",
9 "@ void changed" : "()",
10 "@ void node_selected" : "(JsRender.Node? node, string source)",
11 "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
12 "id" : "WindowLeftTree",
17 " this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);",
22 "Gtk.ShadowType shadow_type" : "Gtk.ShadowType.IN",
26 "# bool blockChanges" : false,
27 "# bool drag_in_motion" : "",
30 "# string dragData" : "",
31 "# string[] dropList" : "",
32 "$ enable_tree_lines" : true,
33 "$ string lastEventSource" : "\"\"",
37 " var description = new Pango.FontDescription();",
38 " description.set_size(8000);",
39 " this.el.override_font(description);",
41 " var selection = this.el.get_selection();",
42 " selection.set_mode( Gtk.SelectionMode.SINGLE);",
45 " // is this really needed??",
47 " this.selection.signal['changed'].connect(function() {",
48 "\t _this.get('/LeftTree.view').listeners.cursor_changed.apply(",
49 "\t _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']",
53 " Gtk.drag_source_set (",
54 "\t this.el, /* widget will be drag-able */",
55 "\t Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */",
56 "\t BuilderApplication.targetList, /* lists of target to support */",
57 "\t Gdk.DragAction.COPY | Gdk.DragAction.MOVE | Gdk.DragAction.LINK /* what to do with data after dropped */",
61 " //Gtk.drag_source_add_text_targets(this.el); ",
65 " this.el, /* widget that will accept a drop */",
66 " Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,",
67 " BuilderApplication.targetList, /* lists of target to support */",
68 " Gdk.DragAction.COPY | Gdk.DragAction.MOVE | Gdk.DragAction.LINK /* what to do with data after dropped */",
71 " //Gtk.drag_dest_set_target_list(this.el, Builder.Application.targetList);",
72 " //Gtk.drag_dest_add_text_targets(this.el);",
81 "Boolean id" : "view",
82 "bool button_is_pressed" : false,
84 "bool headers_visible" : false,
85 "bool key_is_pressed" : false,
88 "# DialogTemplateSelect template_select" : "null",
89 "# string activePath" : "\"\"",
94 "typeof(Gdk.Pixbuf),",
99 " var s = this.get('/LeftTree.view').selection;",
100 " print (\"LIST ALL TYPES: \" + s.count_selected_rows() );",
102 " if (s.count_selected_rows() > 0) {",
103 " var iter = new Gtk.TreeIter(); ",
104 " s.get_selected(this.el, iter);",
106 " // set some properties of the tree for use by the dropped element.",
107 " var value = new GObject.Value('');",
108 " this.el.get_value(iter, 2, value);",
109 " var data = JSON.parse(value.value);",
112 " var xname = this.get('/LeftTree.model').file.guessName(data);",
113 " console.log('selected:' + xname);",
114 " if (xname.length) {",
115 " return [ xname ];",
117 " return []; // could not find it..",
122 " var _this = this;",
123 " function addall(li)",
125 " li.forEach(function(el) {",
126 " // this is specific to roo!!!?",
127 " if (!el) { // skip empty?",
130 " var fullpath = _this.file.guessName(el);",
131 " if (fullpath.length && ret.indexOf(fullpath) < 0) {",
132 " ret.push(fullpath);",
136 " if (el.items && el.items.length) {",
137 " addall(el.items);",
145 " addall([this.currentTree]);",
147 " // only if we have nothing, should we add '*top'",
148 " if (!ret.length) {",
149 " ret = [ '*top' ];",
151 " //console.log('all types in tree');",
152 " //console.dump(ret);",
161 "print(\"model initialized\");",
165 "* pack" : "set_model",
166 "currentTree" : false,
169 "xtype" : "TreeStore",
170 "| JsRender.Node pathToNode" : [
174 " Gtk.TreeIter iter;",
175 " _this.model.el.get_iter_from_string(out iter, path);",
177 " GLib.Value value;",
178 " _this.model.el.get_value(iter, 2, out value);",
180 " return (JsRender.Node)value.dup_object();",
184 "| string findDropNode" : [
185 " (string treepath_str, string[] targets) {",
187 " // this is used by the dragdrop code in the roo version AFAIR..",
189 " //var path = treepath_str.replace(/^builder-/, '');",
190 " // treemap is depreciated... - should really check if model has any entries..",
192 " if (this.el.iter_n_children(null) < 1) {",
193 " //print(\"NO KEYS\");",
194 " return \"|%d\".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);",
196 " //print(\"FIND treepath: \" + path);",
197 " //console.dump(this.treemap);",
199 " //if (!treepath_str.match(/^builder-/)) {",
200 " // return []; // nothing!",
202 " if (targets.length > 0 && targets[0] == \"*\") {",
203 " return treepath_str;",
205 " return this.findDropNodeByPath(treepath_str,targets, -1);",
209 "| string findDropNodeByPath" : [
210 " (string treepath_str, string[] targets, int in_pref = -1) {",
212 " var path = treepath_str; // dupe it..",
215 " // pref : 3 = ontop - 0 = after, 1 = before",
216 " int pref = in_pref < 0 ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : in_pref;",
220 " //console.dump(this.treemap);",
222 " print(\"findDropNodeByPath : got path length %d / %s\\n\", path.length, path);",
224 " if (path.length == 0) {",
225 " // top drop. // just return empty..",
226 " return \"|%d\".printf((int)pref) ;",
231 " while (path.length > 0) {",
233 " if (path.length == treepath_str.length && pref != Gtk.TreeViewDropPosition.INTO_OR_AFTER) {",
234 " if (path.last_index_of(\":\") < 0 ) {",
237 " path = path.substring(0, path.last_index_of(\":\"));",
238 " last = treepath_str;",
239 " print(\"DROP before or after : using %s\\n\",path);",
243 " //print(\"LOOKING FOR PATH: \" + path);",
244 " var node_data = this.pathToNode(path);",
246 " if (node_data == null) {",
247 " print(\"node not found\");",
251 " var xname = node_data.fqn();",
252 " var match = \"\";",
255 " for (var i =0; i < targets.length; i++) {",
256 " var tg = targets[i];",
257 " if ((tg == xname) ) {",
261 " // if target is \"xxxx:name\"",
262 " if (tg.contains(xname +\":\")) {",
264 " var ar = tg.split(\":\");",
270 " if (match.length > 0) {",
271 " if (last.length > 0) { // pref is after/before..",
272 " // then it's after last",
273 " //if (pref > 1) {",
276 " return last + \"|%d\".printf((int)pref) + \"|\" + prop;",
280 " // we need to add prop - as :store -> needs to bee added when dropping onto.",
281 " return path + \"|%d\".printf( (int) Gtk.TreeViewDropPosition.INTO_OR_AFTER) + \"|\" + prop;",
284 " last = \"\" + path;",
285 " var par = path.split(\":\");",
286 " string [] ppar = {};",
287 " for (var i = 0; i < par.length-1; i++) {",
291 " path = string.joinv(\":\", ppar);",
302 "| string treePathFromNode" : [
303 "(JsRender.Node node) {",
304 " // iterate through the tree and find the node",
307 " this.el.foreach((mod, pth, iter) => {",
308 " // get the node..",
311 " GLib.Value value;",
312 " _this.model.el.get_value(iter, 2, out value);",
316 " var n = (JsRender.Node)value;",
318 " print(\"compare %s to %s\\n\", n.fqn(), node.fqn());",
320 " ret = pth.to_string();",
330 "| void deleteSelected" : [
333 " print(\"DELETE SELECTED?\");",
334 " //_this.view.blockChanges = true;",
335 " print(\"GET SELECTION?\");",
337 " var s = _this.view.el.get_selection();",
339 " print(\"GET SELECTED?\");",
340 " Gtk.TreeIter iter;",
341 " Gtk.TreeModel mod;",
344 " if (!s.get_selected(out mod, out iter)) {",
345 " return; // nothing seleted..",
350 " this.activePath= \"\"; ",
351 " print(\"GET vnode value?\");",
353 " GLib.Value value;",
354 " this.el.get_value(iter, 2, out value);",
355 " var data = (JsRender.Node)(value.get_object());",
356 " print(\"removing node from Render\\n\");",
357 " if (data.parent == null) {",
358 " _this.main_window.windowstate.file.tree = null;",
362 " print(\"removing node from Tree\\n\"); ",
363 " s.unselect_all();",
364 " this.el.remove(ref iter);",
374 " this.activePath= \"\"; // again!?!? ",
375 " //this.changed(null,true);",
379 " _this.view.blockChanges = false;",
383 "| void dropNode" : [
384 "(string target_data_str, JsRender.Node node, bool show_templates) {",
385 "// print(\"drop Node\");",
386 " // console.dump(node);",
387 " // console.dump(target_data);",
389 " \t\t//target_data_str",
390 " \t\t// {parent}|{pos}|{prop}",
393 " // 0 = before , 1=after 2/3 onto",
395 " \t\tGLib.debug(\"dropNode %s\", target_data_str);",
397 " var target_data= target_data_str.split(\"|\");",
399 " var parent_str = target_data[0].length > 0 ? target_data[0] : \"\";",
400 " var pos = target_data.length > 1 ? int.parse(target_data[1]) : 2; // ontop..",
403 " Gtk.TreePath tree_path = parent_str.length > 0 ? new Gtk.TreePath.from_string( parent_str ) : null;",
407 " //print(\"add \" + tp + \"@\" + target_data[1] );",
409 " JsRender.Node parentNode = null;",
411 " Gtk.TreeIter iter_after;",
412 " Gtk.TreeIter iter_par ;",
414 " \t// this appears to be done in drag_ddata_recieved as well.",
415 " if (target_data.length == 3 && target_data[2].length > 0) {",
416 "\t node.set_prop(new JsRender.NodeProp.special(\"prop\", target_data[2]));",
420 " Gtk.TreePath expand_parent = null;",
422 " // we only need to show the template if it's come from else where?",
423 " if (show_templates) {",
425 " var ts = _this.main_window.windowstate.template_select;",
427 " var new_node = ts.show(",
428 " _this.main_window, // (Gtk.Window) _this.el.get_toplevel (),",
429 " _this.main_window.windowstate.file.palete(),",
431 " _this.main_window.windowstate.project);",
433 " if (new_node == null) {",
434 " return; // do not add?",
439 " //print(\"pos is %d \\n\".printf(pos));",
441 " Gtk.TreeIter n_iter; ",
443 " if ( parent_str.length < 1) {",
444 " this.el.append(out n_iter, null); // drop at top level..",
445 " node.parent = null;",
446 " _this.main_window.windowstate.file.tree = node;",
449 " } else if (pos < 2) {",
450 " //print(target_data[1] > 0 ? 'insert_after' : 'insert_before');",
452 " this.el.get_iter(out iter_after, tree_path ); ",
453 " this.el.iter_parent(out iter_par, iter_after);",
454 " expand_parent = this.el.get_path(iter_par);",
457 " // not sure why all the 'dup_object()' stuff? did it crash before?",
458 " GLib.Value value;",
459 " this.el.get_value( iter_par, 2, out value);",
460 " parentNode = (JsRender.Node)value.dup_object();",
463 " this.el.get_value( iter_after, 2, out value);",
464 " var relNode = (JsRender.Node)value.dup_object();",
468 " this.el.insert_after(out n_iter, iter_par , iter_after);",
469 " var ix = parentNode.items.index_of(relNode);",
470 " parentNode.items.insert(ix+1, node);",
473 " this.el.insert_before(out n_iter, iter_par , iter_after);",
474 " var ix = parentNode.items.index_of(relNode);",
475 " parentNode.items.insert(ix, node);",
478 " node.parent = parentNode;",
483 " // print(\"appending to \" + parent_str);",
484 " this.el.get_iter(out iter_par, tree_path);",
485 " this.el.append(out n_iter, iter_par );",
486 " expand_parent = this.el.get_path(iter_par);",
488 " GLib.Value value;",
489 " this.el.get_value( iter_par, 2, out value);",
490 " parentNode = (JsRender.Node)value.dup_object();",
491 " node.parent = parentNode;",
492 " parentNode.items.add(node);",
498 " // work out what kind of packing to use.. -- should be in ",
501 " //_this.main_window.windowstate.file.palete().fillPack(node,parentNode);",
502 " _this.main_window.windowstate.file.palete().on_child_added(parentNode,node);",
505 " this.iterSetValues(n_iter, node);",
506 " // add the node...",
510 "\t\t// load children - if it has any..",
512 " if (node.items.size > 0) {",
513 " this.load(node.items, n_iter);",
514 " _this.view.el.expand_row(this.el.get_path(n_iter), true);",
515 " } else if (expand_parent != null && !_this.view.el.is_row_expanded(expand_parent)) {",
516 " _this.view.el.expand_row(expand_parent,true);",
519 " //if (tp != null && (node.items.length() > 0 || pos > 1)) {",
520 " // _this.view.el.expand_row(this.el.get_path(iter_par), true);",
522 " // wee need to get the empty proptypes from somewhere..",
524 " //var olditer = this.activeIter;",
525 " this.activePath = this.el.get_path(n_iter).to_string();",
528 " // pretend button was pressed, so that we can trigger select node...",
529 " _this.view.button_is_pressed = true;",
530 " _this.view.lastEventSource = \"\";",
531 " _this.view.el.set_cursor(this.el.get_path(n_iter), null, false);",
532 " _this.view.button_is_pressed = false;",
540 "| void iterSetValues" : [
541 "(Gtk.TreeIter iter, JsRender.Node node) {",
542 "\tvar ic = Gtk.IconTheme.get_default();",
545 " var o = GLib.Value(typeof(Object));",
546 " o.set_object((Object)node);",
547 " var clsname = node.fqn();",
549 " var clsb = clsname.split(\".\");",
550 " var sub = clsb.length > 1 ? clsb[1].down() : \"\";",
552 " var addi = ic.load_icon(\"list-add\", 16,0);",
553 " var fn = \"/usr/share/glade/pixmaps/hicolor/16x16/actions/widget-gtk-\" + sub + \".png\";",
554 " if (FileUtils.test (fn, FileTest.IS_REGULAR)) {",
555 " pix = new Gdk.Pixbuf.from_file (fn);",
557 " \tpix = ic.load_icon(\"emblem-new\", 16,0);",
562 " \t\t0, node.nodeTitle(),",
563 " 1, node.nodeTip(), ",
566 " this.el.set_value(iter, 2,o);",
567 " this.el.set_value(iter, 3,pix); ",
568 " \tthis.el.set_value(iter, 4,addi); ",
574 "(Gee.ArrayList<JsRender.Node> tr, Gtk.TreeIter? iter) ",
578 " Gtk.TreeIter citer;",
579 " //this.insert(citer,iter,0);",
582 " for(var i =0 ; i < tr.size; i++) {",
583 " if (iter != null) {",
584 " this.el.insert(out citer,iter,-1); // why not append?",
586 " this.el.append(out citer,null);",
588 " this.iterSetValues(citer, tr.get(i));",
592 " if (tr.get(i).items.size > 0) {",
593 " this.load(tr.get(i).items, citer);",
601 "| void loadFile" : [
602 "(JsRender.JsRender f) {",
603 " //console.dump(f);",
605 " _this.main_window.windowstate.leftTreeNodeSelected(null, \"\");",
607 " _this.main_window.windowstate.file = f;",
610 " if (f.tree == null) {",
612 "\t f.loadItems( );",
613 " } catch (Error e) {",
617 " // if it's still null?",
618 " if (f.tree == null) {",
619 "\t\t_this.main_window.windowstate.showAddObject(_this.view.el);",
624 " var o = new Gee.ArrayList<JsRender.Node>();",
626 " this.load(o,null);",
628 " _this.view.el.expand_all();",
630 " if (f.tree.items.size < 1) {",
633 " //this.get('/Window.leftvpaned').el.set_position(80);",
634 " // select first...",
635 " _this.view.el.set_cursor( ",
636 " new Gtk.TreePath.from_string(\"0\"), null, false);",
640 " //this.get('/Window.leftvpaned').el.set_position(200);",
644 " while (Gtk.events_pending()) {",
645 " Gtk.main_iteration();",
648 " _this.maincol.el.set_max_width(_this.viewwin.el.get_allocated_width() - 32);",
658 "| void moveNode" : [
659 "(string target_data, Gdk.DragAction action) ",
662 " /// target_data = \"path|pos\");",
665 " //print(\"MOVE NODE\");",
666 " // console.dump(target_data);",
667 " Gtk.TreeIter old_iter;",
668 " Gtk.TreeModel mod;",
670 " var s = _this.view.el.get_selection();",
671 " s.get_selected(out mod , out old_iter);",
672 " mod.get_path(old_iter);",
674 " var node = this.pathToNode(mod.get_path(old_iter).to_string());",
675 " //console.dump(node);",
676 " if (node == null) {",
677 " GLib.debug(\"moveNode: ERROR - node is null?\");",
682 " // needs to drop first, otherwise the target_data ",
683 " // treepath will be invalid.",
686 " if ((action & Gdk.DragAction.MOVE) > 0) {",
687 " GLib.debug(\"REMOVING OLD NODE : \" + target_data + \"\\n\");",
689 " this.dropNode(target_data, node, false);",
690 " this.el.remove(ref old_iter);",
695 " GLib.debug(\"DROPPING NODE // copy: \" + target_data + \"\\n\");",
696 " node = node.deepClone();",
697 " this.dropNode(target_data, node, false);",
700 " this.activePath= \"\";",
701 " //this.updateNode(false,true);",
705 "| void updateSelected" : [
709 " var s = _this.view.el.get_selection();",
711 " Gtk.TreeIter iter;",
712 " Gtk.TreeModel mod;",
716 " if (!s.get_selected(out mod, out iter)) {",
717 " return; // nothing seleted..",
720 " GLib.Value value;",
721 " this.el.get_value(iter, 2, out value);",
722 " var node = (JsRender.Node)(value.get_object());",
724 " this.el.set(iter, 0, node.nodeTitle(),",
725 " 1, node.nodeTip(), -1",
732 "$ Gtk.TreeViewColumnSizing sizing" : "Gtk.TreeViewColumnSizing.FIXED",
735 " this.el.add_attribute(_this.renderer.el , \"markup\", 0 );",
736 " this.el.add_attribute(_this.iconrender.el , \"pixbuf\", 3 );",
739 "* pack" : "append_column",
740 "bool expand" : true,
741 "bool resizable" : true,
746 "* pack" : "pack_start,false",
749 "xtype" : "CellRendererPixbuf"
753 "* pack" : "pack_start,true",
755 "xtype" : "CellRendererText"
758 "utf8 title" : "Node",
759 "xtype" : "TreeViewColumn"
762 "$ Gtk.TreeViewColumnSizing sizing" : "Gtk.TreeViewColumnSizing.FIXED",
765 " this.el.add_attribute(_this.addiconrender.el , \"pixbuf\", 4 );",
768 "* pack" : "append_column",
769 "bool expand" : false,
770 "int max_width" : 24,
774 "* pack" : "pack_start,true",
775 "id" : "addiconrender",
777 "xtype" : "CellRendererPixbuf"
780 "utf8 title" : "Add",
781 "xtype" : "TreeViewColumn"
785 "button_press_event" : [
787 " //console.log(\"button press?\");",
788 " this.button_is_pressed = true;",
789 " print(\"BUTTON DOWN\\n\");",
791 " this.lastEventSource = \"tree\";",
792 " if (! _this.before_node_change() ) {",
797 "\tif (ev.type != Gdk.EventType.BUTTON_PRESS) {",
800 " if (_this.model.el.iter_n_children(null) < 1) {",
801 "\t _this.main_window.windowstate.showAddObject(_this.view.el);",
806 " Gtk.TreePath res;",
807 " Gtk.TreeViewColumn col;",
808 " if (!_this.view.el.get_path_at_pos((int)ev.x,(int)ev.y, out res, out col, null, null) ) {",
812 " if (col.title == \"Add\") {",
813 " _this.main_window.windowstate.leftTreeBeforeChange();",
814 " this.el.get_selection().select_path(res);",
815 " \t_this.main_window.windowstate.showAddObject(this.el);",
819 "\tif ( ev.button != 3) {",
820 " //print(\"click\" + ev.type);",
823 " _this.main_window.windowstate.leftTreeBeforeChange();",
827 " this.el.get_selection().select_path(res);",
831 " //if (!this.get('/LeftTreeMenu').el) { ",
832 " // this.get('/LeftTreeMenu').init(); ",
835 " _this.LeftTreeMenu.el.set_screen(Gdk.Screen.get_default());",
836 " _this.LeftTreeMenu.el.show_all();",
837 " _this.LeftTreeMenu.el.popup(null, null, null, 3, ev.time);",
838 " // print(\"click:\" + res.path.to_string());",
842 "button_release_event" : [
844 " this.button_is_pressed = false;",
850 " print(\"LEFT TREE Cursor Changed\\n\");",
851 "\tif (!this.button_is_pressed && !this.key_is_pressed) {",
852 "\t\t// then event was started by some other action",
853 "\t\t// which should manually trigger all the events..",
854 "\t\tprint(\"SKIPPING select - no button or key pressed\\n\");",
859 " if (this.blockChanges) { // probably not needed.. ",
860 "\t\tprint(\"SKIPPING select - blockchanges set..\\n\"); ",
863 " if (!_this.before_node_change( ) ) {",
864 "\t this.blockChanges = true;",
865 "\t this.el.get_selection().unselect_all();",
866 "\t this.blockChanges = false;",
870 " if (_this.main_window.windowstate.file == null) {",
871 " \t\tprint(\"SKIPPING select windowstate file is not set...\\n\"); ",
875 " //var render = this.get('/LeftTree').getRenderer(); ",
876 " print(\"LEFT TREE -> view -> selection changed called\\n\");",
879 " // -- it appears that the selection is not updated.",
881 " GLib.Timeout.add_full(GLib.Priority.DEFAULT,10 , () => {",
882 " print(\"LEFT TREE -> view -> selection changed TIMEOUT CALLED\\n\");",
884 " if (this.el.get_selection().count_selected_rows() < 1) {",
886 " print(\"selected rows < 1\\n\");",
887 " //??this.model.load( false);",
888 " _this.node_selected(null, this.lastEventSource);",
893 " //console.log('changed');",
894 " var s = this.el.get_selection();",
895 " Gtk.TreeIter iter;",
896 " Gtk.TreeModel mod;",
897 " s.get_selected(out mod, out iter);",
900 " // var val = \"\";",
901 " GLib.Value value;",
902 " _this.model.el.get_value(iter, 2, out value);",
903 " _this.model.activePath = mod.get_path(iter).to_string();",
905 " var node = (JsRender.Node)value.dup_object();",
906 " print (\"calling left_tree.node_selected\\n\");",
907 " _this.node_selected(node, this.lastEventSource);",
908 " while (Gtk.events_pending()) {",
909 " Gtk.main_iteration();",
911 " var cp = mod.get_path(iter);",
912 " Gtk.TreePath sp, ep;",
913 " this.el.get_visible_range(out sp, out ep);",
914 " // if sp is before cp then retuns 1.",
915 " // if cp is before ep then retuns 1.",
916 " if (cp.compare(sp) >= 0 && ep.compare(cp) >=1) {",
922 " this.el.scroll_to_cell(new Gtk.TreePath.from_string(_this.model.activePath), null, true, 0.1f,0.0f);",
926 " //_this.after_node_change(node);",
928 "// _this.model.file.changed(node, \"tree\");",
930 " //Seed.print( value.get_string());",
937 "\t//print('SOURCE: drag-begin');",
940 " //this.targetData = \"\";",
942 " // find what is selected in our tree...",
944 " var s = _this.view.el.get_selection();",
945 " if (s.count_selected_rows() < 1) {",
948 " Gtk.TreeIter iter;",
949 " Gtk.TreeModel mod;",
950 " s.get_selected(out mod, out iter);",
954 " // set some properties of the tree for use by the dropped element.",
955 " GLib.Value value;",
956 " _this.model.el.get_value(iter, 2, out value);",
957 " var tp = mod.get_path(iter).to_string();",
958 " var data = (JsRender.Node)(value.dup_object());",
959 " var xname = data.fqn();",
960 " print (\"XNAME IS \" + xname+ \"\\n\");",
961 " this.dragData = tp;",
962 " this.dropList = _this.main_window.windowstate.file.palete().getDropList(xname);",
964 " print (\"DROP LIST IS \" + string.joinv(\", \", this.dropList) + \"\\n\");",
967 " // make the drag icon a picture of the node that was selected",
970 " // by default returns the path..",
971 " var path = _this.model.el.get_path(iter);",
974 " var pix = this.el.create_row_drag_icon ( path);",
976 " Gtk.drag_set_icon_surface (ctx, pix) ;",
982 "( drag_context, data, info, time) => {",
985 "\t//print(\"drag-data-get\");",
986 "\tvar s = this.el.get_selection();",
987 "\tif (s.count_selected_rows() < 1) {",
988 "\t\tdata.set_text(\"\",0); ",
989 "\t\t print(\"return empty string - no selection..\");",
993 "\tGtk.TreeIter iter;",
994 "\tGtk.TreeModel mod;",
996 "\ts.get_selected(out mod, out iter);",
1000 "\tGLib.Value value;",
1001 "\t_this.model.el.get_value(iter, 2, out value);",
1002 "\tvar ndata = (JsRender.Node)(value.dup_object());",
1006 "\tvar tp = mod.get_path(iter).to_string();",
1007 "\t// by default returns the path..",
1009 "\tif ( info != Gdk.Atom.intern(\"STRING\",true) ) {",
1010 "\t\ttp = ndata.toJsonString();",
1013 "\t//data.set_text(tp,tp.length); ",
1015 "\tdata.set (data.get_target (), 8, (uchar[]) tp.to_utf8 ());",
1018 "\t// print(\"return \" + tp);",
1021 "drag_data_received" : [
1022 "\t(ctx, x, y, sel, info, time) => {",
1024 "\t// THIS CODE ONLY RELATES TO drag or drop of \"NEW\" elements or \"FROM another tree..\"",
1027 "\t// print(\"Tree: drag-data-received\\n\");",
1028 "\tvar selection_text = (string)sel.get_data();",
1029 "\t//print(\"selection_text= %s\\n\",selection_text);",
1031 "\tvar is_drag = this.drag_in_motion;",
1035 "\tGLib.debug(\"Is Drag %s\\n\", is_drag ? \"Y\": \"N\");",
1036 "\tvar targetData = \"\";",
1038 "\tGtk.TreePath path;",
1039 "\tGtk.TreeViewDropPosition pos;",
1040 "\tvar isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);",
1042 "\t// if there are not items in the tree.. the we have to set isOver to true for anything..",
1043 "\tvar isEmpty = false;",
1044 "\tif (_this.model.el.iter_n_children(null) < 1) {",
1045 "\t\tGLib.debug(\"got NO children?\\n\");",
1046 "\t\tisOver = true; //??? ",
1047 "\t\tisEmpty = true;",
1048 "\t\tpos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;",
1052 "\t//console.log(\"LEFT-TREE: drag-motion\");",
1053 "\tvar src = Gtk.drag_get_source_widget(ctx);",
1055 "\t// a drag from self - this should be handled by drop and motion.",
1056 "\tif (src == this.el) {",
1057 "\t\tGLib.debug(\"Source == this element should not happen.. ? \\n\");",
1060 "\t//print(\"drag_data_recieved from another element\");",
1065 "\tif (selection_text == null || selection_text.length < 1 || !isOver) {",
1066 "\t\t// nothing valid foudn to drop...",
1067 "\t\t GLib.debug(\"empty sel text or not over\");",
1068 "\t\tif (is_drag) {",
1069 "\t\t Gdk.drag_status(ctx, 0, time);",
1070 "\t\t this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);",
1073 "\t\tGtk.drag_finish (ctx, false, false, time); // drop failed..",
1074 "\t\t// no drop action...",
1078 "\tvar dropNode = new JsRender.Node(); ",
1080 "\tvar dropNodeType = selection_text;",
1081 "\tvar show_templates = true;",
1083 "\tif (dropNodeType[0] == '{') {",
1084 "\t\tvar pa = new Json.Parser();",
1086 "\t\t pa.load_from_data(dropNodeType);",
1087 "\t\t} catch (Error e) {",
1088 "\t\t Gtk.drag_finish (ctx, false, false, time); // drop failed..",
1089 "\t\t // no drop action...",
1093 "\t\tdropNode.loadFromJson( pa.get_root().get_object(), 2);",
1094 "\t\tdropNodeType = dropNode.fqn();",
1095 "\t\tshow_templates = false;",
1099 "\t\t// drop with property.",
1100 "\t\tif (selection_text.contains(\":\")) {",
1101 "\t\t\tvar bits = selection_text.split(\":\");",
1102 "\t\t dropNode.setFqn(bits[0]);",
1103 "\t\t dropNode.set_prop(new JsRender.NodeProp.special(\"prop\", bits[1]));",
1108 "\t\t dropNode.setFqn(selection_text);",
1113 "\t// dropList --- need to gather this ... ",
1114 "\tGLib.debug(\"get dropList for : %s\\n\",dropNodeType); ",
1115 "\tvar dropList = _this.main_window.windowstate.file.palete().getDropList(dropNodeType);",
1117 "\tGLib.debug(\"dropList: %s\\n\", string.joinv(\" , \", dropList));",
1119 "\t// if drag action is link ... then we can drop it anywahere...",
1120 "\t if ((ctx.get_actions() & Gdk.DragAction.LINK) > 0) {",
1121 "\t\t // if path is null?? dragging into an empty tree?",
1122 "\t\t targetData = (path == null ? \"\" : path.to_string()) + \"|%d\".printf((int)pos);",
1126 "\t\ttargetData = _this.model.findDropNodeByPath( isEmpty ? \"\" : path.to_string(), dropList, pos);",
1131 "\tGLib.debug(\"targetDAta: %s\", targetData );",
1133 "\tif (targetData.length < 1) {",
1135 "\t\t// invalid drop path..",
1136 "\t\tif (this.drag_in_motion) {",
1137 "\t\t Gdk.drag_status(ctx, 0, time);",
1138 "\t\t this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);",
1141 "\t\tGtk.drag_finish (ctx, false, false, time); // drop failed..",
1142 "\t\t// no drop action...",
1148 "\t var td_ar = targetData.split(\"|\");",
1151 "\tif (this.drag_in_motion) { ",
1152 "\t\tGdk.drag_status(ctx, Gdk.DragAction.COPY ,time);",
1154 "\t\tthis.highlightDropPath( td_ar[0] , (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));",
1157 "\t// continue on to allow drop..",
1160 "\t// at this point, drag is not in motion... -- as checked above... - so it's a real drop event..",
1162 "\t// {parent}|{pos}|{prop}",
1165 " _this.model.dropNode(targetData, dropNode, show_templates);",
1167 "\tGLib.debug(\"ADD new node!!!\\n\");",
1169 "\t///Xcls_DialogTemplateSelect.singleton().show( _this.model.file.palete(), node);",
1171 "\tGtk.drag_finish (ctx, false, false,time);",
1180 " ( ctx, x, y, time) => {",
1181 " //Seed.print(\"TARGET: drag-drop\");",
1184 " var src = Gtk.drag_get_source_widget(ctx);",
1186 " if (src != this.el) {",
1190 " this.drag_in_motion = false; ",
1191 " // request data that will be recieved by the recieve... ",
1192 " Gtk.drag_get_data",
1194 " this.el, // will receive 'drag-data-received' signal ",
1195 " ctx, // represents the current state of the DnD ",
1196 " Gdk.Atom.intern(\"application/json\",true), // the target type we want ",
1197 " time // time stamp ",
1201 " // No target offered by source => error",
1207 " // handle drop around self..",
1211 " //print(\"GETTING POS\");",
1212 " var targetData = \"\";",
1214 " Gtk.TreePath path;",
1215 " Gtk.TreeViewDropPosition pos;",
1216 " var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);",
1218 " // if there are not items in the tree.. the we have to set isOver to true for anything..",
1219 " var isEmpty = false;",
1220 " if (_this.model.el.iter_n_children(null) < 1) {",
1221 " print(\"got NO children?\\n\");",
1222 " isOver = true; //??? ",
1224 " pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;",
1229 " //var action = Gdk.DragAction.COPY;",
1230 " // unless we are copying!!! ctl button..",
1232 " var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?",
1233 " Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;",
1234 " // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;",
1237 " if (_this.model.el.iter_n_children(null) < 1) {",
1238 " // no children.. -- asume it's ok..",
1240 " targetData = \"|%d|\".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);",
1242 " // continue through to allow drop...",
1250 " //print(\"ISOVER? \" + isOver);",
1253 " Gtk.drag_finish (ctx, false, false, time); // drop failed..",
1254 " return true; // not over apoint!?! - no action on drop or motion..",
1257 " // drag node is parent of child..",
1258 " //console.log(\"SRC TREEPATH: \" + src.treepath);",
1259 " //console.log(\"TARGET TREEPATH: \" + data.path.to_string());",
1261 " // nned to check a few here..",
1262 " //Gtk.TreeViewDropPosition.INTO_OR_AFTER",
1263 " //Gtk.TreeViewDropPosition.INTO_OR_BEFORE",
1264 " //Gtk.TreeViewDropPosition.AFTER",
1265 " //Gtk.TreeViewDropPosition.BEFORE",
1267 " // locally dragged items to not really use the ",
1268 " var selection_text = this.dragData;",
1272 " if (selection_text == null || selection_text.length < 1) {",
1273 " //print(\"Error - drag selection text returned NULL\");",
1275 " Gtk.drag_finish (ctx, false, false, time); // drop failed..",
1276 " return true; /// -- fixme -- this is not really correct..",
1279 " // see if we are dragging into ourself?",
1280 " print (\"got selection text of \" + selection_text);",
1282 " var target_path = path.to_string();",
1283 " //print(\"target_path=\"+target_path);",
1286 " if (selection_text == target_path) {",
1287 " print(\"self drag ?? == we should perhaps allow copy onto self..\\n\");",
1289 " Gtk.drag_finish (ctx, false, false, time); // drop failed..",
1291 " return true; /// -- fixme -- this is not really correct..",
1296 " //print(\"DUMPING DATA\");",
1297 " //console.dump(data);",
1300 " //print(data.path.to_string() +' => '+ data.pos);",
1302 " // dropList is a list of xtypes that this node could be dropped on.",
1303 " // it is set up when we start to drag..",
1306 " targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);",
1308 " print(\"targetDAta: \" + targetData +\"\\n\");",
1310 " if (targetData.length < 1) {",
1311 " //print(\"Can not find drop node path\");",
1313 " Gtk.drag_finish (ctx, false, false, time); // drop failed..",
1319 " // continue on to allow drop..",
1321 " // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..",
1324 " var delete_selection_data = false;",
1326 " if (action == Gdk.DragAction.ASK) {",
1327 " /* Ask the user to move or copy, then set the ctx action. */",
1330 " if (action == Gdk.DragAction.MOVE) {",
1331 " delete_selection_data = true;",
1334 " // drag around.. - reorder..",
1335 " _this.model.moveNode(targetData, action);",
1341 " // we can send stuff to souce here...",
1344 "// do we always say failure, so we handle the reall drop?",
1345 " Gtk.drag_finish (ctx, false, false,time); //delete_selection_data, time);",
1357 " (drag_context) => {",
1358 "\t//Seed.print('LEFT-TREE: drag-end');",
1359 " this.dragData = \"\";",
1360 " this.dropList = null;",
1361 "// this.targetData = \"\";",
1362 " this.highlightDropPath(\"\",0);",
1367 " ( ctx, x, y, time) => {",
1368 " print(\"got drag motion\\n\");",
1369 " var src = Gtk.drag_get_source_widget(ctx);",
1370 " this.drag_x = x;",
1371 " this.drag_y = y; ",
1373 " if (src != this.el) {",
1377 " // the point of this is to detect where an item could be dropped..",
1378 " print(\"requesting drag data\\n\");",
1379 " this.drag_in_motion = true;",
1381 " // request data that will be recieved by the recieve... ",
1382 " Gtk.drag_get_data",
1384 " this.el, // will receive 'drag-data-received' signal ",
1385 " ctx, // represents the current state of the DnD ",
1386 " Gdk.Atom.intern(\"STRING\",true), // the target type we want ",
1387 " time // time stamp ",
1393 " print(\"action: %d\\n\", ctx.get_actions());",
1394 " //print(\"GETTING POS\");",
1395 " var targetData = \"\";",
1397 " Gtk.TreePath path;",
1398 " Gtk.TreeViewDropPosition pos;",
1399 " var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);",
1401 " // if there are not items in the tree.. the we have to set isOver to true for anything..",
1402 " var isEmpty = false;",
1403 " if (_this.model.el.iter_n_children(null) < 1) {",
1404 " print(\"got NO children?\\n\");",
1405 " isOver = true; //??? ",
1407 " pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;",
1411 " // ------------- a drag from self..",
1414 " //var action = Gdk.DragAction.COPY;",
1415 " // unless we are copying!!! ctl button..",
1417 " var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?",
1418 " Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;",
1419 " // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;",
1422 " if (_this.model.el.iter_n_children(null) < 1) {",
1423 " // no children.. -- asume it's ok..",
1425 " targetData = \"|%d|\".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);",
1427 " this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0); ",
1428 " Gdk.drag_status(ctx, action ,time);",
1431 " // continue through to allow drop...",
1439 " //print(\"ISOVER? \" + isOver);",
1442 " Gdk.drag_status(ctx, 0 ,time);",
1443 " this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0); ",
1448 " // drag node is parent of child..",
1449 " //console.log(\"SRC TREEPATH: \" + src.treepath);",
1450 " //console.log(\"TARGET TREEPATH: \" + data.path.to_string());",
1452 " // nned to check a few here..",
1453 " //Gtk.TreeViewDropPosition.INTO_OR_AFTER",
1454 " //Gtk.TreeViewDropPosition.INTO_OR_BEFORE",
1455 " //Gtk.TreeViewDropPosition.AFTER",
1456 " //Gtk.TreeViewDropPosition.BEFORE",
1458 " // locally dragged items to not really use the ",
1459 " var selection_text = this.dragData;",
1463 " if (selection_text == null || selection_text.length < 1) {",
1464 " //print(\"Error - drag selection text returned NULL\");",
1465 " Gdk.drag_status(ctx, 0 ,time);",
1466 " this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);",
1471 " // see if we are dragging into ourself?",
1472 " var target_path = path.to_string(); ",
1473 " print (\"Drag %s onto %s--%d\\n \", selection_text, target_path, pos);",
1475 " // pos : 3 = ontop - 0 = after, 1 = before",
1476 " //print(\"target_path=\"+target_path);",
1479 " if (selection_text == target_path) {",
1480 " print(\"self drag ?? == we should perhaps allow copy onto self..\\n\");",
1482 " Gdk.drag_status(ctx, 0 ,time);",
1483 " this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);",
1485 "// -- fixme -- this is not really correct..",
1490 " //print(\"DUMPING DATA\");",
1491 " //console.dump(data);",
1494 " //print(data.path.to_string() +' => '+ data.pos);",
1496 " // dropList is a list of xtypes that this node could be dropped on.",
1497 " // it is set up when we start to drag..",
1500 " targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);",
1502 " print(\"targetDAta: \" + targetData +\"\\n\");",
1504 " if (targetData.length < 1) {",
1505 " //print(\"Can not find drop node path\");",
1507 " Gdk.drag_status(ctx, 0, time);",
1508 " this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);",
1512 " var td_ar = targetData.split(\"|\");",
1516 " Gdk.drag_status(ctx, action ,time);",
1517 " this.highlightDropPath(td_ar[0], (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));",
1523 "key_press_event" : [
1525 " this.key_is_pressed = true;",
1529 "key_release_event" : [
1531 " this.key_is_pressed = false;",
1537 "tooltip_column" : 1,
1538 "xtype" : "TreeView",
1539 "| void highlightDropPath" : [
1540 " ( string treepath, Gtk.TreeViewDropPosition pos) {",
1542 " // highlighting for drag/drop",
1543 " if (treepath.length > 0) {",
1544 " this.el.set_drag_dest_row( new Gtk.TreePath.from_string( treepath ), pos);",
1546 " this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);",
1551 "| void selectNode" : [
1552 "(string treepath_str, string source) {",
1553 "\tthis.lastEventSource = source;",
1554 " //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));",
1555 " var tp = new Gtk.TreePath.from_string(treepath_str);",
1557 " this.el.set_cursor(tp, null, false); ",
1558 " this.el.scroll_to_cell(tp, null, false, 0,0);",
1562 "| void setCursor" : [
1563 "(string treepath, string sourceEvent) {",
1564 "\tthis.lastEventSource = sourceEvent;",
1565 "\t//this.blockChanges = true; << block changes prevents loading of 'node data' and firing of node_selected..",
1566 " this.el.set_cursor(new Gtk.TreePath.from_string(treepath), null, false); ",
1567 " // fire node_selected..",
1568 " //this.blockChanges = false;",
1569 "\tthis.lastEventSource = \"\";",
1577 "id" : "LeftTreeMenu",
1582 "label" : "Delete Element",
1587 " print(\"ACTIVATE?\");",
1590 " _this.model.deleteSelected();",
1594 "xtype" : "MenuItem"
1599 "label" : "Save as Template",
1604 " DialogSaveTemplate.singleton().show(",
1605 " (Gtk.Window) _this.el.get_toplevel (), ",
1606 " _this.main_window.windowstate.file.palete(), ",
1607 " _this.getActiveElement()",
1614 "xtype" : "MenuItem"
1619 "label" : "Save as Module",
1623 " var node = _this.getActiveElement();",
1624 " var name = DialogSaveModule.singleton().show(",
1625 " (Gtk.Window) _this.el.get_toplevel (), ",
1626 " _this.main_window.windowstate.project, ",
1629 " if (name.length < 1) {",
1633 " node.set_prop( new JsRender.NodeProp.special(\"xinclude\", name));",
1634 " node.items.clear();",
1637 " var s = _this.view.el.get_selection();",
1639 " print(\"GET SELECTED?\");",
1640 " Gtk.TreeIter iter;",
1641 " Gtk.TreeModel mod;",
1644 " if (!s.get_selected(out mod, out iter)) {",
1645 " return; // nothing seleted..",
1647 " Gtk.TreeIter citer;",
1648 " var n_cn = mod.iter_n_children(iter) -1;",
1649 " for (var i = n_cn; i > -1; i--) {",
1650 " mod.iter_nth_child(out citer, iter, i);",
1653 " print(\"removing node from Tree\\n\"); ",
1655 " _this.model.el.remove(ref citer);",
1657 " _this.changed();",
1658 " _this.node_selected(node, \"tree\");",
1664 "xtype" : "MenuItem"
1672 "(allocation) => {",
1675 "\t//GLib.debug(\"Got allocation width of scrolled view %d\", allocation.width );",
1676 "\t_this.maincol.el.set_max_width(allocation.width - 32);",
1681 "xtype" : "ScrolledWindow"
1685 "| JsRender.JsRender getActiveFile" : [
1687 " return this.main_window.windowstate.file;",
1691 "| JsRender.Node? getActiveElement" : [
1692 " () { // return path to actie node.",
1694 " var path = this.getActivePath();",
1695 " if (path.length < 1) {",
1698 " return _this.model.pathToNode(path);",
1703 "| string getActivePath" : [
1706 " var view = this.view.el;",
1707 " if (view.get_selection().count_selected_rows() < 1) {",
1710 " Gtk.TreeIter iter;",
1711 " Gtk.TreeModel mod;",
1712 " view.get_selection().get_selected(out mod, out iter);",
1713 " return mod.get_path(iter).to_string();",
1720 "name" : "WindowLeftTree",
1722 "path" : "/home/alan/gitlive/roobuilder/src/Builder4/WindowLeftTree.bjs",