4769803e75a2799168e7956c75215dbeeafe6e60
[roobuilder] / src / Builder4 / WindowLeftTree.bjs
1 {
2  "build_module" : "builder",
3  "items" : [
4   {
5    "# Xcls_MainWindow main_window" : "null",
6    "$ xns" : "Gtk",
7    "* pack" : "add",
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",
13    "items" : [
14     {
15      "$ xns" : "Gtk",
16      "* init" : [
17       " this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);",
18       " ",
19       ""
20      ],
21      "* pack" : "add",
22      "Gtk.ShadowType shadow_type" : "Gtk.ShadowType.IN",
23      "id" : "viewwin",
24      "items" : [
25       {
26        "# bool blockChanges" : false,
27        "# bool drag_in_motion" : "",
28        "# int drag_x" : "",
29        "# int drag_y" : "",
30        "# string dragData" : "",
31        "# string[] dropList" : "",
32        "$ enable_tree_lines" : true,
33        "$ string lastEventSource" : "\"\"",
34        "$ xns" : "Gtk",
35        "* init" : [
36         "{",
37         "    var description = new Pango.FontDescription();",
38         "    description.set_size(8000);",
39         "    this.el.override_font(description);",
40         "",
41         "    var selection = this.el.get_selection();",
42         "    selection.set_mode( Gtk.SelectionMode.SINGLE);",
43         "",
44         "",
45         "    // is this really needed??",
46         "    /*",
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'), '']",
50         "\t    );",
51         "    });",
52         "    */",
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 */",
58         "    );",
59         "",
60         "    // ?? needed??",
61         "    //Gtk.drag_source_add_text_targets(this.el); ",
62         "",
63         "    Gtk.drag_dest_set",
64         "    (",
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 */",
69         "    );",
70         "",
71         "    //Gtk.drag_dest_set_target_list(this.el, Builder.Application.targetList);",
72         "    //Gtk.drag_dest_add_text_targets(this.el);",
73         "    ",
74         "    ",
75         "   ",
76         "    ",
77         "}",
78         ""
79        ],
80        "* pack" : "add",
81        "Boolean id" : "view",
82        "bool button_is_pressed" : false,
83        "bool expand" : true,
84        "bool headers_visible" : false,
85        "bool key_is_pressed" : false,
86        "items" : [
87         {
88          "# DialogTemplateSelect template_select" : "null",
89          "# string activePath" : "\"\"",
90          "$ columns" : [
91           "typeof(string),",
92           "typeof(string),",
93           "typeof(Object),",
94           "typeof(Gdk.Pixbuf),",
95           "typeof(Gdk.Pixbuf)"
96          ],
97          "$ listAllTypes" : [
98           "function() {",
99           "    var s = this.get('/LeftTree.view').selection;",
100           "    print (\"LIST ALL TYPES: \" + s.count_selected_rows() );",
101           "    ",
102           "    if (s.count_selected_rows() > 0) {",
103           "        var iter = new Gtk.TreeIter();    ",
104           "        s.get_selected(this.el, iter);",
105           "",
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);",
110           "        ",
111           "        ",
112           "        var xname = this.get('/LeftTree.model').file.guessName(data);",
113           "        console.log('selected:' + xname);",
114           "        if (xname.length) {",
115           "            return [ xname ];",
116           "        }",
117           "        return []; // could not find it..",
118           "    }",
119           "    ",
120           "    var ret = [ ];",
121           "    ",
122           "   var _this = this;",
123           "    function addall(li)",
124           "    {",
125           "        li.forEach(function(el) {",
126           "            // this is specific to roo!!!?",
127           "            if (!el) { // skip empty?",
128           "                return;",
129           "            }",
130           "            var fullpath =  _this.file.guessName(el);",
131           "            if (fullpath.length && ret.indexOf(fullpath) < 0) {",
132           "                ret.push(fullpath);",
133           "            }",
134           "            ",
135           "            ",
136           "            if (el.items && el.items.length) {",
137           "                addall(el.items);",
138           "            }",
139           "            ",
140           "        });",
141           "        ",
142           "        ",
143           "    }",
144           "    ",
145           "    addall([this.currentTree]);",
146           "    ",
147           "    // only if we have nothing, should we add '*top'",
148           "    if (!ret.length) {",
149           "        ret = [ '*top' ];",
150           "    }",
151           "    //console.log('all types in tree');",
152           "    //console.dump(ret);",
153           "    ",
154           "    return ret;",
155           "                            ",
156           "}",
157           ""
158          ],
159          "$ xns" : "Gtk",
160          "* init" : [
161           "print(\"model initialized\");",
162           "",
163           ""
164          ],
165          "* pack" : "set_model",
166          "currentTree" : false,
167          "id" : "model",
168          "n_columns" : 5,
169          "xtype" : "TreeStore",
170          "| JsRender.Node pathToNode" : [
171           "(string path) {",
172           " ",
173           "     ",
174           "     Gtk.TreeIter   iter;",
175           "     _this.model.el.get_iter_from_string(out iter, path);",
176           "     ",
177           "     GLib.Value value;",
178           "     _this.model.el.get_value(iter, 2, out value);",
179           "     ",
180           "     return (JsRender.Node)value.dup_object();",
181           "",
182           "}"
183          ],
184          "| string findDropNode" : [
185           " (string treepath_str, string[] targets) {",
186           "",
187           "    // this is used by the dragdrop code in the roo version AFAIR..",
188           "",
189           "    //var path = treepath_str.replace(/^builder-/, '');",
190           "    // treemap is depreciated... - should really check if model has any entries..",
191           "",
192           "    if (this.el.iter_n_children(null) < 1) {",
193           "        //print(\"NO KEYS\");",
194           "        return \"|%d\".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);",
195           "    }",
196           "    //print(\"FIND treepath: \" + path);",
197           "    //console.dump(this.treemap);",
198           "    ",
199           "    //if (!treepath_str.match(/^builder-/)) {",
200           "    //    return []; // nothing!",
201           "    //}",
202           "    if (targets.length > 0 && targets[0] == \"*\") {",
203           "        return  treepath_str;",
204           "    }",
205           "    return this.findDropNodeByPath(treepath_str,targets, -1);",
206           "}",
207           ""
208          ],
209          "| string findDropNodeByPath" : [
210           " (string treepath_str, string[] targets, int in_pref = -1) {",
211           "",
212           "    var path = treepath_str; // dupe it..",
213           "    ",
214           "    ",
215           "    // pref : 3 = ontop - 0 = after, 1 = before",
216           "    int pref = in_pref < 0  ?  Gtk.TreeViewDropPosition.INTO_OR_AFTER : in_pref;",
217           "    ",
218           "    var last = \"\";",
219           "    ",
220           "    //console.dump(this.treemap);",
221           "    ",
222           "    print(\"findDropNodeByPath : got path length %d / %s\\n\", path.length, path);",
223           "    ",
224           "    if (path.length == 0) {",
225           "        // top drop. // just return empty..",
226           "        return \"|%d\".printf((int)pref) ;",
227           "        ",
228           "    }",
229           "    ",
230           "    ",
231           "    while (path.length > 0) {",
232           "    ",
233           "        if (path.length == treepath_str.length && pref != Gtk.TreeViewDropPosition.INTO_OR_AFTER) {",
234           "            if (path.last_index_of(\":\") < 0 ) {",
235           "                return \"\";",
236           "            }",
237           "            path = path.substring(0, path.last_index_of(\":\"));",
238           "            last = treepath_str;",
239           "            print(\"DROP  before or after : using %s\\n\",path);",
240           "            continue;",
241           "        }",
242           "    ",
243           "        //print(\"LOOKING FOR PATH: \" + path);",
244           "        var node_data = this.pathToNode(path);",
245           "        ",
246           "        if (node_data == null) {",
247           "            print(\"node not found\");",
248           "            return \"\";",
249           "        }",
250           "        ",
251           "        var xname = node_data.fqn();",
252           "        var match = \"\";",
253           "        var prop = \"\";",
254           "        ",
255           "        for (var i =0; i < targets.length; i++)  {",
256           "            var tg = targets[i];",
257           "            if ((tg == xname)  ) {",
258           "                match = tg;",
259           "                break;",
260           "            }",
261           "            // if target is \"xxxx:name\"",
262           "            if (tg.contains(xname +\":\")) {",
263           "                match = tg;",
264           "                var ar = tg.split(\":\");",
265           "                prop = ar[1];",
266           "                break;",
267           "            }",
268           "        }",
269           "        ",
270           "        if (match.length > 0) {",
271           "            if (last.length > 0) { // pref is after/before..",
272           "                // then it's after last",
273           "                //if (pref > 1) {",
274           "                //    return \"\";",
275           "                //}",
276           "                return last + \"|%d\".printf((int)pref) + \"|\" + prop;",
277           "",
278           "                ",
279           "            }",
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;",
282           "        }",
283           "        /*",
284           "        last = \"\" + path;",
285           "        var par = path.split(\":\");",
286           "        string [] ppar = {};",
287           "        for (var i = 0; i < par.length-1; i++) {",
288           "            ppar += par[i];",
289           "        }",
290           "        ",
291           "        path = string.joinv(\":\", ppar);",
292           "        */",
293           "        break;",
294           "",
295           "    }",
296           "    ",
297           "    return \"\";",
298           "            ",
299           "}",
300           ""
301          ],
302          "| string treePathFromNode" : [
303           "(JsRender.Node node) {",
304           "    // iterate through the tree and find the node",
305           "    var ret = \"\";",
306           "    ",
307           "    this.el.foreach((mod, pth, iter) => {",
308           "        // get the node..",
309           "      ",
310           "     ",
311           "         GLib.Value value;",
312           "         _this.model.el.get_value(iter, 2, out value);",
313           "         ",
314           "",
315           "         ",
316           "         var n = (JsRender.Node)value;",
317           "",
318           "         print(\"compare %s to %s\\n\", n.fqn(), node.fqn());",
319           "        if (node == n) {",
320           "            ret = pth.to_string();",
321           "            return true;",
322           "        }",
323           "        return false;",
324           "    });",
325           "    return ret;",
326           "",
327           "}",
328           ""
329          ],
330          "| void deleteSelected" : [
331           "() {",
332           "    ",
333           "    print(\"DELETE SELECTED?\");",
334           "    //_this.view.blockChanges = true;",
335           "    print(\"GET SELECTION?\");",
336           "",
337           "    var s = _this.view.el.get_selection();",
338           "    ",
339           "    print(\"GET  SELECTED?\");",
340           "   Gtk.TreeIter iter;",
341           "    Gtk.TreeModel mod;",
342           "",
343           "    ",
344           "    if (!s.get_selected(out mod, out iter)) {",
345           "        return; // nothing seleted..",
346           "    }",
347           "      ",
348           "",
349           "",
350           "    this.activePath= \"\";      ",
351           "    print(\"GET  vnode value?\");",
352           "",
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;",
359           "    } else {",
360           "        data.remove();",
361           "    }",
362           "    print(\"removing node from Tree\\n\");    ",
363           "    s.unselect_all();",
364           "    this.el.remove(ref iter);",
365           "",
366           "    ",
367           "    ",
368           "    ",
369           "    // ",
370           "    ",
371           "    ",
372           "",
373           "",
374           "    this.activePath= \"\"; // again!?!?      ",
375           "    //this.changed(null,true);",
376           "    ",
377           "    _this.changed();",
378           "    ",
379           "    _this.view.blockChanges = false;",
380           "}",
381           ""
382          ],
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);",
388           "  ",
389           "  \t\t//target_data_str",
390           "  \t\t//   {parent}|{pos}|{prop}",
391           "  ",
392           "  ",
393           "        // 0 = before , 1=after 2/3 onto",
394           "  ",
395           "  \t\tGLib.debug(\"dropNode %s\", target_data_str);",
396           "        ",
397           "        var target_data= target_data_str.split(\"|\");",
398           "  ",
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..",
401           "  ",
402           "  ",
403           "        Gtk.TreePath tree_path  =   parent_str.length > 0 ? new  Gtk.TreePath.from_string( parent_str ) : null;",
404           "        ",
405           "        ",
406           "        ",
407           "        //print(\"add \" + tp + \"@\" + target_data[1]  );",
408           "        ",
409           "        JsRender.Node parentNode = null;",
410           "        ",
411           "        Gtk.TreeIter iter_after;",
412           "        Gtk.TreeIter iter_par ;",
413           "        ",
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]));",
417           "",
418           "        }",
419           "",
420           "        Gtk.TreePath expand_parent = null;",
421           "        ",
422           "        // we only need to show the template if it's come from else where?",
423           "         if (show_templates) {",
424           "         ",
425           "             var ts = _this.main_window.windowstate.template_select;",
426           "         ",
427           "             var new_node = ts.show(",
428           "                  _this.main_window, // (Gtk.Window) _this.el.get_toplevel (),",
429           "                 _this.main_window.windowstate.file.palete(),",
430           "                    node,",
431           "                    _this.main_window.windowstate.project);",
432           "                   ",
433           "             if (new_node == null) {",
434           "                 return; // do not add?",
435           "             }",
436           "             node = new_node;",
437           "        }        ",
438           "        ",
439           "         //print(\"pos is %d  \\n\".printf(pos));",
440           "        ",
441           "         Gtk.TreeIter n_iter; ",
442           "         ",
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;",
447           "              ",
448           "              ",
449           "        } else   if (pos  < 2) {",
450           "            //print(target_data[1]  > 0 ? 'insert_after' : 'insert_before');",
451           "            ",
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);",
455           "            ",
456           "            ",
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();",
461           "            ",
462           "            ",
463           "            this.el.get_value( iter_after, 2, out value);",
464           "            var relNode =  (JsRender.Node)value.dup_object();",
465           "            ",
466           "            if ( pos  > 0 ) {",
467           "             ",
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);",
471           "                ",
472           "            } else {",
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);",
476           " ",
477           "            }",
478           "            node.parent = parentNode;",
479           "            ",
480           "            ",
481           "            ",
482           "        } else {",
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);",
487           "            ",
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);",
493           "        }",
494           "        ",
495           "        ",
496           "        ",
497           "        ",
498           "        // work out what kind of packing to use.. -- should be in ",
499           "       ",
500           "            ",
501           "            //_this.main_window.windowstate.file.palete().fillPack(node,parentNode);",
502           "        _this.main_window.windowstate.file.palete().on_child_added(parentNode,node);",
503           "            ",
504           "          ",
505           "        this.iterSetValues(n_iter, node);",
506           "        // add the node...",
507           "         ",
508           "        ",
509           "        ",
510           "\t\t// load children - if it has any..",
511           "      ",
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);",
517           "        }",
518           "",
519           "        //if (tp != null && (node.items.length() > 0 || pos > 1)) {",
520           "        //    _this.view.el.expand_row(this.el.get_path(iter_par), true);",
521           "       // }",
522           "        // wee need to get the empty proptypes from somewhere..",
523           "        ",
524           "        //var olditer = this.activeIter;",
525           "        this.activePath = this.el.get_path(n_iter).to_string();",
526           "",
527           "",
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;",
533           "        _this.changed();",
534           "     ",
535           "        ",
536           "            ",
537           "}",
538           ""
539          ],
540          "| void iterSetValues" : [
541           "(Gtk.TreeIter iter, JsRender.Node node)   {",
542           "\tvar ic = Gtk.IconTheme.get_default();",
543           "    Gdk.Pixbuf pix;",
544           "    ",
545           "    var o =   GLib.Value(typeof(Object));",
546           "    o.set_object((Object)node);",
547           "    var clsname = node.fqn();",
548           "    ",
549           "    var clsb = clsname.split(\".\");",
550           "    var sub = clsb.length > 1 ? clsb[1].down()  : \"\";",
551           "    ",
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);",
556           "    } else {",
557           "    \tpix = ic.load_icon(\"emblem-new\", 16,0);",
558           "    }",
559           "    ",
560           "    var fqn = node.fqn();",
561           "    var cn = _this.main_window.windowstate.project.palete.getChildList(fqn);",
562           "    ",
563           "    this.el.set(",
564           "    \t\titer, ",
565           "    \t\t0, node.nodeTitle(),",
566           "            1, node.nodeTip(), ",
567           "            -1",
568           "    );",
569           "    this.el.set_value(iter, 2,o);",
570           "    this.el.set_value(iter, 3,pix);    ",
571           "  \tthis.el.set_value(iter, 4, cn.length > 0 ? addi : null);   ",
572           "    ",
573           "",
574           "}"
575          ],
576          "| void load" : [
577           "(Gee.ArrayList<JsRender.Node> tr, Gtk.TreeIter? iter) ",
578           "{",
579           "    ",
580           "  \t",
581           "    Gtk.TreeIter citer;",
582           "    //this.insert(citer,iter,0);",
583           "   ",
584           "    ",
585           "    for(var i =0 ; i < tr.size; i++) {",
586           "        if (iter != null) {",
587           "            this.el.insert(out citer,iter,-1); // why not append?",
588           "        } else {",
589           "            this.el.append(out citer,null);",
590           "        }",
591           "        this.iterSetValues(citer, tr.get(i));",
592           "        ",
593           " ",
594           "         ",
595           "        if (tr.get(i).items.size > 0) {",
596           "            this.load(tr.get(i).items, citer);",
597           "        }",
598           "     ",
599           "    }",
600           "",
601           "    ",
602           "}"
603          ],
604          "| void loadFile" : [
605           "(JsRender.JsRender f) {",
606           "    //console.dump(f);",
607           "    this.el.clear();",
608           "    _this.main_window.windowstate.leftTreeNodeSelected(null, \"\");",
609           "    // needed???",
610           "    _this.main_window.windowstate.file = f;",
611           "    ",
612           "   ",
613           "    if (f.tree == null) {",
614           "\t    try {",
615           "\t        f.loadItems( );",
616           "        } catch (Error e) {",
617           "    \t\treturn;",
618           "        }",
619           "    }",
620           "    // if it's still null?",
621           "    if (f.tree == null) {",
622           "\t\t_this.main_window.windowstate.showAddObject(_this.view.el);",
623           "    ",
624           "        return;",
625           "    }",
626           "  ",
627           "    var o = new Gee.ArrayList<JsRender.Node>();",
628           "    o.add(f.tree);",
629           "    this.load(o,null);",
630           "    ",
631           "    _this.view.el.expand_all();",
632           "",
633           "    if (f.tree.items.size < 1) {",
634           "        // single item..",
635           "        ",
636           "        //this.get('/Window.leftvpaned').el.set_position(80);",
637           "        // select first...",
638           "        _this.view.el.set_cursor( ",
639           "            new  Gtk.TreePath.from_string(\"0\"), null, false);",
640           "        ",
641           "        ",
642           "    } else {",
643           "          //this.get('/Window.leftvpaned').el.set_position(200);",
644           "    }",
645           "    ",
646           "    ",
647           "    while (Gtk.events_pending()) {",
648           "        Gtk.main_iteration();",
649           "   }",
650           "",
651           "    _this.maincol.el.set_max_width(_this.viewwin.el.get_allocated_width() - 32);",
652           " ",
653           "    ",
654           "   ",
655           "    return;",
656           " ",
657           "            ",
658           "}",
659           ""
660          ],
661          "| void moveNode" : [
662           "(string target_data, Gdk.DragAction action) ",
663           "{",
664           "   ",
665           "   /// target_data = \"path|pos\");",
666           "   ",
667           "   ",
668           "    //print(\"MOVE NODE\");",
669           "    // console.dump(target_data);",
670           "    Gtk.TreeIter old_iter;",
671           "    Gtk.TreeModel mod;",
672           "    ",
673           "    var s = _this.view.el.get_selection();",
674           "    s.get_selected(out mod , out old_iter);",
675           "    mod.get_path(old_iter);",
676           "    ",
677           "    var node = this.pathToNode(mod.get_path(old_iter).to_string());",
678           "    //console.dump(node);",
679           "    if (node == null) {",
680           "        GLib.debug(\"moveNode: ERROR - node is null?\");",
681           "    }",
682           "    ",
683           "    ",
684           "",
685           "    // needs to drop first, otherwise the target_data ",
686           "    // treepath will be invalid.",
687           "",
688           "    ",
689           "    if ((action & Gdk.DragAction.MOVE) > 0) {",
690           "            GLib.debug(\"REMOVING OLD NODE : \" + target_data + \"\\n\");",
691           "            node.remove();",
692           "            this.dropNode(target_data, node, false);",
693           "            this.el.remove(ref old_iter);",
694           "            ",
695           "            ",
696           "                         ",
697           "    } else {",
698           "        GLib.debug(\"DROPPING NODE // copy: \" + target_data + \"\\n\");",
699           "        node = node.deepClone();",
700           "        this.dropNode(target_data, node, false);",
701           "    }",
702           "    _this.changed();",
703           "    this.activePath= \"\";",
704           "    //this.updateNode(false,true);",
705           "}",
706           ""
707          ],
708          "| void updateSelected" : [
709           "() {",
710           "  ",
711           "   ",
712           "    var s = _this.view.el.get_selection();",
713           "    ",
714           "     Gtk.TreeIter iter;",
715           "    Gtk.TreeModel mod;",
716           "    ",
717           "    ",
718           "    ",
719           "    if (!s.get_selected(out mod, out iter)) {",
720           "        return; // nothing seleted..",
721           "    }",
722           "  ",
723           "  GLib.Value value;",
724           "    this.el.get_value(iter, 2, out value);",
725           "    var node = (JsRender.Node)(value.get_object());",
726           "    ",
727           "      this.el.set(iter, 0, node.nodeTitle(),",
728           "                1, node.nodeTip(), -1",
729           "        );",
730           "}",
731           ""
732          ]
733         },
734         {
735          "$ Gtk.TreeViewColumnSizing sizing" : "Gtk.TreeViewColumnSizing.FIXED",
736          "$ xns" : "Gtk",
737          "* init" : [
738           "  this.el.add_attribute(_this.renderer.el , \"markup\", 0 );",
739           "  this.el.add_attribute(_this.iconrender.el , \"pixbuf\",  3 );",
740           " "
741          ],
742          "* pack" : "append_column",
743          "bool expand" : true,
744          "bool resizable" : true,
745          "id" : "maincol",
746          "items" : [
747           {
748            "$ xns" : "Gtk",
749            "* pack" : "pack_start,false",
750            "id" : "iconrender",
751            "int width" : 16,
752            "xtype" : "CellRendererPixbuf"
753           },
754           {
755            "$ xns" : "Gtk",
756            "* pack" : "pack_start,true",
757            "id" : "renderer",
758            "xtype" : "CellRendererText"
759           }
760          ],
761          "utf8 title" : "Node",
762          "xtype" : "TreeViewColumn"
763         },
764         {
765          "$ Gtk.TreeViewColumnSizing sizing" : "Gtk.TreeViewColumnSizing.FIXED",
766          "$ xns" : "Gtk",
767          "* init" : [
768           " this.el.add_attribute(_this.addiconrender.el , \"pixbuf\",  4 );",
769           " "
770          ],
771          "* pack" : "append_column",
772          "bool expand" : false,
773          "int max_width" : 24,
774          "items" : [
775           {
776            "$ xns" : "Gtk",
777            "* pack" : "pack_start,true",
778            "id" : "addiconrender",
779            "int width" : 16,
780            "xtype" : "CellRendererPixbuf"
781           }
782          ],
783          "utf8 title" : "Add",
784          "xtype" : "TreeViewColumn"
785         }
786        ],
787        "listeners" : {
788         "button_press_event" : [
789          "  ( ev) => {",
790          "    //console.log(\"button press?\");",
791          "    this.button_is_pressed = true;",
792          "    print(\"BUTTON DOWN\\n\");",
793          "    ",
794          "    this.lastEventSource = \"tree\";",
795          "    if (! _this.before_node_change() ) {",
796          "    ",
797          "       return true;",
798          "    }",
799          "    ",
800          "\tif (ev.type != Gdk.EventType.BUTTON_PRESS) {",
801          "\t\treturn false;",
802          "\t}",
803          "    if (_this.model.el.iter_n_children(null) < 1) {",
804          "\t    _this.main_window.windowstate.showAddObject(_this.view.el);",
805          "\t    return true;",
806          "    }",
807          "    ",
808          "   ",
809          "    Gtk.TreePath res;",
810          "    Gtk.TreeViewColumn col;",
811          "    if (!_this.view.el.get_path_at_pos((int)ev.x,(int)ev.y, out res, out col, null, null) ) {",
812          "        return true;",
813          "    }",
814          "    ",
815          "    if (col.title == \"Add\") {",
816          " \t\tGLib.Value value;",
817          " \t\tGtk.TreeIter iter;",
818          "",
819          "\t\t_this.model.el.get_iter (out  iter, res);",
820          "        _this.model.el.get_value(iter, 2, out value);\t\t",
821          "            // why dup_ - gets and and inc's ref count (which in theory should be freed at the end.?",
822          "            ",
823          "        var node = (JsRender.Node)value.dup_object();",
824          "        var fqn = node.fqn();",
825          "    \tvar cn = _this.main_window.windowstate.project.palete.getChildList(fqn);",
826          "  \t\tif (cn.length < 1) {",
827          "  \t\t\treturn true;",
828          "\t\t}",
829          "    ",
830          "         _this.main_window.windowstate.leftTreeBeforeChange();",
831          "         this.el.get_selection().select_path(res);",
832          "     \t_this.main_window.windowstate.showAddObject(this.el);",
833          "     \treturn true;",
834          "     }",
835          "    ",
836          "\tif (  ev.button != 3) {",
837          "        //print(\"click\" + ev.type);",
838          "        return false;",
839          "     }",
840          "    _this.main_window.windowstate.leftTreeBeforeChange();",
841          "",
842          "    ",
843          "     ",
844          "    this.el.get_selection().select_path(res);",
845          "     ",
846          "      ",
847          "     ",
848          "      //if (!this.get('/LeftTreeMenu').el)  { ",
849          "      //      this.get('/LeftTreeMenu').init(); ",
850          "      //  }",
851          "        ",
852          "     _this.LeftTreeMenu.el.set_screen(Gdk.Screen.get_default());",
853          "     _this.LeftTreeMenu.el.show_all();",
854          "      _this.LeftTreeMenu.el.popup(null, null, null,  3, ev.time);",
855          "     //   print(\"click:\" + res.path.to_string());",
856          "      return true;",
857          "}"
858         ],
859         "button_release_event" : [
860          "(ev) => { ",
861          "    this.button_is_pressed = false;",
862          "  return false;",
863          "}"
864         ],
865         "cursor_changed" : [
866          " ( ) => {",
867          "    print(\"LEFT TREE Cursor Changed\\n\");",
868          "\t//if (!this.button_is_pressed && !this.key_is_pressed) {",
869          "\t\t// then event was started by some other action",
870          "\t\t// which should manually trigger all the events..",
871          "\t//\tprint(\"SKIPPING select - no button or key pressed\\n\");",
872          "\t//\treturn;",
873          "\t//}",
874          "",
875          "",
876          "     if (this.blockChanges) { // probably not needed.. ",
877          "\t\tprint(\"SKIPPING select - blockchanges set..\\n\");     ",
878          "       return  ;",
879          "     }",
880          "      if (!_this.before_node_change( ) ) {",
881          "\t     this.blockChanges = true;",
882          "\t     this.el.get_selection().unselect_all();",
883          "\t     this.blockChanges = false;",
884          "\t     ",
885          "\t     return;",
886          "     }",
887          "     if (_this.main_window.windowstate.file == null) {",
888          "   \t\tprint(\"SKIPPING select windowstate file is not set...\\n\");     ",
889          "         return;",
890          "     } ",
891          "     ",
892          "     //var render = this.get('/LeftTree').getRenderer();                ",
893          "    print(\"LEFT TREE -> view -> selection changed called\\n\");",
894          "    ",
895          "    ",
896          "    // -- it appears that the selection is not updated.",
897          "      ",
898          "    GLib.Timeout.add_full(GLib.Priority.DEFAULT,10 , () => {",
899          "         print(\"LEFT TREE -> view -> selection changed TIMEOUT CALLED\\n\");",
900          "",
901          "            if (this.el.get_selection().count_selected_rows() < 1) {",
902          "",
903          "                print(\"selected rows < 1\\n\");",
904          "                //??this.model.load( false);",
905          "                _this.node_selected(null, this.lastEventSource);",
906          "                ",
907          "                return false ;",
908          "            }",
909          "                ",
910          "                //console.log('changed');",
911          "            var s = this.el.get_selection();",
912          "             Gtk.TreeIter iter;",
913          "             Gtk.TreeModel mod;",
914          "            s.get_selected(out mod, out iter);",
915          "            ",
916          "            ",
917          "            // var val = \"\";",
918          "            GLib.Value value;",
919          "            _this.model.el.get_value(iter, 2, out value);",
920          "            _this.model.activePath = mod.get_path(iter).to_string();",
921          "            ",
922          "            // why dup_?",
923          "            ",
924          "            var node = (JsRender.Node)value.dup_object();",
925          "            print (\"calling left_tree.node_selected\\n\");",
926          "            _this.node_selected(node, this.lastEventSource);",
927          "            while (Gtk.events_pending()) {",
928          "                Gtk.main_iteration();",
929          "           }",
930          "            var cp = mod.get_path(iter);",
931          "            Gtk.TreePath sp, ep;",
932          "            this.el.get_visible_range(out sp, out ep);",
933          "            // if sp is before cp then retuns 1.",
934          "            // if cp is before ep then retuns 1.",
935          "            if (cp.compare(sp) >= 0 && ep.compare(cp) >=1) {",
936          "                return false;",
937          "            }",
938          "            ",
939          "             ",
940          "            ",
941          "            this.el.scroll_to_cell(new Gtk.TreePath.from_string(_this.model.activePath), null, true, 0.1f,0.0f);",
942          "            ",
943          "            return false;",
944          "      });  ",
945          "    //_this.after_node_change(node);",
946          "",
947          "//        _this.model.file.changed(node, \"tree\");",
948          "   ",
949          "    //Seed.print( value.get_string());",
950          "    return  ;",
951          "                ",
952          "}"
953         ],
954         "drag_begin" : [
955          "( ctx)  => {",
956          "\t//print('SOURCE: drag-begin');",
957          "        ",
958          "        ",
959          "        //this.targetData = \"\";",
960          "        ",
961          "        // find what is selected in our tree...",
962          "        ",
963          "        var s = _this.view.el.get_selection();",
964          "        if (s.count_selected_rows() < 1) {",
965          "            return;",
966          "        }",
967          "        Gtk.TreeIter iter;",
968          "        Gtk.TreeModel mod;",
969          "        s.get_selected(out mod, out iter);",
970          "",
971          "        ",
972          "",
973          "        // set some properties of the tree for use by the dropped element.",
974          "        GLib.Value value;",
975          "        _this.model.el.get_value(iter, 2, out value);",
976          "        var tp = mod.get_path(iter).to_string();",
977          "        var data = (JsRender.Node)(value.dup_object());",
978          "        var xname = data.fqn();",
979          "        print (\"XNAME  IS \" + xname+ \"\\n\");",
980          "        this.dragData = tp;",
981          "        this.dropList = _this.main_window.windowstate.file.palete().getDropList(xname);",
982          "        ",
983          "        print (\"DROP LIST IS \" + string.joinv(\", \", this.dropList) + \"\\n\");",
984          "        ",
985          "",
986          "        // make the drag icon a picture of the node that was selected",
987          "    ",
988          "        ",
989          "    // by default returns the path..",
990          "       var path = _this.model.el.get_path(iter);",
991          "",
992          "         ",
993          "        var pix = this.el.create_row_drag_icon ( path);",
994          "        ",
995          "        Gtk.drag_set_icon_surface (ctx, pix) ;",
996          "        ",
997          "        return;",
998          "}"
999         ],
1000         "drag_data_get" : [
1001          "( drag_context, data, info, time) => {",
1002          "            ",
1003          "",
1004          "\t//print(\"drag-data-get\");",
1005          "\tvar s = this.el.get_selection();",
1006          "\tif (s.count_selected_rows() < 1) {",
1007          "\t\tdata.set_text(\"\",0);     ",
1008          "\t\t print(\"return empty string - no selection..\");",
1009          "\t\treturn;",
1010          "\t}",
1011          "",
1012          "\tGtk.TreeIter iter;",
1013          "\tGtk.TreeModel mod;",
1014          "",
1015          "\ts.get_selected(out mod, out iter);",
1016          "",
1017          "",
1018          "",
1019          "\tGLib.Value value;",
1020          "\t_this.model.el.get_value(iter, 2, out value);",
1021          "\tvar ndata = (JsRender.Node)(value.dup_object());",
1022          "",
1023          "",
1024          "",
1025          "\tvar tp = mod.get_path(iter).to_string();",
1026          "\t// by default returns the path..",
1027          "",
1028          "\tif ( info != Gdk.Atom.intern(\"STRING\",true) ) {",
1029          "\t\ttp = ndata.toJsonString();",
1030          "\t}   ",
1031          "",
1032          "\t//data.set_text(tp,tp.length);   ",
1033          "",
1034          "\tdata.set (data.get_target (), 8, (uchar[]) tp.to_utf8 ());",
1035          "",
1036          "",
1037          "\t//  print(\"return \" + tp);",
1038          "\t}"
1039         ],
1040         "drag_data_received" : [
1041          "\t(ctx, x, y, sel, info, time)  => {",
1042          "",
1043          "\t// THIS CODE ONLY RELATES TO drag  or drop of \"NEW\" elements or \"FROM another tree..\"",
1044          "",
1045          "",
1046          "\t//  print(\"Tree: drag-data-received\\n\");",
1047          "\tvar selection_text = (string)sel.get_data();",
1048          "\t//print(\"selection_text= %s\\n\",selection_text);",
1049          "",
1050          "\tvar is_drag = this.drag_in_motion;",
1051          "",
1052          "",
1053          "",
1054          "\tGLib.debug(\"Is Drag %s\\n\", is_drag ? \"Y\": \"N\");",
1055          "\tvar  targetData = \"\";",
1056          "",
1057          "\tGtk.TreePath path;",
1058          "\tGtk.TreeViewDropPosition pos;",
1059          "\tvar isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);",
1060          "",
1061          "\t// if there are not items in the tree.. the we have to set isOver to true for anything..",
1062          "\tvar isEmpty = false;",
1063          "\tif (_this.model.el.iter_n_children(null) < 1) {",
1064          "\t\tGLib.debug(\"got NO children?\\n\");",
1065          "\t\tisOver = true; //??? ",
1066          "\t\tisEmpty = true;",
1067          "\t\tpos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;",
1068          "\t}",
1069          "",
1070          "",
1071          "\t//console.log(\"LEFT-TREE: drag-motion\");",
1072          "\tvar src = Gtk.drag_get_source_widget(ctx);",
1073          "",
1074          "\t// a drag from self - this should be handled by drop and motion.",
1075          "\tif (src == this.el) {",
1076          "\t\tGLib.debug(\"Source == this element should not happen.. ? \\n\");",
1077          "\t\treturn;",
1078          "\t}",
1079          "\t//print(\"drag_data_recieved from another element\");",
1080          "",
1081          "\t ",
1082          "",
1083          "",
1084          "\tif (selection_text == null || selection_text.length < 1 || !isOver) {",
1085          "\t\t// nothing valid foudn to drop...",
1086          "\t\t   GLib.debug(\"empty sel text or not over\");",
1087          "\t\tif (is_drag) {",
1088          "\t\t    Gdk.drag_status(ctx, 0, time);",
1089          "\t\t    this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);",
1090          "\t\t    return;",
1091          "\t\t}",
1092          "\t\tGtk.drag_finish (ctx, false, false, time);        // drop failed..",
1093          "\t\t// no drop action...",
1094          "\t\treturn;            ",
1095          "",
1096          "\t}",
1097          "\tvar dropNode = new JsRender.Node(); ",
1098          "",
1099          "\tvar dropNodeType  = selection_text;",
1100          "\tvar show_templates = true;",
1101          "\t// for drop",
1102          "\tif (dropNodeType[0] == '{') {",
1103          "\t\tvar pa = new Json.Parser();",
1104          "\t\ttry {",
1105          "\t\t    pa.load_from_data(dropNodeType);",
1106          "\t\t} catch (Error e) {",
1107          "\t\t    Gtk.drag_finish (ctx, false, false, time);        // drop failed..",
1108          "\t\t    // no drop action...",
1109          "\t\t    return;   ",
1110          "\t\t}",
1111          "\t\t ",
1112          "\t\tdropNode.loadFromJson( pa.get_root().get_object(), 2);",
1113          "\t\tdropNodeType = dropNode.fqn();",
1114          "\t\tshow_templates = false;",
1115          "\t\t",
1116          "\t\t",
1117          "\t} else {",
1118          "\t\t// drop with property.",
1119          "\t\tif (selection_text.contains(\":\")) {",
1120          "\t\t\tvar bits = selection_text.split(\":\");",
1121          "\t\t    dropNode.setFqn(bits[0]);",
1122          "\t\t    dropNode.set_prop(new JsRender.NodeProp.special(\"prop\", bits[1]));",
1123          "\t\t    ",
1124          "\t\t    ",
1125          "\t\t    ",
1126          "\t\t} else {",
1127          "\t\t    dropNode.setFqn(selection_text);",
1128          "\t\t}",
1129          "\t}",
1130          "",
1131          "\t ",
1132          "\t// dropList --- need to gather this ... ",
1133          "\tGLib.debug(\"get dropList for : %s\\n\",dropNodeType);            ",
1134          "\tvar dropList = _this.main_window.windowstate.file.palete().getDropList(dropNodeType);",
1135          "",
1136          "\tGLib.debug(\"dropList: %s\\n\", string.joinv(\" , \", dropList));",
1137          "",
1138          "\t// if drag action is link ... then we can drop it anywahere...",
1139          "\t if ((ctx.get_actions() & Gdk.DragAction.LINK) > 0) {",
1140          "\t\t // if path is null?? dragging into an empty tree?",
1141          "\t\t targetData = (path == null ? \"\" :  path.to_string()) + \"|%d\".printf((int)pos);",
1142          "\t } else {",
1143          "",
1144          "",
1145          "\t\ttargetData = _this.model.findDropNodeByPath( isEmpty ? \"\" : path.to_string(), dropList, pos);",
1146          "\t }",
1147          "",
1148          "",
1149          "\t\t",
1150          "\tGLib.debug(\"targetDAta: %s\", targetData );",
1151          "",
1152          "\tif (targetData.length < 1) {",
1153          "\t ",
1154          "\t\t// invalid drop path..",
1155          "\t\tif (this.drag_in_motion) {",
1156          "\t\t    Gdk.drag_status(ctx, 0, time);",
1157          "\t\t    this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);",
1158          "\t\t    return;",
1159          "\t\t}",
1160          "\t\tGtk.drag_finish (ctx, false, false, time);        // drop failed..",
1161          "\t\t// no drop action...",
1162          "\t\treturn;",
1163          "\t}",
1164          "",
1165          "",
1166          "",
1167          "\t var td_ar = targetData.split(\"|\");",
1168          "\t  ",
1169          "",
1170          "\tif (this.drag_in_motion) { ",
1171          "\t\tGdk.drag_status(ctx, Gdk.DragAction.COPY ,time);",
1172          "",
1173          "\t\tthis.highlightDropPath(  td_ar[0]  , (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));",
1174          "\t\treturn;",
1175          "\t}",
1176          "\t// continue on to allow drop..",
1177          "",
1178          "",
1179          "\t// at this point, drag is not in motion... -- as checked above... - so it's a real drop event..",
1180          "\t//targetData",
1181          "\t//   {parent}|{pos}|{prop}",
1182          "",
1183          "",
1184          "   _this.model.dropNode(targetData, dropNode, show_templates);",
1185          "    ",
1186          "\tGLib.debug(\"ADD new node!!!\\n\");",
1187          "\t\t",
1188          "\t///Xcls_DialogTemplateSelect.singleton().show( _this.model.file.palete(), node);",
1189          "",
1190          "\tGtk.drag_finish (ctx, false, false,time);",
1191          "",
1192          "",
1193          "\t\t",
1194          "\t\t",
1195          "",
1196          "}"
1197         ],
1198         "drag_drop" : [
1199          " (  ctx, x, y, time)  => {",
1200          "      //Seed.print(\"TARGET: drag-drop\");",
1201          "   ",
1202          "   ",
1203          "    var src = Gtk.drag_get_source_widget(ctx);",
1204          "     ",
1205          "   if (src != this.el) {",
1206          "   ",
1207          "    ",
1208          "       ",
1209          "       this.drag_in_motion = false;   ",
1210          "            // request data that will be recieved by the recieve...              ",
1211          "        Gtk.drag_get_data",
1212          "        (",
1213          "                this.el,         // will receive 'drag-data-received' signal ",
1214          "                ctx,        // represents the current state of the DnD ",
1215          "                Gdk.Atom.intern(\"application/json\",true),    // the target type we want ",
1216          "                time            // time stamp ",
1217          "        );",
1218          "",
1219          "         ",
1220          "        // No target offered by source => error",
1221          "   ",
1222          "",
1223          "         return  false;",
1224          "     }",
1225          "     ",
1226          "     // handle drop around self..",
1227          "     ",
1228          "                  ",
1229          "            ",
1230          "    //print(\"GETTING POS\");",
1231          "    var  targetData = \"\";",
1232          "    ",
1233          "    Gtk.TreePath path;",
1234          "    Gtk.TreeViewDropPosition pos;",
1235          "    var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);",
1236          "    ",
1237          "    // if there are not items in the tree.. the we have to set isOver to true for anything..",
1238          "    var isEmpty = false;",
1239          "    if (_this.model.el.iter_n_children(null) < 1) {",
1240          "        print(\"got NO children?\\n\");",
1241          "        isOver = true; //??? ",
1242          "        isEmpty = true;",
1243          "        pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;",
1244          "    }",
1245          "    ",
1246          "     ",
1247          "     ",
1248          "    //var action = Gdk.DragAction.COPY;",
1249          "        // unless we are copying!!! ctl button..",
1250          "    ",
1251          "    var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?",
1252          "                 Gdk.DragAction.COPY  : Gdk.DragAction.MOVE ;",
1253          "                // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;",
1254          "",
1255          "      ",
1256          "    if (_this.model.el.iter_n_children(null) < 1) {",
1257          "        // no children.. -- asume it's ok..",
1258          "        ",
1259          "        targetData = \"|%d|\".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);",
1260          "         ",
1261          "        // continue through to allow drop...",
1262          "",
1263          "    } else {",
1264          "                ",
1265          "                ",
1266          "    ",
1267          "                ",
1268          "                ",
1269          "                //print(\"ISOVER? \" + isOver);",
1270          "        if (!isOver) {",
1271          "            ",
1272          "            Gtk.drag_finish (ctx, false, false, time);        // drop failed..",
1273          "            return true; // not over apoint!?! - no action on drop or motion..",
1274          "        }",
1275          "                ",
1276          "        // drag node is parent of child..",
1277          "        //console.log(\"SRC TREEPATH: \" + src.treepath);",
1278          "        //console.log(\"TARGET TREEPATH: \" + data.path.to_string());",
1279          "        ",
1280          "        // nned to check a  few here..",
1281          "        //Gtk.TreeViewDropPosition.INTO_OR_AFTER",
1282          "        //Gtk.TreeViewDropPosition.INTO_OR_BEFORE",
1283          "        //Gtk.TreeViewDropPosition.AFTER",
1284          "        //Gtk.TreeViewDropPosition.BEFORE",
1285          "        ",
1286          "        // locally dragged items to not really use the ",
1287          "        var selection_text = this.dragData;",
1288          "        ",
1289          "        ",
1290          "        ",
1291          "        if (selection_text == null || selection_text.length < 1) {",
1292          "            //print(\"Error  - drag selection text returned NULL\");",
1293          "          ",
1294          "             Gtk.drag_finish (ctx, false, false, time);        // drop failed..",
1295          "             return true; /// -- fixme -- this is not really correct..",
1296          "        }                ",
1297          "                ",
1298          "                // see if we are dragging into ourself?",
1299          "                print (\"got selection text of  \" + selection_text);",
1300          "        ",
1301          "        var target_path = path.to_string();",
1302          "        //print(\"target_path=\"+target_path);",
1303          "",
1304          "        // ",
1305          "        if (selection_text  == target_path) {",
1306          "            print(\"self drag ?? == we should perhaps allow copy onto self..\\n\");",
1307          "            ",
1308          "             Gtk.drag_finish (ctx, false, false, time);        // drop failed..",
1309          "",
1310          "             return true; /// -- fixme -- this is not really correct..",
1311          "",
1312          "        }",
1313          "                ",
1314          "        // check that ",
1315          "        //print(\"DUMPING DATA\");",
1316          "        //console.dump(data);",
1317          "        // path, pos",
1318          "        ",
1319          "        //print(data.path.to_string() +' => '+  data.pos);",
1320          "        ",
1321          "        // dropList is a list of xtypes that this node could be dropped on.",
1322          "        // it is set up when we start to drag..",
1323          "        ",
1324          "        ",
1325          "        targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);",
1326          "            ",
1327          "        print(\"targetDAta: \" + targetData +\"\\n\");",
1328          "        ",
1329          "        if (targetData.length < 1) {",
1330          "            //print(\"Can not find drop node path\");",
1331          "             ",
1332          "            Gtk.drag_finish (ctx, false, false, time);        // drop failed..",
1333          "            return true;",
1334          "        }",
1335          "                    ",
1336          "                ",
1337          "                ",
1338          "                // continue on to allow drop..",
1339          "  }",
1340          "        // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..",
1341          "",
1342          "",
1343          "     var delete_selection_data = false;",
1344          "        ",
1345          "    if (action == Gdk.DragAction.ASK)  {",
1346          "        /* Ask the user to move or copy, then set the ctx action. */",
1347          "    }",
1348          "",
1349          "    if (action == Gdk.DragAction.MOVE) {",
1350          "        delete_selection_data = true;",
1351          "    }",
1352          "      ",
1353          "                // drag around.. - reorder..",
1354          "    _this.model.moveNode(targetData, action);",
1355          "        ",
1356          "       ",
1357          "        ",
1358          "        ",
1359          "        ",
1360          "        // we can send stuff to souce here...",
1361          "",
1362          "",
1363          "// do we always say failure, so we handle the reall drop?",
1364          "    Gtk.drag_finish (ctx, false, false,time); //delete_selection_data, time);",
1365          "",
1366          "    return true;",
1367          " ",
1368          " ",
1369          " ",
1370          " ",
1371          " ",
1372          " ",
1373          "}"
1374         ],
1375         "drag_end" : [
1376          "  (drag_context) => {",
1377          "\t//Seed.print('LEFT-TREE: drag-end');",
1378          "        this.dragData = \"\";",
1379          "        this.dropList = null;",
1380          "//        this.targetData = \"\";",
1381          "        this.highlightDropPath(\"\",0);",
1382          "//        return true;",
1383          "}"
1384         ],
1385         "drag_motion" : [
1386          " ( ctx, x, y, time)  => {",
1387          "   print(\"got drag motion\\n\");",
1388          "    var src = Gtk.drag_get_source_widget(ctx);",
1389          "   this.drag_x = x;",
1390          "   this.drag_y = y;     ",
1391          "",
1392          "   if (src != this.el) {",
1393          "   ",
1394          " ",
1395          " ",
1396          "    // the point of this is to detect where an item could be dropped..",
1397          "        print(\"requesting drag data\\n\");",
1398          "       this.drag_in_motion = true;",
1399          "       ",
1400          "            // request data that will be recieved by the recieve...              ",
1401          "        Gtk.drag_get_data",
1402          "        (",
1403          "                this.el,         // will receive 'drag-data-received' signal ",
1404          "                ctx,        // represents the current state of the DnD ",
1405          "                Gdk.Atom.intern(\"STRING\",true),    // the target type we want ",
1406          "                time            // time stamp ",
1407          "        );",
1408          "        return true;",
1409          "  }    ",
1410          "",
1411          "",
1412          "  print(\"action: %d\\n\", ctx.get_actions());",
1413          " //print(\"GETTING POS\");",
1414          "    var  targetData = \"\";",
1415          "",
1416          "    Gtk.TreePath path;",
1417          "    Gtk.TreeViewDropPosition pos;",
1418          "    var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);",
1419          "",
1420          "    // if there are not items in the tree.. the we have to set isOver to true for anything..",
1421          "    var isEmpty = false;",
1422          "    if (_this.model.el.iter_n_children(null) < 1) {",
1423          "        print(\"got NO children?\\n\");",
1424          "        isOver = true; //??? ",
1425          "        isEmpty = true;",
1426          "        pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;",
1427          "    }",
1428          "",
1429          "",
1430          "    // ------------- a drag from self..",
1431          "",
1432          "",
1433          "    //var action = Gdk.DragAction.COPY;",
1434          "        // unless we are copying!!! ctl button..",
1435          "    ",
1436          "    var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?",
1437          "                 Gdk.DragAction.COPY  : Gdk.DragAction.MOVE ;",
1438          "                // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;",
1439          "",
1440          "",
1441          "    if (_this.model.el.iter_n_children(null) < 1) {",
1442          "        // no children.. -- asume it's ok..",
1443          "        ",
1444          "        targetData = \"|%d|\".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);",
1445          "           ",
1446          "        this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);        ",
1447          "        Gdk.drag_status(ctx, action ,time);",
1448          "        return true;",
1449          "        ",
1450          "        // continue through to allow drop...",
1451          "",
1452          "    } ",
1453          "        ",
1454          "        ",
1455          "",
1456          "    ",
1457          "    ",
1458          "    //print(\"ISOVER? \" + isOver);",
1459          "    if (!isOver) {",
1460          "  ",
1461          "        Gdk.drag_status(ctx, 0 ,time);",
1462          "         this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);                    ",
1463          "         return false;",
1464          "",
1465          "    }",
1466          "            ",
1467          "    // drag node is parent of child..",
1468          "    //console.log(\"SRC TREEPATH: \" + src.treepath);",
1469          "    //console.log(\"TARGET TREEPATH: \" + data.path.to_string());",
1470          "    ",
1471          "    // nned to check a  few here..",
1472          "    //Gtk.TreeViewDropPosition.INTO_OR_AFTER",
1473          "    //Gtk.TreeViewDropPosition.INTO_OR_BEFORE",
1474          "    //Gtk.TreeViewDropPosition.AFTER",
1475          "    //Gtk.TreeViewDropPosition.BEFORE",
1476          "    ",
1477          "    // locally dragged items to not really use the ",
1478          "    var selection_text = this.dragData;",
1479          "    ",
1480          "            ",
1481          "            ",
1482          "    if (selection_text == null || selection_text.length < 1) {",
1483          "                //print(\"Error  - drag selection text returned NULL\");",
1484          "             Gdk.drag_status(ctx, 0 ,time);",
1485          "            this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);",
1486          "             return false;",
1487          "     }",
1488          "                       ",
1489          "            ",
1490          "            // see if we are dragging into ourself?",
1491          "    var target_path = path.to_string();            ",
1492          "    print (\"Drag  %s onto %s--%d\\n \", selection_text, target_path, pos);",
1493          "    ",
1494          "    // pos : 3 = ontop - 0 = after, 1 = before",
1495          "    //print(\"target_path=\"+target_path);",
1496          "",
1497          "    // ",
1498          "    if (selection_text  == target_path) {",
1499          "        print(\"self drag ?? == we should perhaps allow copy onto self..\\n\");",
1500          "                ",
1501          "         Gdk.drag_status(ctx, 0 ,time);",
1502          "          this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);",
1503          "          return false;",
1504          "//                 -- fixme -- this is not really correct..",
1505          "",
1506          "    }",
1507          "            ",
1508          "    // check that ",
1509          "    //print(\"DUMPING DATA\");",
1510          "    //console.dump(data);",
1511          "    // path, pos",
1512          "    ",
1513          "    //print(data.path.to_string() +' => '+  data.pos);",
1514          "    ",
1515          "    // dropList is a list of xtypes that this node could be dropped on.",
1516          "    // it is set up when we start to drag..",
1517          "    ",
1518          "    ",
1519          "    targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);",
1520          "        ",
1521          "    print(\"targetDAta: \" + targetData +\"\\n\");",
1522          "    ",
1523          "    if (targetData.length < 1) {",
1524          "        //print(\"Can not find drop node path\");",
1525          "       ",
1526          "        Gdk.drag_status(ctx, 0, time);",
1527          "        this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);",
1528          "        return false;",
1529          "    }",
1530          "    ",
1531          "    var td_ar = targetData.split(\"|\");",
1532          "      ",
1533          "    ",
1534          "",
1535          "    Gdk.drag_status(ctx, action ,time);",
1536          "    this.highlightDropPath(td_ar[0], (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));",
1537          "    return true;",
1538          "       ",
1539          "       ",
1540          "}"
1541         ],
1542         "key_press_event" : [
1543          "(ev) => {",
1544          "   this.key_is_pressed = true;",
1545          "    return false;",
1546          "}"
1547         ],
1548         "key_release_event" : [
1549          "(ev) => {",
1550          "       this.key_is_pressed = false;",
1551          "      return false;",
1552          "}",
1553          ""
1554         ]
1555        },
1556        "tooltip_column" : 1,
1557        "xtype" : "TreeView",
1558        "| void highlightDropPath" : [
1559         " ( string treepath, Gtk.TreeViewDropPosition pos) {",
1560         "",
1561         "        // highlighting for drag/drop",
1562         "        if (treepath.length > 0) {",
1563         "            this.el.set_drag_dest_row(  new  Gtk.TreePath.from_string( treepath ), pos);",
1564         "          } else {",
1565         "            this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);",
1566         "         }",
1567         "             ",
1568         "}"
1569        ],
1570        "| void selectNode" : [
1571         "(string treepath_str, string source) {",
1572         "\tthis.lastEventSource = source;",
1573         "    //this.selection.select_path(new  Gtk.TreePath.from_string( treepath_str));",
1574         "     var tp = new Gtk.TreePath.from_string(treepath_str);",
1575         "     ",
1576         "     this.el.set_cursor(tp, null, false);  ",
1577         "     this.el.scroll_to_cell(tp, null, false, 0,0);",
1578         "}",
1579         ""
1580        ],
1581        "| void setCursor" : [
1582         "(string treepath, string sourceEvent)   {",
1583         "\tthis.lastEventSource = sourceEvent;",
1584         "\t//this.blockChanges = true; << block changes prevents loading of 'node data' and firing of node_selected..",
1585         "    this.el.set_cursor(new Gtk.TreePath.from_string(treepath), null, false); ",
1586         "    // fire node_selected..",
1587         "    //this.blockChanges = false;",
1588         "\tthis.lastEventSource = \"\";",
1589         "}",
1590         ""
1591        ]
1592       },
1593       {
1594        "$ xns" : "Gtk",
1595        "* pack" : false,
1596        "id" : "LeftTreeMenu",
1597        "items" : [
1598         {
1599          "$ xns" : "Gtk",
1600          "* pack" : "add",
1601          "label" : "Delete Element",
1602          "listeners" : {
1603           "activate" : [
1604            "  ( ) => {",
1605            "    ",
1606            "    print(\"ACTIVATE?\");",
1607            "    ",
1608            "  ",
1609            "     _this.model.deleteSelected();",
1610            "}"
1611           ]
1612          },
1613          "xtype" : "MenuItem"
1614         },
1615         {
1616          "$ xns" : "Gtk",
1617          "* pack" : "add",
1618          "label" : "Save as Template",
1619          "listeners" : {
1620           "activate" : [
1621            "  () => {",
1622            "",
1623            "     DialogSaveTemplate.singleton().show(",
1624            "            (Gtk.Window) _this.el.get_toplevel (), ",
1625            "            _this.main_window.windowstate.file.palete(), ",
1626            "            _this.getActiveElement()",
1627            "    );",
1628            "     ",
1629            "    ",
1630            "}"
1631           ]
1632          },
1633          "xtype" : "MenuItem"
1634         },
1635         {
1636          "$ xns" : "Gtk",
1637          "* pack" : "add",
1638          "label" : "Save as Module",
1639          "listeners" : {
1640           "activate" : [
1641            "  () => {",
1642            "    var node = _this.getActiveElement();",
1643            "     var name = DialogSaveModule.singleton().show(",
1644            "            (Gtk.Window) _this.el.get_toplevel (), ",
1645            "            _this.main_window.windowstate.project, ",
1646            "            node",
1647            "     );",
1648            "     if (name.length < 1) {",
1649            "            return;",
1650            "  ",
1651            "     }",
1652            "     node.set_prop( new JsRender.NodeProp.special(\"xinclude\", name));",
1653            "     node.items.clear();",
1654            "",
1655            "",
1656            "    var s = _this.view.el.get_selection();",
1657            "    ",
1658            "    print(\"GET  SELECTED?\");",
1659            "    Gtk.TreeIter iter;",
1660            "    Gtk.TreeModel mod;",
1661            "",
1662            "    ",
1663            "    if (!s.get_selected(out mod, out iter)) {",
1664            "        return; // nothing seleted..",
1665            "    }",
1666            "    Gtk.TreeIter citer;",
1667            "    var n_cn = mod.iter_n_children(iter) -1;",
1668            "    for (var i = n_cn; i > -1; i--) {",
1669            "        mod.iter_nth_child(out citer, iter, i);",
1670            "        ",
1671            "",
1672            "        print(\"removing node from Tree\\n\");    ",
1673            "    ",
1674            "        _this.model.el.remove(ref citer);",
1675            "    }",
1676            "    _this.changed();",
1677            "    _this.node_selected(node, \"tree\");",
1678            "     ",
1679            "    ",
1680            "}"
1681           ]
1682          },
1683          "xtype" : "MenuItem"
1684         }
1685        ],
1686        "xtype" : "Menu"
1687       }
1688      ],
1689      "listeners" : {
1690       "size_allocate" : [
1691        "(allocation) => {",
1692        "",
1693        "\t ",
1694        "\t//GLib.debug(\"Got allocation width of scrolled view %d\", allocation.width );",
1695        "\t_this.maincol.el.set_max_width(allocation.width - 32);",
1696        "}",
1697        ""
1698       ]
1699      },
1700      "xtype" : "ScrolledWindow"
1701     }
1702    ],
1703    "xtype" : "Box",
1704    "| JsRender.JsRender getActiveFile" : [
1705     "() {",
1706     "    return this.main_window.windowstate.file;",
1707     "}",
1708     ""
1709    ],
1710    "| JsRender.Node? getActiveElement" : [
1711     " () { // return path to actie node.",
1712     "",
1713     "     var path = this.getActivePath();",
1714     "     if (path.length < 1) {",
1715     "        return null;",
1716     "     }",
1717     "     return _this.model.pathToNode(path);",
1718     "     ",
1719     "}",
1720     ""
1721    ],
1722    "| string getActivePath" : [
1723     " () {",
1724     "    ",
1725     "    var view = this.view.el;",
1726     "    if (view.get_selection().count_selected_rows() < 1) {",
1727     "        return \"\";",
1728     "    }",
1729     "    Gtk.TreeIter iter;",
1730     "    Gtk.TreeModel mod;",
1731     "    view.get_selection().get_selected(out mod, out iter);",
1732     "    return mod.get_path(iter).to_string();",
1733     "}",
1734     " "
1735    ]
1736   }
1737  ],
1738  "modOrder" : "",
1739  "name" : "WindowLeftTree",
1740  "parent" : "",
1741  "path" : "/home/alan/gitlive/roobuilder/src/Builder4/WindowLeftTree.bjs",
1742  "permname" : "",
1743  "title" : ""
1744 }